Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 1 | /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 3 | #include <stddef.h> |
| 4 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5 | #include "Python.h" |
| 6 | #include "Python-ast.h" |
Victor Stinner | 4a21e57 | 2020-04-15 02:35:41 +0200 | [diff] [blame] | 7 | #include "structmember.h" // PyMemberDef |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9 | typedef struct { |
| 10 | int initialized; |
| 11 | PyObject *AST_type; |
| 12 | PyObject *Add_singleton; |
| 13 | PyObject *Add_type; |
| 14 | PyObject *And_singleton; |
| 15 | PyObject *And_type; |
| 16 | PyObject *AnnAssign_type; |
| 17 | PyObject *Assert_type; |
| 18 | PyObject *Assign_type; |
| 19 | PyObject *AsyncFor_type; |
| 20 | PyObject *AsyncFunctionDef_type; |
| 21 | PyObject *AsyncWith_type; |
| 22 | PyObject *Attribute_type; |
| 23 | PyObject *AugAssign_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 24 | PyObject *Await_type; |
| 25 | PyObject *BinOp_type; |
| 26 | PyObject *BitAnd_singleton; |
| 27 | PyObject *BitAnd_type; |
| 28 | PyObject *BitOr_singleton; |
| 29 | PyObject *BitOr_type; |
| 30 | PyObject *BitXor_singleton; |
| 31 | PyObject *BitXor_type; |
| 32 | PyObject *BoolOp_type; |
| 33 | PyObject *Break_type; |
| 34 | PyObject *Call_type; |
| 35 | PyObject *ClassDef_type; |
| 36 | PyObject *Compare_type; |
| 37 | PyObject *Constant_type; |
| 38 | PyObject *Continue_type; |
| 39 | PyObject *Del_singleton; |
| 40 | PyObject *Del_type; |
| 41 | PyObject *Delete_type; |
| 42 | PyObject *DictComp_type; |
| 43 | PyObject *Dict_type; |
| 44 | PyObject *Div_singleton; |
| 45 | PyObject *Div_type; |
| 46 | PyObject *Eq_singleton; |
| 47 | PyObject *Eq_type; |
| 48 | PyObject *ExceptHandler_type; |
| 49 | PyObject *Expr_type; |
| 50 | PyObject *Expression_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 51 | PyObject *FloorDiv_singleton; |
| 52 | PyObject *FloorDiv_type; |
| 53 | PyObject *For_type; |
| 54 | PyObject *FormattedValue_type; |
| 55 | PyObject *FunctionDef_type; |
| 56 | PyObject *FunctionType_type; |
| 57 | PyObject *GeneratorExp_type; |
| 58 | PyObject *Global_type; |
| 59 | PyObject *GtE_singleton; |
| 60 | PyObject *GtE_type; |
| 61 | PyObject *Gt_singleton; |
| 62 | PyObject *Gt_type; |
| 63 | PyObject *IfExp_type; |
| 64 | PyObject *If_type; |
| 65 | PyObject *ImportFrom_type; |
| 66 | PyObject *Import_type; |
| 67 | PyObject *In_singleton; |
| 68 | PyObject *In_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 69 | PyObject *Interactive_type; |
| 70 | PyObject *Invert_singleton; |
| 71 | PyObject *Invert_type; |
| 72 | PyObject *IsNot_singleton; |
| 73 | PyObject *IsNot_type; |
| 74 | PyObject *Is_singleton; |
| 75 | PyObject *Is_type; |
| 76 | PyObject *JoinedStr_type; |
| 77 | PyObject *LShift_singleton; |
| 78 | PyObject *LShift_type; |
| 79 | PyObject *Lambda_type; |
| 80 | PyObject *ListComp_type; |
| 81 | PyObject *List_type; |
| 82 | PyObject *Load_singleton; |
| 83 | PyObject *Load_type; |
| 84 | PyObject *LtE_singleton; |
| 85 | PyObject *LtE_type; |
| 86 | PyObject *Lt_singleton; |
| 87 | PyObject *Lt_type; |
| 88 | PyObject *MatMult_singleton; |
| 89 | PyObject *MatMult_type; |
| 90 | PyObject *Mod_singleton; |
| 91 | PyObject *Mod_type; |
| 92 | PyObject *Module_type; |
| 93 | PyObject *Mult_singleton; |
| 94 | PyObject *Mult_type; |
| 95 | PyObject *Name_type; |
| 96 | PyObject *NamedExpr_type; |
| 97 | PyObject *Nonlocal_type; |
| 98 | PyObject *NotEq_singleton; |
| 99 | PyObject *NotEq_type; |
| 100 | PyObject *NotIn_singleton; |
| 101 | PyObject *NotIn_type; |
| 102 | PyObject *Not_singleton; |
| 103 | PyObject *Not_type; |
| 104 | PyObject *Or_singleton; |
| 105 | PyObject *Or_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 106 | PyObject *Pass_type; |
| 107 | PyObject *Pow_singleton; |
| 108 | PyObject *Pow_type; |
| 109 | PyObject *RShift_singleton; |
| 110 | PyObject *RShift_type; |
| 111 | PyObject *Raise_type; |
| 112 | PyObject *Return_type; |
| 113 | PyObject *SetComp_type; |
| 114 | PyObject *Set_type; |
| 115 | PyObject *Slice_type; |
| 116 | PyObject *Starred_type; |
| 117 | PyObject *Store_singleton; |
| 118 | PyObject *Store_type; |
| 119 | PyObject *Sub_singleton; |
| 120 | PyObject *Sub_type; |
| 121 | PyObject *Subscript_type; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 122 | PyObject *Try_type; |
| 123 | PyObject *Tuple_type; |
| 124 | PyObject *TypeIgnore_type; |
| 125 | PyObject *UAdd_singleton; |
| 126 | PyObject *UAdd_type; |
| 127 | PyObject *USub_singleton; |
| 128 | PyObject *USub_type; |
| 129 | PyObject *UnaryOp_type; |
| 130 | PyObject *While_type; |
| 131 | PyObject *With_type; |
| 132 | PyObject *YieldFrom_type; |
| 133 | PyObject *Yield_type; |
| 134 | PyObject *__dict__; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 135 | PyObject *__doc__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 136 | PyObject *__module__; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 137 | PyObject *_attributes; |
| 138 | PyObject *_fields; |
| 139 | PyObject *alias_type; |
| 140 | PyObject *annotation; |
| 141 | PyObject *arg; |
| 142 | PyObject *arg_type; |
| 143 | PyObject *args; |
| 144 | PyObject *argtypes; |
| 145 | PyObject *arguments_type; |
| 146 | PyObject *asname; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 147 | PyObject *ast; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 148 | PyObject *attr; |
| 149 | PyObject *bases; |
| 150 | PyObject *body; |
| 151 | PyObject *boolop_type; |
| 152 | PyObject *cause; |
| 153 | PyObject *cmpop_type; |
| 154 | PyObject *col_offset; |
| 155 | PyObject *comparators; |
| 156 | PyObject *comprehension_type; |
| 157 | PyObject *context_expr; |
| 158 | PyObject *conversion; |
| 159 | PyObject *ctx; |
| 160 | PyObject *decorator_list; |
| 161 | PyObject *defaults; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 162 | PyObject *elt; |
| 163 | PyObject *elts; |
| 164 | PyObject *end_col_offset; |
| 165 | PyObject *end_lineno; |
| 166 | PyObject *exc; |
| 167 | PyObject *excepthandler_type; |
| 168 | PyObject *expr_context_type; |
| 169 | PyObject *expr_type; |
| 170 | PyObject *finalbody; |
| 171 | PyObject *format_spec; |
| 172 | PyObject *func; |
| 173 | PyObject *generators; |
| 174 | PyObject *handlers; |
| 175 | PyObject *id; |
| 176 | PyObject *ifs; |
| 177 | PyObject *is_async; |
| 178 | PyObject *items; |
| 179 | PyObject *iter; |
| 180 | PyObject *key; |
| 181 | PyObject *keys; |
| 182 | PyObject *keyword_type; |
| 183 | PyObject *keywords; |
| 184 | PyObject *kind; |
| 185 | PyObject *kw_defaults; |
| 186 | PyObject *kwarg; |
| 187 | PyObject *kwonlyargs; |
| 188 | PyObject *left; |
| 189 | PyObject *level; |
| 190 | PyObject *lineno; |
| 191 | PyObject *lower; |
| 192 | PyObject *mod_type; |
| 193 | PyObject *module; |
| 194 | PyObject *msg; |
| 195 | PyObject *name; |
| 196 | PyObject *names; |
| 197 | PyObject *op; |
| 198 | PyObject *operand; |
| 199 | PyObject *operator_type; |
| 200 | PyObject *ops; |
| 201 | PyObject *optional_vars; |
| 202 | PyObject *orelse; |
| 203 | PyObject *posonlyargs; |
| 204 | PyObject *returns; |
| 205 | PyObject *right; |
| 206 | PyObject *simple; |
| 207 | PyObject *slice; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 208 | PyObject *step; |
| 209 | PyObject *stmt_type; |
| 210 | PyObject *tag; |
| 211 | PyObject *target; |
| 212 | PyObject *targets; |
| 213 | PyObject *test; |
| 214 | PyObject *type; |
| 215 | PyObject *type_comment; |
| 216 | PyObject *type_ignore_type; |
| 217 | PyObject *type_ignores; |
| 218 | PyObject *unaryop_type; |
| 219 | PyObject *upper; |
| 220 | PyObject *value; |
| 221 | PyObject *values; |
| 222 | PyObject *vararg; |
| 223 | PyObject *withitem_type; |
| 224 | } astmodulestate; |
| 225 | |
| 226 | |
| 227 | #define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o)) |
| 228 | |
| 229 | static int astmodule_clear(PyObject *module) |
| 230 | { |
| 231 | Py_CLEAR(astmodulestate(module)->AST_type); |
| 232 | Py_CLEAR(astmodulestate(module)->Add_singleton); |
| 233 | Py_CLEAR(astmodulestate(module)->Add_type); |
| 234 | Py_CLEAR(astmodulestate(module)->And_singleton); |
| 235 | Py_CLEAR(astmodulestate(module)->And_type); |
| 236 | Py_CLEAR(astmodulestate(module)->AnnAssign_type); |
| 237 | Py_CLEAR(astmodulestate(module)->Assert_type); |
| 238 | Py_CLEAR(astmodulestate(module)->Assign_type); |
| 239 | Py_CLEAR(astmodulestate(module)->AsyncFor_type); |
| 240 | Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type); |
| 241 | Py_CLEAR(astmodulestate(module)->AsyncWith_type); |
| 242 | Py_CLEAR(astmodulestate(module)->Attribute_type); |
| 243 | Py_CLEAR(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 244 | Py_CLEAR(astmodulestate(module)->Await_type); |
| 245 | Py_CLEAR(astmodulestate(module)->BinOp_type); |
| 246 | Py_CLEAR(astmodulestate(module)->BitAnd_singleton); |
| 247 | Py_CLEAR(astmodulestate(module)->BitAnd_type); |
| 248 | Py_CLEAR(astmodulestate(module)->BitOr_singleton); |
| 249 | Py_CLEAR(astmodulestate(module)->BitOr_type); |
| 250 | Py_CLEAR(astmodulestate(module)->BitXor_singleton); |
| 251 | Py_CLEAR(astmodulestate(module)->BitXor_type); |
| 252 | Py_CLEAR(astmodulestate(module)->BoolOp_type); |
| 253 | Py_CLEAR(astmodulestate(module)->Break_type); |
| 254 | Py_CLEAR(astmodulestate(module)->Call_type); |
| 255 | Py_CLEAR(astmodulestate(module)->ClassDef_type); |
| 256 | Py_CLEAR(astmodulestate(module)->Compare_type); |
| 257 | Py_CLEAR(astmodulestate(module)->Constant_type); |
| 258 | Py_CLEAR(astmodulestate(module)->Continue_type); |
| 259 | Py_CLEAR(astmodulestate(module)->Del_singleton); |
| 260 | Py_CLEAR(astmodulestate(module)->Del_type); |
| 261 | Py_CLEAR(astmodulestate(module)->Delete_type); |
| 262 | Py_CLEAR(astmodulestate(module)->DictComp_type); |
| 263 | Py_CLEAR(astmodulestate(module)->Dict_type); |
| 264 | Py_CLEAR(astmodulestate(module)->Div_singleton); |
| 265 | Py_CLEAR(astmodulestate(module)->Div_type); |
| 266 | Py_CLEAR(astmodulestate(module)->Eq_singleton); |
| 267 | Py_CLEAR(astmodulestate(module)->Eq_type); |
| 268 | Py_CLEAR(astmodulestate(module)->ExceptHandler_type); |
| 269 | Py_CLEAR(astmodulestate(module)->Expr_type); |
| 270 | Py_CLEAR(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 271 | Py_CLEAR(astmodulestate(module)->FloorDiv_singleton); |
| 272 | Py_CLEAR(astmodulestate(module)->FloorDiv_type); |
| 273 | Py_CLEAR(astmodulestate(module)->For_type); |
| 274 | Py_CLEAR(astmodulestate(module)->FormattedValue_type); |
| 275 | Py_CLEAR(astmodulestate(module)->FunctionDef_type); |
| 276 | Py_CLEAR(astmodulestate(module)->FunctionType_type); |
| 277 | Py_CLEAR(astmodulestate(module)->GeneratorExp_type); |
| 278 | Py_CLEAR(astmodulestate(module)->Global_type); |
| 279 | Py_CLEAR(astmodulestate(module)->GtE_singleton); |
| 280 | Py_CLEAR(astmodulestate(module)->GtE_type); |
| 281 | Py_CLEAR(astmodulestate(module)->Gt_singleton); |
| 282 | Py_CLEAR(astmodulestate(module)->Gt_type); |
| 283 | Py_CLEAR(astmodulestate(module)->IfExp_type); |
| 284 | Py_CLEAR(astmodulestate(module)->If_type); |
| 285 | Py_CLEAR(astmodulestate(module)->ImportFrom_type); |
| 286 | Py_CLEAR(astmodulestate(module)->Import_type); |
| 287 | Py_CLEAR(astmodulestate(module)->In_singleton); |
| 288 | Py_CLEAR(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 289 | Py_CLEAR(astmodulestate(module)->Interactive_type); |
| 290 | Py_CLEAR(astmodulestate(module)->Invert_singleton); |
| 291 | Py_CLEAR(astmodulestate(module)->Invert_type); |
| 292 | Py_CLEAR(astmodulestate(module)->IsNot_singleton); |
| 293 | Py_CLEAR(astmodulestate(module)->IsNot_type); |
| 294 | Py_CLEAR(astmodulestate(module)->Is_singleton); |
| 295 | Py_CLEAR(astmodulestate(module)->Is_type); |
| 296 | Py_CLEAR(astmodulestate(module)->JoinedStr_type); |
| 297 | Py_CLEAR(astmodulestate(module)->LShift_singleton); |
| 298 | Py_CLEAR(astmodulestate(module)->LShift_type); |
| 299 | Py_CLEAR(astmodulestate(module)->Lambda_type); |
| 300 | Py_CLEAR(astmodulestate(module)->ListComp_type); |
| 301 | Py_CLEAR(astmodulestate(module)->List_type); |
| 302 | Py_CLEAR(astmodulestate(module)->Load_singleton); |
| 303 | Py_CLEAR(astmodulestate(module)->Load_type); |
| 304 | Py_CLEAR(astmodulestate(module)->LtE_singleton); |
| 305 | Py_CLEAR(astmodulestate(module)->LtE_type); |
| 306 | Py_CLEAR(astmodulestate(module)->Lt_singleton); |
| 307 | Py_CLEAR(astmodulestate(module)->Lt_type); |
| 308 | Py_CLEAR(astmodulestate(module)->MatMult_singleton); |
| 309 | Py_CLEAR(astmodulestate(module)->MatMult_type); |
| 310 | Py_CLEAR(astmodulestate(module)->Mod_singleton); |
| 311 | Py_CLEAR(astmodulestate(module)->Mod_type); |
| 312 | Py_CLEAR(astmodulestate(module)->Module_type); |
| 313 | Py_CLEAR(astmodulestate(module)->Mult_singleton); |
| 314 | Py_CLEAR(astmodulestate(module)->Mult_type); |
| 315 | Py_CLEAR(astmodulestate(module)->Name_type); |
| 316 | Py_CLEAR(astmodulestate(module)->NamedExpr_type); |
| 317 | Py_CLEAR(astmodulestate(module)->Nonlocal_type); |
| 318 | Py_CLEAR(astmodulestate(module)->NotEq_singleton); |
| 319 | Py_CLEAR(astmodulestate(module)->NotEq_type); |
| 320 | Py_CLEAR(astmodulestate(module)->NotIn_singleton); |
| 321 | Py_CLEAR(astmodulestate(module)->NotIn_type); |
| 322 | Py_CLEAR(astmodulestate(module)->Not_singleton); |
| 323 | Py_CLEAR(astmodulestate(module)->Not_type); |
| 324 | Py_CLEAR(astmodulestate(module)->Or_singleton); |
| 325 | Py_CLEAR(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 326 | Py_CLEAR(astmodulestate(module)->Pass_type); |
| 327 | Py_CLEAR(astmodulestate(module)->Pow_singleton); |
| 328 | Py_CLEAR(astmodulestate(module)->Pow_type); |
| 329 | Py_CLEAR(astmodulestate(module)->RShift_singleton); |
| 330 | Py_CLEAR(astmodulestate(module)->RShift_type); |
| 331 | Py_CLEAR(astmodulestate(module)->Raise_type); |
| 332 | Py_CLEAR(astmodulestate(module)->Return_type); |
| 333 | Py_CLEAR(astmodulestate(module)->SetComp_type); |
| 334 | Py_CLEAR(astmodulestate(module)->Set_type); |
| 335 | Py_CLEAR(astmodulestate(module)->Slice_type); |
| 336 | Py_CLEAR(astmodulestate(module)->Starred_type); |
| 337 | Py_CLEAR(astmodulestate(module)->Store_singleton); |
| 338 | Py_CLEAR(astmodulestate(module)->Store_type); |
| 339 | Py_CLEAR(astmodulestate(module)->Sub_singleton); |
| 340 | Py_CLEAR(astmodulestate(module)->Sub_type); |
| 341 | Py_CLEAR(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 342 | Py_CLEAR(astmodulestate(module)->Try_type); |
| 343 | Py_CLEAR(astmodulestate(module)->Tuple_type); |
| 344 | Py_CLEAR(astmodulestate(module)->TypeIgnore_type); |
| 345 | Py_CLEAR(astmodulestate(module)->UAdd_singleton); |
| 346 | Py_CLEAR(astmodulestate(module)->UAdd_type); |
| 347 | Py_CLEAR(astmodulestate(module)->USub_singleton); |
| 348 | Py_CLEAR(astmodulestate(module)->USub_type); |
| 349 | Py_CLEAR(astmodulestate(module)->UnaryOp_type); |
| 350 | Py_CLEAR(astmodulestate(module)->While_type); |
| 351 | Py_CLEAR(astmodulestate(module)->With_type); |
| 352 | Py_CLEAR(astmodulestate(module)->YieldFrom_type); |
| 353 | Py_CLEAR(astmodulestate(module)->Yield_type); |
| 354 | Py_CLEAR(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 355 | Py_CLEAR(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 356 | Py_CLEAR(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 357 | Py_CLEAR(astmodulestate(module)->_attributes); |
| 358 | Py_CLEAR(astmodulestate(module)->_fields); |
| 359 | Py_CLEAR(astmodulestate(module)->alias_type); |
| 360 | Py_CLEAR(astmodulestate(module)->annotation); |
| 361 | Py_CLEAR(astmodulestate(module)->arg); |
| 362 | Py_CLEAR(astmodulestate(module)->arg_type); |
| 363 | Py_CLEAR(astmodulestate(module)->args); |
| 364 | Py_CLEAR(astmodulestate(module)->argtypes); |
| 365 | Py_CLEAR(astmodulestate(module)->arguments_type); |
| 366 | Py_CLEAR(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 367 | Py_CLEAR(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 368 | Py_CLEAR(astmodulestate(module)->attr); |
| 369 | Py_CLEAR(astmodulestate(module)->bases); |
| 370 | Py_CLEAR(astmodulestate(module)->body); |
| 371 | Py_CLEAR(astmodulestate(module)->boolop_type); |
| 372 | Py_CLEAR(astmodulestate(module)->cause); |
| 373 | Py_CLEAR(astmodulestate(module)->cmpop_type); |
| 374 | Py_CLEAR(astmodulestate(module)->col_offset); |
| 375 | Py_CLEAR(astmodulestate(module)->comparators); |
| 376 | Py_CLEAR(astmodulestate(module)->comprehension_type); |
| 377 | Py_CLEAR(astmodulestate(module)->context_expr); |
| 378 | Py_CLEAR(astmodulestate(module)->conversion); |
| 379 | Py_CLEAR(astmodulestate(module)->ctx); |
| 380 | Py_CLEAR(astmodulestate(module)->decorator_list); |
| 381 | Py_CLEAR(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 382 | Py_CLEAR(astmodulestate(module)->elt); |
| 383 | Py_CLEAR(astmodulestate(module)->elts); |
| 384 | Py_CLEAR(astmodulestate(module)->end_col_offset); |
| 385 | Py_CLEAR(astmodulestate(module)->end_lineno); |
| 386 | Py_CLEAR(astmodulestate(module)->exc); |
| 387 | Py_CLEAR(astmodulestate(module)->excepthandler_type); |
| 388 | Py_CLEAR(astmodulestate(module)->expr_context_type); |
| 389 | Py_CLEAR(astmodulestate(module)->expr_type); |
| 390 | Py_CLEAR(astmodulestate(module)->finalbody); |
| 391 | Py_CLEAR(astmodulestate(module)->format_spec); |
| 392 | Py_CLEAR(astmodulestate(module)->func); |
| 393 | Py_CLEAR(astmodulestate(module)->generators); |
| 394 | Py_CLEAR(astmodulestate(module)->handlers); |
| 395 | Py_CLEAR(astmodulestate(module)->id); |
| 396 | Py_CLEAR(astmodulestate(module)->ifs); |
| 397 | Py_CLEAR(astmodulestate(module)->is_async); |
| 398 | Py_CLEAR(astmodulestate(module)->items); |
| 399 | Py_CLEAR(astmodulestate(module)->iter); |
| 400 | Py_CLEAR(astmodulestate(module)->key); |
| 401 | Py_CLEAR(astmodulestate(module)->keys); |
| 402 | Py_CLEAR(astmodulestate(module)->keyword_type); |
| 403 | Py_CLEAR(astmodulestate(module)->keywords); |
| 404 | Py_CLEAR(astmodulestate(module)->kind); |
| 405 | Py_CLEAR(astmodulestate(module)->kw_defaults); |
| 406 | Py_CLEAR(astmodulestate(module)->kwarg); |
| 407 | Py_CLEAR(astmodulestate(module)->kwonlyargs); |
| 408 | Py_CLEAR(astmodulestate(module)->left); |
| 409 | Py_CLEAR(astmodulestate(module)->level); |
| 410 | Py_CLEAR(astmodulestate(module)->lineno); |
| 411 | Py_CLEAR(astmodulestate(module)->lower); |
| 412 | Py_CLEAR(astmodulestate(module)->mod_type); |
| 413 | Py_CLEAR(astmodulestate(module)->module); |
| 414 | Py_CLEAR(astmodulestate(module)->msg); |
| 415 | Py_CLEAR(astmodulestate(module)->name); |
| 416 | Py_CLEAR(astmodulestate(module)->names); |
| 417 | Py_CLEAR(astmodulestate(module)->op); |
| 418 | Py_CLEAR(astmodulestate(module)->operand); |
| 419 | Py_CLEAR(astmodulestate(module)->operator_type); |
| 420 | Py_CLEAR(astmodulestate(module)->ops); |
| 421 | Py_CLEAR(astmodulestate(module)->optional_vars); |
| 422 | Py_CLEAR(astmodulestate(module)->orelse); |
| 423 | Py_CLEAR(astmodulestate(module)->posonlyargs); |
| 424 | Py_CLEAR(astmodulestate(module)->returns); |
| 425 | Py_CLEAR(astmodulestate(module)->right); |
| 426 | Py_CLEAR(astmodulestate(module)->simple); |
| 427 | Py_CLEAR(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 428 | Py_CLEAR(astmodulestate(module)->step); |
| 429 | Py_CLEAR(astmodulestate(module)->stmt_type); |
| 430 | Py_CLEAR(astmodulestate(module)->tag); |
| 431 | Py_CLEAR(astmodulestate(module)->target); |
| 432 | Py_CLEAR(astmodulestate(module)->targets); |
| 433 | Py_CLEAR(astmodulestate(module)->test); |
| 434 | Py_CLEAR(astmodulestate(module)->type); |
| 435 | Py_CLEAR(astmodulestate(module)->type_comment); |
| 436 | Py_CLEAR(astmodulestate(module)->type_ignore_type); |
| 437 | Py_CLEAR(astmodulestate(module)->type_ignores); |
| 438 | Py_CLEAR(astmodulestate(module)->unaryop_type); |
| 439 | Py_CLEAR(astmodulestate(module)->upper); |
| 440 | Py_CLEAR(astmodulestate(module)->value); |
| 441 | Py_CLEAR(astmodulestate(module)->values); |
| 442 | Py_CLEAR(astmodulestate(module)->vararg); |
| 443 | Py_CLEAR(astmodulestate(module)->withitem_type); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int astmodule_traverse(PyObject *module, visitproc visit, void* arg) |
| 449 | { |
| 450 | Py_VISIT(astmodulestate(module)->AST_type); |
| 451 | Py_VISIT(astmodulestate(module)->Add_singleton); |
| 452 | Py_VISIT(astmodulestate(module)->Add_type); |
| 453 | Py_VISIT(astmodulestate(module)->And_singleton); |
| 454 | Py_VISIT(astmodulestate(module)->And_type); |
| 455 | Py_VISIT(astmodulestate(module)->AnnAssign_type); |
| 456 | Py_VISIT(astmodulestate(module)->Assert_type); |
| 457 | Py_VISIT(astmodulestate(module)->Assign_type); |
| 458 | Py_VISIT(astmodulestate(module)->AsyncFor_type); |
| 459 | Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type); |
| 460 | Py_VISIT(astmodulestate(module)->AsyncWith_type); |
| 461 | Py_VISIT(astmodulestate(module)->Attribute_type); |
| 462 | Py_VISIT(astmodulestate(module)->AugAssign_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 463 | Py_VISIT(astmodulestate(module)->Await_type); |
| 464 | Py_VISIT(astmodulestate(module)->BinOp_type); |
| 465 | Py_VISIT(astmodulestate(module)->BitAnd_singleton); |
| 466 | Py_VISIT(astmodulestate(module)->BitAnd_type); |
| 467 | Py_VISIT(astmodulestate(module)->BitOr_singleton); |
| 468 | Py_VISIT(astmodulestate(module)->BitOr_type); |
| 469 | Py_VISIT(astmodulestate(module)->BitXor_singleton); |
| 470 | Py_VISIT(astmodulestate(module)->BitXor_type); |
| 471 | Py_VISIT(astmodulestate(module)->BoolOp_type); |
| 472 | Py_VISIT(astmodulestate(module)->Break_type); |
| 473 | Py_VISIT(astmodulestate(module)->Call_type); |
| 474 | Py_VISIT(astmodulestate(module)->ClassDef_type); |
| 475 | Py_VISIT(astmodulestate(module)->Compare_type); |
| 476 | Py_VISIT(astmodulestate(module)->Constant_type); |
| 477 | Py_VISIT(astmodulestate(module)->Continue_type); |
| 478 | Py_VISIT(astmodulestate(module)->Del_singleton); |
| 479 | Py_VISIT(astmodulestate(module)->Del_type); |
| 480 | Py_VISIT(astmodulestate(module)->Delete_type); |
| 481 | Py_VISIT(astmodulestate(module)->DictComp_type); |
| 482 | Py_VISIT(astmodulestate(module)->Dict_type); |
| 483 | Py_VISIT(astmodulestate(module)->Div_singleton); |
| 484 | Py_VISIT(astmodulestate(module)->Div_type); |
| 485 | Py_VISIT(astmodulestate(module)->Eq_singleton); |
| 486 | Py_VISIT(astmodulestate(module)->Eq_type); |
| 487 | Py_VISIT(astmodulestate(module)->ExceptHandler_type); |
| 488 | Py_VISIT(astmodulestate(module)->Expr_type); |
| 489 | Py_VISIT(astmodulestate(module)->Expression_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 490 | Py_VISIT(astmodulestate(module)->FloorDiv_singleton); |
| 491 | Py_VISIT(astmodulestate(module)->FloorDiv_type); |
| 492 | Py_VISIT(astmodulestate(module)->For_type); |
| 493 | Py_VISIT(astmodulestate(module)->FormattedValue_type); |
| 494 | Py_VISIT(astmodulestate(module)->FunctionDef_type); |
| 495 | Py_VISIT(astmodulestate(module)->FunctionType_type); |
| 496 | Py_VISIT(astmodulestate(module)->GeneratorExp_type); |
| 497 | Py_VISIT(astmodulestate(module)->Global_type); |
| 498 | Py_VISIT(astmodulestate(module)->GtE_singleton); |
| 499 | Py_VISIT(astmodulestate(module)->GtE_type); |
| 500 | Py_VISIT(astmodulestate(module)->Gt_singleton); |
| 501 | Py_VISIT(astmodulestate(module)->Gt_type); |
| 502 | Py_VISIT(astmodulestate(module)->IfExp_type); |
| 503 | Py_VISIT(astmodulestate(module)->If_type); |
| 504 | Py_VISIT(astmodulestate(module)->ImportFrom_type); |
| 505 | Py_VISIT(astmodulestate(module)->Import_type); |
| 506 | Py_VISIT(astmodulestate(module)->In_singleton); |
| 507 | Py_VISIT(astmodulestate(module)->In_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 508 | Py_VISIT(astmodulestate(module)->Interactive_type); |
| 509 | Py_VISIT(astmodulestate(module)->Invert_singleton); |
| 510 | Py_VISIT(astmodulestate(module)->Invert_type); |
| 511 | Py_VISIT(astmodulestate(module)->IsNot_singleton); |
| 512 | Py_VISIT(astmodulestate(module)->IsNot_type); |
| 513 | Py_VISIT(astmodulestate(module)->Is_singleton); |
| 514 | Py_VISIT(astmodulestate(module)->Is_type); |
| 515 | Py_VISIT(astmodulestate(module)->JoinedStr_type); |
| 516 | Py_VISIT(astmodulestate(module)->LShift_singleton); |
| 517 | Py_VISIT(astmodulestate(module)->LShift_type); |
| 518 | Py_VISIT(astmodulestate(module)->Lambda_type); |
| 519 | Py_VISIT(astmodulestate(module)->ListComp_type); |
| 520 | Py_VISIT(astmodulestate(module)->List_type); |
| 521 | Py_VISIT(astmodulestate(module)->Load_singleton); |
| 522 | Py_VISIT(astmodulestate(module)->Load_type); |
| 523 | Py_VISIT(astmodulestate(module)->LtE_singleton); |
| 524 | Py_VISIT(astmodulestate(module)->LtE_type); |
| 525 | Py_VISIT(astmodulestate(module)->Lt_singleton); |
| 526 | Py_VISIT(astmodulestate(module)->Lt_type); |
| 527 | Py_VISIT(astmodulestate(module)->MatMult_singleton); |
| 528 | Py_VISIT(astmodulestate(module)->MatMult_type); |
| 529 | Py_VISIT(astmodulestate(module)->Mod_singleton); |
| 530 | Py_VISIT(astmodulestate(module)->Mod_type); |
| 531 | Py_VISIT(astmodulestate(module)->Module_type); |
| 532 | Py_VISIT(astmodulestate(module)->Mult_singleton); |
| 533 | Py_VISIT(astmodulestate(module)->Mult_type); |
| 534 | Py_VISIT(astmodulestate(module)->Name_type); |
| 535 | Py_VISIT(astmodulestate(module)->NamedExpr_type); |
| 536 | Py_VISIT(astmodulestate(module)->Nonlocal_type); |
| 537 | Py_VISIT(astmodulestate(module)->NotEq_singleton); |
| 538 | Py_VISIT(astmodulestate(module)->NotEq_type); |
| 539 | Py_VISIT(astmodulestate(module)->NotIn_singleton); |
| 540 | Py_VISIT(astmodulestate(module)->NotIn_type); |
| 541 | Py_VISIT(astmodulestate(module)->Not_singleton); |
| 542 | Py_VISIT(astmodulestate(module)->Not_type); |
| 543 | Py_VISIT(astmodulestate(module)->Or_singleton); |
| 544 | Py_VISIT(astmodulestate(module)->Or_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 545 | Py_VISIT(astmodulestate(module)->Pass_type); |
| 546 | Py_VISIT(astmodulestate(module)->Pow_singleton); |
| 547 | Py_VISIT(astmodulestate(module)->Pow_type); |
| 548 | Py_VISIT(astmodulestate(module)->RShift_singleton); |
| 549 | Py_VISIT(astmodulestate(module)->RShift_type); |
| 550 | Py_VISIT(astmodulestate(module)->Raise_type); |
| 551 | Py_VISIT(astmodulestate(module)->Return_type); |
| 552 | Py_VISIT(astmodulestate(module)->SetComp_type); |
| 553 | Py_VISIT(astmodulestate(module)->Set_type); |
| 554 | Py_VISIT(astmodulestate(module)->Slice_type); |
| 555 | Py_VISIT(astmodulestate(module)->Starred_type); |
| 556 | Py_VISIT(astmodulestate(module)->Store_singleton); |
| 557 | Py_VISIT(astmodulestate(module)->Store_type); |
| 558 | Py_VISIT(astmodulestate(module)->Sub_singleton); |
| 559 | Py_VISIT(astmodulestate(module)->Sub_type); |
| 560 | Py_VISIT(astmodulestate(module)->Subscript_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 561 | Py_VISIT(astmodulestate(module)->Try_type); |
| 562 | Py_VISIT(astmodulestate(module)->Tuple_type); |
| 563 | Py_VISIT(astmodulestate(module)->TypeIgnore_type); |
| 564 | Py_VISIT(astmodulestate(module)->UAdd_singleton); |
| 565 | Py_VISIT(astmodulestate(module)->UAdd_type); |
| 566 | Py_VISIT(astmodulestate(module)->USub_singleton); |
| 567 | Py_VISIT(astmodulestate(module)->USub_type); |
| 568 | Py_VISIT(astmodulestate(module)->UnaryOp_type); |
| 569 | Py_VISIT(astmodulestate(module)->While_type); |
| 570 | Py_VISIT(astmodulestate(module)->With_type); |
| 571 | Py_VISIT(astmodulestate(module)->YieldFrom_type); |
| 572 | Py_VISIT(astmodulestate(module)->Yield_type); |
| 573 | Py_VISIT(astmodulestate(module)->__dict__); |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 574 | Py_VISIT(astmodulestate(module)->__doc__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 575 | Py_VISIT(astmodulestate(module)->__module__); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 576 | Py_VISIT(astmodulestate(module)->_attributes); |
| 577 | Py_VISIT(astmodulestate(module)->_fields); |
| 578 | Py_VISIT(astmodulestate(module)->alias_type); |
| 579 | Py_VISIT(astmodulestate(module)->annotation); |
| 580 | Py_VISIT(astmodulestate(module)->arg); |
| 581 | Py_VISIT(astmodulestate(module)->arg_type); |
| 582 | Py_VISIT(astmodulestate(module)->args); |
| 583 | Py_VISIT(astmodulestate(module)->argtypes); |
| 584 | Py_VISIT(astmodulestate(module)->arguments_type); |
| 585 | Py_VISIT(astmodulestate(module)->asname); |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 586 | Py_VISIT(astmodulestate(module)->ast); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 587 | Py_VISIT(astmodulestate(module)->attr); |
| 588 | Py_VISIT(astmodulestate(module)->bases); |
| 589 | Py_VISIT(astmodulestate(module)->body); |
| 590 | Py_VISIT(astmodulestate(module)->boolop_type); |
| 591 | Py_VISIT(astmodulestate(module)->cause); |
| 592 | Py_VISIT(astmodulestate(module)->cmpop_type); |
| 593 | Py_VISIT(astmodulestate(module)->col_offset); |
| 594 | Py_VISIT(astmodulestate(module)->comparators); |
| 595 | Py_VISIT(astmodulestate(module)->comprehension_type); |
| 596 | Py_VISIT(astmodulestate(module)->context_expr); |
| 597 | Py_VISIT(astmodulestate(module)->conversion); |
| 598 | Py_VISIT(astmodulestate(module)->ctx); |
| 599 | Py_VISIT(astmodulestate(module)->decorator_list); |
| 600 | Py_VISIT(astmodulestate(module)->defaults); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 601 | Py_VISIT(astmodulestate(module)->elt); |
| 602 | Py_VISIT(astmodulestate(module)->elts); |
| 603 | Py_VISIT(astmodulestate(module)->end_col_offset); |
| 604 | Py_VISIT(astmodulestate(module)->end_lineno); |
| 605 | Py_VISIT(astmodulestate(module)->exc); |
| 606 | Py_VISIT(astmodulestate(module)->excepthandler_type); |
| 607 | Py_VISIT(astmodulestate(module)->expr_context_type); |
| 608 | Py_VISIT(astmodulestate(module)->expr_type); |
| 609 | Py_VISIT(astmodulestate(module)->finalbody); |
| 610 | Py_VISIT(astmodulestate(module)->format_spec); |
| 611 | Py_VISIT(astmodulestate(module)->func); |
| 612 | Py_VISIT(astmodulestate(module)->generators); |
| 613 | Py_VISIT(astmodulestate(module)->handlers); |
| 614 | Py_VISIT(astmodulestate(module)->id); |
| 615 | Py_VISIT(astmodulestate(module)->ifs); |
| 616 | Py_VISIT(astmodulestate(module)->is_async); |
| 617 | Py_VISIT(astmodulestate(module)->items); |
| 618 | Py_VISIT(astmodulestate(module)->iter); |
| 619 | Py_VISIT(astmodulestate(module)->key); |
| 620 | Py_VISIT(astmodulestate(module)->keys); |
| 621 | Py_VISIT(astmodulestate(module)->keyword_type); |
| 622 | Py_VISIT(astmodulestate(module)->keywords); |
| 623 | Py_VISIT(astmodulestate(module)->kind); |
| 624 | Py_VISIT(astmodulestate(module)->kw_defaults); |
| 625 | Py_VISIT(astmodulestate(module)->kwarg); |
| 626 | Py_VISIT(astmodulestate(module)->kwonlyargs); |
| 627 | Py_VISIT(astmodulestate(module)->left); |
| 628 | Py_VISIT(astmodulestate(module)->level); |
| 629 | Py_VISIT(astmodulestate(module)->lineno); |
| 630 | Py_VISIT(astmodulestate(module)->lower); |
| 631 | Py_VISIT(astmodulestate(module)->mod_type); |
| 632 | Py_VISIT(astmodulestate(module)->module); |
| 633 | Py_VISIT(astmodulestate(module)->msg); |
| 634 | Py_VISIT(astmodulestate(module)->name); |
| 635 | Py_VISIT(astmodulestate(module)->names); |
| 636 | Py_VISIT(astmodulestate(module)->op); |
| 637 | Py_VISIT(astmodulestate(module)->operand); |
| 638 | Py_VISIT(astmodulestate(module)->operator_type); |
| 639 | Py_VISIT(astmodulestate(module)->ops); |
| 640 | Py_VISIT(astmodulestate(module)->optional_vars); |
| 641 | Py_VISIT(astmodulestate(module)->orelse); |
| 642 | Py_VISIT(astmodulestate(module)->posonlyargs); |
| 643 | Py_VISIT(astmodulestate(module)->returns); |
| 644 | Py_VISIT(astmodulestate(module)->right); |
| 645 | Py_VISIT(astmodulestate(module)->simple); |
| 646 | Py_VISIT(astmodulestate(module)->slice); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 647 | Py_VISIT(astmodulestate(module)->step); |
| 648 | Py_VISIT(astmodulestate(module)->stmt_type); |
| 649 | Py_VISIT(astmodulestate(module)->tag); |
| 650 | Py_VISIT(astmodulestate(module)->target); |
| 651 | Py_VISIT(astmodulestate(module)->targets); |
| 652 | Py_VISIT(astmodulestate(module)->test); |
| 653 | Py_VISIT(astmodulestate(module)->type); |
| 654 | Py_VISIT(astmodulestate(module)->type_comment); |
| 655 | Py_VISIT(astmodulestate(module)->type_ignore_type); |
| 656 | Py_VISIT(astmodulestate(module)->type_ignores); |
| 657 | Py_VISIT(astmodulestate(module)->unaryop_type); |
| 658 | Py_VISIT(astmodulestate(module)->upper); |
| 659 | Py_VISIT(astmodulestate(module)->value); |
| 660 | Py_VISIT(astmodulestate(module)->values); |
| 661 | Py_VISIT(astmodulestate(module)->vararg); |
| 662 | Py_VISIT(astmodulestate(module)->withitem_type); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void astmodule_free(void* module) { |
| 668 | astmodule_clear((PyObject*)module); |
| 669 | } |
| 670 | |
| 671 | static struct PyModuleDef _astmodule = { |
| 672 | PyModuleDef_HEAD_INIT, |
| 673 | "_ast", |
| 674 | NULL, |
| 675 | sizeof(astmodulestate), |
| 676 | NULL, |
| 677 | NULL, |
| 678 | astmodule_traverse, |
| 679 | astmodule_clear, |
| 680 | astmodule_free, |
| 681 | }; |
| 682 | |
| 683 | #define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule))) |
| 684 | |
| 685 | static int init_identifiers(void) |
| 686 | { |
| 687 | astmodulestate *state = astmodulestate_global; |
| 688 | if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 689 | if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 690 | if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 691 | if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0; |
| 692 | if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0; |
| 693 | if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0; |
| 694 | if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0; |
| 695 | if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0; |
| 696 | if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0; |
| 697 | if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0; |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 698 | if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 699 | if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0; |
| 700 | if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0; |
| 701 | if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0; |
| 702 | if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0; |
| 703 | if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0; |
| 704 | if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0; |
| 705 | if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0; |
| 706 | if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0; |
| 707 | if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0; |
| 708 | if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0; |
| 709 | if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 710 | if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0; |
| 711 | if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0; |
| 712 | if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0; |
| 713 | if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0; |
| 714 | if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0; |
| 715 | if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0; |
| 716 | if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0; |
| 717 | if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0; |
| 718 | if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0; |
| 719 | if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0; |
| 720 | if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0; |
| 721 | if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0; |
| 722 | if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0; |
| 723 | if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0; |
| 724 | if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0; |
| 725 | if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0; |
| 726 | if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0; |
| 727 | if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0; |
| 728 | if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0; |
| 729 | if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0; |
| 730 | if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0; |
| 731 | if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0; |
| 732 | if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0; |
| 733 | if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0; |
| 734 | if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0; |
| 735 | if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0; |
| 736 | if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0; |
| 737 | if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0; |
| 738 | if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0; |
| 739 | if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0; |
| 740 | if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0; |
| 741 | if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0; |
| 742 | if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0; |
| 743 | if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0; |
| 744 | if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0; |
| 745 | if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0; |
| 746 | if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0; |
| 747 | if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0; |
| 748 | if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0; |
| 749 | if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0; |
| 750 | if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0; |
| 751 | if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0; |
| 752 | if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0; |
| 753 | if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0; |
| 754 | if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0; |
| 755 | if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0; |
| 756 | if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0; |
| 757 | if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0; |
| 758 | if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0; |
| 759 | if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0; |
| 760 | if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0; |
| 761 | if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0; |
| 762 | return 1; |
| 763 | }; |
| 764 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 765 | static PyObject* ast2obj_mod(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 766 | static const char * const Module_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 767 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 768 | "type_ignores", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 769 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 770 | static const char * const Interactive_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 771 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 772 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 773 | static const char * const Expression_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 774 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 775 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 776 | static const char * const FunctionType_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 777 | "argtypes", |
| 778 | "returns", |
| 779 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 780 | static const char * const stmt_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 781 | "lineno", |
| 782 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 783 | "end_lineno", |
| 784 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 785 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 786 | static PyObject* ast2obj_stmt(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 787 | static const char * const FunctionDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 788 | "name", |
| 789 | "args", |
| 790 | "body", |
| 791 | "decorator_list", |
| 792 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 793 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 794 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 795 | static const char * const AsyncFunctionDef_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 796 | "name", |
| 797 | "args", |
| 798 | "body", |
| 799 | "decorator_list", |
| 800 | "returns", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 801 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 802 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 803 | static const char * const ClassDef_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 804 | "name", |
| 805 | "bases", |
| 806 | "keywords", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 807 | "body", |
| 808 | "decorator_list", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 809 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 810 | static const char * const Return_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 811 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 812 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 813 | static const char * const Delete_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 814 | "targets", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 815 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 816 | static const char * const Assign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 817 | "targets", |
| 818 | "value", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 819 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 820 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 821 | static const char * const AugAssign_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 822 | "target", |
| 823 | "op", |
| 824 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 825 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 826 | static const char * const AnnAssign_fields[]={ |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 827 | "target", |
| 828 | "annotation", |
| 829 | "value", |
| 830 | "simple", |
| 831 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 832 | static const char * const For_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 833 | "target", |
| 834 | "iter", |
| 835 | "body", |
| 836 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 837 | "type_comment", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 838 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 839 | static const char * const AsyncFor_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 840 | "target", |
| 841 | "iter", |
| 842 | "body", |
| 843 | "orelse", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 844 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 845 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 846 | static const char * const While_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 847 | "test", |
| 848 | "body", |
| 849 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 850 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 851 | static const char * const If_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 852 | "test", |
| 853 | "body", |
| 854 | "orelse", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 855 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 856 | static const char * const With_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 857 | "items", |
| 858 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 859 | "type_comment", |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 860 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 861 | static const char * const AsyncWith_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 862 | "items", |
| 863 | "body", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 864 | "type_comment", |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 865 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 866 | static const char * const Raise_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 867 | "exc", |
| 868 | "cause", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 869 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 870 | static const char * const Try_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 871 | "body", |
| 872 | "handlers", |
| 873 | "orelse", |
| 874 | "finalbody", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 875 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 876 | static const char * const Assert_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 877 | "test", |
| 878 | "msg", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 879 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 880 | static const char * const Import_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 881 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 882 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 883 | static const char * const ImportFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 884 | "module", |
| 885 | "names", |
| 886 | "level", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 887 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 888 | static const char * const Global_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 889 | "names", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 890 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 891 | static const char * const Nonlocal_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 892 | "names", |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 893 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 894 | static const char * const Expr_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 895 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 896 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 897 | static const char * const expr_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 898 | "lineno", |
| 899 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 900 | "end_lineno", |
| 901 | "end_col_offset", |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 902 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 903 | static PyObject* ast2obj_expr(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 904 | static const char * const BoolOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 905 | "op", |
| 906 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 907 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 908 | static const char * const NamedExpr_fields[]={ |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 909 | "target", |
| 910 | "value", |
| 911 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 912 | static const char * const BinOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 913 | "left", |
| 914 | "op", |
| 915 | "right", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 916 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 917 | static const char * const UnaryOp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 918 | "op", |
| 919 | "operand", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 920 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 921 | static const char * const Lambda_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 922 | "args", |
| 923 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 924 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 925 | static const char * const IfExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 926 | "test", |
| 927 | "body", |
| 928 | "orelse", |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 929 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 930 | static const char * const Dict_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 931 | "keys", |
| 932 | "values", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 933 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 934 | static const char * const Set_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 935 | "elts", |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 936 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 937 | static const char * const ListComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 938 | "elt", |
| 939 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 940 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 941 | static const char * const SetComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 942 | "elt", |
| 943 | "generators", |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 944 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 945 | static const char * const DictComp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 946 | "key", |
| 947 | "value", |
| 948 | "generators", |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 949 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 950 | static const char * const GeneratorExp_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 951 | "elt", |
| 952 | "generators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 953 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 954 | static const char * const Await_fields[]={ |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 955 | "value", |
| 956 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 957 | static const char * const Yield_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 958 | "value", |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 959 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 960 | static const char * const YieldFrom_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 961 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 962 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 963 | static const char * const Compare_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 964 | "left", |
| 965 | "ops", |
| 966 | "comparators", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 967 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 968 | static const char * const Call_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 969 | "func", |
| 970 | "args", |
| 971 | "keywords", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 972 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 973 | static const char * const FormattedValue_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 974 | "value", |
| 975 | "conversion", |
| 976 | "format_spec", |
| 977 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 978 | static const char * const JoinedStr_fields[]={ |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 979 | "values", |
| 980 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 981 | static const char * const Constant_fields[]={ |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 982 | "value", |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 983 | "kind", |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 984 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 985 | static const char * const Attribute_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 986 | "value", |
| 987 | "attr", |
| 988 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 989 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 990 | static const char * const Subscript_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 991 | "value", |
| 992 | "slice", |
| 993 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 994 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 995 | static const char * const Starred_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 996 | "value", |
| 997 | "ctx", |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 998 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 999 | static const char * const Name_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1000 | "id", |
| 1001 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1002 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1003 | static const char * const List_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1004 | "elts", |
| 1005 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1006 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1007 | static const char * const Tuple_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1008 | "elts", |
| 1009 | "ctx", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1010 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1011 | static const char * const Slice_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1012 | "lower", |
| 1013 | "upper", |
| 1014 | "step", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1015 | }; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1016 | static PyObject* ast2obj_expr_context(expr_context_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1017 | static PyObject* ast2obj_boolop(boolop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1018 | static PyObject* ast2obj_operator(operator_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1019 | static PyObject* ast2obj_unaryop(unaryop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1020 | static PyObject* ast2obj_cmpop(cmpop_ty); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1021 | static PyObject* ast2obj_comprehension(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1022 | static const char * const comprehension_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1023 | "target", |
| 1024 | "iter", |
| 1025 | "ifs", |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 1026 | "is_async", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1027 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1028 | static const char * const excepthandler_attributes[] = { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1029 | "lineno", |
| 1030 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1031 | "end_lineno", |
| 1032 | "end_col_offset", |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 1033 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1034 | static PyObject* ast2obj_excepthandler(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1035 | static const char * const ExceptHandler_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1036 | "type", |
| 1037 | "name", |
| 1038 | "body", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1039 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1040 | static PyObject* ast2obj_arguments(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1041 | static const char * const arguments_fields[]={ |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 1042 | "posonlyargs", |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 1043 | "args", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1044 | "vararg", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1045 | "kwonlyargs", |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1046 | "kw_defaults", |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1047 | "kwarg", |
| 1048 | "defaults", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1049 | }; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1050 | static PyObject* ast2obj_arg(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1051 | static const char * const arg_attributes[] = { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 1052 | "lineno", |
| 1053 | "col_offset", |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 1054 | "end_lineno", |
| 1055 | "end_col_offset", |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 1056 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1057 | static const char * const arg_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1058 | "arg", |
| 1059 | "annotation", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1060 | "type_comment", |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 1061 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1062 | static PyObject* ast2obj_keyword(void*); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1063 | static const char * const keyword_attributes[] = { |
| 1064 | "lineno", |
| 1065 | "col_offset", |
| 1066 | "end_lineno", |
| 1067 | "end_col_offset", |
| 1068 | }; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1069 | static const char * const keyword_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1070 | "arg", |
| 1071 | "value", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1072 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1073 | static PyObject* ast2obj_alias(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1074 | static const char * const alias_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1075 | "name", |
| 1076 | "asname", |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1077 | }; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1078 | static PyObject* ast2obj_withitem(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1079 | static const char * const withitem_fields[]={ |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1080 | "context_expr", |
| 1081 | "optional_vars", |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 1082 | }; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1083 | static PyObject* ast2obj_type_ignore(void*); |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1084 | static const char * const TypeIgnore_fields[]={ |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1085 | "lineno", |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 1086 | "tag", |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1087 | }; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1088 | |
| 1089 | |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1090 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1091 | typedef struct { |
Victor Stinner | 45e50de | 2012-03-13 01:17:31 +0100 | [diff] [blame] | 1092 | PyObject_HEAD |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1093 | PyObject *dict; |
| 1094 | } AST_object; |
| 1095 | |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1096 | static void |
| 1097 | ast_dealloc(AST_object *self) |
| 1098 | { |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1099 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1100 | PyTypeObject *tp = Py_TYPE(self); |
INADA Naoki | a6296d3 | 2017-08-24 14:55:17 +0900 | [diff] [blame] | 1101 | PyObject_GC_UnTrack(self); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1102 | Py_CLEAR(self->dict); |
Eddie Elizondo | 0247e80 | 2019-09-14 09:38:17 -0400 | [diff] [blame] | 1103 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 1104 | assert(free_func != NULL); |
| 1105 | free_func(self); |
| 1106 | Py_DECREF(tp); |
Benjamin Peterson | 1767e02 | 2012-03-14 21:50:29 -0500 | [diff] [blame] | 1107 | } |
| 1108 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1109 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1110 | ast_traverse(AST_object *self, visitproc visit, void *arg) |
| 1111 | { |
| 1112 | Py_VISIT(self->dict); |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1116 | static int |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1117 | ast_clear(AST_object *self) |
| 1118 | { |
| 1119 | Py_CLEAR(self->dict); |
Serhiy Storchaka | a5c4228 | 2018-05-31 07:34:34 +0300 | [diff] [blame] | 1120 | return 0; |
Benjamin Peterson | 8107176 | 2012-07-08 11:03:46 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static int |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1124 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 1125 | { |
| 1126 | Py_ssize_t i, numfields = 0; |
| 1127 | int res = -1; |
| 1128 | PyObject *key, *value, *fields; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1129 | if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1130 | goto cleanup; |
| 1131 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1132 | if (fields) { |
| 1133 | numfields = PySequence_Size(fields); |
| 1134 | if (numfields == -1) |
| 1135 | goto cleanup; |
| 1136 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1137 | |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1138 | res = 0; /* if no error occurs, this stays 0 to the end */ |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1139 | if (numfields < PyTuple_GET_SIZE(args)) { |
| 1140 | PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most " |
| 1141 | "%zd positional argument%s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1142 | _PyType_Name(Py_TYPE(self)), |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1143 | numfields, numfields == 1 ? "" : "s"); |
| 1144 | res = -1; |
| 1145 | goto cleanup; |
| 1146 | } |
| 1147 | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
| 1148 | /* cannot be reached when fields is NULL */ |
| 1149 | PyObject *name = PySequence_GetItem(fields, i); |
| 1150 | if (!name) { |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1151 | res = -1; |
| 1152 | goto cleanup; |
| 1153 | } |
INADA Naoki | 4c78c52 | 2017-02-24 02:48:17 +0900 | [diff] [blame] | 1154 | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
| 1155 | Py_DECREF(name); |
| 1156 | if (res < 0) |
| 1157 | goto cleanup; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1158 | } |
| 1159 | if (kw) { |
| 1160 | i = 0; /* needed by PyDict_Next */ |
| 1161 | while (PyDict_Next(kw, &i, &key, &value)) { |
| 1162 | res = PyObject_SetAttr(self, key, value); |
| 1163 | if (res < 0) |
| 1164 | goto cleanup; |
| 1165 | } |
| 1166 | } |
| 1167 | cleanup: |
| 1168 | Py_XDECREF(fields); |
| 1169 | return res; |
| 1170 | } |
| 1171 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1172 | /* Pickling support */ |
| 1173 | static PyObject * |
| 1174 | ast_type_reduce(PyObject *self, PyObject *unused) |
| 1175 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1176 | PyObject *dict; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1177 | if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1178 | return NULL; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1179 | } |
| 1180 | if (dict) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 1181 | return Py_BuildValue("O()N", Py_TYPE(self), dict); |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1182 | } |
| 1183 | return Py_BuildValue("O()", Py_TYPE(self)); |
| 1184 | } |
| 1185 | |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1186 | static PyMemberDef ast_type_members[] = { |
| 1187 | {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, |
| 1188 | {NULL} /* Sentinel */ |
| 1189 | }; |
| 1190 | |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1191 | static PyMethodDef ast_type_methods[] = { |
| 1192 | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
| 1193 | {NULL} |
| 1194 | }; |
| 1195 | |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1196 | static PyGetSetDef ast_type_getsets[] = { |
| 1197 | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
| 1198 | {NULL} |
| 1199 | }; |
| 1200 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1201 | static PyType_Slot AST_type_slots[] = { |
| 1202 | {Py_tp_dealloc, ast_dealloc}, |
| 1203 | {Py_tp_getattro, PyObject_GenericGetAttr}, |
| 1204 | {Py_tp_setattro, PyObject_GenericSetAttr}, |
| 1205 | {Py_tp_traverse, ast_traverse}, |
| 1206 | {Py_tp_clear, ast_clear}, |
Eddie Elizondo | 3368f3c | 2019-09-19 09:29:05 -0700 | [diff] [blame] | 1207 | {Py_tp_members, ast_type_members}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1208 | {Py_tp_methods, ast_type_methods}, |
| 1209 | {Py_tp_getset, ast_type_getsets}, |
| 1210 | {Py_tp_init, ast_type_init}, |
| 1211 | {Py_tp_alloc, PyType_GenericAlloc}, |
| 1212 | {Py_tp_new, PyType_GenericNew}, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1213 | {Py_tp_free, PyObject_GC_Del}, |
| 1214 | {0, 0}, |
| 1215 | }; |
| 1216 | |
| 1217 | static PyType_Spec AST_type_spec = { |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1218 | "ast.AST", |
Benjamin Peterson | 7e0dbfb | 2012-03-12 09:46:44 -0700 | [diff] [blame] | 1219 | sizeof(AST_object), |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1220 | 0, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1221 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, |
| 1222 | AST_type_slots |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1223 | }; |
| 1224 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1225 | static PyObject * |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1226 | 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] | 1227 | { |
| 1228 | PyObject *fnames, *result; |
| 1229 | int i; |
Neal Norwitz | ee9b10a | 2008-03-31 05:29:39 +0000 | [diff] [blame] | 1230 | fnames = PyTuple_New(num_fields); |
| 1231 | if (!fnames) return NULL; |
| 1232 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1233 | PyObject *field = PyUnicode_InternFromString(fields[i]); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1234 | if (!field) { |
| 1235 | Py_DECREF(fnames); |
| 1236 | return NULL; |
| 1237 | } |
| 1238 | PyTuple_SET_ITEM(fnames, i, field); |
| 1239 | } |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1240 | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}", |
INADA Naoki | fc48908 | 2017-01-25 22:33:43 +0900 | [diff] [blame] | 1241 | type, base, |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1242 | astmodulestate_global->_fields, fnames, |
| 1243 | astmodulestate_global->__module__, |
Serhiy Storchaka | bace59d | 2020-03-22 20:33:34 +0200 | [diff] [blame] | 1244 | astmodulestate_global->ast, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1245 | astmodulestate_global->__doc__, doc); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1246 | Py_DECREF(fnames); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1247 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1250 | static int |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1251 | 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] | 1252 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1253 | int i, result; |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1254 | PyObject *s, *l = PyTuple_New(num_fields); |
Benjamin Peterson | 3e5cd1d | 2010-06-27 21:45:24 +0000 | [diff] [blame] | 1255 | if (!l) |
| 1256 | return 0; |
| 1257 | for (i = 0; i < num_fields; i++) { |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 1258 | s = PyUnicode_InternFromString(attrs[i]); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1259 | if (!s) { |
| 1260 | Py_DECREF(l); |
| 1261 | return 0; |
| 1262 | } |
Neal Norwitz | 207c9f3 | 2008-03-31 04:42:11 +0000 | [diff] [blame] | 1263 | PyTuple_SET_ITEM(l, i, s); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1264 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1265 | result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1266 | Py_DECREF(l); |
| 1267 | return result; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1270 | /* Conversion AST -> Python */ |
| 1271 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1272 | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
| 1273 | { |
Benjamin Peterson | 77fa937 | 2012-05-15 10:10:27 -0700 | [diff] [blame] | 1274 | Py_ssize_t i, n = asdl_seq_LEN(seq); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1275 | PyObject *result = PyList_New(n); |
| 1276 | PyObject *value; |
| 1277 | if (!result) |
| 1278 | return NULL; |
| 1279 | for (i = 0; i < n; i++) { |
| 1280 | value = func(asdl_seq_GET(seq, i)); |
| 1281 | if (!value) { |
| 1282 | Py_DECREF(result); |
| 1283 | return NULL; |
| 1284 | } |
| 1285 | PyList_SET_ITEM(result, i, value); |
| 1286 | } |
| 1287 | return result; |
| 1288 | } |
| 1289 | |
| 1290 | static PyObject* ast2obj_object(void *o) |
| 1291 | { |
| 1292 | if (!o) |
| 1293 | o = Py_None; |
| 1294 | Py_INCREF((PyObject*)o); |
| 1295 | return (PyObject*)o; |
| 1296 | } |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1297 | #define ast2obj_constant ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1298 | #define ast2obj_identifier ast2obj_object |
| 1299 | #define ast2obj_string ast2obj_object |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1300 | |
Thomas Wouters | a44f3a3 | 2007-02-26 18:20:15 +0000 | [diff] [blame] | 1301 | static PyObject* ast2obj_int(long b) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1302 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 1303 | return PyLong_FromLong(b); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1306 | /* Conversion Python -> AST */ |
| 1307 | |
| 1308 | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
| 1309 | { |
| 1310 | if (obj == Py_None) |
| 1311 | obj = NULL; |
Christian Heimes | 70c94e7 | 2013-07-27 00:33:13 +0200 | [diff] [blame] | 1312 | if (obj) { |
| 1313 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1314 | *out = NULL; |
| 1315 | return -1; |
| 1316 | } |
| 1317 | Py_INCREF(obj); |
| 1318 | } |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1319 | *out = obj; |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1323 | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
| 1324 | { |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1325 | if (PyArena_AddPyObject(arena, obj) < 0) { |
| 1326 | *out = NULL; |
| 1327 | return -1; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1328 | } |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1329 | Py_INCREF(obj); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1330 | *out = obj; |
| 1331 | return 0; |
| 1332 | } |
| 1333 | |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1334 | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1335 | { |
Benjamin Peterson | 180e635 | 2011-07-22 11:09:07 -0500 | [diff] [blame] | 1336 | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
| 1337 | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
Benjamin Peterson | 2193d2b | 2011-07-22 10:50:23 -0500 | [diff] [blame] | 1338 | return 1; |
| 1339 | } |
| 1340 | return obj2ast_object(obj, out, arena); |
| 1341 | } |
| 1342 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 1343 | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
| 1344 | { |
| 1345 | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
| 1346 | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
| 1347 | return 1; |
| 1348 | } |
| 1349 | return obj2ast_object(obj, out, arena); |
| 1350 | } |
| 1351 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1352 | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 1353 | { |
| 1354 | int i; |
| 1355 | if (!PyLong_Check(obj)) { |
Amaury Forgeot d'Arc | 5e8f810 | 2011-11-22 21:52:30 +0100 | [diff] [blame] | 1356 | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1357 | return 1; |
| 1358 | } |
| 1359 | |
Serhiy Storchaka | 56f6e76 | 2015-09-06 21:25:30 +0300 | [diff] [blame] | 1360 | i = _PyLong_AsInt(obj); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1361 | if (i == -1 && PyErr_Occurred()) |
| 1362 | return 1; |
| 1363 | *out = i; |
| 1364 | return 0; |
| 1365 | } |
| 1366 | |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1367 | static int add_ast_fields(void) |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1368 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1369 | PyObject *empty_tuple; |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1370 | empty_tuple = PyTuple_New(0); |
| 1371 | if (!empty_tuple || |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1372 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 || |
| 1373 | PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) { |
Benjamin Peterson | ce825f1 | 2008-10-24 23:11:02 +0000 | [diff] [blame] | 1374 | Py_XDECREF(empty_tuple); |
| 1375 | return -1; |
| 1376 | } |
| 1377 | Py_DECREF(empty_tuple); |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 1381 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 1382 | static int init_types(void) |
| 1383 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1384 | PyObject *m; |
| 1385 | if (PyState_FindModule(&_astmodule) == NULL) { |
| 1386 | m = PyModule_Create(&_astmodule); |
| 1387 | if (!m) return 0; |
| 1388 | PyState_AddModule(m, &_astmodule); |
| 1389 | } |
| 1390 | astmodulestate *state = astmodulestate_global; |
| 1391 | if (state->initialized) return 1; |
| 1392 | if (init_identifiers() < 0) return 0; |
| 1393 | state->AST_type = PyType_FromSpec(&AST_type_spec); |
| 1394 | if (!state->AST_type) return 0; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 1395 | if (add_ast_fields() < 0) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1396 | state->mod_type = make_type("mod", state->AST_type, NULL, 0, |
| 1397 | "mod = Module(stmt* body, type_ignore* type_ignores)\n" |
| 1398 | " | Interactive(stmt* body)\n" |
| 1399 | " | Expression(expr body)\n" |
| 1400 | " | FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1401 | if (!state->mod_type) return 0; |
| 1402 | if (!add_attributes(state->mod_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1403 | state->Module_type = make_type("Module", state->mod_type, Module_fields, 2, |
| 1404 | "Module(stmt* body, type_ignore* type_ignores)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1405 | if (!state->Module_type) return 0; |
| 1406 | state->Interactive_type = make_type("Interactive", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1407 | Interactive_fields, 1, |
| 1408 | "Interactive(stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1409 | if (!state->Interactive_type) return 0; |
| 1410 | state->Expression_type = make_type("Expression", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1411 | Expression_fields, 1, |
| 1412 | "Expression(expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1413 | if (!state->Expression_type) return 0; |
| 1414 | state->FunctionType_type = make_type("FunctionType", state->mod_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1415 | FunctionType_fields, 2, |
| 1416 | "FunctionType(expr* argtypes, expr returns)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1417 | if (!state->FunctionType_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1418 | state->stmt_type = make_type("stmt", state->AST_type, NULL, 0, |
| 1419 | "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1420 | " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n" |
| 1421 | " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n" |
| 1422 | " | Return(expr? value)\n" |
| 1423 | " | Delete(expr* targets)\n" |
| 1424 | " | Assign(expr* targets, expr value, string? type_comment)\n" |
| 1425 | " | AugAssign(expr target, operator op, expr value)\n" |
| 1426 | " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n" |
| 1427 | " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1428 | " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n" |
| 1429 | " | While(expr test, stmt* body, stmt* orelse)\n" |
| 1430 | " | If(expr test, stmt* body, stmt* orelse)\n" |
| 1431 | " | With(withitem* items, stmt* body, string? type_comment)\n" |
| 1432 | " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n" |
| 1433 | " | Raise(expr? exc, expr? cause)\n" |
| 1434 | " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n" |
| 1435 | " | Assert(expr test, expr? msg)\n" |
| 1436 | " | Import(alias* names)\n" |
| 1437 | " | ImportFrom(identifier? module, alias* names, int? level)\n" |
| 1438 | " | Global(identifier* names)\n" |
| 1439 | " | Nonlocal(identifier* names)\n" |
| 1440 | " | Expr(expr value)\n" |
| 1441 | " | Pass\n" |
| 1442 | " | Break\n" |
| 1443 | " | Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1444 | if (!state->stmt_type) return 0; |
| 1445 | if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1446 | if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1) |
| 1447 | return 0; |
| 1448 | if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) == |
| 1449 | -1) |
| 1450 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1451 | state->FunctionDef_type = make_type("FunctionDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1452 | FunctionDef_fields, 6, |
| 1453 | "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] | 1454 | if (!state->FunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1455 | if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) == |
| 1456 | -1) |
| 1457 | return 0; |
| 1458 | if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None) |
| 1459 | == -1) |
| 1460 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1461 | state->AsyncFunctionDef_type = make_type("AsyncFunctionDef", |
| 1462 | state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1463 | AsyncFunctionDef_fields, 6, |
| 1464 | "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] | 1465 | if (!state->AsyncFunctionDef_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1466 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None) |
| 1467 | == -1) |
| 1468 | return 0; |
| 1469 | if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment, |
| 1470 | Py_None) == -1) |
| 1471 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1472 | state->ClassDef_type = make_type("ClassDef", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1473 | ClassDef_fields, 5, |
| 1474 | "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1475 | if (!state->ClassDef_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1476 | state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1, |
| 1477 | "Return(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1478 | if (!state->Return_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1479 | if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1) |
| 1480 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1481 | state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1, |
| 1482 | "Delete(expr* targets)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1483 | if (!state->Delete_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1484 | state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3, |
| 1485 | "Assign(expr* targets, expr value, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1486 | if (!state->Assign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1487 | if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) == |
| 1488 | -1) |
| 1489 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1490 | state->AugAssign_type = make_type("AugAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1491 | AugAssign_fields, 3, |
| 1492 | "AugAssign(expr target, operator op, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1493 | if (!state->AugAssign_type) return 0; |
| 1494 | state->AnnAssign_type = make_type("AnnAssign", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1495 | AnnAssign_fields, 4, |
| 1496 | "AnnAssign(expr target, expr annotation, expr? value, int simple)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1497 | if (!state->AnnAssign_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1498 | if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1) |
| 1499 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1500 | state->For_type = make_type("For", state->stmt_type, For_fields, 5, |
| 1501 | "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1502 | if (!state->For_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1503 | if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1) |
| 1504 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1505 | state->AsyncFor_type = make_type("AsyncFor", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1506 | AsyncFor_fields, 5, |
| 1507 | "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1508 | if (!state->AsyncFor_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1509 | if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) == |
| 1510 | -1) |
| 1511 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1512 | state->While_type = make_type("While", state->stmt_type, While_fields, 3, |
| 1513 | "While(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1514 | if (!state->While_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1515 | state->If_type = make_type("If", state->stmt_type, If_fields, 3, |
| 1516 | "If(expr test, stmt* body, stmt* orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1517 | if (!state->If_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1518 | state->With_type = make_type("With", state->stmt_type, With_fields, 3, |
| 1519 | "With(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1520 | if (!state->With_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1521 | if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1) |
| 1522 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1523 | state->AsyncWith_type = make_type("AsyncWith", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1524 | AsyncWith_fields, 3, |
| 1525 | "AsyncWith(withitem* items, stmt* body, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1526 | if (!state->AsyncWith_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1527 | if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None) |
| 1528 | == -1) |
| 1529 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1530 | state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2, |
| 1531 | "Raise(expr? exc, expr? cause)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1532 | if (!state->Raise_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1533 | if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1) |
| 1534 | return 0; |
| 1535 | if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1) |
| 1536 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1537 | state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4, |
| 1538 | "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1539 | if (!state->Try_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1540 | state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2, |
| 1541 | "Assert(expr test, expr? msg)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1542 | if (!state->Assert_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1543 | if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1) |
| 1544 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1545 | state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1, |
| 1546 | "Import(alias* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1547 | if (!state->Import_type) return 0; |
| 1548 | state->ImportFrom_type = make_type("ImportFrom", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1549 | ImportFrom_fields, 3, |
| 1550 | "ImportFrom(identifier? module, alias* names, int? level)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1551 | if (!state->ImportFrom_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1552 | if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1) |
| 1553 | return 0; |
| 1554 | if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1) |
| 1555 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1556 | state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1, |
| 1557 | "Global(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1558 | if (!state->Global_type) return 0; |
| 1559 | state->Nonlocal_type = make_type("Nonlocal", state->stmt_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1560 | Nonlocal_fields, 1, |
| 1561 | "Nonlocal(identifier* names)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1562 | if (!state->Nonlocal_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1563 | state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1, |
| 1564 | "Expr(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1565 | if (!state->Expr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1566 | state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0, |
| 1567 | "Pass"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1568 | if (!state->Pass_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1569 | state->Break_type = make_type("Break", state->stmt_type, NULL, 0, |
| 1570 | "Break"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1571 | if (!state->Break_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1572 | state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0, |
| 1573 | "Continue"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1574 | if (!state->Continue_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1575 | state->expr_type = make_type("expr", state->AST_type, NULL, 0, |
| 1576 | "expr = BoolOp(boolop op, expr* values)\n" |
| 1577 | " | NamedExpr(expr target, expr value)\n" |
| 1578 | " | BinOp(expr left, operator op, expr right)\n" |
| 1579 | " | UnaryOp(unaryop op, expr operand)\n" |
| 1580 | " | Lambda(arguments args, expr body)\n" |
| 1581 | " | IfExp(expr test, expr body, expr orelse)\n" |
| 1582 | " | Dict(expr* keys, expr* values)\n" |
| 1583 | " | Set(expr* elts)\n" |
| 1584 | " | ListComp(expr elt, comprehension* generators)\n" |
| 1585 | " | SetComp(expr elt, comprehension* generators)\n" |
| 1586 | " | DictComp(expr key, expr value, comprehension* generators)\n" |
| 1587 | " | GeneratorExp(expr elt, comprehension* generators)\n" |
| 1588 | " | Await(expr value)\n" |
| 1589 | " | Yield(expr? value)\n" |
| 1590 | " | YieldFrom(expr value)\n" |
| 1591 | " | Compare(expr left, cmpop* ops, expr* comparators)\n" |
| 1592 | " | Call(expr func, expr* args, keyword* keywords)\n" |
| 1593 | " | FormattedValue(expr value, int? conversion, expr? format_spec)\n" |
| 1594 | " | JoinedStr(expr* values)\n" |
| 1595 | " | Constant(constant value, string? kind)\n" |
| 1596 | " | Attribute(expr value, identifier attr, expr_context ctx)\n" |
| 1597 | " | Subscript(expr value, expr slice, expr_context ctx)\n" |
| 1598 | " | Starred(expr value, expr_context ctx)\n" |
| 1599 | " | Name(identifier id, expr_context ctx)\n" |
| 1600 | " | List(expr* elts, expr_context ctx)\n" |
| 1601 | " | Tuple(expr* elts, expr_context ctx)\n" |
| 1602 | " | Slice(expr? lower, expr? upper, expr? step)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1603 | if (!state->expr_type) return 0; |
| 1604 | if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1605 | if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1) |
| 1606 | return 0; |
| 1607 | if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) == |
| 1608 | -1) |
| 1609 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1610 | state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2, |
| 1611 | "BoolOp(boolop op, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1612 | if (!state->BoolOp_type) return 0; |
| 1613 | state->NamedExpr_type = make_type("NamedExpr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1614 | NamedExpr_fields, 2, |
| 1615 | "NamedExpr(expr target, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1616 | if (!state->NamedExpr_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1617 | state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3, |
| 1618 | "BinOp(expr left, operator op, expr right)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1619 | if (!state->BinOp_type) return 0; |
| 1620 | state->UnaryOp_type = make_type("UnaryOp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1621 | UnaryOp_fields, 2, |
| 1622 | "UnaryOp(unaryop op, expr operand)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1623 | if (!state->UnaryOp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1624 | state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2, |
| 1625 | "Lambda(arguments args, expr body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1626 | if (!state->Lambda_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1627 | state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3, |
| 1628 | "IfExp(expr test, expr body, expr orelse)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1629 | if (!state->IfExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1630 | state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2, |
| 1631 | "Dict(expr* keys, expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1632 | if (!state->Dict_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1633 | state->Set_type = make_type("Set", state->expr_type, Set_fields, 1, |
| 1634 | "Set(expr* elts)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1635 | if (!state->Set_type) return 0; |
| 1636 | state->ListComp_type = make_type("ListComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1637 | ListComp_fields, 2, |
| 1638 | "ListComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1639 | if (!state->ListComp_type) return 0; |
| 1640 | state->SetComp_type = make_type("SetComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1641 | SetComp_fields, 2, |
| 1642 | "SetComp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1643 | if (!state->SetComp_type) return 0; |
| 1644 | state->DictComp_type = make_type("DictComp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1645 | DictComp_fields, 3, |
| 1646 | "DictComp(expr key, expr value, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1647 | if (!state->DictComp_type) return 0; |
| 1648 | state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1649 | GeneratorExp_fields, 2, |
| 1650 | "GeneratorExp(expr elt, comprehension* generators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1651 | if (!state->GeneratorExp_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1652 | state->Await_type = make_type("Await", state->expr_type, Await_fields, 1, |
| 1653 | "Await(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1654 | if (!state->Await_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1655 | state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1, |
| 1656 | "Yield(expr? value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1657 | if (!state->Yield_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1658 | if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1) |
| 1659 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1660 | state->YieldFrom_type = make_type("YieldFrom", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1661 | YieldFrom_fields, 1, |
| 1662 | "YieldFrom(expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1663 | if (!state->YieldFrom_type) return 0; |
| 1664 | state->Compare_type = make_type("Compare", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1665 | Compare_fields, 3, |
| 1666 | "Compare(expr left, cmpop* ops, expr* comparators)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1667 | if (!state->Compare_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1668 | state->Call_type = make_type("Call", state->expr_type, Call_fields, 3, |
| 1669 | "Call(expr func, expr* args, keyword* keywords)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1670 | if (!state->Call_type) return 0; |
| 1671 | state->FormattedValue_type = make_type("FormattedValue", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1672 | FormattedValue_fields, 3, |
| 1673 | "FormattedValue(expr value, int? conversion, expr? format_spec)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1674 | if (!state->FormattedValue_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1675 | if (PyObject_SetAttr(state->FormattedValue_type, state->conversion, |
| 1676 | Py_None) == -1) |
| 1677 | return 0; |
| 1678 | if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec, |
| 1679 | Py_None) == -1) |
| 1680 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1681 | state->JoinedStr_type = make_type("JoinedStr", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1682 | JoinedStr_fields, 1, |
| 1683 | "JoinedStr(expr* values)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1684 | if (!state->JoinedStr_type) return 0; |
| 1685 | state->Constant_type = make_type("Constant", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1686 | Constant_fields, 2, |
| 1687 | "Constant(constant value, string? kind)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1688 | if (!state->Constant_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1689 | if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1) |
| 1690 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1691 | state->Attribute_type = make_type("Attribute", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1692 | Attribute_fields, 3, |
| 1693 | "Attribute(expr value, identifier attr, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1694 | if (!state->Attribute_type) return 0; |
| 1695 | state->Subscript_type = make_type("Subscript", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1696 | Subscript_fields, 3, |
| 1697 | "Subscript(expr value, expr slice, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1698 | if (!state->Subscript_type) return 0; |
| 1699 | state->Starred_type = make_type("Starred", state->expr_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1700 | Starred_fields, 2, |
| 1701 | "Starred(expr value, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1702 | if (!state->Starred_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1703 | state->Name_type = make_type("Name", state->expr_type, Name_fields, 2, |
| 1704 | "Name(identifier id, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1705 | if (!state->Name_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1706 | state->List_type = make_type("List", state->expr_type, List_fields, 2, |
| 1707 | "List(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1708 | if (!state->List_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1709 | state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2, |
| 1710 | "Tuple(expr* elts, expr_context ctx)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1711 | if (!state->Tuple_type) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1712 | state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3, |
| 1713 | "Slice(expr? lower, expr? upper, expr? step)"); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 1714 | if (!state->Slice_type) return 0; |
| 1715 | if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1) |
| 1716 | return 0; |
| 1717 | if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1) |
| 1718 | return 0; |
| 1719 | if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1) |
| 1720 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1721 | 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] | 1722 | 0, |
Serhiy Storchaka | 6b97598 | 2020-03-17 23:41:08 +0200 | [diff] [blame] | 1723 | "expr_context = Load | Store | Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1724 | if (!state->expr_context_type) return 0; |
| 1725 | if (!add_attributes(state->expr_context_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1726 | state->Load_type = make_type("Load", state->expr_context_type, NULL, 0, |
| 1727 | "Load"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1728 | if (!state->Load_type) return 0; |
| 1729 | state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type, |
| 1730 | NULL, NULL); |
| 1731 | if (!state->Load_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1732 | state->Store_type = make_type("Store", state->expr_context_type, NULL, 0, |
| 1733 | "Store"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1734 | if (!state->Store_type) return 0; |
| 1735 | state->Store_singleton = PyType_GenericNew((PyTypeObject |
| 1736 | *)state->Store_type, NULL, NULL); |
| 1737 | if (!state->Store_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1738 | state->Del_type = make_type("Del", state->expr_context_type, NULL, 0, |
| 1739 | "Del"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1740 | if (!state->Del_type) return 0; |
| 1741 | state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type, |
| 1742 | NULL, NULL); |
| 1743 | if (!state->Del_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1744 | state->boolop_type = make_type("boolop", state->AST_type, NULL, 0, |
| 1745 | "boolop = And | Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1746 | if (!state->boolop_type) return 0; |
| 1747 | if (!add_attributes(state->boolop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1748 | state->And_type = make_type("And", state->boolop_type, NULL, 0, |
| 1749 | "And"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1750 | if (!state->And_type) return 0; |
| 1751 | state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type, |
| 1752 | NULL, NULL); |
| 1753 | if (!state->And_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1754 | state->Or_type = make_type("Or", state->boolop_type, NULL, 0, |
| 1755 | "Or"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1756 | if (!state->Or_type) return 0; |
| 1757 | state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type, |
| 1758 | NULL, NULL); |
| 1759 | if (!state->Or_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1760 | state->operator_type = make_type("operator", state->AST_type, NULL, 0, |
| 1761 | "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] | 1762 | if (!state->operator_type) return 0; |
| 1763 | if (!add_attributes(state->operator_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1764 | state->Add_type = make_type("Add", state->operator_type, NULL, 0, |
| 1765 | "Add"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1766 | if (!state->Add_type) return 0; |
| 1767 | state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type, |
| 1768 | NULL, NULL); |
| 1769 | if (!state->Add_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1770 | state->Sub_type = make_type("Sub", state->operator_type, NULL, 0, |
| 1771 | "Sub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1772 | if (!state->Sub_type) return 0; |
| 1773 | state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type, |
| 1774 | NULL, NULL); |
| 1775 | if (!state->Sub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1776 | state->Mult_type = make_type("Mult", state->operator_type, NULL, 0, |
| 1777 | "Mult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1778 | if (!state->Mult_type) return 0; |
| 1779 | state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type, |
| 1780 | NULL, NULL); |
| 1781 | if (!state->Mult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1782 | state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0, |
| 1783 | "MatMult"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1784 | if (!state->MatMult_type) return 0; |
| 1785 | state->MatMult_singleton = PyType_GenericNew((PyTypeObject |
| 1786 | *)state->MatMult_type, NULL, |
| 1787 | NULL); |
| 1788 | if (!state->MatMult_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1789 | state->Div_type = make_type("Div", state->operator_type, NULL, 0, |
| 1790 | "Div"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1791 | if (!state->Div_type) return 0; |
| 1792 | state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type, |
| 1793 | NULL, NULL); |
| 1794 | if (!state->Div_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1795 | state->Mod_type = make_type("Mod", state->operator_type, NULL, 0, |
| 1796 | "Mod"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1797 | if (!state->Mod_type) return 0; |
| 1798 | state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type, |
| 1799 | NULL, NULL); |
| 1800 | if (!state->Mod_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1801 | state->Pow_type = make_type("Pow", state->operator_type, NULL, 0, |
| 1802 | "Pow"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1803 | if (!state->Pow_type) return 0; |
| 1804 | state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type, |
| 1805 | NULL, NULL); |
| 1806 | if (!state->Pow_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1807 | state->LShift_type = make_type("LShift", state->operator_type, NULL, 0, |
| 1808 | "LShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1809 | if (!state->LShift_type) return 0; |
| 1810 | state->LShift_singleton = PyType_GenericNew((PyTypeObject |
| 1811 | *)state->LShift_type, NULL, |
| 1812 | NULL); |
| 1813 | if (!state->LShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1814 | state->RShift_type = make_type("RShift", state->operator_type, NULL, 0, |
| 1815 | "RShift"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1816 | if (!state->RShift_type) return 0; |
| 1817 | state->RShift_singleton = PyType_GenericNew((PyTypeObject |
| 1818 | *)state->RShift_type, NULL, |
| 1819 | NULL); |
| 1820 | if (!state->RShift_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1821 | state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0, |
| 1822 | "BitOr"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1823 | if (!state->BitOr_type) return 0; |
| 1824 | state->BitOr_singleton = PyType_GenericNew((PyTypeObject |
| 1825 | *)state->BitOr_type, NULL, NULL); |
| 1826 | if (!state->BitOr_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1827 | state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0, |
| 1828 | "BitXor"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1829 | if (!state->BitXor_type) return 0; |
| 1830 | state->BitXor_singleton = PyType_GenericNew((PyTypeObject |
| 1831 | *)state->BitXor_type, NULL, |
| 1832 | NULL); |
| 1833 | if (!state->BitXor_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1834 | state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0, |
| 1835 | "BitAnd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1836 | if (!state->BitAnd_type) return 0; |
| 1837 | state->BitAnd_singleton = PyType_GenericNew((PyTypeObject |
| 1838 | *)state->BitAnd_type, NULL, |
| 1839 | NULL); |
| 1840 | if (!state->BitAnd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1841 | state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0, |
| 1842 | "FloorDiv"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1843 | if (!state->FloorDiv_type) return 0; |
| 1844 | state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject |
| 1845 | *)state->FloorDiv_type, NULL, |
| 1846 | NULL); |
| 1847 | if (!state->FloorDiv_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1848 | state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0, |
| 1849 | "unaryop = Invert | Not | UAdd | USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1850 | if (!state->unaryop_type) return 0; |
| 1851 | if (!add_attributes(state->unaryop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1852 | state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0, |
| 1853 | "Invert"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1854 | if (!state->Invert_type) return 0; |
| 1855 | state->Invert_singleton = PyType_GenericNew((PyTypeObject |
| 1856 | *)state->Invert_type, NULL, |
| 1857 | NULL); |
| 1858 | if (!state->Invert_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1859 | state->Not_type = make_type("Not", state->unaryop_type, NULL, 0, |
| 1860 | "Not"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1861 | if (!state->Not_type) return 0; |
| 1862 | state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type, |
| 1863 | NULL, NULL); |
| 1864 | if (!state->Not_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1865 | state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0, |
| 1866 | "UAdd"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1867 | if (!state->UAdd_type) return 0; |
| 1868 | state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type, |
| 1869 | NULL, NULL); |
| 1870 | if (!state->UAdd_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1871 | state->USub_type = make_type("USub", state->unaryop_type, NULL, 0, |
| 1872 | "USub"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1873 | if (!state->USub_type) return 0; |
| 1874 | state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type, |
| 1875 | NULL, NULL); |
| 1876 | if (!state->USub_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1877 | state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0, |
| 1878 | "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1879 | if (!state->cmpop_type) return 0; |
| 1880 | if (!add_attributes(state->cmpop_type, NULL, 0)) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1881 | state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0, |
| 1882 | "Eq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1883 | if (!state->Eq_type) return 0; |
| 1884 | state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type, |
| 1885 | NULL, NULL); |
| 1886 | if (!state->Eq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1887 | state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0, |
| 1888 | "NotEq"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1889 | if (!state->NotEq_type) return 0; |
| 1890 | state->NotEq_singleton = PyType_GenericNew((PyTypeObject |
| 1891 | *)state->NotEq_type, NULL, NULL); |
| 1892 | if (!state->NotEq_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1893 | state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0, |
| 1894 | "Lt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1895 | if (!state->Lt_type) return 0; |
| 1896 | state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type, |
| 1897 | NULL, NULL); |
| 1898 | if (!state->Lt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1899 | state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0, |
| 1900 | "LtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1901 | if (!state->LtE_type) return 0; |
| 1902 | state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type, |
| 1903 | NULL, NULL); |
| 1904 | if (!state->LtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1905 | state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0, |
| 1906 | "Gt"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1907 | if (!state->Gt_type) return 0; |
| 1908 | state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type, |
| 1909 | NULL, NULL); |
| 1910 | if (!state->Gt_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1911 | state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0, |
| 1912 | "GtE"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1913 | if (!state->GtE_type) return 0; |
| 1914 | state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type, |
| 1915 | NULL, NULL); |
| 1916 | if (!state->GtE_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1917 | state->Is_type = make_type("Is", state->cmpop_type, NULL, 0, |
| 1918 | "Is"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1919 | if (!state->Is_type) return 0; |
| 1920 | state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type, |
| 1921 | NULL, NULL); |
| 1922 | if (!state->Is_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1923 | state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0, |
| 1924 | "IsNot"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1925 | if (!state->IsNot_type) return 0; |
| 1926 | state->IsNot_singleton = PyType_GenericNew((PyTypeObject |
| 1927 | *)state->IsNot_type, NULL, NULL); |
| 1928 | if (!state->IsNot_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1929 | state->In_type = make_type("In", state->cmpop_type, NULL, 0, |
| 1930 | "In"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1931 | if (!state->In_type) return 0; |
| 1932 | state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type, |
| 1933 | NULL, NULL); |
| 1934 | if (!state->In_singleton) return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1935 | state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0, |
| 1936 | "NotIn"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1937 | if (!state->NotIn_type) return 0; |
| 1938 | state->NotIn_singleton = PyType_GenericNew((PyTypeObject |
| 1939 | *)state->NotIn_type, NULL, NULL); |
| 1940 | if (!state->NotIn_singleton) return 0; |
| 1941 | state->comprehension_type = make_type("comprehension", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1942 | comprehension_fields, 4, |
| 1943 | "comprehension(expr target, expr iter, expr* ifs, int is_async)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1944 | if (!state->comprehension_type) return 0; |
| 1945 | if (!add_attributes(state->comprehension_type, NULL, 0)) return 0; |
| 1946 | state->excepthandler_type = make_type("excepthandler", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1947 | NULL, 0, |
| 1948 | "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1949 | if (!state->excepthandler_type) return 0; |
| 1950 | if (!add_attributes(state->excepthandler_type, excepthandler_attributes, |
| 1951 | 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1952 | if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None) |
| 1953 | == -1) |
| 1954 | return 0; |
| 1955 | if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset, |
| 1956 | Py_None) == -1) |
| 1957 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1958 | state->ExceptHandler_type = make_type("ExceptHandler", |
| 1959 | state->excepthandler_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1960 | ExceptHandler_fields, 3, |
| 1961 | "ExceptHandler(expr? type, identifier? name, stmt* body)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1962 | if (!state->ExceptHandler_type) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1963 | if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1) |
| 1964 | return 0; |
| 1965 | if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1) |
| 1966 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1967 | state->arguments_type = make_type("arguments", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1968 | arguments_fields, 7, |
| 1969 | "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] | 1970 | if (!state->arguments_type) return 0; |
| 1971 | if (!add_attributes(state->arguments_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1972 | if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1) |
| 1973 | return 0; |
| 1974 | if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1) |
| 1975 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1976 | state->arg_type = make_type("arg", state->AST_type, arg_fields, 3, |
| 1977 | "arg(identifier arg, expr? annotation, string? type_comment)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1978 | if (!state->arg_type) return 0; |
| 1979 | if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1980 | if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1) |
| 1981 | return 0; |
| 1982 | if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1) |
| 1983 | return 0; |
| 1984 | if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1) |
| 1985 | return 0; |
| 1986 | if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1) |
| 1987 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1988 | state->keyword_type = make_type("keyword", state->AST_type, keyword_fields, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 1989 | 2, |
| 1990 | "keyword(identifier? arg, expr value)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 1991 | if (!state->keyword_type) return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1992 | if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 1993 | if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1) |
| 1994 | return 0; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 1995 | if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1) |
| 1996 | return 0; |
| 1997 | if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None) |
| 1998 | == -1) |
| 1999 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2000 | state->alias_type = make_type("alias", state->AST_type, alias_fields, 2, |
| 2001 | "alias(identifier name, identifier? asname)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2002 | if (!state->alias_type) return 0; |
| 2003 | if (!add_attributes(state->alias_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2004 | if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1) |
| 2005 | return 0; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2006 | state->withitem_type = make_type("withitem", state->AST_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2007 | withitem_fields, 2, |
| 2008 | "withitem(expr context_expr, expr? optional_vars)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2009 | if (!state->withitem_type) return 0; |
| 2010 | if (!add_attributes(state->withitem_type, NULL, 0)) return 0; |
Serhiy Storchaka | b7e9525 | 2020-03-10 00:07:47 +0200 | [diff] [blame] | 2011 | if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None) |
| 2012 | == -1) |
| 2013 | return 0; |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2014 | state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0, |
| 2015 | "type_ignore = TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2016 | if (!state->type_ignore_type) return 0; |
| 2017 | if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0; |
| 2018 | state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type, |
Batuhan Taşkaya | 4ab362c | 2020-03-16 11:12:53 +0300 | [diff] [blame] | 2019 | TypeIgnore_fields, 2, |
| 2020 | "TypeIgnore(int lineno, string tag)"); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 2021 | if (!state->TypeIgnore_type) return 0; |
| 2022 | state->initialized = 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2023 | return 1; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 2024 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 2025 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2026 | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
| 2027 | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
| 2028 | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
| 2029 | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
| 2030 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2031 | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
| 2032 | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
| 2033 | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
| 2034 | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
| 2035 | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
| 2036 | arena); |
| 2037 | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
| 2038 | arena); |
| 2039 | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
| 2040 | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
| 2041 | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
| 2042 | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 2043 | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2044 | static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* |
| 2045 | arena); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 2046 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2047 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2048 | Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2049 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2050 | mod_ty p; |
| 2051 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2052 | if (!p) |
| 2053 | return NULL; |
| 2054 | p->kind = Module_kind; |
| 2055 | p->v.Module.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2056 | p->v.Module.type_ignores = type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2057 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2061 | Interactive(asdl_seq * body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2062 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2063 | mod_ty p; |
| 2064 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2065 | if (!p) |
| 2066 | return NULL; |
| 2067 | p->kind = Interactive_kind; |
| 2068 | p->v.Interactive.body = body; |
| 2069 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | mod_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 2073 | Expression(expr_ty body, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2074 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2075 | mod_ty p; |
| 2076 | if (!body) { |
| 2077 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2078 | "field 'body' is required for Expression"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2079 | return NULL; |
| 2080 | } |
| 2081 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2082 | if (!p) |
| 2083 | return NULL; |
| 2084 | p->kind = Expression_kind; |
| 2085 | p->v.Expression.body = body; |
| 2086 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | mod_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2090 | FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena) |
| 2091 | { |
| 2092 | mod_ty p; |
| 2093 | if (!returns) { |
| 2094 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2095 | "field 'returns' is required for FunctionType"); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2096 | return NULL; |
| 2097 | } |
| 2098 | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2099 | if (!p) |
| 2100 | return NULL; |
| 2101 | p->kind = FunctionType_kind; |
| 2102 | p->v.FunctionType.argtypes = argtypes; |
| 2103 | p->v.FunctionType.returns = returns; |
| 2104 | return p; |
| 2105 | } |
| 2106 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2107 | stmt_ty |
| 2108 | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2109 | decorator_list, expr_ty returns, string type_comment, int lineno, |
| 2110 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2111 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2112 | stmt_ty p; |
| 2113 | if (!name) { |
| 2114 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2115 | "field 'name' is required for FunctionDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2116 | return NULL; |
| 2117 | } |
| 2118 | if (!args) { |
| 2119 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2120 | "field 'args' is required for FunctionDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2121 | return NULL; |
| 2122 | } |
| 2123 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2124 | if (!p) |
| 2125 | return NULL; |
| 2126 | p->kind = FunctionDef_kind; |
| 2127 | p->v.FunctionDef.name = name; |
| 2128 | p->v.FunctionDef.args = args; |
| 2129 | p->v.FunctionDef.body = body; |
| 2130 | p->v.FunctionDef.decorator_list = decorator_list; |
| 2131 | p->v.FunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2132 | p->v.FunctionDef.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2133 | p->lineno = lineno; |
| 2134 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2135 | p->end_lineno = end_lineno; |
| 2136 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2137 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | stmt_ty |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2141 | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2142 | * decorator_list, expr_ty returns, string type_comment, int |
| 2143 | lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2144 | PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2145 | { |
| 2146 | stmt_ty p; |
| 2147 | if (!name) { |
| 2148 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2149 | "field 'name' is required for AsyncFunctionDef"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2150 | return NULL; |
| 2151 | } |
| 2152 | if (!args) { |
| 2153 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2154 | "field 'args' is required for AsyncFunctionDef"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2155 | return NULL; |
| 2156 | } |
| 2157 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2158 | if (!p) |
| 2159 | return NULL; |
| 2160 | p->kind = AsyncFunctionDef_kind; |
| 2161 | p->v.AsyncFunctionDef.name = name; |
| 2162 | p->v.AsyncFunctionDef.args = args; |
| 2163 | p->v.AsyncFunctionDef.body = body; |
| 2164 | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
| 2165 | p->v.AsyncFunctionDef.returns = returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2166 | p->v.AsyncFunctionDef.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2167 | p->lineno = lineno; |
| 2168 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2169 | p->end_lineno = end_lineno; |
| 2170 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2171 | return p; |
| 2172 | } |
| 2173 | |
| 2174 | stmt_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 2175 | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2176 | body, asdl_seq * decorator_list, int lineno, int col_offset, int |
| 2177 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2178 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2179 | stmt_ty p; |
| 2180 | if (!name) { |
| 2181 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2182 | "field 'name' is required for ClassDef"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2183 | return NULL; |
| 2184 | } |
| 2185 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2186 | if (!p) |
| 2187 | return NULL; |
| 2188 | p->kind = ClassDef_kind; |
| 2189 | p->v.ClassDef.name = name; |
| 2190 | p->v.ClassDef.bases = bases; |
| 2191 | p->v.ClassDef.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2192 | p->v.ClassDef.body = body; |
| 2193 | p->v.ClassDef.decorator_list = decorator_list; |
| 2194 | p->lineno = lineno; |
| 2195 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2196 | p->end_lineno = end_lineno; |
| 2197 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2198 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2202 | Return(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2203 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2204 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2205 | stmt_ty p; |
| 2206 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2207 | if (!p) |
| 2208 | return NULL; |
| 2209 | p->kind = Return_kind; |
| 2210 | p->v.Return.value = value; |
| 2211 | p->lineno = lineno; |
| 2212 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2213 | p->end_lineno = end_lineno; |
| 2214 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2215 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2219 | Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int |
| 2220 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2221 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2222 | stmt_ty p; |
| 2223 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2224 | if (!p) |
| 2225 | return NULL; |
| 2226 | p->kind = Delete_kind; |
| 2227 | p->v.Delete.targets = targets; |
| 2228 | p->lineno = lineno; |
| 2229 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2230 | p->end_lineno = end_lineno; |
| 2231 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2232 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2236 | Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int |
| 2237 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2238 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2239 | stmt_ty p; |
| 2240 | if (!value) { |
| 2241 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2242 | "field 'value' is required for Assign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2243 | return NULL; |
| 2244 | } |
| 2245 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2246 | if (!p) |
| 2247 | return NULL; |
| 2248 | p->kind = Assign_kind; |
| 2249 | p->v.Assign.targets = targets; |
| 2250 | p->v.Assign.value = value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2251 | p->v.Assign.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2252 | p->lineno = lineno; |
| 2253 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2254 | p->end_lineno = end_lineno; |
| 2255 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2256 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2260 | 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] | 2261 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2262 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2263 | stmt_ty p; |
| 2264 | if (!target) { |
| 2265 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2266 | "field 'target' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2267 | return NULL; |
| 2268 | } |
| 2269 | if (!op) { |
| 2270 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2271 | "field 'op' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2272 | return NULL; |
| 2273 | } |
| 2274 | if (!value) { |
| 2275 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2276 | "field 'value' is required for AugAssign"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2277 | return NULL; |
| 2278 | } |
| 2279 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2280 | if (!p) |
| 2281 | return NULL; |
| 2282 | p->kind = AugAssign_kind; |
| 2283 | p->v.AugAssign.target = target; |
| 2284 | p->v.AugAssign.op = op; |
| 2285 | p->v.AugAssign.value = value; |
| 2286 | p->lineno = lineno; |
| 2287 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2288 | p->end_lineno = end_lineno; |
| 2289 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2290 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | stmt_ty |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2294 | 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] | 2295 | lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2296 | *arena) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2297 | { |
| 2298 | stmt_ty p; |
| 2299 | if (!target) { |
| 2300 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2301 | "field 'target' is required for AnnAssign"); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2302 | return NULL; |
| 2303 | } |
| 2304 | if (!annotation) { |
| 2305 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2306 | "field 'annotation' is required for AnnAssign"); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2307 | return NULL; |
| 2308 | } |
| 2309 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2310 | if (!p) |
| 2311 | return NULL; |
| 2312 | p->kind = AnnAssign_kind; |
| 2313 | p->v.AnnAssign.target = target; |
| 2314 | p->v.AnnAssign.annotation = annotation; |
| 2315 | p->v.AnnAssign.value = value; |
| 2316 | p->v.AnnAssign.simple = simple; |
| 2317 | p->lineno = lineno; |
| 2318 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2319 | p->end_lineno = end_lineno; |
| 2320 | p->end_col_offset = end_col_offset; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 2321 | return p; |
| 2322 | } |
| 2323 | |
| 2324 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2325 | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string |
| 2326 | type_comment, int lineno, int col_offset, int end_lineno, int |
| 2327 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2328 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2329 | stmt_ty p; |
| 2330 | if (!target) { |
| 2331 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2332 | "field 'target' is required for For"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2333 | return NULL; |
| 2334 | } |
| 2335 | if (!iter) { |
| 2336 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2337 | "field 'iter' is required for For"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2338 | return NULL; |
| 2339 | } |
| 2340 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2341 | if (!p) |
| 2342 | return NULL; |
| 2343 | p->kind = For_kind; |
| 2344 | p->v.For.target = target; |
| 2345 | p->v.For.iter = iter; |
| 2346 | p->v.For.body = body; |
| 2347 | p->v.For.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2348 | p->v.For.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2349 | p->lineno = lineno; |
| 2350 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2351 | p->end_lineno = end_lineno; |
| 2352 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2353 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2357 | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, |
| 2358 | string type_comment, int lineno, int col_offset, int end_lineno, int |
| 2359 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2360 | { |
| 2361 | stmt_ty p; |
| 2362 | if (!target) { |
| 2363 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2364 | "field 'target' is required for AsyncFor"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2365 | return NULL; |
| 2366 | } |
| 2367 | if (!iter) { |
| 2368 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2369 | "field 'iter' is required for AsyncFor"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2370 | return NULL; |
| 2371 | } |
| 2372 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2373 | if (!p) |
| 2374 | return NULL; |
| 2375 | p->kind = AsyncFor_kind; |
| 2376 | p->v.AsyncFor.target = target; |
| 2377 | p->v.AsyncFor.iter = iter; |
| 2378 | p->v.AsyncFor.body = body; |
| 2379 | p->v.AsyncFor.orelse = orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2380 | p->v.AsyncFor.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2381 | p->lineno = lineno; |
| 2382 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2383 | p->end_lineno = end_lineno; |
| 2384 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2385 | return p; |
| 2386 | } |
| 2387 | |
| 2388 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2389 | 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] | 2390 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2391 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2392 | stmt_ty p; |
| 2393 | if (!test) { |
| 2394 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2395 | "field 'test' is required for While"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2396 | return NULL; |
| 2397 | } |
| 2398 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2399 | if (!p) |
| 2400 | return NULL; |
| 2401 | p->kind = While_kind; |
| 2402 | p->v.While.test = test; |
| 2403 | p->v.While.body = body; |
| 2404 | p->v.While.orelse = orelse; |
| 2405 | p->lineno = lineno; |
| 2406 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2407 | p->end_lineno = end_lineno; |
| 2408 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2409 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2413 | 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] | 2414 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2415 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2416 | stmt_ty p; |
| 2417 | if (!test) { |
| 2418 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2419 | "field 'test' is required for If"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2420 | return NULL; |
| 2421 | } |
| 2422 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2423 | if (!p) |
| 2424 | return NULL; |
| 2425 | p->kind = If_kind; |
| 2426 | p->v.If.test = test; |
| 2427 | p->v.If.body = body; |
| 2428 | p->v.If.orelse = orelse; |
| 2429 | p->lineno = lineno; |
| 2430 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2431 | p->end_lineno = end_lineno; |
| 2432 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2433 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2437 | With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int |
| 2438 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2439 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2440 | stmt_ty p; |
| 2441 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2442 | if (!p) |
| 2443 | return NULL; |
| 2444 | p->kind = With_kind; |
| 2445 | p->v.With.items = items; |
| 2446 | p->v.With.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2447 | p->v.With.type_comment = type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2448 | p->lineno = lineno; |
| 2449 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2450 | p->end_lineno = end_lineno; |
| 2451 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2452 | return p; |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | stmt_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2456 | AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, |
| 2457 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2458 | { |
| 2459 | stmt_ty p; |
| 2460 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2461 | if (!p) |
| 2462 | return NULL; |
| 2463 | p->kind = AsyncWith_kind; |
| 2464 | p->v.AsyncWith.items = items; |
| 2465 | p->v.AsyncWith.body = body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 2466 | p->v.AsyncWith.type_comment = type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2467 | p->lineno = lineno; |
| 2468 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2469 | p->end_lineno = end_lineno; |
| 2470 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2471 | return p; |
| 2472 | } |
| 2473 | |
| 2474 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2475 | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno, |
| 2476 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2477 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2478 | stmt_ty p; |
| 2479 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2480 | if (!p) |
| 2481 | return NULL; |
| 2482 | p->kind = Raise_kind; |
| 2483 | p->v.Raise.exc = exc; |
| 2484 | p->v.Raise.cause = cause; |
| 2485 | p->lineno = lineno; |
| 2486 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2487 | p->end_lineno = end_lineno; |
| 2488 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2489 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | stmt_ty |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 2493 | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2494 | finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2495 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2496 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2497 | stmt_ty p; |
| 2498 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2499 | if (!p) |
| 2500 | return NULL; |
| 2501 | p->kind = Try_kind; |
| 2502 | p->v.Try.body = body; |
| 2503 | p->v.Try.handlers = handlers; |
| 2504 | p->v.Try.orelse = orelse; |
| 2505 | p->v.Try.finalbody = finalbody; |
| 2506 | p->lineno = lineno; |
| 2507 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2508 | p->end_lineno = end_lineno; |
| 2509 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2510 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2514 | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno, |
| 2515 | int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2516 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2517 | stmt_ty p; |
| 2518 | if (!test) { |
| 2519 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2520 | "field 'test' is required for Assert"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2521 | return NULL; |
| 2522 | } |
| 2523 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2524 | if (!p) |
| 2525 | return NULL; |
| 2526 | p->kind = Assert_kind; |
| 2527 | p->v.Assert.test = test; |
| 2528 | p->v.Assert.msg = msg; |
| 2529 | p->lineno = lineno; |
| 2530 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2531 | p->end_lineno = end_lineno; |
| 2532 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2533 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2537 | Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2538 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2539 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2540 | stmt_ty p; |
| 2541 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2542 | if (!p) |
| 2543 | return NULL; |
| 2544 | p->kind = Import_kind; |
| 2545 | p->v.Import.names = names; |
| 2546 | p->lineno = lineno; |
| 2547 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2548 | p->end_lineno = end_lineno; |
| 2549 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2550 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | stmt_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2554 | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2555 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2556 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2557 | stmt_ty p; |
| 2558 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2559 | if (!p) |
| 2560 | return NULL; |
| 2561 | p->kind = ImportFrom_kind; |
| 2562 | p->v.ImportFrom.module = module; |
| 2563 | p->v.ImportFrom.names = names; |
| 2564 | p->v.ImportFrom.level = level; |
| 2565 | p->lineno = lineno; |
| 2566 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2567 | p->end_lineno = end_lineno; |
| 2568 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2569 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2573 | Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2574 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2575 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2576 | stmt_ty p; |
| 2577 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2578 | if (!p) |
| 2579 | return NULL; |
| 2580 | p->kind = Global_kind; |
| 2581 | p->v.Global.names = names; |
| 2582 | p->lineno = lineno; |
| 2583 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2584 | p->end_lineno = end_lineno; |
| 2585 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2586 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2590 | Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int |
| 2591 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2592 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2593 | stmt_ty p; |
| 2594 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2595 | if (!p) |
| 2596 | return NULL; |
| 2597 | p->kind = Nonlocal_kind; |
| 2598 | p->v.Nonlocal.names = names; |
| 2599 | p->lineno = lineno; |
| 2600 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2601 | p->end_lineno = end_lineno; |
| 2602 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2603 | return p; |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2607 | Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2608 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2609 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2610 | stmt_ty p; |
| 2611 | if (!value) { |
| 2612 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2613 | "field 'value' is required for Expr"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2614 | return NULL; |
| 2615 | } |
| 2616 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2617 | if (!p) |
| 2618 | return NULL; |
| 2619 | p->kind = Expr_kind; |
| 2620 | p->v.Expr.value = value; |
| 2621 | p->lineno = lineno; |
| 2622 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2623 | p->end_lineno = end_lineno; |
| 2624 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2625 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2629 | Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2630 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2631 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2632 | stmt_ty p; |
| 2633 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2634 | if (!p) |
| 2635 | return NULL; |
| 2636 | p->kind = Pass_kind; |
| 2637 | p->lineno = lineno; |
| 2638 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2639 | p->end_lineno = end_lineno; |
| 2640 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2641 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2645 | Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena |
| 2646 | *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2647 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2648 | stmt_ty p; |
| 2649 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2650 | if (!p) |
| 2651 | return NULL; |
| 2652 | p->kind = Break_kind; |
| 2653 | p->lineno = lineno; |
| 2654 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2655 | p->end_lineno = end_lineno; |
| 2656 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2657 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | stmt_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2661 | Continue(int lineno, int col_offset, int end_lineno, int end_col_offset, |
| 2662 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2663 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2664 | stmt_ty p; |
| 2665 | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2666 | if (!p) |
| 2667 | return NULL; |
| 2668 | p->kind = Continue_kind; |
| 2669 | p->lineno = lineno; |
| 2670 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2671 | p->end_lineno = end_lineno; |
| 2672 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2673 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2677 | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int |
| 2678 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2679 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2680 | expr_ty p; |
| 2681 | if (!op) { |
| 2682 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2683 | "field 'op' is required for BoolOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2684 | return NULL; |
| 2685 | } |
| 2686 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2687 | if (!p) |
| 2688 | return NULL; |
| 2689 | p->kind = BoolOp_kind; |
| 2690 | p->v.BoolOp.op = op; |
| 2691 | p->v.BoolOp.values = values; |
| 2692 | p->lineno = lineno; |
| 2693 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2694 | p->end_lineno = end_lineno; |
| 2695 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2696 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | expr_ty |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2700 | NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int |
| 2701 | end_lineno, int end_col_offset, PyArena *arena) |
| 2702 | { |
| 2703 | expr_ty p; |
| 2704 | if (!target) { |
| 2705 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2706 | "field 'target' is required for NamedExpr"); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2707 | return NULL; |
| 2708 | } |
| 2709 | if (!value) { |
| 2710 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2711 | "field 'value' is required for NamedExpr"); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 2712 | return NULL; |
| 2713 | } |
| 2714 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2715 | if (!p) |
| 2716 | return NULL; |
| 2717 | p->kind = NamedExpr_kind; |
| 2718 | p->v.NamedExpr.target = target; |
| 2719 | p->v.NamedExpr.value = value; |
| 2720 | p->lineno = lineno; |
| 2721 | p->col_offset = col_offset; |
| 2722 | p->end_lineno = end_lineno; |
| 2723 | p->end_col_offset = end_col_offset; |
| 2724 | return p; |
| 2725 | } |
| 2726 | |
| 2727 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2728 | 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] | 2729 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2730 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2731 | expr_ty p; |
| 2732 | if (!left) { |
| 2733 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2734 | "field 'left' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2735 | return NULL; |
| 2736 | } |
| 2737 | if (!op) { |
| 2738 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2739 | "field 'op' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2740 | return NULL; |
| 2741 | } |
| 2742 | if (!right) { |
| 2743 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2744 | "field 'right' is required for BinOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2745 | return NULL; |
| 2746 | } |
| 2747 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2748 | if (!p) |
| 2749 | return NULL; |
| 2750 | p->kind = BinOp_kind; |
| 2751 | p->v.BinOp.left = left; |
| 2752 | p->v.BinOp.op = op; |
| 2753 | p->v.BinOp.right = right; |
| 2754 | p->lineno = lineno; |
| 2755 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2756 | p->end_lineno = end_lineno; |
| 2757 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2758 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2762 | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int |
| 2763 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2764 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2765 | expr_ty p; |
| 2766 | if (!op) { |
| 2767 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2768 | "field 'op' is required for UnaryOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2769 | return NULL; |
| 2770 | } |
| 2771 | if (!operand) { |
| 2772 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2773 | "field 'operand' is required for UnaryOp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2774 | return NULL; |
| 2775 | } |
| 2776 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2777 | if (!p) |
| 2778 | return NULL; |
| 2779 | p->kind = UnaryOp_kind; |
| 2780 | p->v.UnaryOp.op = op; |
| 2781 | p->v.UnaryOp.operand = operand; |
| 2782 | p->lineno = lineno; |
| 2783 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2784 | p->end_lineno = end_lineno; |
| 2785 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2786 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2790 | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int |
| 2791 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2792 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2793 | expr_ty p; |
| 2794 | if (!args) { |
| 2795 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2796 | "field 'args' is required for Lambda"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2797 | return NULL; |
| 2798 | } |
| 2799 | if (!body) { |
| 2800 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2801 | "field 'body' is required for Lambda"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2802 | return NULL; |
| 2803 | } |
| 2804 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2805 | if (!p) |
| 2806 | return NULL; |
| 2807 | p->kind = Lambda_kind; |
| 2808 | p->v.Lambda.args = args; |
| 2809 | p->v.Lambda.body = body; |
| 2810 | p->lineno = lineno; |
| 2811 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2812 | p->end_lineno = end_lineno; |
| 2813 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2814 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2818 | 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] | 2819 | int end_lineno, int end_col_offset, PyArena *arena) |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2820 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2821 | expr_ty p; |
| 2822 | if (!test) { |
| 2823 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2824 | "field 'test' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2825 | return NULL; |
| 2826 | } |
| 2827 | if (!body) { |
| 2828 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2829 | "field 'body' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2830 | return NULL; |
| 2831 | } |
| 2832 | if (!orelse) { |
| 2833 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2834 | "field 'orelse' is required for IfExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2835 | return NULL; |
| 2836 | } |
| 2837 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2838 | if (!p) |
| 2839 | return NULL; |
| 2840 | p->kind = IfExp_kind; |
| 2841 | p->v.IfExp.test = test; |
| 2842 | p->v.IfExp.body = body; |
| 2843 | p->v.IfExp.orelse = orelse; |
| 2844 | p->lineno = lineno; |
| 2845 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2846 | p->end_lineno = end_lineno; |
| 2847 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2848 | return p; |
Thomas Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2852 | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int |
| 2853 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2854 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2855 | expr_ty p; |
| 2856 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2857 | if (!p) |
| 2858 | return NULL; |
| 2859 | p->kind = Dict_kind; |
| 2860 | p->v.Dict.keys = keys; |
| 2861 | p->v.Dict.values = values; |
| 2862 | p->lineno = lineno; |
| 2863 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2864 | p->end_lineno = end_lineno; |
| 2865 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2866 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2870 | Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int |
| 2871 | end_col_offset, PyArena *arena) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2872 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2873 | expr_ty p; |
| 2874 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2875 | if (!p) |
| 2876 | return NULL; |
| 2877 | p->kind = Set_kind; |
| 2878 | p->v.Set.elts = elts; |
| 2879 | p->lineno = lineno; |
| 2880 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2881 | p->end_lineno = end_lineno; |
| 2882 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2883 | return p; |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2887 | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2888 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2889 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2890 | expr_ty p; |
| 2891 | if (!elt) { |
| 2892 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2893 | "field 'elt' is required for ListComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2894 | return NULL; |
| 2895 | } |
| 2896 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2897 | if (!p) |
| 2898 | return NULL; |
| 2899 | p->kind = ListComp_kind; |
| 2900 | p->v.ListComp.elt = elt; |
| 2901 | p->v.ListComp.generators = generators; |
| 2902 | p->lineno = lineno; |
| 2903 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2904 | p->end_lineno = end_lineno; |
| 2905 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2906 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2910 | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int |
| 2911 | end_lineno, int end_col_offset, PyArena *arena) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2912 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2913 | expr_ty p; |
| 2914 | if (!elt) { |
| 2915 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2916 | "field 'elt' is required for SetComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2917 | return NULL; |
| 2918 | } |
| 2919 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2920 | if (!p) |
| 2921 | return NULL; |
| 2922 | p->kind = SetComp_kind; |
| 2923 | p->v.SetComp.elt = elt; |
| 2924 | p->v.SetComp.generators = generators; |
| 2925 | p->lineno = lineno; |
| 2926 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2927 | p->end_lineno = end_lineno; |
| 2928 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2929 | return p; |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | expr_ty |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2933 | 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] | 2934 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2935 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2936 | expr_ty p; |
| 2937 | if (!key) { |
| 2938 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2939 | "field 'key' is required for DictComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2940 | return NULL; |
| 2941 | } |
| 2942 | if (!value) { |
| 2943 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2944 | "field 'value' is required for DictComp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2945 | return NULL; |
| 2946 | } |
| 2947 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2948 | if (!p) |
| 2949 | return NULL; |
| 2950 | p->kind = DictComp_kind; |
| 2951 | p->v.DictComp.key = key; |
| 2952 | p->v.DictComp.value = value; |
| 2953 | p->v.DictComp.generators = generators; |
| 2954 | p->lineno = lineno; |
| 2955 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2956 | p->end_lineno = end_lineno; |
| 2957 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2958 | return p; |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 2962 | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2963 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2964 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2965 | expr_ty p; |
| 2966 | if (!elt) { |
| 2967 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2968 | "field 'elt' is required for GeneratorExp"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2969 | return NULL; |
| 2970 | } |
| 2971 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2972 | if (!p) |
| 2973 | return NULL; |
| 2974 | p->kind = GeneratorExp_kind; |
| 2975 | p->v.GeneratorExp.elt = elt; |
| 2976 | p->v.GeneratorExp.generators = generators; |
| 2977 | p->lineno = lineno; |
| 2978 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2979 | p->end_lineno = end_lineno; |
| 2980 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 2981 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 2985 | Await(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 2986 | end_col_offset, PyArena *arena) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2987 | { |
| 2988 | expr_ty p; |
| 2989 | if (!value) { |
| 2990 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 2991 | "field 'value' is required for Await"); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 2992 | return NULL; |
| 2993 | } |
| 2994 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 2995 | if (!p) |
| 2996 | return NULL; |
| 2997 | p->kind = Await_kind; |
| 2998 | p->v.Await.value = value; |
| 2999 | p->lineno = lineno; |
| 3000 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3001 | p->end_lineno = end_lineno; |
| 3002 | p->end_col_offset = end_col_offset; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3003 | return p; |
| 3004 | } |
| 3005 | |
| 3006 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3007 | Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3008 | end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3009 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3010 | expr_ty p; |
| 3011 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3012 | if (!p) |
| 3013 | return NULL; |
| 3014 | p->kind = Yield_kind; |
| 3015 | p->v.Yield.value = value; |
| 3016 | p->lineno = lineno; |
| 3017 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3018 | p->end_lineno = end_lineno; |
| 3019 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3020 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3024 | YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int |
| 3025 | end_col_offset, PyArena *arena) |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3026 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3027 | expr_ty p; |
| 3028 | if (!value) { |
| 3029 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3030 | "field 'value' is required for YieldFrom"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3031 | return NULL; |
| 3032 | } |
| 3033 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3034 | if (!p) |
| 3035 | return NULL; |
| 3036 | p->kind = YieldFrom_kind; |
| 3037 | p->v.YieldFrom.value = value; |
| 3038 | p->lineno = lineno; |
| 3039 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3040 | p->end_lineno = end_lineno; |
| 3041 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3042 | return p; |
Benjamin Peterson | 527c622 | 2012-01-14 08:58:23 -0500 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | expr_ty |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 3046 | 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] | 3047 | int col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3048 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3049 | expr_ty p; |
| 3050 | if (!left) { |
| 3051 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3052 | "field 'left' is required for Compare"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3053 | return NULL; |
| 3054 | } |
| 3055 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3056 | if (!p) |
| 3057 | return NULL; |
| 3058 | p->kind = Compare_kind; |
| 3059 | p->v.Compare.left = left; |
| 3060 | p->v.Compare.ops = ops; |
| 3061 | p->v.Compare.comparators = comparators; |
| 3062 | p->lineno = lineno; |
| 3063 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3064 | p->end_lineno = end_lineno; |
| 3065 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3066 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | expr_ty |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 3070 | 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] | 3071 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3072 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3073 | expr_ty p; |
| 3074 | if (!func) { |
| 3075 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3076 | "field 'func' is required for Call"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3077 | return NULL; |
| 3078 | } |
| 3079 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3080 | if (!p) |
| 3081 | return NULL; |
| 3082 | p->kind = Call_kind; |
| 3083 | p->v.Call.func = func; |
| 3084 | p->v.Call.args = args; |
| 3085 | p->v.Call.keywords = keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3086 | p->lineno = lineno; |
| 3087 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3088 | p->end_lineno = end_lineno; |
| 3089 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3090 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | expr_ty |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 3094 | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
| 3095 | int col_offset, int end_lineno, int end_col_offset, PyArena |
| 3096 | *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3097 | { |
| 3098 | expr_ty p; |
| 3099 | if (!value) { |
| 3100 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3101 | "field 'value' is required for FormattedValue"); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3102 | return NULL; |
| 3103 | } |
| 3104 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3105 | if (!p) |
| 3106 | return NULL; |
| 3107 | p->kind = FormattedValue_kind; |
| 3108 | p->v.FormattedValue.value = value; |
| 3109 | p->v.FormattedValue.conversion = conversion; |
| 3110 | p->v.FormattedValue.format_spec = format_spec; |
| 3111 | p->lineno = lineno; |
| 3112 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3113 | p->end_lineno = end_lineno; |
| 3114 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3115 | return p; |
| 3116 | } |
| 3117 | |
| 3118 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3119 | JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int |
| 3120 | end_col_offset, PyArena *arena) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3121 | { |
| 3122 | expr_ty p; |
| 3123 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3124 | if (!p) |
| 3125 | return NULL; |
| 3126 | p->kind = JoinedStr_kind; |
| 3127 | p->v.JoinedStr.values = values; |
| 3128 | p->lineno = lineno; |
| 3129 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3130 | p->end_lineno = end_lineno; |
| 3131 | p->end_col_offset = end_col_offset; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 3132 | return p; |
| 3133 | } |
| 3134 | |
| 3135 | expr_ty |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3136 | Constant(constant value, string kind, int lineno, int col_offset, int |
| 3137 | end_lineno, int end_col_offset, PyArena *arena) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3138 | { |
| 3139 | expr_ty p; |
| 3140 | if (!value) { |
| 3141 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3142 | "field 'value' is required for Constant"); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3143 | return NULL; |
| 3144 | } |
| 3145 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3146 | if (!p) |
| 3147 | return NULL; |
| 3148 | p->kind = Constant_kind; |
| 3149 | p->v.Constant.value = value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 3150 | p->v.Constant.kind = kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3151 | p->lineno = lineno; |
| 3152 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3153 | p->end_lineno = end_lineno; |
| 3154 | p->end_col_offset = end_col_offset; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 3155 | return p; |
| 3156 | } |
| 3157 | |
| 3158 | expr_ty |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3159 | 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] | 3160 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3161 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3162 | expr_ty p; |
| 3163 | if (!value) { |
| 3164 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3165 | "field 'value' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3166 | return NULL; |
| 3167 | } |
| 3168 | if (!attr) { |
| 3169 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3170 | "field 'attr' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3171 | return NULL; |
| 3172 | } |
| 3173 | if (!ctx) { |
| 3174 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3175 | "field 'ctx' is required for Attribute"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3176 | return NULL; |
| 3177 | } |
| 3178 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3179 | if (!p) |
| 3180 | return NULL; |
| 3181 | p->kind = Attribute_kind; |
| 3182 | p->v.Attribute.value = value; |
| 3183 | p->v.Attribute.attr = attr; |
| 3184 | p->v.Attribute.ctx = ctx; |
| 3185 | p->lineno = lineno; |
| 3186 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3187 | p->end_lineno = end_lineno; |
| 3188 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3189 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | expr_ty |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3193 | 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] | 3194 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3195 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3196 | expr_ty p; |
| 3197 | if (!value) { |
| 3198 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3199 | "field 'value' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3200 | return NULL; |
| 3201 | } |
| 3202 | if (!slice) { |
| 3203 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3204 | "field 'slice' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3205 | return NULL; |
| 3206 | } |
| 3207 | if (!ctx) { |
| 3208 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3209 | "field 'ctx' is required for Subscript"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3210 | return NULL; |
| 3211 | } |
| 3212 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3213 | if (!p) |
| 3214 | return NULL; |
| 3215 | p->kind = Subscript_kind; |
| 3216 | p->v.Subscript.value = value; |
| 3217 | p->v.Subscript.slice = slice; |
| 3218 | p->v.Subscript.ctx = ctx; |
| 3219 | p->lineno = lineno; |
| 3220 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3221 | p->end_lineno = end_lineno; |
| 3222 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3223 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3227 | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int |
| 3228 | end_lineno, int end_col_offset, PyArena *arena) |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3229 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3230 | expr_ty p; |
| 3231 | if (!value) { |
| 3232 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3233 | "field 'value' is required for Starred"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3234 | return NULL; |
| 3235 | } |
| 3236 | if (!ctx) { |
| 3237 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3238 | "field 'ctx' is required for Starred"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3239 | return NULL; |
| 3240 | } |
| 3241 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3242 | if (!p) |
| 3243 | return NULL; |
| 3244 | p->kind = Starred_kind; |
| 3245 | p->v.Starred.value = value; |
| 3246 | p->v.Starred.ctx = ctx; |
| 3247 | p->lineno = lineno; |
| 3248 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3249 | p->end_lineno = end_lineno; |
| 3250 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3251 | return p; |
Guido van Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3255 | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int |
| 3256 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3257 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3258 | expr_ty p; |
| 3259 | if (!id) { |
| 3260 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3261 | "field 'id' is required for Name"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3262 | return NULL; |
| 3263 | } |
| 3264 | if (!ctx) { |
| 3265 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3266 | "field 'ctx' is required for Name"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3267 | return NULL; |
| 3268 | } |
| 3269 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3270 | if (!p) |
| 3271 | return NULL; |
| 3272 | p->kind = Name_kind; |
| 3273 | p->v.Name.id = id; |
| 3274 | p->v.Name.ctx = ctx; |
| 3275 | p->lineno = lineno; |
| 3276 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3277 | p->end_lineno = end_lineno; |
| 3278 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3279 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3283 | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3284 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3285 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3286 | expr_ty p; |
| 3287 | if (!ctx) { |
| 3288 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3289 | "field 'ctx' is required for List"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3290 | return NULL; |
| 3291 | } |
| 3292 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3293 | if (!p) |
| 3294 | return NULL; |
| 3295 | p->kind = List_kind; |
| 3296 | p->v.List.elts = elts; |
| 3297 | p->v.List.ctx = ctx; |
| 3298 | p->lineno = lineno; |
| 3299 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3300 | p->end_lineno = end_lineno; |
| 3301 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3302 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | expr_ty |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3306 | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int |
| 3307 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3308 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3309 | expr_ty p; |
| 3310 | if (!ctx) { |
| 3311 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3312 | "field 'ctx' is required for Tuple"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3313 | return NULL; |
| 3314 | } |
| 3315 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3316 | if (!p) |
| 3317 | return NULL; |
| 3318 | p->kind = Tuple_kind; |
| 3319 | p->v.Tuple.elts = elts; |
| 3320 | p->v.Tuple.ctx = ctx; |
| 3321 | p->lineno = lineno; |
| 3322 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3323 | p->end_lineno = end_lineno; |
| 3324 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3325 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3328 | expr_ty |
| 3329 | Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset, |
| 3330 | int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3331 | { |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3332 | expr_ty p; |
| 3333 | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3334 | if (!p) |
| 3335 | return NULL; |
| 3336 | p->kind = Slice_kind; |
| 3337 | p->v.Slice.lower = lower; |
| 3338 | p->v.Slice.upper = upper; |
| 3339 | p->v.Slice.step = step; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 3340 | p->lineno = lineno; |
| 3341 | p->col_offset = col_offset; |
| 3342 | p->end_lineno = end_lineno; |
| 3343 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3344 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | comprehension_ty |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3348 | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
| 3349 | PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3350 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3351 | comprehension_ty p; |
| 3352 | if (!target) { |
| 3353 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3354 | "field 'target' is required for comprehension"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3355 | return NULL; |
| 3356 | } |
| 3357 | if (!iter) { |
| 3358 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3359 | "field 'iter' is required for comprehension"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3360 | return NULL; |
| 3361 | } |
| 3362 | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3363 | if (!p) |
| 3364 | return NULL; |
| 3365 | p->target = target; |
| 3366 | p->iter = iter; |
| 3367 | p->ifs = ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 3368 | p->is_async = is_async; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3369 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | excepthandler_ty |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 3373 | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3374 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3375 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3376 | excepthandler_ty p; |
| 3377 | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3378 | if (!p) |
| 3379 | return NULL; |
| 3380 | p->kind = ExceptHandler_kind; |
| 3381 | p->v.ExceptHandler.type = type; |
| 3382 | p->v.ExceptHandler.name = name; |
| 3383 | p->v.ExceptHandler.body = body; |
| 3384 | p->lineno = lineno; |
| 3385 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3386 | p->end_lineno = end_lineno; |
| 3387 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3388 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | arguments_ty |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3392 | arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq * |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3393 | kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq * |
| 3394 | defaults, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3395 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3396 | arguments_ty p; |
| 3397 | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3398 | if (!p) |
| 3399 | return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 3400 | p->posonlyargs = posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 3401 | p->args = args; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3402 | p->vararg = vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3403 | p->kwonlyargs = kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3404 | p->kw_defaults = kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 3405 | p->kwarg = kwarg; |
| 3406 | p->defaults = defaults; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3407 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3408 | } |
| 3409 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3410 | arg_ty |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3411 | arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int |
| 3412 | col_offset, int end_lineno, int end_col_offset, PyArena *arena) |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3413 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3414 | arg_ty p; |
| 3415 | if (!arg) { |
| 3416 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3417 | "field 'arg' is required for arg"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3418 | return NULL; |
| 3419 | } |
| 3420 | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3421 | if (!p) |
| 3422 | return NULL; |
| 3423 | p->arg = arg; |
| 3424 | p->annotation = annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3425 | p->type_comment = type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 3426 | p->lineno = lineno; |
| 3427 | p->col_offset = col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 3428 | p->end_lineno = end_lineno; |
| 3429 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3430 | return p; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 3431 | } |
| 3432 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3433 | keyword_ty |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3434 | keyword(identifier arg, expr_ty value, int lineno, int col_offset, int |
| 3435 | end_lineno, int end_col_offset, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3436 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3437 | keyword_ty p; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3438 | if (!value) { |
| 3439 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3440 | "field 'value' is required for keyword"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3441 | return NULL; |
| 3442 | } |
| 3443 | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3444 | if (!p) |
| 3445 | return NULL; |
| 3446 | p->arg = arg; |
| 3447 | p->value = value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 3448 | p->lineno = lineno; |
| 3449 | p->col_offset = col_offset; |
| 3450 | p->end_lineno = end_lineno; |
| 3451 | p->end_col_offset = end_col_offset; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3452 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | alias_ty |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 3456 | alias(identifier name, identifier asname, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3457 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3458 | alias_ty p; |
| 3459 | if (!name) { |
| 3460 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3461 | "field 'name' is required for alias"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3462 | return NULL; |
| 3463 | } |
| 3464 | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3465 | if (!p) |
| 3466 | return NULL; |
| 3467 | p->name = name; |
| 3468 | p->asname = asname; |
| 3469 | return p; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3472 | withitem_ty |
| 3473 | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
| 3474 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3475 | withitem_ty p; |
| 3476 | if (!context_expr) { |
| 3477 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3478 | "field 'context_expr' is required for withitem"); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3479 | return NULL; |
| 3480 | } |
| 3481 | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3482 | if (!p) |
| 3483 | return NULL; |
| 3484 | p->context_expr = context_expr; |
| 3485 | p->optional_vars = optional_vars; |
| 3486 | return p; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 3487 | } |
| 3488 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3489 | type_ignore_ty |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3490 | TypeIgnore(int lineno, string tag, PyArena *arena) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3491 | { |
| 3492 | type_ignore_ty p; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3493 | if (!tag) { |
| 3494 | PyErr_SetString(PyExc_ValueError, |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 3495 | "field 'tag' is required for TypeIgnore"); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3496 | return NULL; |
| 3497 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3498 | p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 3499 | if (!p) |
| 3500 | return NULL; |
| 3501 | p->kind = TypeIgnore_kind; |
| 3502 | p->v.TypeIgnore.lineno = lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 3503 | p->v.TypeIgnore.tag = tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3504 | return p; |
| 3505 | } |
| 3506 | |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3507 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3508 | PyObject* |
| 3509 | ast2obj_mod(void* _o) |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3510 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3511 | mod_ty o = (mod_ty)_o; |
| 3512 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3513 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3514 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3515 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3516 | } |
Neal Norwitz | 7b5a604 | 2005-11-13 19:14:20 +0000 | [diff] [blame] | 3517 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3518 | switch (o->kind) { |
| 3519 | case Module_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3520 | tp = (PyTypeObject *)astmodulestate_global->Module_type; |
| 3521 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3522 | if (!result) goto failed; |
| 3523 | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
| 3524 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3525 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3526 | goto failed; |
| 3527 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3528 | value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore); |
| 3529 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3530 | if (PyObject_SetAttr(result, astmodulestate_global->type_ignores, |
| 3531 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3532 | goto failed; |
| 3533 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3534 | break; |
| 3535 | case Interactive_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3536 | tp = (PyTypeObject *)astmodulestate_global->Interactive_type; |
| 3537 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3538 | if (!result) goto failed; |
| 3539 | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
| 3540 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3541 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3542 | goto failed; |
| 3543 | Py_DECREF(value); |
| 3544 | break; |
| 3545 | case Expression_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3546 | tp = (PyTypeObject *)astmodulestate_global->Expression_type; |
| 3547 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3548 | if (!result) goto failed; |
| 3549 | value = ast2obj_expr(o->v.Expression.body); |
| 3550 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3551 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3552 | goto failed; |
| 3553 | Py_DECREF(value); |
| 3554 | break; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3555 | case FunctionType_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3556 | tp = (PyTypeObject *)astmodulestate_global->FunctionType_type; |
| 3557 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3558 | if (!result) goto failed; |
| 3559 | value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr); |
| 3560 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3561 | if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) == |
| 3562 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3563 | goto failed; |
| 3564 | Py_DECREF(value); |
| 3565 | value = ast2obj_expr(o->v.FunctionType.returns); |
| 3566 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3567 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3568 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3569 | goto failed; |
| 3570 | Py_DECREF(value); |
| 3571 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3572 | } |
| 3573 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3574 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3575 | Py_XDECREF(value); |
| 3576 | Py_XDECREF(result); |
| 3577 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3580 | PyObject* |
| 3581 | ast2obj_stmt(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3582 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3583 | stmt_ty o = (stmt_ty)_o; |
| 3584 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3585 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3586 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 3587 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3588 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 3589 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3590 | switch (o->kind) { |
| 3591 | case FunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3592 | tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type; |
| 3593 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3594 | if (!result) goto failed; |
| 3595 | value = ast2obj_identifier(o->v.FunctionDef.name); |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 3596 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3597 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3598 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3599 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3600 | value = ast2obj_arguments(o->v.FunctionDef.args); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 3601 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3602 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3603 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 3604 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3605 | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
| 3606 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3607 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3608 | goto failed; |
| 3609 | Py_DECREF(value); |
| 3610 | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
| 3611 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3612 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3613 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3614 | goto failed; |
| 3615 | Py_DECREF(value); |
| 3616 | value = ast2obj_expr(o->v.FunctionDef.returns); |
| 3617 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3618 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3619 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3620 | goto failed; |
| 3621 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3622 | value = ast2obj_string(o->v.FunctionDef.type_comment); |
| 3623 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3624 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3625 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3626 | goto failed; |
| 3627 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3628 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3629 | case AsyncFunctionDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3630 | tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type; |
| 3631 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3632 | if (!result) goto failed; |
| 3633 | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
| 3634 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3635 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3636 | goto failed; |
| 3637 | Py_DECREF(value); |
| 3638 | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
| 3639 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3640 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3641 | goto failed; |
| 3642 | Py_DECREF(value); |
| 3643 | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
| 3644 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3645 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3646 | goto failed; |
| 3647 | Py_DECREF(value); |
| 3648 | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
| 3649 | ast2obj_expr); |
| 3650 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3651 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3652 | value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3653 | goto failed; |
| 3654 | Py_DECREF(value); |
| 3655 | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
| 3656 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3657 | if (PyObject_SetAttr(result, astmodulestate_global->returns, value) == |
| 3658 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3659 | goto failed; |
| 3660 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3661 | value = ast2obj_string(o->v.AsyncFunctionDef.type_comment); |
| 3662 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3663 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3664 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3665 | goto failed; |
| 3666 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3667 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3668 | case ClassDef_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3669 | tp = (PyTypeObject *)astmodulestate_global->ClassDef_type; |
| 3670 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3671 | if (!result) goto failed; |
| 3672 | value = ast2obj_identifier(o->v.ClassDef.name); |
| 3673 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3674 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3675 | goto failed; |
| 3676 | Py_DECREF(value); |
| 3677 | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
| 3678 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3679 | if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3680 | goto failed; |
| 3681 | Py_DECREF(value); |
| 3682 | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
| 3683 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3684 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 3685 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3686 | goto failed; |
| 3687 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3688 | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
| 3689 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3690 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3691 | goto failed; |
| 3692 | Py_DECREF(value); |
| 3693 | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
| 3694 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3695 | if (PyObject_SetAttr(result, astmodulestate_global->decorator_list, |
| 3696 | value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3697 | goto failed; |
| 3698 | Py_DECREF(value); |
| 3699 | break; |
| 3700 | case Return_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3701 | tp = (PyTypeObject *)astmodulestate_global->Return_type; |
| 3702 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3703 | if (!result) goto failed; |
| 3704 | value = ast2obj_expr(o->v.Return.value); |
| 3705 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3706 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3707 | goto failed; |
| 3708 | Py_DECREF(value); |
| 3709 | break; |
| 3710 | case Delete_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3711 | tp = (PyTypeObject *)astmodulestate_global->Delete_type; |
| 3712 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3713 | if (!result) goto failed; |
| 3714 | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
| 3715 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3716 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3717 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3718 | goto failed; |
| 3719 | Py_DECREF(value); |
| 3720 | break; |
| 3721 | case Assign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3722 | tp = (PyTypeObject *)astmodulestate_global->Assign_type; |
| 3723 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3724 | if (!result) goto failed; |
| 3725 | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
| 3726 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3727 | if (PyObject_SetAttr(result, astmodulestate_global->targets, value) == |
| 3728 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3729 | goto failed; |
| 3730 | Py_DECREF(value); |
| 3731 | value = ast2obj_expr(o->v.Assign.value); |
| 3732 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3733 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3734 | goto failed; |
| 3735 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3736 | value = ast2obj_string(o->v.Assign.type_comment); |
| 3737 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3738 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3739 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3740 | goto failed; |
| 3741 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3742 | break; |
| 3743 | case AugAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3744 | tp = (PyTypeObject *)astmodulestate_global->AugAssign_type; |
| 3745 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3746 | if (!result) goto failed; |
| 3747 | value = ast2obj_expr(o->v.AugAssign.target); |
| 3748 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3749 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3750 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3751 | goto failed; |
| 3752 | Py_DECREF(value); |
| 3753 | value = ast2obj_operator(o->v.AugAssign.op); |
| 3754 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3755 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3756 | goto failed; |
| 3757 | Py_DECREF(value); |
| 3758 | value = ast2obj_expr(o->v.AugAssign.value); |
| 3759 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3760 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3761 | goto failed; |
| 3762 | Py_DECREF(value); |
| 3763 | break; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3764 | case AnnAssign_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3765 | tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type; |
| 3766 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3767 | if (!result) goto failed; |
| 3768 | value = ast2obj_expr(o->v.AnnAssign.target); |
| 3769 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3770 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3771 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3772 | goto failed; |
| 3773 | Py_DECREF(value); |
| 3774 | value = ast2obj_expr(o->v.AnnAssign.annotation); |
| 3775 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3776 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) |
| 3777 | == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3778 | goto failed; |
| 3779 | Py_DECREF(value); |
| 3780 | value = ast2obj_expr(o->v.AnnAssign.value); |
| 3781 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3782 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3783 | goto failed; |
| 3784 | Py_DECREF(value); |
| 3785 | value = ast2obj_int(o->v.AnnAssign.simple); |
| 3786 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3787 | if (PyObject_SetAttr(result, astmodulestate_global->simple, value) == |
| 3788 | -1) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 3789 | goto failed; |
| 3790 | Py_DECREF(value); |
| 3791 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3792 | case For_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3793 | tp = (PyTypeObject *)astmodulestate_global->For_type; |
| 3794 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3795 | if (!result) goto failed; |
| 3796 | value = ast2obj_expr(o->v.For.target); |
| 3797 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3798 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3799 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3800 | goto failed; |
| 3801 | Py_DECREF(value); |
| 3802 | value = ast2obj_expr(o->v.For.iter); |
| 3803 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3804 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3805 | goto failed; |
| 3806 | Py_DECREF(value); |
| 3807 | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
| 3808 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3809 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3810 | goto failed; |
| 3811 | Py_DECREF(value); |
| 3812 | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
| 3813 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3814 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3815 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3816 | goto failed; |
| 3817 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3818 | value = ast2obj_string(o->v.For.type_comment); |
| 3819 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3820 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3821 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3822 | goto failed; |
| 3823 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3824 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3825 | case AsyncFor_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3826 | tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type; |
| 3827 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3828 | if (!result) goto failed; |
| 3829 | value = ast2obj_expr(o->v.AsyncFor.target); |
| 3830 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3831 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 3832 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3833 | goto failed; |
| 3834 | Py_DECREF(value); |
| 3835 | value = ast2obj_expr(o->v.AsyncFor.iter); |
| 3836 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3837 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3838 | goto failed; |
| 3839 | Py_DECREF(value); |
| 3840 | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
| 3841 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3842 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3843 | goto failed; |
| 3844 | Py_DECREF(value); |
| 3845 | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
| 3846 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3847 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3848 | -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3849 | goto failed; |
| 3850 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3851 | value = ast2obj_string(o->v.AsyncFor.type_comment); |
| 3852 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3853 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3854 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3855 | goto failed; |
| 3856 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3857 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3858 | case While_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3859 | tp = (PyTypeObject *)astmodulestate_global->While_type; |
| 3860 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3861 | if (!result) goto failed; |
| 3862 | value = ast2obj_expr(o->v.While.test); |
| 3863 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3864 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3865 | goto failed; |
| 3866 | Py_DECREF(value); |
| 3867 | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
| 3868 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3869 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3870 | goto failed; |
| 3871 | Py_DECREF(value); |
| 3872 | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
| 3873 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3874 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3875 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3876 | goto failed; |
| 3877 | Py_DECREF(value); |
| 3878 | break; |
| 3879 | case If_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3880 | tp = (PyTypeObject *)astmodulestate_global->If_type; |
| 3881 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3882 | if (!result) goto failed; |
| 3883 | value = ast2obj_expr(o->v.If.test); |
| 3884 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3885 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3886 | goto failed; |
| 3887 | Py_DECREF(value); |
| 3888 | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
| 3889 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3890 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3891 | goto failed; |
| 3892 | Py_DECREF(value); |
| 3893 | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
| 3894 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3895 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3896 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3897 | goto failed; |
| 3898 | Py_DECREF(value); |
| 3899 | break; |
| 3900 | case With_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3901 | tp = (PyTypeObject *)astmodulestate_global->With_type; |
| 3902 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3903 | if (!result) goto failed; |
| 3904 | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
| 3905 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3906 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3907 | goto failed; |
| 3908 | Py_DECREF(value); |
| 3909 | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
| 3910 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3911 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3912 | goto failed; |
| 3913 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3914 | value = ast2obj_string(o->v.With.type_comment); |
| 3915 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3916 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3917 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3918 | goto failed; |
| 3919 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3920 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3921 | case AsyncWith_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3922 | tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type; |
| 3923 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3924 | if (!result) goto failed; |
| 3925 | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
| 3926 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3927 | if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3928 | goto failed; |
| 3929 | Py_DECREF(value); |
| 3930 | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
| 3931 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3932 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3933 | goto failed; |
| 3934 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3935 | value = ast2obj_string(o->v.AsyncWith.type_comment); |
| 3936 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3937 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, |
| 3938 | value) == -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 3939 | goto failed; |
| 3940 | Py_DECREF(value); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 3941 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3942 | case Raise_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3943 | tp = (PyTypeObject *)astmodulestate_global->Raise_type; |
| 3944 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3945 | if (!result) goto failed; |
| 3946 | value = ast2obj_expr(o->v.Raise.exc); |
| 3947 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3948 | if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3949 | goto failed; |
| 3950 | Py_DECREF(value); |
| 3951 | value = ast2obj_expr(o->v.Raise.cause); |
| 3952 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3953 | if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3954 | goto failed; |
| 3955 | Py_DECREF(value); |
| 3956 | break; |
| 3957 | case Try_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3958 | tp = (PyTypeObject *)astmodulestate_global->Try_type; |
| 3959 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3960 | if (!result) goto failed; |
| 3961 | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
| 3962 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3963 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3964 | goto failed; |
| 3965 | Py_DECREF(value); |
| 3966 | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
| 3967 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3968 | if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) == |
| 3969 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3970 | goto failed; |
| 3971 | Py_DECREF(value); |
| 3972 | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
| 3973 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3974 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 3975 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3976 | goto failed; |
| 3977 | Py_DECREF(value); |
| 3978 | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
| 3979 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3980 | if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value) |
| 3981 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3982 | goto failed; |
| 3983 | Py_DECREF(value); |
| 3984 | break; |
| 3985 | case Assert_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3986 | tp = (PyTypeObject *)astmodulestate_global->Assert_type; |
| 3987 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3988 | if (!result) goto failed; |
| 3989 | value = ast2obj_expr(o->v.Assert.test); |
| 3990 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3991 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3992 | goto failed; |
| 3993 | Py_DECREF(value); |
| 3994 | value = ast2obj_expr(o->v.Assert.msg); |
| 3995 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 3996 | if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 3997 | goto failed; |
| 3998 | Py_DECREF(value); |
| 3999 | break; |
| 4000 | case Import_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4001 | tp = (PyTypeObject *)astmodulestate_global->Import_type; |
| 4002 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4003 | if (!result) goto failed; |
| 4004 | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
| 4005 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4006 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4007 | goto failed; |
| 4008 | Py_DECREF(value); |
| 4009 | break; |
| 4010 | case ImportFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4011 | tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type; |
| 4012 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4013 | if (!result) goto failed; |
| 4014 | value = ast2obj_identifier(o->v.ImportFrom.module); |
| 4015 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4016 | if (PyObject_SetAttr(result, astmodulestate_global->module, value) == |
| 4017 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4018 | goto failed; |
| 4019 | Py_DECREF(value); |
| 4020 | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
| 4021 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4022 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4023 | goto failed; |
| 4024 | Py_DECREF(value); |
| 4025 | value = ast2obj_int(o->v.ImportFrom.level); |
| 4026 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4027 | if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4028 | goto failed; |
| 4029 | Py_DECREF(value); |
| 4030 | break; |
| 4031 | case Global_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4032 | tp = (PyTypeObject *)astmodulestate_global->Global_type; |
| 4033 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4034 | if (!result) goto failed; |
| 4035 | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
| 4036 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4037 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4038 | goto failed; |
| 4039 | Py_DECREF(value); |
| 4040 | break; |
| 4041 | case Nonlocal_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4042 | tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type; |
| 4043 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4044 | if (!result) goto failed; |
| 4045 | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
| 4046 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4047 | if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4048 | goto failed; |
| 4049 | Py_DECREF(value); |
| 4050 | break; |
| 4051 | case Expr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4052 | tp = (PyTypeObject *)astmodulestate_global->Expr_type; |
| 4053 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4054 | if (!result) goto failed; |
| 4055 | value = ast2obj_expr(o->v.Expr.value); |
| 4056 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4057 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4058 | goto failed; |
| 4059 | Py_DECREF(value); |
| 4060 | break; |
| 4061 | case Pass_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4062 | tp = (PyTypeObject *)astmodulestate_global->Pass_type; |
| 4063 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4064 | if (!result) goto failed; |
| 4065 | break; |
| 4066 | case Break_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4067 | tp = (PyTypeObject *)astmodulestate_global->Break_type; |
| 4068 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4069 | if (!result) goto failed; |
| 4070 | break; |
| 4071 | case Continue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4072 | tp = (PyTypeObject *)astmodulestate_global->Continue_type; |
| 4073 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4074 | if (!result) goto failed; |
| 4075 | break; |
| 4076 | } |
| 4077 | value = ast2obj_int(o->lineno); |
| 4078 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4079 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4080 | goto failed; |
| 4081 | Py_DECREF(value); |
| 4082 | value = ast2obj_int(o->col_offset); |
| 4083 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4084 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4085 | goto failed; |
| 4086 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4087 | value = ast2obj_int(o->end_lineno); |
| 4088 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4089 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4090 | goto failed; |
| 4091 | Py_DECREF(value); |
| 4092 | value = ast2obj_int(o->end_col_offset); |
| 4093 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4094 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4095 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4096 | goto failed; |
| 4097 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4098 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4099 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4100 | Py_XDECREF(value); |
| 4101 | Py_XDECREF(result); |
| 4102 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4103 | } |
| 4104 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4105 | PyObject* |
| 4106 | ast2obj_expr(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4107 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4108 | expr_ty o = (expr_ty)_o; |
| 4109 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4110 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4111 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4112 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4113 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4114 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4115 | switch (o->kind) { |
| 4116 | case BoolOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4117 | tp = (PyTypeObject *)astmodulestate_global->BoolOp_type; |
| 4118 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4119 | if (!result) goto failed; |
| 4120 | value = ast2obj_boolop(o->v.BoolOp.op); |
| 4121 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4122 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4123 | goto failed; |
| 4124 | Py_DECREF(value); |
| 4125 | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
| 4126 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4127 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4128 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4129 | goto failed; |
| 4130 | Py_DECREF(value); |
| 4131 | break; |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4132 | case NamedExpr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4133 | tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type; |
| 4134 | result = PyType_GenericNew(tp, NULL, NULL); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4135 | if (!result) goto failed; |
| 4136 | value = ast2obj_expr(o->v.NamedExpr.target); |
| 4137 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4138 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == |
| 4139 | -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4140 | goto failed; |
| 4141 | Py_DECREF(value); |
| 4142 | value = ast2obj_expr(o->v.NamedExpr.value); |
| 4143 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4144 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 4145 | goto failed; |
| 4146 | Py_DECREF(value); |
| 4147 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4148 | case BinOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4149 | tp = (PyTypeObject *)astmodulestate_global->BinOp_type; |
| 4150 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4151 | if (!result) goto failed; |
| 4152 | value = ast2obj_expr(o->v.BinOp.left); |
| 4153 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4154 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4155 | goto failed; |
| 4156 | Py_DECREF(value); |
| 4157 | value = ast2obj_operator(o->v.BinOp.op); |
| 4158 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4159 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4160 | goto failed; |
| 4161 | Py_DECREF(value); |
| 4162 | value = ast2obj_expr(o->v.BinOp.right); |
| 4163 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4164 | if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4165 | goto failed; |
| 4166 | Py_DECREF(value); |
| 4167 | break; |
| 4168 | case UnaryOp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4169 | tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type; |
| 4170 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4171 | if (!result) goto failed; |
| 4172 | value = ast2obj_unaryop(o->v.UnaryOp.op); |
| 4173 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4174 | if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4175 | goto failed; |
| 4176 | Py_DECREF(value); |
| 4177 | value = ast2obj_expr(o->v.UnaryOp.operand); |
| 4178 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4179 | if (PyObject_SetAttr(result, astmodulestate_global->operand, value) == |
| 4180 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4181 | goto failed; |
| 4182 | Py_DECREF(value); |
| 4183 | break; |
| 4184 | case Lambda_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4185 | tp = (PyTypeObject *)astmodulestate_global->Lambda_type; |
| 4186 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4187 | if (!result) goto failed; |
| 4188 | value = ast2obj_arguments(o->v.Lambda.args); |
| 4189 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4190 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4191 | goto failed; |
| 4192 | Py_DECREF(value); |
| 4193 | value = ast2obj_expr(o->v.Lambda.body); |
| 4194 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4195 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4196 | goto failed; |
| 4197 | Py_DECREF(value); |
| 4198 | break; |
| 4199 | case IfExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4200 | tp = (PyTypeObject *)astmodulestate_global->IfExp_type; |
| 4201 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4202 | if (!result) goto failed; |
| 4203 | value = ast2obj_expr(o->v.IfExp.test); |
| 4204 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4205 | if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4206 | goto failed; |
| 4207 | Py_DECREF(value); |
| 4208 | value = ast2obj_expr(o->v.IfExp.body); |
| 4209 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4210 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4211 | goto failed; |
| 4212 | Py_DECREF(value); |
| 4213 | value = ast2obj_expr(o->v.IfExp.orelse); |
| 4214 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4215 | if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) == |
| 4216 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4217 | goto failed; |
| 4218 | Py_DECREF(value); |
| 4219 | break; |
| 4220 | case Dict_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4221 | tp = (PyTypeObject *)astmodulestate_global->Dict_type; |
| 4222 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4223 | if (!result) goto failed; |
| 4224 | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
| 4225 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4226 | if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4227 | goto failed; |
| 4228 | Py_DECREF(value); |
| 4229 | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 4230 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4231 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4232 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4233 | goto failed; |
| 4234 | Py_DECREF(value); |
| 4235 | break; |
| 4236 | case Set_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4237 | tp = (PyTypeObject *)astmodulestate_global->Set_type; |
| 4238 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4239 | if (!result) goto failed; |
| 4240 | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
| 4241 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4242 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4243 | goto failed; |
| 4244 | Py_DECREF(value); |
| 4245 | break; |
| 4246 | case ListComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4247 | tp = (PyTypeObject *)astmodulestate_global->ListComp_type; |
| 4248 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4249 | if (!result) goto failed; |
| 4250 | value = ast2obj_expr(o->v.ListComp.elt); |
| 4251 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4252 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4253 | goto failed; |
| 4254 | Py_DECREF(value); |
| 4255 | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
| 4256 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4257 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4258 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4259 | goto failed; |
| 4260 | Py_DECREF(value); |
| 4261 | break; |
| 4262 | case SetComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4263 | tp = (PyTypeObject *)astmodulestate_global->SetComp_type; |
| 4264 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4265 | if (!result) goto failed; |
| 4266 | value = ast2obj_expr(o->v.SetComp.elt); |
| 4267 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4268 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4269 | goto failed; |
| 4270 | Py_DECREF(value); |
| 4271 | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
| 4272 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4273 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4274 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4275 | goto failed; |
| 4276 | Py_DECREF(value); |
| 4277 | break; |
| 4278 | case DictComp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4279 | tp = (PyTypeObject *)astmodulestate_global->DictComp_type; |
| 4280 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4281 | if (!result) goto failed; |
| 4282 | value = ast2obj_expr(o->v.DictComp.key); |
| 4283 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4284 | if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4285 | goto failed; |
| 4286 | Py_DECREF(value); |
| 4287 | value = ast2obj_expr(o->v.DictComp.value); |
| 4288 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4289 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4290 | goto failed; |
| 4291 | Py_DECREF(value); |
| 4292 | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
| 4293 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4294 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4295 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4296 | goto failed; |
| 4297 | Py_DECREF(value); |
| 4298 | break; |
| 4299 | case GeneratorExp_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4300 | tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type; |
| 4301 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4302 | if (!result) goto failed; |
| 4303 | value = ast2obj_expr(o->v.GeneratorExp.elt); |
| 4304 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4305 | if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4306 | goto failed; |
| 4307 | Py_DECREF(value); |
| 4308 | value = ast2obj_list(o->v.GeneratorExp.generators, |
| 4309 | ast2obj_comprehension); |
| 4310 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4311 | if (PyObject_SetAttr(result, astmodulestate_global->generators, value) |
| 4312 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4313 | goto failed; |
| 4314 | Py_DECREF(value); |
| 4315 | break; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4316 | case Await_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4317 | tp = (PyTypeObject *)astmodulestate_global->Await_type; |
| 4318 | result = PyType_GenericNew(tp, NULL, NULL); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4319 | if (!result) goto failed; |
| 4320 | value = ast2obj_expr(o->v.Await.value); |
| 4321 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4322 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 4323 | goto failed; |
| 4324 | Py_DECREF(value); |
| 4325 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4326 | case Yield_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4327 | tp = (PyTypeObject *)astmodulestate_global->Yield_type; |
| 4328 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4329 | if (!result) goto failed; |
| 4330 | value = ast2obj_expr(o->v.Yield.value); |
| 4331 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4332 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4333 | goto failed; |
| 4334 | Py_DECREF(value); |
| 4335 | break; |
| 4336 | case YieldFrom_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4337 | tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type; |
| 4338 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4339 | if (!result) goto failed; |
| 4340 | value = ast2obj_expr(o->v.YieldFrom.value); |
| 4341 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4342 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4343 | goto failed; |
| 4344 | Py_DECREF(value); |
| 4345 | break; |
| 4346 | case Compare_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4347 | tp = (PyTypeObject *)astmodulestate_global->Compare_type; |
| 4348 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4349 | if (!result) goto failed; |
| 4350 | value = ast2obj_expr(o->v.Compare.left); |
| 4351 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4352 | if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4353 | goto failed; |
| 4354 | Py_DECREF(value); |
| 4355 | { |
| 4356 | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
| 4357 | value = PyList_New(n); |
| 4358 | if (!value) goto failed; |
| 4359 | for(i = 0; i < n; i++) |
| 4360 | 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] | 4361 | } |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 4362 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4363 | if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4364 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4365 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4366 | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 4367 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4368 | if (PyObject_SetAttr(result, astmodulestate_global->comparators, value) |
| 4369 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4370 | goto failed; |
Martin v. Löwis | 03e5bc0 | 2006-03-02 00:31:27 +0000 | [diff] [blame] | 4371 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4372 | break; |
| 4373 | case Call_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4374 | tp = (PyTypeObject *)astmodulestate_global->Call_type; |
| 4375 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4376 | if (!result) goto failed; |
| 4377 | value = ast2obj_expr(o->v.Call.func); |
| 4378 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4379 | if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4380 | goto failed; |
| 4381 | Py_DECREF(value); |
| 4382 | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
| 4383 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4384 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4385 | goto failed; |
| 4386 | Py_DECREF(value); |
| 4387 | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
| 4388 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4389 | if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) == |
| 4390 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4391 | goto failed; |
| 4392 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4393 | break; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4394 | case FormattedValue_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4395 | tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type; |
| 4396 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4397 | if (!result) goto failed; |
| 4398 | value = ast2obj_expr(o->v.FormattedValue.value); |
| 4399 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4400 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4401 | goto failed; |
| 4402 | Py_DECREF(value); |
| 4403 | value = ast2obj_int(o->v.FormattedValue.conversion); |
| 4404 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4405 | if (PyObject_SetAttr(result, astmodulestate_global->conversion, value) |
| 4406 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4407 | goto failed; |
| 4408 | Py_DECREF(value); |
| 4409 | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
| 4410 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4411 | if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value) |
| 4412 | == -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4413 | goto failed; |
| 4414 | Py_DECREF(value); |
| 4415 | break; |
| 4416 | case JoinedStr_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4417 | tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type; |
| 4418 | result = PyType_GenericNew(tp, NULL, NULL); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4419 | if (!result) goto failed; |
| 4420 | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
| 4421 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4422 | if (PyObject_SetAttr(result, astmodulestate_global->values, value) == |
| 4423 | -1) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 4424 | goto failed; |
| 4425 | Py_DECREF(value); |
| 4426 | break; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4427 | case Constant_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4428 | tp = (PyTypeObject *)astmodulestate_global->Constant_type; |
| 4429 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4430 | if (!result) goto failed; |
| 4431 | value = ast2obj_constant(o->v.Constant.value); |
| 4432 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4433 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4434 | goto failed; |
| 4435 | Py_DECREF(value); |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4436 | value = ast2obj_string(o->v.Constant.kind); |
| 4437 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4438 | if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 4439 | goto failed; |
| 4440 | Py_DECREF(value); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 4441 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4442 | case Attribute_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4443 | tp = (PyTypeObject *)astmodulestate_global->Attribute_type; |
| 4444 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4445 | if (!result) goto failed; |
| 4446 | value = ast2obj_expr(o->v.Attribute.value); |
| 4447 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4448 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4449 | goto failed; |
| 4450 | Py_DECREF(value); |
| 4451 | value = ast2obj_identifier(o->v.Attribute.attr); |
| 4452 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4453 | if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4454 | goto failed; |
| 4455 | Py_DECREF(value); |
| 4456 | value = ast2obj_expr_context(o->v.Attribute.ctx); |
| 4457 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4458 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4459 | goto failed; |
| 4460 | Py_DECREF(value); |
| 4461 | break; |
| 4462 | case Subscript_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4463 | tp = (PyTypeObject *)astmodulestate_global->Subscript_type; |
| 4464 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4465 | if (!result) goto failed; |
| 4466 | value = ast2obj_expr(o->v.Subscript.value); |
| 4467 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4468 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4469 | goto failed; |
| 4470 | Py_DECREF(value); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4471 | value = ast2obj_expr(o->v.Subscript.slice); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4472 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4473 | if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4474 | goto failed; |
| 4475 | Py_DECREF(value); |
| 4476 | value = ast2obj_expr_context(o->v.Subscript.ctx); |
| 4477 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4478 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4479 | goto failed; |
| 4480 | Py_DECREF(value); |
| 4481 | break; |
| 4482 | case Starred_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4483 | tp = (PyTypeObject *)astmodulestate_global->Starred_type; |
| 4484 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4485 | if (!result) goto failed; |
| 4486 | value = ast2obj_expr(o->v.Starred.value); |
| 4487 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4488 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4489 | goto failed; |
| 4490 | Py_DECREF(value); |
| 4491 | value = ast2obj_expr_context(o->v.Starred.ctx); |
| 4492 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4493 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4494 | goto failed; |
| 4495 | Py_DECREF(value); |
| 4496 | break; |
| 4497 | case Name_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4498 | tp = (PyTypeObject *)astmodulestate_global->Name_type; |
| 4499 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4500 | if (!result) goto failed; |
| 4501 | value = ast2obj_identifier(o->v.Name.id); |
| 4502 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4503 | if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4504 | goto failed; |
| 4505 | Py_DECREF(value); |
| 4506 | value = ast2obj_expr_context(o->v.Name.ctx); |
| 4507 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4508 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4509 | goto failed; |
| 4510 | Py_DECREF(value); |
| 4511 | break; |
| 4512 | case List_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4513 | tp = (PyTypeObject *)astmodulestate_global->List_type; |
| 4514 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4515 | if (!result) goto failed; |
| 4516 | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
| 4517 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4518 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4519 | goto failed; |
| 4520 | Py_DECREF(value); |
| 4521 | value = ast2obj_expr_context(o->v.List.ctx); |
| 4522 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4523 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4524 | goto failed; |
| 4525 | Py_DECREF(value); |
| 4526 | break; |
| 4527 | case Tuple_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4528 | tp = (PyTypeObject *)astmodulestate_global->Tuple_type; |
| 4529 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4530 | if (!result) goto failed; |
| 4531 | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
| 4532 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4533 | if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4534 | goto failed; |
| 4535 | Py_DECREF(value); |
| 4536 | value = ast2obj_expr_context(o->v.Tuple.ctx); |
| 4537 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4538 | if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4539 | goto failed; |
| 4540 | Py_DECREF(value); |
| 4541 | break; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 4542 | case Slice_kind: |
| 4543 | tp = (PyTypeObject *)astmodulestate_global->Slice_type; |
| 4544 | result = PyType_GenericNew(tp, NULL, NULL); |
| 4545 | if (!result) goto failed; |
| 4546 | value = ast2obj_expr(o->v.Slice.lower); |
| 4547 | if (!value) goto failed; |
| 4548 | if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1) |
| 4549 | goto failed; |
| 4550 | Py_DECREF(value); |
| 4551 | value = ast2obj_expr(o->v.Slice.upper); |
| 4552 | if (!value) goto failed; |
| 4553 | if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1) |
| 4554 | goto failed; |
| 4555 | Py_DECREF(value); |
| 4556 | value = ast2obj_expr(o->v.Slice.step); |
| 4557 | if (!value) goto failed; |
| 4558 | if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1) |
| 4559 | goto failed; |
| 4560 | Py_DECREF(value); |
| 4561 | break; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4562 | } |
| 4563 | value = ast2obj_int(o->lineno); |
| 4564 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4565 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4566 | goto failed; |
| 4567 | Py_DECREF(value); |
| 4568 | value = ast2obj_int(o->col_offset); |
| 4569 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4570 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4571 | goto failed; |
| 4572 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4573 | value = ast2obj_int(o->end_lineno); |
| 4574 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4575 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4576 | goto failed; |
| 4577 | Py_DECREF(value); |
| 4578 | value = ast2obj_int(o->end_col_offset); |
| 4579 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4580 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4581 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4582 | goto failed; |
| 4583 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4584 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4585 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4586 | Py_XDECREF(value); |
| 4587 | Py_XDECREF(result); |
| 4588 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4591 | PyObject* ast2obj_expr_context(expr_context_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4592 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4593 | switch(o) { |
| 4594 | case Load: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4595 | Py_INCREF(astmodulestate_global->Load_singleton); |
| 4596 | return astmodulestate_global->Load_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4597 | case Store: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4598 | Py_INCREF(astmodulestate_global->Store_singleton); |
| 4599 | return astmodulestate_global->Store_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4600 | case Del: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4601 | Py_INCREF(astmodulestate_global->Del_singleton); |
| 4602 | return astmodulestate_global->Del_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4603 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4604 | Py_UNREACHABLE(); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4605 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4606 | PyObject* ast2obj_boolop(boolop_ty o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4607 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4608 | switch(o) { |
| 4609 | case And: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4610 | Py_INCREF(astmodulestate_global->And_singleton); |
| 4611 | return astmodulestate_global->And_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4612 | case Or: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4613 | Py_INCREF(astmodulestate_global->Or_singleton); |
| 4614 | return astmodulestate_global->Or_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4615 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4616 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4617 | } |
| 4618 | PyObject* ast2obj_operator(operator_ty o) |
| 4619 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4620 | switch(o) { |
| 4621 | case Add: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4622 | Py_INCREF(astmodulestate_global->Add_singleton); |
| 4623 | return astmodulestate_global->Add_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4624 | case Sub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4625 | Py_INCREF(astmodulestate_global->Sub_singleton); |
| 4626 | return astmodulestate_global->Sub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4627 | case Mult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4628 | Py_INCREF(astmodulestate_global->Mult_singleton); |
| 4629 | return astmodulestate_global->Mult_singleton; |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 4630 | case MatMult: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4631 | Py_INCREF(astmodulestate_global->MatMult_singleton); |
| 4632 | return astmodulestate_global->MatMult_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4633 | case Div: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4634 | Py_INCREF(astmodulestate_global->Div_singleton); |
| 4635 | return astmodulestate_global->Div_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4636 | case Mod: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4637 | Py_INCREF(astmodulestate_global->Mod_singleton); |
| 4638 | return astmodulestate_global->Mod_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4639 | case Pow: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4640 | Py_INCREF(astmodulestate_global->Pow_singleton); |
| 4641 | return astmodulestate_global->Pow_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4642 | case LShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4643 | Py_INCREF(astmodulestate_global->LShift_singleton); |
| 4644 | return astmodulestate_global->LShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4645 | case RShift: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4646 | Py_INCREF(astmodulestate_global->RShift_singleton); |
| 4647 | return astmodulestate_global->RShift_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4648 | case BitOr: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4649 | Py_INCREF(astmodulestate_global->BitOr_singleton); |
| 4650 | return astmodulestate_global->BitOr_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4651 | case BitXor: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4652 | Py_INCREF(astmodulestate_global->BitXor_singleton); |
| 4653 | return astmodulestate_global->BitXor_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4654 | case BitAnd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4655 | Py_INCREF(astmodulestate_global->BitAnd_singleton); |
| 4656 | return astmodulestate_global->BitAnd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4657 | case FloorDiv: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4658 | Py_INCREF(astmodulestate_global->FloorDiv_singleton); |
| 4659 | return astmodulestate_global->FloorDiv_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4660 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4661 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4662 | } |
| 4663 | PyObject* ast2obj_unaryop(unaryop_ty o) |
| 4664 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4665 | switch(o) { |
| 4666 | case Invert: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4667 | Py_INCREF(astmodulestate_global->Invert_singleton); |
| 4668 | return astmodulestate_global->Invert_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4669 | case Not: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4670 | Py_INCREF(astmodulestate_global->Not_singleton); |
| 4671 | return astmodulestate_global->Not_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4672 | case UAdd: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4673 | Py_INCREF(astmodulestate_global->UAdd_singleton); |
| 4674 | return astmodulestate_global->UAdd_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4675 | case USub: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4676 | Py_INCREF(astmodulestate_global->USub_singleton); |
| 4677 | return astmodulestate_global->USub_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4678 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4679 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4680 | } |
| 4681 | PyObject* ast2obj_cmpop(cmpop_ty o) |
| 4682 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4683 | switch(o) { |
| 4684 | case Eq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4685 | Py_INCREF(astmodulestate_global->Eq_singleton); |
| 4686 | return astmodulestate_global->Eq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4687 | case NotEq: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4688 | Py_INCREF(astmodulestate_global->NotEq_singleton); |
| 4689 | return astmodulestate_global->NotEq_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4690 | case Lt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4691 | Py_INCREF(astmodulestate_global->Lt_singleton); |
| 4692 | return astmodulestate_global->Lt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4693 | case LtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4694 | Py_INCREF(astmodulestate_global->LtE_singleton); |
| 4695 | return astmodulestate_global->LtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4696 | case Gt: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4697 | Py_INCREF(astmodulestate_global->Gt_singleton); |
| 4698 | return astmodulestate_global->Gt_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4699 | case GtE: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4700 | Py_INCREF(astmodulestate_global->GtE_singleton); |
| 4701 | return astmodulestate_global->GtE_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4702 | case Is: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4703 | Py_INCREF(astmodulestate_global->Is_singleton); |
| 4704 | return astmodulestate_global->Is_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4705 | case IsNot: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4706 | Py_INCREF(astmodulestate_global->IsNot_singleton); |
| 4707 | return astmodulestate_global->IsNot_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4708 | case In: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4709 | Py_INCREF(astmodulestate_global->In_singleton); |
| 4710 | return astmodulestate_global->In_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4711 | case NotIn: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4712 | Py_INCREF(astmodulestate_global->NotIn_singleton); |
| 4713 | return astmodulestate_global->NotIn_singleton; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4714 | } |
Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 4715 | Py_UNREACHABLE(); |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4716 | } |
| 4717 | PyObject* |
| 4718 | ast2obj_comprehension(void* _o) |
| 4719 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4720 | comprehension_ty o = (comprehension_ty)_o; |
| 4721 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4722 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4723 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4724 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4725 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4726 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4727 | tp = (PyTypeObject *)astmodulestate_global->comprehension_type; |
| 4728 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4729 | if (!result) return NULL; |
| 4730 | value = ast2obj_expr(o->target); |
| 4731 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4732 | if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4733 | goto failed; |
| 4734 | Py_DECREF(value); |
| 4735 | value = ast2obj_expr(o->iter); |
| 4736 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4737 | if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4738 | goto failed; |
| 4739 | Py_DECREF(value); |
| 4740 | value = ast2obj_list(o->ifs, ast2obj_expr); |
| 4741 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4742 | if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4743 | goto failed; |
| 4744 | Py_DECREF(value); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4745 | value = ast2obj_int(o->is_async); |
| 4746 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4747 | if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1) |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 4748 | goto failed; |
| 4749 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4750 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4751 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4752 | Py_XDECREF(value); |
| 4753 | Py_XDECREF(result); |
| 4754 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4755 | } |
| 4756 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4757 | PyObject* |
| 4758 | ast2obj_excepthandler(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4759 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4760 | excepthandler_ty o = (excepthandler_ty)_o; |
| 4761 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4762 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4763 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4764 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4765 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4766 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4767 | switch (o->kind) { |
| 4768 | case ExceptHandler_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4769 | tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type; |
| 4770 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4771 | if (!result) goto failed; |
| 4772 | value = ast2obj_expr(o->v.ExceptHandler.type); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4773 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4774 | if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4775 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4776 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4777 | value = ast2obj_identifier(o->v.ExceptHandler.name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4778 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4779 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4780 | goto failed; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 4781 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4782 | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
| 4783 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4784 | if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4785 | goto failed; |
| 4786 | Py_DECREF(value); |
| 4787 | break; |
| 4788 | } |
| 4789 | value = ast2obj_int(o->lineno); |
| 4790 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4791 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4792 | goto failed; |
| 4793 | Py_DECREF(value); |
| 4794 | value = ast2obj_int(o->col_offset); |
| 4795 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4796 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4797 | goto failed; |
| 4798 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4799 | value = ast2obj_int(o->end_lineno); |
| 4800 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4801 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4802 | goto failed; |
| 4803 | Py_DECREF(value); |
| 4804 | value = ast2obj_int(o->end_col_offset); |
| 4805 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4806 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4807 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4808 | goto failed; |
| 4809 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4810 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4811 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4812 | Py_XDECREF(value); |
| 4813 | Py_XDECREF(result); |
| 4814 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4817 | PyObject* |
| 4818 | ast2obj_arguments(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4819 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4820 | arguments_ty o = (arguments_ty)_o; |
| 4821 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4822 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4823 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4824 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4825 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4826 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4827 | tp = (PyTypeObject *)astmodulestate_global->arguments_type; |
| 4828 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4829 | if (!result) return NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4830 | value = ast2obj_list(o->posonlyargs, ast2obj_arg); |
| 4831 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4832 | if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) == |
| 4833 | -1) |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 4834 | goto failed; |
| 4835 | Py_DECREF(value); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4836 | value = ast2obj_list(o->args, ast2obj_arg); |
| 4837 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4838 | if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1) |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 4839 | goto failed; |
| 4840 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4841 | value = ast2obj_arg(o->vararg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4842 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4843 | if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4844 | goto failed; |
| 4845 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4846 | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
| 4847 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4848 | if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) == |
| 4849 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4850 | goto failed; |
| 4851 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4852 | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4853 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4854 | if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) == |
| 4855 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4856 | goto failed; |
| 4857 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4858 | value = ast2obj_arg(o->kwarg); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4859 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4860 | if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4861 | goto failed; |
| 4862 | Py_DECREF(value); |
| 4863 | value = ast2obj_list(o->defaults, ast2obj_expr); |
| 4864 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4865 | if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4866 | goto failed; |
| 4867 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4868 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4869 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4870 | Py_XDECREF(value); |
| 4871 | Py_XDECREF(result); |
| 4872 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4875 | PyObject* |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4876 | ast2obj_arg(void* _o) |
| 4877 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4878 | arg_ty o = (arg_ty)_o; |
| 4879 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4880 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4881 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4882 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4883 | } |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4884 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4885 | tp = (PyTypeObject *)astmodulestate_global->arg_type; |
| 4886 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4887 | if (!result) return NULL; |
| 4888 | value = ast2obj_identifier(o->arg); |
| 4889 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4890 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4891 | goto failed; |
| 4892 | Py_DECREF(value); |
| 4893 | value = ast2obj_expr(o->annotation); |
| 4894 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4895 | if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) == |
| 4896 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4897 | goto failed; |
| 4898 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4899 | value = ast2obj_string(o->type_comment); |
| 4900 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4901 | if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) == |
| 4902 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 4903 | goto failed; |
| 4904 | Py_DECREF(value); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4905 | value = ast2obj_int(o->lineno); |
| 4906 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4907 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4908 | goto failed; |
| 4909 | Py_DECREF(value); |
| 4910 | value = ast2obj_int(o->col_offset); |
| 4911 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4912 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 4913 | goto failed; |
| 4914 | Py_DECREF(value); |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4915 | value = ast2obj_int(o->end_lineno); |
| 4916 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4917 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4918 | goto failed; |
| 4919 | Py_DECREF(value); |
| 4920 | value = ast2obj_int(o->end_col_offset); |
| 4921 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4922 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4923 | < 0) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 4924 | goto failed; |
| 4925 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4926 | return result; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4927 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4928 | Py_XDECREF(value); |
| 4929 | Py_XDECREF(result); |
| 4930 | return NULL; |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | PyObject* |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4934 | ast2obj_keyword(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4935 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4936 | keyword_ty o = (keyword_ty)_o; |
| 4937 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4938 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4939 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4940 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4941 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4942 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4943 | tp = (PyTypeObject *)astmodulestate_global->keyword_type; |
| 4944 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4945 | if (!result) return NULL; |
| 4946 | value = ast2obj_identifier(o->arg); |
| 4947 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4948 | if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4949 | goto failed; |
| 4950 | Py_DECREF(value); |
| 4951 | value = ast2obj_expr(o->value); |
| 4952 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4953 | if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4954 | goto failed; |
| 4955 | Py_DECREF(value); |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 4956 | value = ast2obj_int(o->lineno); |
| 4957 | if (!value) goto failed; |
| 4958 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0) |
| 4959 | goto failed; |
| 4960 | Py_DECREF(value); |
| 4961 | value = ast2obj_int(o->col_offset); |
| 4962 | if (!value) goto failed; |
| 4963 | if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0) |
| 4964 | goto failed; |
| 4965 | Py_DECREF(value); |
| 4966 | value = ast2obj_int(o->end_lineno); |
| 4967 | if (!value) goto failed; |
| 4968 | if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0) |
| 4969 | goto failed; |
| 4970 | Py_DECREF(value); |
| 4971 | value = ast2obj_int(o->end_col_offset); |
| 4972 | if (!value) goto failed; |
| 4973 | if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value) |
| 4974 | < 0) |
| 4975 | goto failed; |
| 4976 | Py_DECREF(value); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4977 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4978 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4979 | Py_XDECREF(value); |
| 4980 | Py_XDECREF(result); |
| 4981 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4982 | } |
| 4983 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4984 | PyObject* |
| 4985 | ast2obj_alias(void* _o) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4986 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4987 | alias_ty o = (alias_ty)_o; |
| 4988 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4989 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4990 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 4991 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4992 | } |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 4993 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4994 | tp = (PyTypeObject *)astmodulestate_global->alias_type; |
| 4995 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 4996 | if (!result) return NULL; |
| 4997 | value = ast2obj_identifier(o->name); |
| 4998 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 4999 | if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5000 | goto failed; |
| 5001 | Py_DECREF(value); |
| 5002 | value = ast2obj_identifier(o->asname); |
| 5003 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5004 | if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5005 | goto failed; |
| 5006 | Py_DECREF(value); |
| 5007 | return result; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 5008 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5009 | Py_XDECREF(value); |
| 5010 | Py_XDECREF(result); |
| 5011 | return NULL; |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5014 | PyObject* |
| 5015 | ast2obj_withitem(void* _o) |
| 5016 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5017 | withitem_ty o = (withitem_ty)_o; |
| 5018 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5019 | PyTypeObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5020 | if (!o) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 5021 | Py_RETURN_NONE; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5022 | } |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5023 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5024 | tp = (PyTypeObject *)astmodulestate_global->withitem_type; |
| 5025 | result = PyType_GenericNew(tp, NULL, NULL); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5026 | if (!result) return NULL; |
| 5027 | value = ast2obj_expr(o->context_expr); |
| 5028 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5029 | if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) == |
| 5030 | -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5031 | goto failed; |
| 5032 | Py_DECREF(value); |
| 5033 | value = ast2obj_expr(o->optional_vars); |
| 5034 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5035 | if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value) |
| 5036 | == -1) |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5037 | goto failed; |
| 5038 | Py_DECREF(value); |
| 5039 | return result; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5040 | failed: |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5041 | Py_XDECREF(value); |
| 5042 | Py_XDECREF(result); |
| 5043 | return NULL; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 5044 | } |
| 5045 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5046 | PyObject* |
| 5047 | ast2obj_type_ignore(void* _o) |
| 5048 | { |
| 5049 | type_ignore_ty o = (type_ignore_ty)_o; |
| 5050 | PyObject *result = NULL, *value = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5051 | PyTypeObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5052 | if (!o) { |
| 5053 | Py_RETURN_NONE; |
| 5054 | } |
| 5055 | |
| 5056 | switch (o->kind) { |
| 5057 | case TypeIgnore_kind: |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5058 | tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type; |
| 5059 | result = PyType_GenericNew(tp, NULL, NULL); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5060 | if (!result) goto failed; |
| 5061 | value = ast2obj_int(o->v.TypeIgnore.lineno); |
| 5062 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5063 | if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) == |
| 5064 | -1) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5065 | goto failed; |
| 5066 | Py_DECREF(value); |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5067 | value = ast2obj_string(o->v.TypeIgnore.tag); |
| 5068 | if (!value) goto failed; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5069 | if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1) |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 5070 | goto failed; |
| 5071 | Py_DECREF(value); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5072 | break; |
| 5073 | } |
| 5074 | return result; |
| 5075 | failed: |
| 5076 | Py_XDECREF(value); |
| 5077 | Py_XDECREF(result); |
| 5078 | return NULL; |
| 5079 | } |
| 5080 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5081 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5082 | int |
| 5083 | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
| 5084 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5085 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5086 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5087 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5088 | PyObject *tp; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5089 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5090 | if (obj == Py_None) { |
| 5091 | *out = NULL; |
| 5092 | return 0; |
| 5093 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5094 | tp = astmodulestate_global->Module_type; |
| 5095 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5096 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5097 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5098 | } |
| 5099 | if (isinstance) { |
| 5100 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5101 | asdl_seq* type_ignores; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5102 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5103 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5104 | return 1; |
| 5105 | } |
| 5106 | if (tmp == NULL) { |
| 5107 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
| 5108 | return 1; |
| 5109 | } |
| 5110 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5111 | int res; |
| 5112 | Py_ssize_t len; |
| 5113 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5114 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5115 | 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] | 5116 | goto failed; |
| 5117 | } |
| 5118 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5119 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5120 | if (body == NULL) goto failed; |
| 5121 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5122 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5123 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5124 | Py_INCREF(tmp2); |
| 5125 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5126 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5127 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5128 | if (len != PyList_GET_SIZE(tmp)) { |
| 5129 | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
| 5130 | goto failed; |
| 5131 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5132 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5133 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5134 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5135 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5136 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores, |
| 5137 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5138 | return 1; |
| 5139 | } |
| 5140 | if (tmp == NULL) { |
| 5141 | PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module"); |
| 5142 | return 1; |
| 5143 | } |
| 5144 | else { |
| 5145 | int res; |
| 5146 | Py_ssize_t len; |
| 5147 | Py_ssize_t i; |
| 5148 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5149 | 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] | 5150 | goto failed; |
| 5151 | } |
| 5152 | len = PyList_GET_SIZE(tmp); |
| 5153 | type_ignores = _Py_asdl_seq_new(len, arena); |
| 5154 | if (type_ignores == NULL) goto failed; |
| 5155 | for (i = 0; i < len; i++) { |
| 5156 | type_ignore_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5157 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5158 | Py_INCREF(tmp2); |
| 5159 | res = obj2ast_type_ignore(tmp2, &val, arena); |
| 5160 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5161 | if (res != 0) goto failed; |
| 5162 | if (len != PyList_GET_SIZE(tmp)) { |
| 5163 | PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration"); |
| 5164 | goto failed; |
| 5165 | } |
| 5166 | asdl_seq_SET(type_ignores, i, val); |
| 5167 | } |
| 5168 | Py_CLEAR(tmp); |
| 5169 | } |
| 5170 | *out = Module(body, type_ignores, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5171 | if (*out == NULL) goto failed; |
| 5172 | return 0; |
| 5173 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5174 | tp = astmodulestate_global->Interactive_type; |
| 5175 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5176 | if (isinstance == -1) { |
| 5177 | return 1; |
| 5178 | } |
| 5179 | if (isinstance) { |
| 5180 | asdl_seq* body; |
| 5181 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5182 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5183 | return 1; |
| 5184 | } |
| 5185 | if (tmp == NULL) { |
| 5186 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
| 5187 | return 1; |
| 5188 | } |
| 5189 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5190 | int res; |
| 5191 | Py_ssize_t len; |
| 5192 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5193 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5194 | 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] | 5195 | goto failed; |
| 5196 | } |
| 5197 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5198 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5199 | if (body == NULL) goto failed; |
| 5200 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5201 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5202 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5203 | Py_INCREF(tmp2); |
| 5204 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5205 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5206 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5207 | if (len != PyList_GET_SIZE(tmp)) { |
| 5208 | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
| 5209 | goto failed; |
| 5210 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5211 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5212 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5213 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5214 | } |
| 5215 | *out = Interactive(body, arena); |
| 5216 | if (*out == NULL) goto failed; |
| 5217 | return 0; |
| 5218 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5219 | tp = astmodulestate_global->Expression_type; |
| 5220 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5221 | if (isinstance == -1) { |
| 5222 | return 1; |
| 5223 | } |
| 5224 | if (isinstance) { |
| 5225 | expr_ty body; |
| 5226 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5227 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5228 | return 1; |
| 5229 | } |
| 5230 | if (tmp == NULL) { |
| 5231 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
| 5232 | return 1; |
| 5233 | } |
| 5234 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5235 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5236 | res = obj2ast_expr(tmp, &body, arena); |
| 5237 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5238 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5239 | } |
| 5240 | *out = Expression(body, arena); |
| 5241 | if (*out == NULL) goto failed; |
| 5242 | return 0; |
| 5243 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5244 | tp = astmodulestate_global->FunctionType_type; |
| 5245 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5246 | if (isinstance == -1) { |
| 5247 | return 1; |
| 5248 | } |
| 5249 | if (isinstance) { |
| 5250 | asdl_seq* argtypes; |
| 5251 | expr_ty returns; |
| 5252 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5253 | if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) < |
| 5254 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5255 | return 1; |
| 5256 | } |
| 5257 | if (tmp == NULL) { |
| 5258 | PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType"); |
| 5259 | return 1; |
| 5260 | } |
| 5261 | else { |
| 5262 | int res; |
| 5263 | Py_ssize_t len; |
| 5264 | Py_ssize_t i; |
| 5265 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5266 | 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] | 5267 | goto failed; |
| 5268 | } |
| 5269 | len = PyList_GET_SIZE(tmp); |
| 5270 | argtypes = _Py_asdl_seq_new(len, arena); |
| 5271 | if (argtypes == NULL) goto failed; |
| 5272 | for (i = 0; i < len; i++) { |
| 5273 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5274 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5275 | Py_INCREF(tmp2); |
| 5276 | res = obj2ast_expr(tmp2, &val, arena); |
| 5277 | Py_DECREF(tmp2); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5278 | if (res != 0) goto failed; |
| 5279 | if (len != PyList_GET_SIZE(tmp)) { |
| 5280 | PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration"); |
| 5281 | goto failed; |
| 5282 | } |
| 5283 | asdl_seq_SET(argtypes, i, val); |
| 5284 | } |
| 5285 | Py_CLEAR(tmp); |
| 5286 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5287 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5288 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5289 | return 1; |
| 5290 | } |
| 5291 | if (tmp == NULL) { |
| 5292 | PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType"); |
| 5293 | return 1; |
| 5294 | } |
| 5295 | else { |
| 5296 | int res; |
| 5297 | res = obj2ast_expr(tmp, &returns, arena); |
| 5298 | if (res != 0) goto failed; |
| 5299 | Py_CLEAR(tmp); |
| 5300 | } |
| 5301 | *out = FunctionType(argtypes, returns, arena); |
| 5302 | if (*out == NULL) goto failed; |
| 5303 | return 0; |
| 5304 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5305 | |
| 5306 | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
| 5307 | failed: |
| 5308 | Py_XDECREF(tmp); |
| 5309 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | int |
| 5313 | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
| 5314 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5315 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5316 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5317 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5318 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5319 | int lineno; |
| 5320 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5321 | int end_lineno; |
| 5322 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5323 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5324 | if (obj == Py_None) { |
| 5325 | *out = NULL; |
| 5326 | return 0; |
| 5327 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5328 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5329 | return 1; |
| 5330 | } |
| 5331 | if (tmp == NULL) { |
| 5332 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
| 5333 | return 1; |
| 5334 | } |
| 5335 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5336 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5337 | res = obj2ast_int(tmp, &lineno, arena); |
| 5338 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5339 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5340 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5341 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 5342 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 5343 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5344 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5345 | if (tmp == NULL) { |
| 5346 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
| 5347 | return 1; |
| 5348 | } |
| 5349 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5350 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5351 | res = obj2ast_int(tmp, &col_offset, arena); |
| 5352 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5353 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5354 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5355 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 5356 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5357 | return 1; |
| 5358 | } |
| 5359 | if (tmp == NULL || tmp == Py_None) { |
| 5360 | Py_CLEAR(tmp); |
| 5361 | end_lineno = 0; |
| 5362 | } |
| 5363 | else { |
| 5364 | int res; |
| 5365 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 5366 | if (res != 0) goto failed; |
| 5367 | Py_CLEAR(tmp); |
| 5368 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5369 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 5370 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5371 | return 1; |
| 5372 | } |
| 5373 | if (tmp == NULL || tmp == Py_None) { |
| 5374 | Py_CLEAR(tmp); |
| 5375 | end_col_offset = 0; |
| 5376 | } |
| 5377 | else { |
| 5378 | int res; |
| 5379 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 5380 | if (res != 0) goto failed; |
| 5381 | Py_CLEAR(tmp); |
| 5382 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5383 | tp = astmodulestate_global->FunctionDef_type; |
| 5384 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5385 | if (isinstance == -1) { |
| 5386 | return 1; |
| 5387 | } |
| 5388 | if (isinstance) { |
| 5389 | identifier name; |
| 5390 | arguments_ty args; |
| 5391 | asdl_seq* body; |
| 5392 | asdl_seq* decorator_list; |
| 5393 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5394 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5395 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5396 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5397 | return 1; |
| 5398 | } |
| 5399 | if (tmp == NULL) { |
| 5400 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
| 5401 | return 1; |
| 5402 | } |
| 5403 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5404 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5405 | res = obj2ast_identifier(tmp, &name, arena); |
| 5406 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5407 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5408 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5409 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5410 | return 1; |
| 5411 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5412 | if (tmp == NULL) { |
| 5413 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
| 5414 | return 1; |
| 5415 | } |
| 5416 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5417 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5418 | res = obj2ast_arguments(tmp, &args, arena); |
| 5419 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5420 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5421 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5422 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5423 | return 1; |
| 5424 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5425 | if (tmp == NULL) { |
| 5426 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
| 5427 | return 1; |
| 5428 | } |
| 5429 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5430 | int res; |
| 5431 | Py_ssize_t len; |
| 5432 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5433 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5434 | 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] | 5435 | goto failed; |
| 5436 | } |
| 5437 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5438 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5439 | if (body == NULL) goto failed; |
| 5440 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5441 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5442 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5443 | Py_INCREF(tmp2); |
| 5444 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5445 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5446 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5447 | if (len != PyList_GET_SIZE(tmp)) { |
| 5448 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
| 5449 | goto failed; |
| 5450 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5451 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5452 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5453 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5454 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5455 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5456 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5457 | return 1; |
| 5458 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5459 | if (tmp == NULL) { |
| 5460 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
| 5461 | return 1; |
| 5462 | } |
| 5463 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5464 | int res; |
| 5465 | Py_ssize_t len; |
| 5466 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5467 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5468 | 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] | 5469 | goto failed; |
| 5470 | } |
| 5471 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5472 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5473 | if (decorator_list == NULL) goto failed; |
| 5474 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5475 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5476 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5477 | Py_INCREF(tmp2); |
| 5478 | res = obj2ast_expr(tmp2, &val, arena); |
| 5479 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5480 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5481 | if (len != PyList_GET_SIZE(tmp)) { |
| 5482 | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
| 5483 | goto failed; |
| 5484 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5485 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5486 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5487 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5488 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5489 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5490 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5491 | return 1; |
| 5492 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5493 | if (tmp == NULL || tmp == Py_None) { |
| 5494 | Py_CLEAR(tmp); |
| 5495 | returns = NULL; |
| 5496 | } |
| 5497 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5498 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5499 | res = obj2ast_expr(tmp, &returns, arena); |
| 5500 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5501 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5502 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5503 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5504 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5505 | return 1; |
| 5506 | } |
| 5507 | if (tmp == NULL || tmp == Py_None) { |
| 5508 | Py_CLEAR(tmp); |
| 5509 | type_comment = NULL; |
| 5510 | } |
| 5511 | else { |
| 5512 | int res; |
| 5513 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5514 | if (res != 0) goto failed; |
| 5515 | Py_CLEAR(tmp); |
| 5516 | } |
| 5517 | *out = FunctionDef(name, args, body, decorator_list, returns, |
| 5518 | type_comment, lineno, col_offset, end_lineno, |
| 5519 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5520 | if (*out == NULL) goto failed; |
| 5521 | return 0; |
| 5522 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5523 | tp = astmodulestate_global->AsyncFunctionDef_type; |
| 5524 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5525 | if (isinstance == -1) { |
| 5526 | return 1; |
| 5527 | } |
| 5528 | if (isinstance) { |
| 5529 | identifier name; |
| 5530 | arguments_ty args; |
| 5531 | asdl_seq* body; |
| 5532 | asdl_seq* decorator_list; |
| 5533 | expr_ty returns; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5534 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5535 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5536 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5537 | return 1; |
| 5538 | } |
| 5539 | if (tmp == NULL) { |
| 5540 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
| 5541 | return 1; |
| 5542 | } |
| 5543 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5544 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5545 | res = obj2ast_identifier(tmp, &name, arena); |
| 5546 | if (res != 0) goto failed; |
| 5547 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5548 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5549 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5550 | return 1; |
| 5551 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5552 | if (tmp == NULL) { |
| 5553 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
| 5554 | return 1; |
| 5555 | } |
| 5556 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5557 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5558 | res = obj2ast_arguments(tmp, &args, arena); |
| 5559 | if (res != 0) goto failed; |
| 5560 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5561 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5562 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5563 | return 1; |
| 5564 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5565 | if (tmp == NULL) { |
| 5566 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
| 5567 | return 1; |
| 5568 | } |
| 5569 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5570 | int res; |
| 5571 | Py_ssize_t len; |
| 5572 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5573 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5574 | 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] | 5575 | goto failed; |
| 5576 | } |
| 5577 | len = PyList_GET_SIZE(tmp); |
| 5578 | body = _Py_asdl_seq_new(len, arena); |
| 5579 | if (body == NULL) goto failed; |
| 5580 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5581 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5582 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5583 | Py_INCREF(tmp2); |
| 5584 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5585 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5586 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5587 | if (len != PyList_GET_SIZE(tmp)) { |
| 5588 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
| 5589 | goto failed; |
| 5590 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5591 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5592 | } |
| 5593 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5594 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5595 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5596 | &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5597 | return 1; |
| 5598 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5599 | if (tmp == NULL) { |
| 5600 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
| 5601 | return 1; |
| 5602 | } |
| 5603 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5604 | int res; |
| 5605 | Py_ssize_t len; |
| 5606 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5607 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5608 | 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] | 5609 | goto failed; |
| 5610 | } |
| 5611 | len = PyList_GET_SIZE(tmp); |
| 5612 | decorator_list = _Py_asdl_seq_new(len, arena); |
| 5613 | if (decorator_list == NULL) goto failed; |
| 5614 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5615 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5616 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5617 | Py_INCREF(tmp2); |
| 5618 | res = obj2ast_expr(tmp2, &val, arena); |
| 5619 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5620 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5621 | if (len != PyList_GET_SIZE(tmp)) { |
| 5622 | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
| 5623 | goto failed; |
| 5624 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5625 | asdl_seq_SET(decorator_list, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5626 | } |
| 5627 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5628 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5629 | if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) < |
| 5630 | 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5631 | return 1; |
| 5632 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5633 | if (tmp == NULL || tmp == Py_None) { |
| 5634 | Py_CLEAR(tmp); |
| 5635 | returns = NULL; |
| 5636 | } |
| 5637 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5638 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5639 | res = obj2ast_expr(tmp, &returns, arena); |
| 5640 | if (res != 0) goto failed; |
| 5641 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5642 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5643 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5644 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5645 | return 1; |
| 5646 | } |
| 5647 | if (tmp == NULL || tmp == Py_None) { |
| 5648 | Py_CLEAR(tmp); |
| 5649 | type_comment = NULL; |
| 5650 | } |
| 5651 | else { |
| 5652 | int res; |
| 5653 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5654 | if (res != 0) goto failed; |
| 5655 | Py_CLEAR(tmp); |
| 5656 | } |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5657 | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5658 | type_comment, lineno, col_offset, end_lineno, |
| 5659 | end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 5660 | if (*out == NULL) goto failed; |
| 5661 | return 0; |
| 5662 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5663 | tp = astmodulestate_global->ClassDef_type; |
| 5664 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5665 | if (isinstance == -1) { |
| 5666 | return 1; |
| 5667 | } |
| 5668 | if (isinstance) { |
| 5669 | identifier name; |
| 5670 | asdl_seq* bases; |
| 5671 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5672 | asdl_seq* body; |
| 5673 | asdl_seq* decorator_list; |
| 5674 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5675 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5676 | return 1; |
| 5677 | } |
| 5678 | if (tmp == NULL) { |
| 5679 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
| 5680 | return 1; |
| 5681 | } |
| 5682 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5683 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5684 | res = obj2ast_identifier(tmp, &name, arena); |
| 5685 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5686 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5687 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5688 | if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5689 | return 1; |
| 5690 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5691 | if (tmp == NULL) { |
| 5692 | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
| 5693 | return 1; |
| 5694 | } |
| 5695 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5696 | int res; |
| 5697 | Py_ssize_t len; |
| 5698 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5699 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5700 | 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] | 5701 | goto failed; |
| 5702 | } |
| 5703 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5704 | bases = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5705 | if (bases == NULL) goto failed; |
| 5706 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5707 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5708 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5709 | Py_INCREF(tmp2); |
| 5710 | res = obj2ast_expr(tmp2, &val, arena); |
| 5711 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5712 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5713 | if (len != PyList_GET_SIZE(tmp)) { |
| 5714 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
| 5715 | goto failed; |
| 5716 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5717 | asdl_seq_SET(bases, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5718 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5719 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5720 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5721 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 5722 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5723 | return 1; |
| 5724 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5725 | if (tmp == NULL) { |
| 5726 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
| 5727 | return 1; |
| 5728 | } |
| 5729 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5730 | int res; |
| 5731 | Py_ssize_t len; |
| 5732 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5733 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5734 | 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] | 5735 | goto failed; |
| 5736 | } |
| 5737 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5738 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5739 | if (keywords == NULL) goto failed; |
| 5740 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5741 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5742 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5743 | Py_INCREF(tmp2); |
| 5744 | res = obj2ast_keyword(tmp2, &val, arena); |
| 5745 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5746 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5747 | if (len != PyList_GET_SIZE(tmp)) { |
| 5748 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
| 5749 | goto failed; |
| 5750 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5751 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5752 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5753 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5754 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5755 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5756 | return 1; |
| 5757 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5758 | if (tmp == NULL) { |
| 5759 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
| 5760 | return 1; |
| 5761 | } |
| 5762 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5763 | int res; |
| 5764 | Py_ssize_t len; |
| 5765 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5766 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5767 | 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] | 5768 | goto failed; |
| 5769 | } |
| 5770 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5771 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5772 | if (body == NULL) goto failed; |
| 5773 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5774 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5775 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5776 | Py_INCREF(tmp2); |
| 5777 | res = obj2ast_stmt(tmp2, &val, arena); |
| 5778 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5779 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5780 | if (len != PyList_GET_SIZE(tmp)) { |
| 5781 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
| 5782 | goto failed; |
| 5783 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5784 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5785 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5786 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5787 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5788 | if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list, |
| 5789 | &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5790 | return 1; |
| 5791 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5792 | if (tmp == NULL) { |
| 5793 | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
| 5794 | return 1; |
| 5795 | } |
| 5796 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5797 | int res; |
| 5798 | Py_ssize_t len; |
| 5799 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5800 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5801 | 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] | 5802 | goto failed; |
| 5803 | } |
| 5804 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5805 | decorator_list = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5806 | if (decorator_list == NULL) goto failed; |
| 5807 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5808 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5809 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5810 | Py_INCREF(tmp2); |
| 5811 | res = obj2ast_expr(tmp2, &val, arena); |
| 5812 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5813 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5814 | if (len != PyList_GET_SIZE(tmp)) { |
| 5815 | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
| 5816 | goto failed; |
| 5817 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5818 | asdl_seq_SET(decorator_list, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5819 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5820 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5821 | } |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 5822 | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5823 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5824 | if (*out == NULL) goto failed; |
| 5825 | return 0; |
| 5826 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5827 | tp = astmodulestate_global->Return_type; |
| 5828 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5829 | if (isinstance == -1) { |
| 5830 | return 1; |
| 5831 | } |
| 5832 | if (isinstance) { |
| 5833 | expr_ty value; |
| 5834 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5835 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5836 | return 1; |
| 5837 | } |
| 5838 | if (tmp == NULL || tmp == Py_None) { |
| 5839 | Py_CLEAR(tmp); |
| 5840 | value = NULL; |
| 5841 | } |
| 5842 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5843 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5844 | res = obj2ast_expr(tmp, &value, arena); |
| 5845 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5846 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5847 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5848 | *out = Return(value, lineno, col_offset, end_lineno, end_col_offset, |
| 5849 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5850 | if (*out == NULL) goto failed; |
| 5851 | return 0; |
| 5852 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5853 | tp = astmodulestate_global->Delete_type; |
| 5854 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5855 | if (isinstance == -1) { |
| 5856 | return 1; |
| 5857 | } |
| 5858 | if (isinstance) { |
| 5859 | asdl_seq* targets; |
| 5860 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5861 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5862 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5863 | return 1; |
| 5864 | } |
| 5865 | if (tmp == NULL) { |
| 5866 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
| 5867 | return 1; |
| 5868 | } |
| 5869 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5870 | int res; |
| 5871 | Py_ssize_t len; |
| 5872 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5873 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5874 | 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] | 5875 | goto failed; |
| 5876 | } |
| 5877 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5878 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5879 | if (targets == NULL) goto failed; |
| 5880 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5881 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5882 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5883 | Py_INCREF(tmp2); |
| 5884 | res = obj2ast_expr(tmp2, &val, arena); |
| 5885 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5886 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5887 | if (len != PyList_GET_SIZE(tmp)) { |
| 5888 | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
| 5889 | goto failed; |
| 5890 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5891 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5892 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5893 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5894 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 5895 | *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset, |
| 5896 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5897 | if (*out == NULL) goto failed; |
| 5898 | return 0; |
| 5899 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5900 | tp = astmodulestate_global->Assign_type; |
| 5901 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5902 | if (isinstance == -1) { |
| 5903 | return 1; |
| 5904 | } |
| 5905 | if (isinstance) { |
| 5906 | asdl_seq* targets; |
| 5907 | expr_ty value; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5908 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5909 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5910 | if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) < |
| 5911 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5912 | return 1; |
| 5913 | } |
| 5914 | if (tmp == NULL) { |
| 5915 | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
| 5916 | return 1; |
| 5917 | } |
| 5918 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5919 | int res; |
| 5920 | Py_ssize_t len; |
| 5921 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5922 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5923 | 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] | 5924 | goto failed; |
| 5925 | } |
| 5926 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 5927 | targets = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5928 | if (targets == NULL) goto failed; |
| 5929 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5930 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 5931 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 5932 | Py_INCREF(tmp2); |
| 5933 | res = obj2ast_expr(tmp2, &val, arena); |
| 5934 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5935 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 5936 | if (len != PyList_GET_SIZE(tmp)) { |
| 5937 | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
| 5938 | goto failed; |
| 5939 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 5940 | asdl_seq_SET(targets, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5941 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5942 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5944 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5945 | return 1; |
| 5946 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5947 | if (tmp == NULL) { |
| 5948 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
| 5949 | return 1; |
| 5950 | } |
| 5951 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5952 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5953 | res = obj2ast_expr(tmp, &value, arena); |
| 5954 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5955 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5956 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5957 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 5958 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 5959 | return 1; |
| 5960 | } |
| 5961 | if (tmp == NULL || tmp == Py_None) { |
| 5962 | Py_CLEAR(tmp); |
| 5963 | type_comment = NULL; |
| 5964 | } |
| 5965 | else { |
| 5966 | int res; |
| 5967 | res = obj2ast_string(tmp, &type_comment, arena); |
| 5968 | if (res != 0) goto failed; |
| 5969 | Py_CLEAR(tmp); |
| 5970 | } |
| 5971 | *out = Assign(targets, value, type_comment, lineno, col_offset, |
| 5972 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5973 | if (*out == NULL) goto failed; |
| 5974 | return 0; |
| 5975 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5976 | tp = astmodulestate_global->AugAssign_type; |
| 5977 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5978 | if (isinstance == -1) { |
| 5979 | return 1; |
| 5980 | } |
| 5981 | if (isinstance) { |
| 5982 | expr_ty target; |
| 5983 | operator_ty op; |
| 5984 | expr_ty value; |
| 5985 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 5986 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 5987 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5988 | return 1; |
| 5989 | } |
| 5990 | if (tmp == NULL) { |
| 5991 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
| 5992 | return 1; |
| 5993 | } |
| 5994 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5995 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 5996 | res = obj2ast_expr(tmp, &target, arena); |
| 5997 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 5998 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 5999 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6000 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6001 | return 1; |
| 6002 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6003 | if (tmp == NULL) { |
| 6004 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
| 6005 | return 1; |
| 6006 | } |
| 6007 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6008 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6009 | res = obj2ast_operator(tmp, &op, arena); |
| 6010 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6011 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6012 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6013 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6014 | return 1; |
| 6015 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6016 | if (tmp == NULL) { |
| 6017 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
| 6018 | return 1; |
| 6019 | } |
| 6020 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6021 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6022 | res = obj2ast_expr(tmp, &value, arena); |
| 6023 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6024 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6025 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6026 | *out = AugAssign(target, op, value, lineno, col_offset, end_lineno, |
| 6027 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6028 | if (*out == NULL) goto failed; |
| 6029 | return 0; |
| 6030 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6031 | tp = astmodulestate_global->AnnAssign_type; |
| 6032 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6033 | if (isinstance == -1) { |
| 6034 | return 1; |
| 6035 | } |
| 6036 | if (isinstance) { |
| 6037 | expr_ty target; |
| 6038 | expr_ty annotation; |
| 6039 | expr_ty value; |
| 6040 | int simple; |
| 6041 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6042 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6043 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6044 | return 1; |
| 6045 | } |
| 6046 | if (tmp == NULL) { |
| 6047 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
| 6048 | return 1; |
| 6049 | } |
| 6050 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6051 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6052 | res = obj2ast_expr(tmp, &target, arena); |
| 6053 | if (res != 0) goto failed; |
| 6054 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6055 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6056 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) |
| 6057 | < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6058 | return 1; |
| 6059 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6060 | if (tmp == NULL) { |
| 6061 | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
| 6062 | return 1; |
| 6063 | } |
| 6064 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6065 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6066 | res = obj2ast_expr(tmp, &annotation, arena); |
| 6067 | if (res != 0) goto failed; |
| 6068 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6069 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6070 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6071 | return 1; |
| 6072 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6073 | if (tmp == NULL || tmp == Py_None) { |
| 6074 | Py_CLEAR(tmp); |
| 6075 | value = NULL; |
| 6076 | } |
| 6077 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6078 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6079 | res = obj2ast_expr(tmp, &value, arena); |
| 6080 | if (res != 0) goto failed; |
| 6081 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6082 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6083 | if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0) |
| 6084 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6085 | return 1; |
| 6086 | } |
| 6087 | if (tmp == NULL) { |
| 6088 | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
| 6089 | return 1; |
| 6090 | } |
| 6091 | else { |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6092 | int res; |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6093 | res = obj2ast_int(tmp, &simple, arena); |
| 6094 | if (res != 0) goto failed; |
| 6095 | Py_CLEAR(tmp); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6096 | } |
| 6097 | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6098 | end_lineno, end_col_offset, arena); |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 6099 | if (*out == NULL) goto failed; |
| 6100 | return 0; |
| 6101 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6102 | tp = astmodulestate_global->For_type; |
| 6103 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6104 | if (isinstance == -1) { |
| 6105 | return 1; |
| 6106 | } |
| 6107 | if (isinstance) { |
| 6108 | expr_ty target; |
| 6109 | expr_ty iter; |
| 6110 | asdl_seq* body; |
| 6111 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6112 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6113 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6114 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6115 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6116 | return 1; |
| 6117 | } |
| 6118 | if (tmp == NULL) { |
| 6119 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
| 6120 | return 1; |
| 6121 | } |
| 6122 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6123 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6124 | res = obj2ast_expr(tmp, &target, arena); |
| 6125 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6126 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6127 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6128 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6129 | return 1; |
| 6130 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6131 | if (tmp == NULL) { |
| 6132 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
| 6133 | return 1; |
| 6134 | } |
| 6135 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6136 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6137 | res = obj2ast_expr(tmp, &iter, arena); |
| 6138 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6139 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6140 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6141 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6142 | return 1; |
| 6143 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6144 | if (tmp == NULL) { |
| 6145 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
| 6146 | return 1; |
| 6147 | } |
| 6148 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6149 | int res; |
| 6150 | Py_ssize_t len; |
| 6151 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6152 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6153 | 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] | 6154 | goto failed; |
| 6155 | } |
| 6156 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6157 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6158 | if (body == NULL) goto failed; |
| 6159 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6160 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6161 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6162 | Py_INCREF(tmp2); |
| 6163 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6164 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6165 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6166 | if (len != PyList_GET_SIZE(tmp)) { |
| 6167 | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
| 6168 | goto failed; |
| 6169 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6170 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6171 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6172 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6173 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6174 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6175 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6176 | return 1; |
| 6177 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6178 | if (tmp == NULL) { |
| 6179 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
| 6180 | return 1; |
| 6181 | } |
| 6182 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6183 | int res; |
| 6184 | Py_ssize_t len; |
| 6185 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6186 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6187 | 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] | 6188 | goto failed; |
| 6189 | } |
| 6190 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6191 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6192 | if (orelse == NULL) goto failed; |
| 6193 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6194 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6195 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6196 | Py_INCREF(tmp2); |
| 6197 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6198 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6199 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6200 | if (len != PyList_GET_SIZE(tmp)) { |
| 6201 | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
| 6202 | goto failed; |
| 6203 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6204 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6205 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6206 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6207 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6208 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6209 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6210 | return 1; |
| 6211 | } |
| 6212 | if (tmp == NULL || tmp == Py_None) { |
| 6213 | Py_CLEAR(tmp); |
| 6214 | type_comment = NULL; |
| 6215 | } |
| 6216 | else { |
| 6217 | int res; |
| 6218 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6219 | if (res != 0) goto failed; |
| 6220 | Py_CLEAR(tmp); |
| 6221 | } |
| 6222 | *out = For(target, iter, body, orelse, type_comment, lineno, |
| 6223 | col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6224 | if (*out == NULL) goto failed; |
| 6225 | return 0; |
| 6226 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6227 | tp = astmodulestate_global->AsyncFor_type; |
| 6228 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6229 | if (isinstance == -1) { |
| 6230 | return 1; |
| 6231 | } |
| 6232 | if (isinstance) { |
| 6233 | expr_ty target; |
| 6234 | expr_ty iter; |
| 6235 | asdl_seq* body; |
| 6236 | asdl_seq* orelse; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6237 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6238 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6239 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 6240 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6241 | return 1; |
| 6242 | } |
| 6243 | if (tmp == NULL) { |
| 6244 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
| 6245 | return 1; |
| 6246 | } |
| 6247 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6248 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6249 | res = obj2ast_expr(tmp, &target, arena); |
| 6250 | if (res != 0) goto failed; |
| 6251 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6252 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6253 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6254 | return 1; |
| 6255 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6256 | if (tmp == NULL) { |
| 6257 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
| 6258 | return 1; |
| 6259 | } |
| 6260 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6261 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6262 | res = obj2ast_expr(tmp, &iter, arena); |
| 6263 | if (res != 0) goto failed; |
| 6264 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6265 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6266 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6267 | return 1; |
| 6268 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6269 | if (tmp == NULL) { |
| 6270 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
| 6271 | return 1; |
| 6272 | } |
| 6273 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6274 | int res; |
| 6275 | Py_ssize_t len; |
| 6276 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6277 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6278 | 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] | 6279 | goto failed; |
| 6280 | } |
| 6281 | len = PyList_GET_SIZE(tmp); |
| 6282 | body = _Py_asdl_seq_new(len, arena); |
| 6283 | if (body == NULL) goto failed; |
| 6284 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6285 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6286 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6287 | Py_INCREF(tmp2); |
| 6288 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6289 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6290 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6291 | if (len != PyList_GET_SIZE(tmp)) { |
| 6292 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
| 6293 | goto failed; |
| 6294 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6295 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6296 | } |
| 6297 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6298 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6299 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6300 | { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6301 | return 1; |
| 6302 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6303 | if (tmp == NULL) { |
| 6304 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
| 6305 | return 1; |
| 6306 | } |
| 6307 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6308 | int res; |
| 6309 | Py_ssize_t len; |
| 6310 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6311 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6312 | 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] | 6313 | goto failed; |
| 6314 | } |
| 6315 | len = PyList_GET_SIZE(tmp); |
| 6316 | orelse = _Py_asdl_seq_new(len, arena); |
| 6317 | if (orelse == NULL) goto failed; |
| 6318 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6319 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6320 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6321 | Py_INCREF(tmp2); |
| 6322 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6323 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6324 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6325 | if (len != PyList_GET_SIZE(tmp)) { |
| 6326 | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
| 6327 | goto failed; |
| 6328 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6329 | asdl_seq_SET(orelse, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6330 | } |
| 6331 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6332 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6333 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6334 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6335 | return 1; |
| 6336 | } |
| 6337 | if (tmp == NULL || tmp == Py_None) { |
| 6338 | Py_CLEAR(tmp); |
| 6339 | type_comment = NULL; |
| 6340 | } |
| 6341 | else { |
| 6342 | int res; |
| 6343 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6344 | if (res != 0) goto failed; |
| 6345 | Py_CLEAR(tmp); |
| 6346 | } |
| 6347 | *out = AsyncFor(target, iter, body, orelse, type_comment, lineno, |
| 6348 | col_offset, end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6349 | if (*out == NULL) goto failed; |
| 6350 | return 0; |
| 6351 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6352 | tp = astmodulestate_global->While_type; |
| 6353 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6354 | if (isinstance == -1) { |
| 6355 | return 1; |
| 6356 | } |
| 6357 | if (isinstance) { |
| 6358 | expr_ty test; |
| 6359 | asdl_seq* body; |
| 6360 | asdl_seq* orelse; |
| 6361 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6362 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6363 | return 1; |
| 6364 | } |
| 6365 | if (tmp == NULL) { |
| 6366 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
| 6367 | return 1; |
| 6368 | } |
| 6369 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6370 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6371 | res = obj2ast_expr(tmp, &test, arena); |
| 6372 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6373 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6374 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6375 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6376 | return 1; |
| 6377 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6378 | if (tmp == NULL) { |
| 6379 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
| 6380 | return 1; |
| 6381 | } |
| 6382 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6383 | int res; |
| 6384 | Py_ssize_t len; |
| 6385 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6386 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6387 | 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] | 6388 | goto failed; |
| 6389 | } |
| 6390 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6391 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6392 | if (body == NULL) goto failed; |
| 6393 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6394 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6395 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6396 | Py_INCREF(tmp2); |
| 6397 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6398 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6399 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6400 | if (len != PyList_GET_SIZE(tmp)) { |
| 6401 | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
| 6402 | goto failed; |
| 6403 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6404 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6405 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6406 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6407 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6408 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6409 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6410 | return 1; |
| 6411 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6412 | if (tmp == NULL) { |
| 6413 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
| 6414 | return 1; |
| 6415 | } |
| 6416 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6417 | int res; |
| 6418 | Py_ssize_t len; |
| 6419 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6420 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6421 | 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] | 6422 | goto failed; |
| 6423 | } |
| 6424 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6425 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6426 | if (orelse == NULL) goto failed; |
| 6427 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6428 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6429 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6430 | Py_INCREF(tmp2); |
| 6431 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6432 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6433 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6434 | if (len != PyList_GET_SIZE(tmp)) { |
| 6435 | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
| 6436 | goto failed; |
| 6437 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6438 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6439 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6440 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6441 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6442 | *out = While(test, body, orelse, lineno, col_offset, end_lineno, |
| 6443 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6444 | if (*out == NULL) goto failed; |
| 6445 | return 0; |
| 6446 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6447 | tp = astmodulestate_global->If_type; |
| 6448 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6449 | if (isinstance == -1) { |
| 6450 | return 1; |
| 6451 | } |
| 6452 | if (isinstance) { |
| 6453 | expr_ty test; |
| 6454 | asdl_seq* body; |
| 6455 | asdl_seq* orelse; |
| 6456 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6457 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6458 | return 1; |
| 6459 | } |
| 6460 | if (tmp == NULL) { |
| 6461 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
| 6462 | return 1; |
| 6463 | } |
| 6464 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6465 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6466 | res = obj2ast_expr(tmp, &test, arena); |
| 6467 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6468 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6469 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6470 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6471 | return 1; |
| 6472 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6473 | if (tmp == NULL) { |
| 6474 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
| 6475 | return 1; |
| 6476 | } |
| 6477 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6478 | int res; |
| 6479 | Py_ssize_t len; |
| 6480 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6481 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6482 | 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] | 6483 | goto failed; |
| 6484 | } |
| 6485 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6486 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6487 | if (body == NULL) goto failed; |
| 6488 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6489 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6490 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6491 | Py_INCREF(tmp2); |
| 6492 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6493 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6494 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6495 | if (len != PyList_GET_SIZE(tmp)) { |
| 6496 | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
| 6497 | goto failed; |
| 6498 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6499 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6500 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6501 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6502 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6503 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6504 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6505 | return 1; |
| 6506 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6507 | if (tmp == NULL) { |
| 6508 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
| 6509 | return 1; |
| 6510 | } |
| 6511 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6512 | int res; |
| 6513 | Py_ssize_t len; |
| 6514 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6515 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6516 | 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] | 6517 | goto failed; |
| 6518 | } |
| 6519 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6520 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6521 | if (orelse == NULL) goto failed; |
| 6522 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6523 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6524 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6525 | Py_INCREF(tmp2); |
| 6526 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6527 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6528 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6529 | if (len != PyList_GET_SIZE(tmp)) { |
| 6530 | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
| 6531 | goto failed; |
| 6532 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6533 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6534 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6535 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6536 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6537 | *out = If(test, body, orelse, lineno, col_offset, end_lineno, |
| 6538 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6539 | if (*out == NULL) goto failed; |
| 6540 | return 0; |
| 6541 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6542 | tp = astmodulestate_global->With_type; |
| 6543 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6544 | if (isinstance == -1) { |
| 6545 | return 1; |
| 6546 | } |
| 6547 | if (isinstance) { |
| 6548 | asdl_seq* items; |
| 6549 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6550 | string type_comment; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6551 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6552 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6553 | return 1; |
| 6554 | } |
| 6555 | if (tmp == NULL) { |
| 6556 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
| 6557 | return 1; |
| 6558 | } |
| 6559 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6560 | int res; |
| 6561 | Py_ssize_t len; |
| 6562 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6563 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6564 | 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] | 6565 | goto failed; |
| 6566 | } |
| 6567 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6568 | items = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6569 | if (items == NULL) goto failed; |
| 6570 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6571 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6572 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6573 | Py_INCREF(tmp2); |
| 6574 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6575 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6576 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6577 | if (len != PyList_GET_SIZE(tmp)) { |
| 6578 | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
| 6579 | goto failed; |
| 6580 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6581 | asdl_seq_SET(items, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6582 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6583 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6584 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6585 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6586 | return 1; |
| 6587 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6588 | if (tmp == NULL) { |
| 6589 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
| 6590 | return 1; |
| 6591 | } |
| 6592 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6593 | int res; |
| 6594 | Py_ssize_t len; |
| 6595 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6596 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6597 | 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] | 6598 | goto failed; |
| 6599 | } |
| 6600 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6601 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6602 | if (body == NULL) goto failed; |
| 6603 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6604 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6605 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6606 | Py_INCREF(tmp2); |
| 6607 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6608 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6609 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6610 | if (len != PyList_GET_SIZE(tmp)) { |
| 6611 | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
| 6612 | goto failed; |
| 6613 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6614 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6615 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6616 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6617 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6618 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6619 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6620 | return 1; |
| 6621 | } |
| 6622 | if (tmp == NULL || tmp == Py_None) { |
| 6623 | Py_CLEAR(tmp); |
| 6624 | type_comment = NULL; |
| 6625 | } |
| 6626 | else { |
| 6627 | int res; |
| 6628 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6629 | if (res != 0) goto failed; |
| 6630 | Py_CLEAR(tmp); |
| 6631 | } |
| 6632 | *out = With(items, body, type_comment, lineno, col_offset, end_lineno, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6633 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6634 | if (*out == NULL) goto failed; |
| 6635 | return 0; |
| 6636 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6637 | tp = astmodulestate_global->AsyncWith_type; |
| 6638 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6639 | if (isinstance == -1) { |
| 6640 | return 1; |
| 6641 | } |
| 6642 | if (isinstance) { |
| 6643 | asdl_seq* items; |
| 6644 | asdl_seq* body; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6645 | string type_comment; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6646 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6647 | if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6648 | return 1; |
| 6649 | } |
| 6650 | if (tmp == NULL) { |
| 6651 | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
| 6652 | return 1; |
| 6653 | } |
| 6654 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6655 | int res; |
| 6656 | Py_ssize_t len; |
| 6657 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6658 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6659 | 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] | 6660 | goto failed; |
| 6661 | } |
| 6662 | len = PyList_GET_SIZE(tmp); |
| 6663 | items = _Py_asdl_seq_new(len, arena); |
| 6664 | if (items == NULL) goto failed; |
| 6665 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6666 | withitem_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6667 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6668 | Py_INCREF(tmp2); |
| 6669 | res = obj2ast_withitem(tmp2, &val, arena); |
| 6670 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6671 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6672 | if (len != PyList_GET_SIZE(tmp)) { |
| 6673 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
| 6674 | goto failed; |
| 6675 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6676 | asdl_seq_SET(items, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6677 | } |
| 6678 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6679 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6680 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6681 | return 1; |
| 6682 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6683 | if (tmp == NULL) { |
| 6684 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
| 6685 | return 1; |
| 6686 | } |
| 6687 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6688 | int res; |
| 6689 | Py_ssize_t len; |
| 6690 | Py_ssize_t i; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6691 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6692 | 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] | 6693 | goto failed; |
| 6694 | } |
| 6695 | len = PyList_GET_SIZE(tmp); |
| 6696 | body = _Py_asdl_seq_new(len, arena); |
| 6697 | if (body == NULL) goto failed; |
| 6698 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6699 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6700 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6701 | Py_INCREF(tmp2); |
| 6702 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6703 | Py_DECREF(tmp2); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6704 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6705 | if (len != PyList_GET_SIZE(tmp)) { |
| 6706 | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
| 6707 | goto failed; |
| 6708 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6709 | asdl_seq_SET(body, i, val); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6710 | } |
| 6711 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6712 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6713 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, |
| 6714 | &tmp) < 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 6715 | return 1; |
| 6716 | } |
| 6717 | if (tmp == NULL || tmp == Py_None) { |
| 6718 | Py_CLEAR(tmp); |
| 6719 | type_comment = NULL; |
| 6720 | } |
| 6721 | else { |
| 6722 | int res; |
| 6723 | res = obj2ast_string(tmp, &type_comment, arena); |
| 6724 | if (res != 0) goto failed; |
| 6725 | Py_CLEAR(tmp); |
| 6726 | } |
| 6727 | *out = AsyncWith(items, body, type_comment, lineno, col_offset, |
| 6728 | end_lineno, end_col_offset, arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 6729 | if (*out == NULL) goto failed; |
| 6730 | return 0; |
| 6731 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6732 | tp = astmodulestate_global->Raise_type; |
| 6733 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6734 | if (isinstance == -1) { |
| 6735 | return 1; |
| 6736 | } |
| 6737 | if (isinstance) { |
| 6738 | expr_ty exc; |
| 6739 | expr_ty cause; |
| 6740 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6741 | if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6742 | return 1; |
| 6743 | } |
| 6744 | if (tmp == NULL || tmp == Py_None) { |
| 6745 | Py_CLEAR(tmp); |
| 6746 | exc = NULL; |
| 6747 | } |
| 6748 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6749 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6750 | res = obj2ast_expr(tmp, &exc, arena); |
| 6751 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6752 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6753 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6754 | if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6755 | return 1; |
| 6756 | } |
| 6757 | if (tmp == NULL || tmp == Py_None) { |
| 6758 | Py_CLEAR(tmp); |
| 6759 | cause = NULL; |
| 6760 | } |
| 6761 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6762 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6763 | res = obj2ast_expr(tmp, &cause, arena); |
| 6764 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6765 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6766 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6767 | *out = Raise(exc, cause, lineno, col_offset, end_lineno, |
| 6768 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6769 | if (*out == NULL) goto failed; |
| 6770 | return 0; |
| 6771 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6772 | tp = astmodulestate_global->Try_type; |
| 6773 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6774 | if (isinstance == -1) { |
| 6775 | return 1; |
| 6776 | } |
| 6777 | if (isinstance) { |
| 6778 | asdl_seq* body; |
| 6779 | asdl_seq* handlers; |
| 6780 | asdl_seq* orelse; |
| 6781 | asdl_seq* finalbody; |
| 6782 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6783 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6784 | return 1; |
| 6785 | } |
| 6786 | if (tmp == NULL) { |
| 6787 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
| 6788 | return 1; |
| 6789 | } |
| 6790 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6791 | int res; |
| 6792 | Py_ssize_t len; |
| 6793 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6794 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6795 | 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] | 6796 | goto failed; |
| 6797 | } |
| 6798 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6799 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6800 | if (body == NULL) goto failed; |
| 6801 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6802 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6803 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6804 | Py_INCREF(tmp2); |
| 6805 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6806 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6807 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6808 | if (len != PyList_GET_SIZE(tmp)) { |
| 6809 | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
| 6810 | goto failed; |
| 6811 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6812 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6813 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6814 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6815 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6816 | if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) < |
| 6817 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6818 | return 1; |
| 6819 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6820 | if (tmp == NULL) { |
| 6821 | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
| 6822 | return 1; |
| 6823 | } |
| 6824 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6825 | int res; |
| 6826 | Py_ssize_t len; |
| 6827 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6828 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6829 | 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] | 6830 | goto failed; |
| 6831 | } |
| 6832 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6833 | handlers = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6834 | if (handlers == NULL) goto failed; |
| 6835 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6836 | excepthandler_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6837 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6838 | Py_INCREF(tmp2); |
| 6839 | res = obj2ast_excepthandler(tmp2, &val, arena); |
| 6840 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6841 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6842 | if (len != PyList_GET_SIZE(tmp)) { |
| 6843 | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
| 6844 | goto failed; |
| 6845 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6846 | asdl_seq_SET(handlers, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6847 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6848 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6849 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6850 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 6851 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6852 | return 1; |
| 6853 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6854 | if (tmp == NULL) { |
| 6855 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
| 6856 | return 1; |
| 6857 | } |
| 6858 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6859 | int res; |
| 6860 | Py_ssize_t len; |
| 6861 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6862 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6863 | 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] | 6864 | goto failed; |
| 6865 | } |
| 6866 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6867 | orelse = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6868 | if (orelse == NULL) goto failed; |
| 6869 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6870 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6871 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6872 | Py_INCREF(tmp2); |
| 6873 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6874 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6875 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6876 | if (len != PyList_GET_SIZE(tmp)) { |
| 6877 | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
| 6878 | goto failed; |
| 6879 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6880 | asdl_seq_SET(orelse, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6881 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6882 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6883 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6884 | if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) < |
| 6885 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6886 | return 1; |
| 6887 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6888 | if (tmp == NULL) { |
| 6889 | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
| 6890 | return 1; |
| 6891 | } |
| 6892 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6893 | int res; |
| 6894 | Py_ssize_t len; |
| 6895 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6896 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6897 | 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] | 6898 | goto failed; |
| 6899 | } |
| 6900 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6901 | finalbody = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6902 | if (finalbody == NULL) goto failed; |
| 6903 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6904 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6905 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6906 | Py_INCREF(tmp2); |
| 6907 | res = obj2ast_stmt(tmp2, &val, arena); |
| 6908 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6909 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6910 | if (len != PyList_GET_SIZE(tmp)) { |
| 6911 | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
| 6912 | goto failed; |
| 6913 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6914 | asdl_seq_SET(finalbody, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6915 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6916 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6917 | } |
| 6918 | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6919 | end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6920 | if (*out == NULL) goto failed; |
| 6921 | return 0; |
| 6922 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6923 | tp = astmodulestate_global->Assert_type; |
| 6924 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6925 | if (isinstance == -1) { |
| 6926 | return 1; |
| 6927 | } |
| 6928 | if (isinstance) { |
| 6929 | expr_ty test; |
| 6930 | expr_ty msg; |
| 6931 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6932 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6933 | return 1; |
| 6934 | } |
| 6935 | if (tmp == NULL) { |
| 6936 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
| 6937 | return 1; |
| 6938 | } |
| 6939 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6940 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6941 | res = obj2ast_expr(tmp, &test, arena); |
| 6942 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6943 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6944 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6945 | if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6946 | return 1; |
| 6947 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6948 | if (tmp == NULL || tmp == Py_None) { |
| 6949 | Py_CLEAR(tmp); |
| 6950 | msg = NULL; |
| 6951 | } |
| 6952 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6953 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6954 | res = obj2ast_expr(tmp, &msg, arena); |
| 6955 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 6956 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6957 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 6958 | *out = Assert(test, msg, lineno, col_offset, end_lineno, |
| 6959 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6960 | if (*out == NULL) goto failed; |
| 6961 | return 0; |
| 6962 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6963 | tp = astmodulestate_global->Import_type; |
| 6964 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6965 | if (isinstance == -1) { |
| 6966 | return 1; |
| 6967 | } |
| 6968 | if (isinstance) { |
| 6969 | asdl_seq* names; |
| 6970 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6971 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 6972 | return 1; |
| 6973 | } |
| 6974 | if (tmp == NULL) { |
| 6975 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
| 6976 | return 1; |
| 6977 | } |
| 6978 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6979 | int res; |
| 6980 | Py_ssize_t len; |
| 6981 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6982 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 6983 | 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] | 6984 | goto failed; |
| 6985 | } |
| 6986 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 6987 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6988 | if (names == NULL) goto failed; |
| 6989 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 6990 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 6991 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 6992 | Py_INCREF(tmp2); |
| 6993 | res = obj2ast_alias(tmp2, &val, arena); |
| 6994 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 6995 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 6996 | if (len != PyList_GET_SIZE(tmp)) { |
| 6997 | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
| 6998 | goto failed; |
| 6999 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7000 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7001 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7002 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7003 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7004 | *out = Import(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7005 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7006 | if (*out == NULL) goto failed; |
| 7007 | return 0; |
| 7008 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7009 | tp = astmodulestate_global->ImportFrom_type; |
| 7010 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7011 | if (isinstance == -1) { |
| 7012 | return 1; |
| 7013 | } |
| 7014 | if (isinstance) { |
| 7015 | identifier module; |
| 7016 | asdl_seq* names; |
| 7017 | int level; |
| 7018 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7019 | if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0) |
| 7020 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7021 | return 1; |
| 7022 | } |
| 7023 | if (tmp == NULL || tmp == Py_None) { |
| 7024 | Py_CLEAR(tmp); |
| 7025 | module = NULL; |
| 7026 | } |
| 7027 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7028 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7029 | res = obj2ast_identifier(tmp, &module, arena); |
| 7030 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7031 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7032 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7033 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7034 | return 1; |
| 7035 | } |
| 7036 | if (tmp == NULL) { |
| 7037 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
| 7038 | return 1; |
| 7039 | } |
| 7040 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7041 | int res; |
| 7042 | Py_ssize_t len; |
| 7043 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7044 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7045 | 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] | 7046 | goto failed; |
| 7047 | } |
| 7048 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7049 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7050 | if (names == NULL) goto failed; |
| 7051 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7052 | alias_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7053 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7054 | Py_INCREF(tmp2); |
| 7055 | res = obj2ast_alias(tmp2, &val, arena); |
| 7056 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7057 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7058 | if (len != PyList_GET_SIZE(tmp)) { |
| 7059 | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
| 7060 | goto failed; |
| 7061 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7062 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7063 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7064 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7065 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7066 | if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7067 | return 1; |
| 7068 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7069 | if (tmp == NULL || tmp == Py_None) { |
| 7070 | Py_CLEAR(tmp); |
| 7071 | level = 0; |
| 7072 | } |
| 7073 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7074 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7075 | res = obj2ast_int(tmp, &level, arena); |
| 7076 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7077 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7078 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7079 | *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno, |
| 7080 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7081 | if (*out == NULL) goto failed; |
| 7082 | return 0; |
| 7083 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7084 | tp = astmodulestate_global->Global_type; |
| 7085 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7086 | if (isinstance == -1) { |
| 7087 | return 1; |
| 7088 | } |
| 7089 | if (isinstance) { |
| 7090 | asdl_seq* names; |
| 7091 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7092 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7093 | return 1; |
| 7094 | } |
| 7095 | if (tmp == NULL) { |
| 7096 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
| 7097 | return 1; |
| 7098 | } |
| 7099 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7100 | int res; |
| 7101 | Py_ssize_t len; |
| 7102 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7103 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7104 | 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] | 7105 | goto failed; |
| 7106 | } |
| 7107 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7108 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7109 | if (names == NULL) goto failed; |
| 7110 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7111 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7112 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7113 | Py_INCREF(tmp2); |
| 7114 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7115 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7116 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7117 | if (len != PyList_GET_SIZE(tmp)) { |
| 7118 | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
| 7119 | goto failed; |
| 7120 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7121 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7122 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7123 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7124 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7125 | *out = Global(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7126 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7127 | if (*out == NULL) goto failed; |
| 7128 | return 0; |
| 7129 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7130 | tp = astmodulestate_global->Nonlocal_type; |
| 7131 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7132 | if (isinstance == -1) { |
| 7133 | return 1; |
| 7134 | } |
| 7135 | if (isinstance) { |
| 7136 | asdl_seq* names; |
| 7137 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7138 | if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7139 | return 1; |
| 7140 | } |
| 7141 | if (tmp == NULL) { |
| 7142 | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
| 7143 | return 1; |
| 7144 | } |
| 7145 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7146 | int res; |
| 7147 | Py_ssize_t len; |
| 7148 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7149 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7150 | 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] | 7151 | goto failed; |
| 7152 | } |
| 7153 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7154 | names = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7155 | if (names == NULL) goto failed; |
| 7156 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7157 | identifier val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7158 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7159 | Py_INCREF(tmp2); |
| 7160 | res = obj2ast_identifier(tmp2, &val, arena); |
| 7161 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7162 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7163 | if (len != PyList_GET_SIZE(tmp)) { |
| 7164 | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
| 7165 | goto failed; |
| 7166 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7167 | asdl_seq_SET(names, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7168 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7169 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7170 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7171 | *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset, |
| 7172 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7173 | if (*out == NULL) goto failed; |
| 7174 | return 0; |
| 7175 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7176 | tp = astmodulestate_global->Expr_type; |
| 7177 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7178 | if (isinstance == -1) { |
| 7179 | return 1; |
| 7180 | } |
| 7181 | if (isinstance) { |
| 7182 | expr_ty value; |
| 7183 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7184 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7185 | return 1; |
| 7186 | } |
| 7187 | if (tmp == NULL) { |
| 7188 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
| 7189 | return 1; |
| 7190 | } |
| 7191 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7192 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7193 | res = obj2ast_expr(tmp, &value, arena); |
| 7194 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7195 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7196 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7197 | *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset, |
| 7198 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7199 | if (*out == NULL) goto failed; |
| 7200 | return 0; |
| 7201 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7202 | tp = astmodulestate_global->Pass_type; |
| 7203 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7204 | if (isinstance == -1) { |
| 7205 | return 1; |
| 7206 | } |
| 7207 | if (isinstance) { |
| 7208 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7209 | *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7210 | if (*out == NULL) goto failed; |
| 7211 | return 0; |
| 7212 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7213 | tp = astmodulestate_global->Break_type; |
| 7214 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7215 | if (isinstance == -1) { |
| 7216 | return 1; |
| 7217 | } |
| 7218 | if (isinstance) { |
| 7219 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7220 | *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7221 | if (*out == NULL) goto failed; |
| 7222 | return 0; |
| 7223 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7224 | tp = astmodulestate_global->Continue_type; |
| 7225 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7226 | if (isinstance == -1) { |
| 7227 | return 1; |
| 7228 | } |
| 7229 | if (isinstance) { |
| 7230 | |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7231 | *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7232 | if (*out == NULL) goto failed; |
| 7233 | return 0; |
| 7234 | } |
| 7235 | |
| 7236 | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
| 7237 | failed: |
| 7238 | Py_XDECREF(tmp); |
| 7239 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | int |
| 7243 | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
| 7244 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7245 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7246 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7247 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7248 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7249 | int lineno; |
| 7250 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7251 | int end_lineno; |
| 7252 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7253 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7254 | if (obj == Py_None) { |
| 7255 | *out = NULL; |
| 7256 | return 0; |
| 7257 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7258 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7259 | return 1; |
| 7260 | } |
| 7261 | if (tmp == NULL) { |
| 7262 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
| 7263 | return 1; |
| 7264 | } |
| 7265 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7266 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7267 | res = obj2ast_int(tmp, &lineno, arena); |
| 7268 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7269 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7270 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7271 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 7272 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 7273 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7274 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7275 | if (tmp == NULL) { |
| 7276 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
| 7277 | return 1; |
| 7278 | } |
| 7279 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7280 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7281 | res = obj2ast_int(tmp, &col_offset, arena); |
| 7282 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7283 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7284 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7285 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 7286 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7287 | return 1; |
| 7288 | } |
| 7289 | if (tmp == NULL || tmp == Py_None) { |
| 7290 | Py_CLEAR(tmp); |
| 7291 | end_lineno = 0; |
| 7292 | } |
| 7293 | else { |
| 7294 | int res; |
| 7295 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 7296 | if (res != 0) goto failed; |
| 7297 | Py_CLEAR(tmp); |
| 7298 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7299 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 7300 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7301 | return 1; |
| 7302 | } |
| 7303 | if (tmp == NULL || tmp == Py_None) { |
| 7304 | Py_CLEAR(tmp); |
| 7305 | end_col_offset = 0; |
| 7306 | } |
| 7307 | else { |
| 7308 | int res; |
| 7309 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 7310 | if (res != 0) goto failed; |
| 7311 | Py_CLEAR(tmp); |
| 7312 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7313 | tp = astmodulestate_global->BoolOp_type; |
| 7314 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7315 | if (isinstance == -1) { |
| 7316 | return 1; |
| 7317 | } |
| 7318 | if (isinstance) { |
| 7319 | boolop_ty op; |
| 7320 | asdl_seq* values; |
| 7321 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7322 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7323 | return 1; |
| 7324 | } |
| 7325 | if (tmp == NULL) { |
| 7326 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
| 7327 | return 1; |
| 7328 | } |
| 7329 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7330 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7331 | res = obj2ast_boolop(tmp, &op, arena); |
| 7332 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7333 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7334 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7335 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7336 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7337 | return 1; |
| 7338 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7339 | if (tmp == NULL) { |
| 7340 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
| 7341 | return 1; |
| 7342 | } |
| 7343 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7344 | int res; |
| 7345 | Py_ssize_t len; |
| 7346 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7347 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7348 | 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] | 7349 | goto failed; |
| 7350 | } |
| 7351 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7352 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7353 | if (values == NULL) goto failed; |
| 7354 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7355 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7356 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7357 | Py_INCREF(tmp2); |
| 7358 | res = obj2ast_expr(tmp2, &val, arena); |
| 7359 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7360 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7361 | if (len != PyList_GET_SIZE(tmp)) { |
| 7362 | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
| 7363 | goto failed; |
| 7364 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7365 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7366 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7367 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7368 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7369 | *out = BoolOp(op, values, lineno, col_offset, end_lineno, |
| 7370 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7371 | if (*out == NULL) goto failed; |
| 7372 | return 0; |
| 7373 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7374 | tp = astmodulestate_global->NamedExpr_type; |
| 7375 | isinstance = PyObject_IsInstance(obj, tp); |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7376 | if (isinstance == -1) { |
| 7377 | return 1; |
| 7378 | } |
| 7379 | if (isinstance) { |
| 7380 | expr_ty target; |
| 7381 | expr_ty value; |
| 7382 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7383 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) |
| 7384 | { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7385 | return 1; |
| 7386 | } |
| 7387 | if (tmp == NULL) { |
| 7388 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr"); |
| 7389 | return 1; |
| 7390 | } |
| 7391 | else { |
| 7392 | int res; |
| 7393 | res = obj2ast_expr(tmp, &target, arena); |
| 7394 | if (res != 0) goto failed; |
| 7395 | Py_CLEAR(tmp); |
| 7396 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7397 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 7398 | return 1; |
| 7399 | } |
| 7400 | if (tmp == NULL) { |
| 7401 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr"); |
| 7402 | return 1; |
| 7403 | } |
| 7404 | else { |
| 7405 | int res; |
| 7406 | res = obj2ast_expr(tmp, &value, arena); |
| 7407 | if (res != 0) goto failed; |
| 7408 | Py_CLEAR(tmp); |
| 7409 | } |
| 7410 | *out = NamedExpr(target, value, lineno, col_offset, end_lineno, |
| 7411 | end_col_offset, arena); |
| 7412 | if (*out == NULL) goto failed; |
| 7413 | return 0; |
| 7414 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7415 | tp = astmodulestate_global->BinOp_type; |
| 7416 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7417 | if (isinstance == -1) { |
| 7418 | return 1; |
| 7419 | } |
| 7420 | if (isinstance) { |
| 7421 | expr_ty left; |
| 7422 | operator_ty op; |
| 7423 | expr_ty right; |
| 7424 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7425 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7426 | return 1; |
| 7427 | } |
| 7428 | if (tmp == NULL) { |
| 7429 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
| 7430 | return 1; |
| 7431 | } |
| 7432 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7433 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7434 | res = obj2ast_expr(tmp, &left, arena); |
| 7435 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7436 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7437 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7438 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7439 | return 1; |
| 7440 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7441 | if (tmp == NULL) { |
| 7442 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
| 7443 | return 1; |
| 7444 | } |
| 7445 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7446 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7447 | res = obj2ast_operator(tmp, &op, arena); |
| 7448 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7449 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7450 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7451 | if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7452 | return 1; |
| 7453 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7454 | if (tmp == NULL) { |
| 7455 | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
| 7456 | return 1; |
| 7457 | } |
| 7458 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7459 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7460 | res = obj2ast_expr(tmp, &right, arena); |
| 7461 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7462 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7463 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7464 | *out = BinOp(left, op, right, lineno, col_offset, end_lineno, |
| 7465 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7466 | if (*out == NULL) goto failed; |
| 7467 | return 0; |
| 7468 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7469 | tp = astmodulestate_global->UnaryOp_type; |
| 7470 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7471 | if (isinstance == -1) { |
| 7472 | return 1; |
| 7473 | } |
| 7474 | if (isinstance) { |
| 7475 | unaryop_ty op; |
| 7476 | expr_ty operand; |
| 7477 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7478 | if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7479 | return 1; |
| 7480 | } |
| 7481 | if (tmp == NULL) { |
| 7482 | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
| 7483 | return 1; |
| 7484 | } |
| 7485 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7486 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7487 | res = obj2ast_unaryop(tmp, &op, arena); |
| 7488 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7489 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7490 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7491 | if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) < |
| 7492 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7493 | return 1; |
| 7494 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7495 | if (tmp == NULL) { |
| 7496 | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
| 7497 | return 1; |
| 7498 | } |
| 7499 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7500 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7501 | res = obj2ast_expr(tmp, &operand, arena); |
| 7502 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7503 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7504 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7505 | *out = UnaryOp(op, operand, lineno, col_offset, end_lineno, |
| 7506 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7507 | if (*out == NULL) goto failed; |
| 7508 | return 0; |
| 7509 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7510 | tp = astmodulestate_global->Lambda_type; |
| 7511 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7512 | if (isinstance == -1) { |
| 7513 | return 1; |
| 7514 | } |
| 7515 | if (isinstance) { |
| 7516 | arguments_ty args; |
| 7517 | expr_ty body; |
| 7518 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7519 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7520 | return 1; |
| 7521 | } |
| 7522 | if (tmp == NULL) { |
| 7523 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
| 7524 | return 1; |
| 7525 | } |
| 7526 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7527 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7528 | res = obj2ast_arguments(tmp, &args, arena); |
| 7529 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7530 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7531 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7532 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7533 | return 1; |
| 7534 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7535 | if (tmp == NULL) { |
| 7536 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
| 7537 | return 1; |
| 7538 | } |
| 7539 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7540 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7541 | res = obj2ast_expr(tmp, &body, arena); |
| 7542 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7543 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7544 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7545 | *out = Lambda(args, body, lineno, col_offset, end_lineno, |
| 7546 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7547 | if (*out == NULL) goto failed; |
| 7548 | return 0; |
| 7549 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7550 | tp = astmodulestate_global->IfExp_type; |
| 7551 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7552 | if (isinstance == -1) { |
| 7553 | return 1; |
| 7554 | } |
| 7555 | if (isinstance) { |
| 7556 | expr_ty test; |
| 7557 | expr_ty body; |
| 7558 | expr_ty orelse; |
| 7559 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7560 | if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7561 | return 1; |
| 7562 | } |
| 7563 | if (tmp == NULL) { |
| 7564 | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
| 7565 | return 1; |
| 7566 | } |
| 7567 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7568 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7569 | res = obj2ast_expr(tmp, &test, arena); |
| 7570 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7571 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7572 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7573 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7574 | return 1; |
| 7575 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7576 | if (tmp == NULL) { |
| 7577 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
| 7578 | return 1; |
| 7579 | } |
| 7580 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7581 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7582 | res = obj2ast_expr(tmp, &body, arena); |
| 7583 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7584 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7585 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7586 | if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0) |
| 7587 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7588 | return 1; |
| 7589 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7590 | if (tmp == NULL) { |
| 7591 | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
| 7592 | return 1; |
| 7593 | } |
| 7594 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7595 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7596 | res = obj2ast_expr(tmp, &orelse, arena); |
| 7597 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7598 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7599 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7600 | *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno, |
| 7601 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7602 | if (*out == NULL) goto failed; |
| 7603 | return 0; |
| 7604 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7605 | tp = astmodulestate_global->Dict_type; |
| 7606 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7607 | if (isinstance == -1) { |
| 7608 | return 1; |
| 7609 | } |
| 7610 | if (isinstance) { |
| 7611 | asdl_seq* keys; |
| 7612 | asdl_seq* values; |
| 7613 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7614 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7615 | return 1; |
| 7616 | } |
| 7617 | if (tmp == NULL) { |
| 7618 | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
| 7619 | return 1; |
| 7620 | } |
| 7621 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7622 | int res; |
| 7623 | Py_ssize_t len; |
| 7624 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7625 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7626 | 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] | 7627 | goto failed; |
| 7628 | } |
| 7629 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7630 | keys = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7631 | if (keys == NULL) goto failed; |
| 7632 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7633 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7634 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7635 | Py_INCREF(tmp2); |
| 7636 | res = obj2ast_expr(tmp2, &val, arena); |
| 7637 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7638 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7639 | if (len != PyList_GET_SIZE(tmp)) { |
| 7640 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
| 7641 | goto failed; |
| 7642 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7643 | asdl_seq_SET(keys, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7644 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7645 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7646 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7647 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 7648 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7649 | return 1; |
| 7650 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7651 | if (tmp == NULL) { |
| 7652 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
| 7653 | return 1; |
| 7654 | } |
| 7655 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7656 | int res; |
| 7657 | Py_ssize_t len; |
| 7658 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7659 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7660 | 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] | 7661 | goto failed; |
| 7662 | } |
| 7663 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7664 | values = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7665 | if (values == NULL) goto failed; |
| 7666 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7667 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7668 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7669 | Py_INCREF(tmp2); |
| 7670 | res = obj2ast_expr(tmp2, &val, arena); |
| 7671 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7672 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7673 | if (len != PyList_GET_SIZE(tmp)) { |
| 7674 | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
| 7675 | goto failed; |
| 7676 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7677 | asdl_seq_SET(values, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7678 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7679 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7680 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7681 | *out = Dict(keys, values, lineno, col_offset, end_lineno, |
| 7682 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7683 | if (*out == NULL) goto failed; |
| 7684 | return 0; |
| 7685 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7686 | tp = astmodulestate_global->Set_type; |
| 7687 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7688 | if (isinstance == -1) { |
| 7689 | return 1; |
| 7690 | } |
| 7691 | if (isinstance) { |
| 7692 | asdl_seq* elts; |
| 7693 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7694 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7695 | return 1; |
| 7696 | } |
| 7697 | if (tmp == NULL) { |
| 7698 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
| 7699 | return 1; |
| 7700 | } |
| 7701 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7702 | int res; |
| 7703 | Py_ssize_t len; |
| 7704 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7705 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7706 | 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] | 7707 | goto failed; |
| 7708 | } |
| 7709 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7710 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7711 | if (elts == NULL) goto failed; |
| 7712 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7713 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7714 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7715 | Py_INCREF(tmp2); |
| 7716 | res = obj2ast_expr(tmp2, &val, arena); |
| 7717 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7718 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7719 | if (len != PyList_GET_SIZE(tmp)) { |
| 7720 | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
| 7721 | goto failed; |
| 7722 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7723 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7724 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7725 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7726 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7727 | *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7728 | if (*out == NULL) goto failed; |
| 7729 | return 0; |
| 7730 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7731 | tp = astmodulestate_global->ListComp_type; |
| 7732 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7733 | if (isinstance == -1) { |
| 7734 | return 1; |
| 7735 | } |
| 7736 | if (isinstance) { |
| 7737 | expr_ty elt; |
| 7738 | asdl_seq* generators; |
| 7739 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7740 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7741 | return 1; |
| 7742 | } |
| 7743 | if (tmp == NULL) { |
| 7744 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
| 7745 | return 1; |
| 7746 | } |
| 7747 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7748 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7749 | res = obj2ast_expr(tmp, &elt, arena); |
| 7750 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7751 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7752 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7753 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7754 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7755 | return 1; |
| 7756 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7757 | if (tmp == NULL) { |
| 7758 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
| 7759 | return 1; |
| 7760 | } |
| 7761 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7762 | int res; |
| 7763 | Py_ssize_t len; |
| 7764 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7765 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7766 | 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] | 7767 | goto failed; |
| 7768 | } |
| 7769 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7770 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7771 | if (generators == NULL) goto failed; |
| 7772 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7773 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7774 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7775 | Py_INCREF(tmp2); |
| 7776 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7777 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7778 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7779 | if (len != PyList_GET_SIZE(tmp)) { |
| 7780 | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
| 7781 | goto failed; |
| 7782 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7783 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7784 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7785 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7786 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7787 | *out = ListComp(elt, generators, lineno, col_offset, end_lineno, |
| 7788 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7789 | if (*out == NULL) goto failed; |
| 7790 | return 0; |
| 7791 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7792 | tp = astmodulestate_global->SetComp_type; |
| 7793 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7794 | if (isinstance == -1) { |
| 7795 | return 1; |
| 7796 | } |
| 7797 | if (isinstance) { |
| 7798 | expr_ty elt; |
| 7799 | asdl_seq* generators; |
| 7800 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7801 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7802 | return 1; |
| 7803 | } |
| 7804 | if (tmp == NULL) { |
| 7805 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
| 7806 | return 1; |
| 7807 | } |
| 7808 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7809 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7810 | res = obj2ast_expr(tmp, &elt, arena); |
| 7811 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7812 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7813 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7814 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7815 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7816 | return 1; |
| 7817 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7818 | if (tmp == NULL) { |
| 7819 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
| 7820 | return 1; |
| 7821 | } |
| 7822 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7823 | int res; |
| 7824 | Py_ssize_t len; |
| 7825 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7826 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7827 | 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] | 7828 | goto failed; |
| 7829 | } |
| 7830 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7831 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7832 | if (generators == NULL) goto failed; |
| 7833 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7834 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7835 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7836 | Py_INCREF(tmp2); |
| 7837 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7838 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7839 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7840 | if (len != PyList_GET_SIZE(tmp)) { |
| 7841 | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
| 7842 | goto failed; |
| 7843 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7844 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7845 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7846 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7847 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7848 | *out = SetComp(elt, generators, lineno, col_offset, end_lineno, |
| 7849 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7850 | if (*out == NULL) goto failed; |
| 7851 | return 0; |
| 7852 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7853 | tp = astmodulestate_global->DictComp_type; |
| 7854 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7855 | if (isinstance == -1) { |
| 7856 | return 1; |
| 7857 | } |
| 7858 | if (isinstance) { |
| 7859 | expr_ty key; |
| 7860 | expr_ty value; |
| 7861 | asdl_seq* generators; |
| 7862 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7863 | if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7864 | return 1; |
| 7865 | } |
| 7866 | if (tmp == NULL) { |
| 7867 | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
| 7868 | return 1; |
| 7869 | } |
| 7870 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7871 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7872 | res = obj2ast_expr(tmp, &key, arena); |
| 7873 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7874 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7875 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7876 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7877 | return 1; |
| 7878 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7879 | if (tmp == NULL) { |
| 7880 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
| 7881 | return 1; |
| 7882 | } |
| 7883 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7884 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7885 | res = obj2ast_expr(tmp, &value, arena); |
| 7886 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7887 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7888 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7889 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7890 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7891 | return 1; |
| 7892 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7893 | if (tmp == NULL) { |
| 7894 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
| 7895 | return 1; |
| 7896 | } |
| 7897 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7898 | int res; |
| 7899 | Py_ssize_t len; |
| 7900 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7901 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7902 | 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] | 7903 | goto failed; |
| 7904 | } |
| 7905 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7906 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7907 | if (generators == NULL) goto failed; |
| 7908 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7909 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7910 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7911 | Py_INCREF(tmp2); |
| 7912 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7913 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7914 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7915 | if (len != PyList_GET_SIZE(tmp)) { |
| 7916 | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
| 7917 | goto failed; |
| 7918 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7919 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7920 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7921 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7922 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7923 | *out = DictComp(key, value, generators, lineno, col_offset, end_lineno, |
| 7924 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7925 | if (*out == NULL) goto failed; |
| 7926 | return 0; |
| 7927 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7928 | tp = astmodulestate_global->GeneratorExp_type; |
| 7929 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7930 | if (isinstance == -1) { |
| 7931 | return 1; |
| 7932 | } |
| 7933 | if (isinstance) { |
| 7934 | expr_ty elt; |
| 7935 | asdl_seq* generators; |
| 7936 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7937 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7938 | return 1; |
| 7939 | } |
| 7940 | if (tmp == NULL) { |
| 7941 | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
| 7942 | return 1; |
| 7943 | } |
| 7944 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7945 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7946 | res = obj2ast_expr(tmp, &elt, arena); |
| 7947 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7948 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7949 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7950 | if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp) |
| 7951 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7952 | return 1; |
| 7953 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7954 | if (tmp == NULL) { |
| 7955 | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
| 7956 | return 1; |
| 7957 | } |
| 7958 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7959 | int res; |
| 7960 | Py_ssize_t len; |
| 7961 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7962 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7963 | 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] | 7964 | goto failed; |
| 7965 | } |
| 7966 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 7967 | generators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7968 | if (generators == NULL) goto failed; |
| 7969 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7970 | comprehension_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 7971 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 7972 | Py_INCREF(tmp2); |
| 7973 | res = obj2ast_comprehension(tmp2, &val, arena); |
| 7974 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7975 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 7976 | if (len != PyList_GET_SIZE(tmp)) { |
| 7977 | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
| 7978 | goto failed; |
| 7979 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 7980 | asdl_seq_SET(generators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7981 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 7982 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7983 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 7984 | *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno, |
| 7985 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 7986 | if (*out == NULL) goto failed; |
| 7987 | return 0; |
| 7988 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7989 | tp = astmodulestate_global->Await_type; |
| 7990 | isinstance = PyObject_IsInstance(obj, tp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 7991 | if (isinstance == -1) { |
| 7992 | return 1; |
| 7993 | } |
| 7994 | if (isinstance) { |
| 7995 | expr_ty value; |
| 7996 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 7997 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 7998 | return 1; |
| 7999 | } |
| 8000 | if (tmp == NULL) { |
| 8001 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
| 8002 | return 1; |
| 8003 | } |
| 8004 | else { |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8005 | int res; |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8006 | res = obj2ast_expr(tmp, &value, arena); |
| 8007 | if (res != 0) goto failed; |
| 8008 | Py_CLEAR(tmp); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8009 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8010 | *out = Await(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8011 | arena); |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 8012 | if (*out == NULL) goto failed; |
| 8013 | return 0; |
| 8014 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8015 | tp = astmodulestate_global->Yield_type; |
| 8016 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8017 | if (isinstance == -1) { |
| 8018 | return 1; |
| 8019 | } |
| 8020 | if (isinstance) { |
| 8021 | expr_ty value; |
| 8022 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8023 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8024 | return 1; |
| 8025 | } |
| 8026 | if (tmp == NULL || tmp == Py_None) { |
| 8027 | Py_CLEAR(tmp); |
| 8028 | value = NULL; |
| 8029 | } |
| 8030 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8031 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8032 | res = obj2ast_expr(tmp, &value, arena); |
| 8033 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8034 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8035 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8036 | *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8037 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8038 | if (*out == NULL) goto failed; |
| 8039 | return 0; |
| 8040 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8041 | tp = astmodulestate_global->YieldFrom_type; |
| 8042 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8043 | if (isinstance == -1) { |
| 8044 | return 1; |
| 8045 | } |
| 8046 | if (isinstance) { |
| 8047 | expr_ty value; |
| 8048 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8049 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8050 | return 1; |
| 8051 | } |
| 8052 | if (tmp == NULL) { |
| 8053 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
| 8054 | return 1; |
| 8055 | } |
| 8056 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8057 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8058 | res = obj2ast_expr(tmp, &value, arena); |
| 8059 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8060 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8061 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8062 | *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset, |
| 8063 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8064 | if (*out == NULL) goto failed; |
| 8065 | return 0; |
| 8066 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8067 | tp = astmodulestate_global->Compare_type; |
| 8068 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8069 | if (isinstance == -1) { |
| 8070 | return 1; |
| 8071 | } |
| 8072 | if (isinstance) { |
| 8073 | expr_ty left; |
| 8074 | asdl_int_seq* ops; |
| 8075 | asdl_seq* comparators; |
| 8076 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8077 | if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8078 | return 1; |
| 8079 | } |
| 8080 | if (tmp == NULL) { |
| 8081 | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
| 8082 | return 1; |
| 8083 | } |
| 8084 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8085 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8086 | res = obj2ast_expr(tmp, &left, arena); |
| 8087 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8088 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8090 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8091 | return 1; |
| 8092 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8093 | if (tmp == NULL) { |
| 8094 | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
| 8095 | return 1; |
| 8096 | } |
| 8097 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8098 | int res; |
| 8099 | Py_ssize_t len; |
| 8100 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8101 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8102 | 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] | 8103 | goto failed; |
| 8104 | } |
| 8105 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8106 | ops = _Py_asdl_int_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8107 | if (ops == NULL) goto failed; |
| 8108 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8109 | cmpop_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8110 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8111 | Py_INCREF(tmp2); |
| 8112 | res = obj2ast_cmpop(tmp2, &val, arena); |
| 8113 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8114 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8115 | if (len != PyList_GET_SIZE(tmp)) { |
| 8116 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
| 8117 | goto failed; |
| 8118 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8119 | asdl_seq_SET(ops, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8120 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8121 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8122 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8123 | if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp) |
| 8124 | < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8125 | return 1; |
| 8126 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8127 | if (tmp == NULL) { |
| 8128 | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
| 8129 | return 1; |
| 8130 | } |
| 8131 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8132 | int res; |
| 8133 | Py_ssize_t len; |
| 8134 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8135 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8136 | 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] | 8137 | goto failed; |
| 8138 | } |
| 8139 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8140 | comparators = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8141 | if (comparators == NULL) goto failed; |
| 8142 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8143 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8144 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8145 | Py_INCREF(tmp2); |
| 8146 | res = obj2ast_expr(tmp2, &val, arena); |
| 8147 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8148 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8149 | if (len != PyList_GET_SIZE(tmp)) { |
| 8150 | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
| 8151 | goto failed; |
| 8152 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8153 | asdl_seq_SET(comparators, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8154 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8155 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8156 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8157 | *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno, |
| 8158 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8159 | if (*out == NULL) goto failed; |
| 8160 | return 0; |
| 8161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8162 | tp = astmodulestate_global->Call_type; |
| 8163 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8164 | if (isinstance == -1) { |
| 8165 | return 1; |
| 8166 | } |
| 8167 | if (isinstance) { |
| 8168 | expr_ty func; |
| 8169 | asdl_seq* args; |
| 8170 | asdl_seq* keywords; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8171 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8172 | if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8173 | return 1; |
| 8174 | } |
| 8175 | if (tmp == NULL) { |
| 8176 | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
| 8177 | return 1; |
| 8178 | } |
| 8179 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8180 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8181 | res = obj2ast_expr(tmp, &func, arena); |
| 8182 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8183 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8184 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8185 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8186 | return 1; |
| 8187 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8188 | if (tmp == NULL) { |
| 8189 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
| 8190 | return 1; |
| 8191 | } |
| 8192 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8193 | int res; |
| 8194 | Py_ssize_t len; |
| 8195 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8196 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8197 | 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] | 8198 | goto failed; |
| 8199 | } |
| 8200 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8201 | args = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8202 | if (args == NULL) goto failed; |
| 8203 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8204 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8205 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8206 | Py_INCREF(tmp2); |
| 8207 | res = obj2ast_expr(tmp2, &val, arena); |
| 8208 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8209 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8210 | if (len != PyList_GET_SIZE(tmp)) { |
| 8211 | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
| 8212 | goto failed; |
| 8213 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8214 | asdl_seq_SET(args, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8215 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8216 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8217 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8218 | if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) < |
| 8219 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8220 | return 1; |
| 8221 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8222 | if (tmp == NULL) { |
| 8223 | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
| 8224 | return 1; |
| 8225 | } |
| 8226 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8227 | int res; |
| 8228 | Py_ssize_t len; |
| 8229 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8230 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8231 | 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] | 8232 | goto failed; |
| 8233 | } |
| 8234 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8235 | keywords = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8236 | if (keywords == NULL) goto failed; |
| 8237 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8238 | keyword_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8239 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8240 | Py_INCREF(tmp2); |
| 8241 | res = obj2ast_keyword(tmp2, &val, arena); |
| 8242 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8243 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8244 | if (len != PyList_GET_SIZE(tmp)) { |
| 8245 | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
| 8246 | goto failed; |
| 8247 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8248 | asdl_seq_SET(keywords, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8249 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8250 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8251 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8252 | *out = Call(func, args, keywords, lineno, col_offset, end_lineno, |
| 8253 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8254 | if (*out == NULL) goto failed; |
| 8255 | return 0; |
| 8256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8257 | tp = astmodulestate_global->FormattedValue_type; |
| 8258 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8259 | if (isinstance == -1) { |
| 8260 | return 1; |
| 8261 | } |
| 8262 | if (isinstance) { |
| 8263 | expr_ty value; |
| 8264 | int conversion; |
| 8265 | expr_ty format_spec; |
| 8266 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8267 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8268 | return 1; |
| 8269 | } |
| 8270 | if (tmp == NULL) { |
| 8271 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
| 8272 | return 1; |
| 8273 | } |
| 8274 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8275 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8276 | res = obj2ast_expr(tmp, &value, arena); |
| 8277 | if (res != 0) goto failed; |
| 8278 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8279 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8280 | if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp) |
| 8281 | < 0) { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8282 | return 1; |
| 8283 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8284 | if (tmp == NULL || tmp == Py_None) { |
| 8285 | Py_CLEAR(tmp); |
| 8286 | conversion = 0; |
| 8287 | } |
| 8288 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8289 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8290 | res = obj2ast_int(tmp, &conversion, arena); |
| 8291 | if (res != 0) goto failed; |
| 8292 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8293 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8294 | if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp) |
| 8295 | < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8296 | return 1; |
| 8297 | } |
| 8298 | if (tmp == NULL || tmp == Py_None) { |
| 8299 | Py_CLEAR(tmp); |
| 8300 | format_spec = NULL; |
| 8301 | } |
| 8302 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8303 | int res; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8304 | res = obj2ast_expr(tmp, &format_spec, arena); |
| 8305 | if (res != 0) goto failed; |
| 8306 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8307 | } |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 8308 | *out = FormattedValue(value, conversion, format_spec, lineno, |
| 8309 | col_offset, end_lineno, end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8310 | if (*out == NULL) goto failed; |
| 8311 | return 0; |
| 8312 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8313 | tp = astmodulestate_global->JoinedStr_type; |
| 8314 | isinstance = PyObject_IsInstance(obj, tp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8315 | if (isinstance == -1) { |
| 8316 | return 1; |
| 8317 | } |
| 8318 | if (isinstance) { |
| 8319 | asdl_seq* values; |
| 8320 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8321 | if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0) |
| 8322 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8323 | return 1; |
| 8324 | } |
| 8325 | if (tmp == NULL) { |
| 8326 | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
| 8327 | return 1; |
| 8328 | } |
| 8329 | else { |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8330 | int res; |
| 8331 | Py_ssize_t len; |
| 8332 | Py_ssize_t i; |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8333 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8334 | 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] | 8335 | goto failed; |
| 8336 | } |
| 8337 | len = PyList_GET_SIZE(tmp); |
| 8338 | values = _Py_asdl_seq_new(len, arena); |
| 8339 | if (values == NULL) goto failed; |
| 8340 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8341 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8342 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8343 | Py_INCREF(tmp2); |
| 8344 | res = obj2ast_expr(tmp2, &val, arena); |
| 8345 | Py_DECREF(tmp2); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8346 | if (res != 0) goto failed; |
Serhiy Storchaka | 5e80855 | 2016-10-07 21:55:49 +0300 | [diff] [blame] | 8347 | if (len != PyList_GET_SIZE(tmp)) { |
| 8348 | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
| 8349 | goto failed; |
| 8350 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8351 | asdl_seq_SET(values, i, val); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8352 | } |
| 8353 | Py_CLEAR(tmp); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8354 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8355 | *out = JoinedStr(values, lineno, col_offset, end_lineno, |
| 8356 | end_col_offset, arena); |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 8357 | if (*out == NULL) goto failed; |
| 8358 | return 0; |
| 8359 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8360 | tp = astmodulestate_global->Constant_type; |
| 8361 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8362 | if (isinstance == -1) { |
| 8363 | return 1; |
| 8364 | } |
| 8365 | if (isinstance) { |
| 8366 | constant value; |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8367 | string kind; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8368 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8369 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8370 | return 1; |
| 8371 | } |
| 8372 | if (tmp == NULL) { |
| 8373 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
| 8374 | return 1; |
| 8375 | } |
| 8376 | else { |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8377 | int res; |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8378 | res = obj2ast_constant(tmp, &value, arena); |
| 8379 | if (res != 0) goto failed; |
| 8380 | Py_CLEAR(tmp); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8381 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8382 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) { |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 8383 | return 1; |
| 8384 | } |
| 8385 | if (tmp == NULL || tmp == Py_None) { |
| 8386 | Py_CLEAR(tmp); |
| 8387 | kind = NULL; |
| 8388 | } |
| 8389 | else { |
| 8390 | int res; |
| 8391 | res = obj2ast_string(tmp, &kind, arena); |
| 8392 | if (res != 0) goto failed; |
| 8393 | Py_CLEAR(tmp); |
| 8394 | } |
| 8395 | *out = Constant(value, kind, lineno, col_offset, end_lineno, |
| 8396 | end_col_offset, arena); |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 8397 | if (*out == NULL) goto failed; |
| 8398 | return 0; |
| 8399 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8400 | tp = astmodulestate_global->Attribute_type; |
| 8401 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8402 | if (isinstance == -1) { |
| 8403 | return 1; |
| 8404 | } |
| 8405 | if (isinstance) { |
| 8406 | expr_ty value; |
| 8407 | identifier attr; |
| 8408 | expr_context_ty ctx; |
| 8409 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8410 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8411 | return 1; |
| 8412 | } |
| 8413 | if (tmp == NULL) { |
| 8414 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
| 8415 | return 1; |
| 8416 | } |
| 8417 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8418 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8419 | res = obj2ast_expr(tmp, &value, arena); |
| 8420 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8421 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8422 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8423 | if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8424 | return 1; |
| 8425 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8426 | if (tmp == NULL) { |
| 8427 | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
| 8428 | return 1; |
| 8429 | } |
| 8430 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8431 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8432 | res = obj2ast_identifier(tmp, &attr, arena); |
| 8433 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8434 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8435 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8436 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8437 | return 1; |
| 8438 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8439 | if (tmp == NULL) { |
| 8440 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
| 8441 | return 1; |
| 8442 | } |
| 8443 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8444 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8445 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8446 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8447 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8448 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8449 | *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno, |
| 8450 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8451 | if (*out == NULL) goto failed; |
| 8452 | return 0; |
| 8453 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8454 | tp = astmodulestate_global->Subscript_type; |
| 8455 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8456 | if (isinstance == -1) { |
| 8457 | return 1; |
| 8458 | } |
| 8459 | if (isinstance) { |
| 8460 | expr_ty value; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8461 | expr_ty slice; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8462 | expr_context_ty ctx; |
| 8463 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8464 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8465 | return 1; |
| 8466 | } |
| 8467 | if (tmp == NULL) { |
| 8468 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
| 8469 | return 1; |
| 8470 | } |
| 8471 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8472 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8473 | res = obj2ast_expr(tmp, &value, arena); |
| 8474 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8475 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8476 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8477 | if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8478 | return 1; |
| 8479 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8480 | if (tmp == NULL) { |
| 8481 | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
| 8482 | return 1; |
| 8483 | } |
| 8484 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8485 | int res; |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8486 | res = obj2ast_expr(tmp, &slice, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8487 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8488 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8489 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8490 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8491 | return 1; |
| 8492 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8493 | if (tmp == NULL) { |
| 8494 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
| 8495 | return 1; |
| 8496 | } |
| 8497 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8498 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8499 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8500 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8501 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8502 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8503 | *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno, |
| 8504 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8505 | if (*out == NULL) goto failed; |
| 8506 | return 0; |
| 8507 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8508 | tp = astmodulestate_global->Starred_type; |
| 8509 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8510 | if (isinstance == -1) { |
| 8511 | return 1; |
| 8512 | } |
| 8513 | if (isinstance) { |
| 8514 | expr_ty value; |
| 8515 | expr_context_ty ctx; |
| 8516 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8517 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8518 | return 1; |
| 8519 | } |
| 8520 | if (tmp == NULL) { |
| 8521 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
| 8522 | return 1; |
| 8523 | } |
| 8524 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8525 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8526 | res = obj2ast_expr(tmp, &value, arena); |
| 8527 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8528 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8529 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8530 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8531 | return 1; |
| 8532 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8533 | if (tmp == NULL) { |
| 8534 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
| 8535 | return 1; |
| 8536 | } |
| 8537 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8538 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8539 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8540 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8541 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8542 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8543 | *out = Starred(value, ctx, lineno, col_offset, end_lineno, |
| 8544 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8545 | if (*out == NULL) goto failed; |
| 8546 | return 0; |
| 8547 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8548 | tp = astmodulestate_global->Name_type; |
| 8549 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8550 | if (isinstance == -1) { |
| 8551 | return 1; |
| 8552 | } |
| 8553 | if (isinstance) { |
| 8554 | identifier id; |
| 8555 | expr_context_ty ctx; |
| 8556 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8557 | if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8558 | return 1; |
| 8559 | } |
| 8560 | if (tmp == NULL) { |
| 8561 | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
| 8562 | return 1; |
| 8563 | } |
| 8564 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8565 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8566 | res = obj2ast_identifier(tmp, &id, arena); |
| 8567 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8568 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8569 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8570 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8571 | return 1; |
| 8572 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8573 | if (tmp == NULL) { |
| 8574 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
| 8575 | return 1; |
| 8576 | } |
| 8577 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8578 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8579 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8580 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8581 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8582 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8583 | *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8584 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8585 | if (*out == NULL) goto failed; |
| 8586 | return 0; |
| 8587 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8588 | tp = astmodulestate_global->List_type; |
| 8589 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8590 | if (isinstance == -1) { |
| 8591 | return 1; |
| 8592 | } |
| 8593 | if (isinstance) { |
| 8594 | asdl_seq* elts; |
| 8595 | expr_context_ty ctx; |
| 8596 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8597 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8598 | return 1; |
| 8599 | } |
| 8600 | if (tmp == NULL) { |
| 8601 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
| 8602 | return 1; |
| 8603 | } |
| 8604 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8605 | int res; |
| 8606 | Py_ssize_t len; |
| 8607 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8608 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8609 | 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] | 8610 | goto failed; |
| 8611 | } |
| 8612 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8613 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8614 | if (elts == NULL) goto failed; |
| 8615 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8616 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8617 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8618 | Py_INCREF(tmp2); |
| 8619 | res = obj2ast_expr(tmp2, &val, arena); |
| 8620 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8621 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8622 | if (len != PyList_GET_SIZE(tmp)) { |
| 8623 | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
| 8624 | goto failed; |
| 8625 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8626 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8627 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8628 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8629 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8630 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8631 | return 1; |
| 8632 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8633 | if (tmp == NULL) { |
| 8634 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
| 8635 | return 1; |
| 8636 | } |
| 8637 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8638 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8639 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8640 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8641 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8642 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8643 | *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8644 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8645 | if (*out == NULL) goto failed; |
| 8646 | return 0; |
| 8647 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8648 | tp = astmodulestate_global->Tuple_type; |
| 8649 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8650 | if (isinstance == -1) { |
| 8651 | return 1; |
| 8652 | } |
| 8653 | if (isinstance) { |
| 8654 | asdl_seq* elts; |
| 8655 | expr_context_ty ctx; |
| 8656 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8657 | if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8658 | return 1; |
| 8659 | } |
| 8660 | if (tmp == NULL) { |
| 8661 | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
| 8662 | return 1; |
| 8663 | } |
| 8664 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8665 | int res; |
| 8666 | Py_ssize_t len; |
| 8667 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8668 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8669 | 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] | 8670 | goto failed; |
| 8671 | } |
| 8672 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 8673 | elts = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8674 | if (elts == NULL) goto failed; |
| 8675 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8676 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 8677 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 8678 | Py_INCREF(tmp2); |
| 8679 | res = obj2ast_expr(tmp2, &val, arena); |
| 8680 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8681 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 8682 | if (len != PyList_GET_SIZE(tmp)) { |
| 8683 | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
| 8684 | goto failed; |
| 8685 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 8686 | asdl_seq_SET(elts, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8687 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8688 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8689 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8690 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8691 | return 1; |
| 8692 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 8693 | if (tmp == NULL) { |
| 8694 | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
| 8695 | return 1; |
| 8696 | } |
| 8697 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8698 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8699 | res = obj2ast_expr_context(tmp, &ctx, arena); |
| 8700 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 8701 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8702 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 8703 | *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset, |
| 8704 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8705 | if (*out == NULL) goto failed; |
| 8706 | return 0; |
| 8707 | } |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 8708 | tp = astmodulestate_global->Slice_type; |
| 8709 | isinstance = PyObject_IsInstance(obj, tp); |
| 8710 | if (isinstance == -1) { |
| 8711 | return 1; |
| 8712 | } |
| 8713 | if (isinstance) { |
| 8714 | expr_ty lower; |
| 8715 | expr_ty upper; |
| 8716 | expr_ty step; |
| 8717 | |
| 8718 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) { |
| 8719 | return 1; |
| 8720 | } |
| 8721 | if (tmp == NULL || tmp == Py_None) { |
| 8722 | Py_CLEAR(tmp); |
| 8723 | lower = NULL; |
| 8724 | } |
| 8725 | else { |
| 8726 | int res; |
| 8727 | res = obj2ast_expr(tmp, &lower, arena); |
| 8728 | if (res != 0) goto failed; |
| 8729 | Py_CLEAR(tmp); |
| 8730 | } |
| 8731 | if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) { |
| 8732 | return 1; |
| 8733 | } |
| 8734 | if (tmp == NULL || tmp == Py_None) { |
| 8735 | Py_CLEAR(tmp); |
| 8736 | upper = NULL; |
| 8737 | } |
| 8738 | else { |
| 8739 | int res; |
| 8740 | res = obj2ast_expr(tmp, &upper, arena); |
| 8741 | if (res != 0) goto failed; |
| 8742 | Py_CLEAR(tmp); |
| 8743 | } |
| 8744 | if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) { |
| 8745 | return 1; |
| 8746 | } |
| 8747 | if (tmp == NULL || tmp == Py_None) { |
| 8748 | Py_CLEAR(tmp); |
| 8749 | step = NULL; |
| 8750 | } |
| 8751 | else { |
| 8752 | int res; |
| 8753 | res = obj2ast_expr(tmp, &step, arena); |
| 8754 | if (res != 0) goto failed; |
| 8755 | Py_CLEAR(tmp); |
| 8756 | } |
| 8757 | *out = Slice(lower, upper, step, lineno, col_offset, end_lineno, |
| 8758 | end_col_offset, arena); |
| 8759 | if (*out == NULL) goto failed; |
| 8760 | return 0; |
| 8761 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8762 | |
| 8763 | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
| 8764 | failed: |
| 8765 | Py_XDECREF(tmp); |
| 8766 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8767 | } |
| 8768 | |
| 8769 | int |
| 8770 | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
| 8771 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8772 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8773 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8774 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8775 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8776 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8777 | } |
| 8778 | if (isinstance) { |
| 8779 | *out = Load; |
| 8780 | return 0; |
| 8781 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8782 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8783 | if (isinstance == -1) { |
| 8784 | return 1; |
| 8785 | } |
| 8786 | if (isinstance) { |
| 8787 | *out = Store; |
| 8788 | return 0; |
| 8789 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8790 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8791 | if (isinstance == -1) { |
| 8792 | return 1; |
| 8793 | } |
| 8794 | if (isinstance) { |
| 8795 | *out = Del; |
| 8796 | return 0; |
| 8797 | } |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8798 | |
| 8799 | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
| 8800 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8801 | } |
| 8802 | |
| 8803 | int |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8804 | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
| 8805 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8806 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8807 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8808 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8809 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8810 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8811 | } |
| 8812 | if (isinstance) { |
| 8813 | *out = And; |
| 8814 | return 0; |
| 8815 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8816 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8817 | if (isinstance == -1) { |
| 8818 | return 1; |
| 8819 | } |
| 8820 | if (isinstance) { |
| 8821 | *out = Or; |
| 8822 | return 0; |
| 8823 | } |
| 8824 | |
| 8825 | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
| 8826 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8827 | } |
| 8828 | |
| 8829 | int |
| 8830 | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
| 8831 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8832 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8833 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8834 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8835 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8836 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8837 | } |
| 8838 | if (isinstance) { |
| 8839 | *out = Add; |
| 8840 | return 0; |
| 8841 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8842 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8843 | if (isinstance == -1) { |
| 8844 | return 1; |
| 8845 | } |
| 8846 | if (isinstance) { |
| 8847 | *out = Sub; |
| 8848 | return 0; |
| 8849 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8850 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8851 | if (isinstance == -1) { |
| 8852 | return 1; |
| 8853 | } |
| 8854 | if (isinstance) { |
| 8855 | *out = Mult; |
| 8856 | return 0; |
| 8857 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8858 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type); |
Benjamin Peterson | d51374e | 2014-04-09 23:55:56 -0400 | [diff] [blame] | 8859 | if (isinstance == -1) { |
| 8860 | return 1; |
| 8861 | } |
| 8862 | if (isinstance) { |
| 8863 | *out = MatMult; |
| 8864 | return 0; |
| 8865 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8866 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8867 | if (isinstance == -1) { |
| 8868 | return 1; |
| 8869 | } |
| 8870 | if (isinstance) { |
| 8871 | *out = Div; |
| 8872 | return 0; |
| 8873 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8874 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8875 | if (isinstance == -1) { |
| 8876 | return 1; |
| 8877 | } |
| 8878 | if (isinstance) { |
| 8879 | *out = Mod; |
| 8880 | return 0; |
| 8881 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8882 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8883 | if (isinstance == -1) { |
| 8884 | return 1; |
| 8885 | } |
| 8886 | if (isinstance) { |
| 8887 | *out = Pow; |
| 8888 | return 0; |
| 8889 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8890 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8891 | if (isinstance == -1) { |
| 8892 | return 1; |
| 8893 | } |
| 8894 | if (isinstance) { |
| 8895 | *out = LShift; |
| 8896 | return 0; |
| 8897 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8898 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8899 | if (isinstance == -1) { |
| 8900 | return 1; |
| 8901 | } |
| 8902 | if (isinstance) { |
| 8903 | *out = RShift; |
| 8904 | return 0; |
| 8905 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8906 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8907 | if (isinstance == -1) { |
| 8908 | return 1; |
| 8909 | } |
| 8910 | if (isinstance) { |
| 8911 | *out = BitOr; |
| 8912 | return 0; |
| 8913 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8914 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8915 | if (isinstance == -1) { |
| 8916 | return 1; |
| 8917 | } |
| 8918 | if (isinstance) { |
| 8919 | *out = BitXor; |
| 8920 | return 0; |
| 8921 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8922 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8923 | if (isinstance == -1) { |
| 8924 | return 1; |
| 8925 | } |
| 8926 | if (isinstance) { |
| 8927 | *out = BitAnd; |
| 8928 | return 0; |
| 8929 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8930 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8931 | if (isinstance == -1) { |
| 8932 | return 1; |
| 8933 | } |
| 8934 | if (isinstance) { |
| 8935 | *out = FloorDiv; |
| 8936 | return 0; |
| 8937 | } |
| 8938 | |
| 8939 | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
| 8940 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8941 | } |
| 8942 | |
| 8943 | int |
| 8944 | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
| 8945 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8946 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8947 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8948 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8949 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8950 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8951 | } |
| 8952 | if (isinstance) { |
| 8953 | *out = Invert; |
| 8954 | return 0; |
| 8955 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8956 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8957 | if (isinstance == -1) { |
| 8958 | return 1; |
| 8959 | } |
| 8960 | if (isinstance) { |
| 8961 | *out = Not; |
| 8962 | return 0; |
| 8963 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8964 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8965 | if (isinstance == -1) { |
| 8966 | return 1; |
| 8967 | } |
| 8968 | if (isinstance) { |
| 8969 | *out = UAdd; |
| 8970 | return 0; |
| 8971 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8972 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8973 | if (isinstance == -1) { |
| 8974 | return 1; |
| 8975 | } |
| 8976 | if (isinstance) { |
| 8977 | *out = USub; |
| 8978 | return 0; |
| 8979 | } |
| 8980 | |
| 8981 | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
| 8982 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | int |
| 8986 | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
| 8987 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8988 | int isinstance; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8989 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8990 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8991 | if (isinstance == -1) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 8992 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8993 | } |
| 8994 | if (isinstance) { |
| 8995 | *out = Eq; |
| 8996 | return 0; |
| 8997 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 8998 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 8999 | if (isinstance == -1) { |
| 9000 | return 1; |
| 9001 | } |
| 9002 | if (isinstance) { |
| 9003 | *out = NotEq; |
| 9004 | return 0; |
| 9005 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9006 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9007 | if (isinstance == -1) { |
| 9008 | return 1; |
| 9009 | } |
| 9010 | if (isinstance) { |
| 9011 | *out = Lt; |
| 9012 | return 0; |
| 9013 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9014 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9015 | if (isinstance == -1) { |
| 9016 | return 1; |
| 9017 | } |
| 9018 | if (isinstance) { |
| 9019 | *out = LtE; |
| 9020 | return 0; |
| 9021 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9022 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9023 | if (isinstance == -1) { |
| 9024 | return 1; |
| 9025 | } |
| 9026 | if (isinstance) { |
| 9027 | *out = Gt; |
| 9028 | return 0; |
| 9029 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9030 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9031 | if (isinstance == -1) { |
| 9032 | return 1; |
| 9033 | } |
| 9034 | if (isinstance) { |
| 9035 | *out = GtE; |
| 9036 | return 0; |
| 9037 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9038 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9039 | if (isinstance == -1) { |
| 9040 | return 1; |
| 9041 | } |
| 9042 | if (isinstance) { |
| 9043 | *out = Is; |
| 9044 | return 0; |
| 9045 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9046 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9047 | if (isinstance == -1) { |
| 9048 | return 1; |
| 9049 | } |
| 9050 | if (isinstance) { |
| 9051 | *out = IsNot; |
| 9052 | return 0; |
| 9053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9054 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9055 | if (isinstance == -1) { |
| 9056 | return 1; |
| 9057 | } |
| 9058 | if (isinstance) { |
| 9059 | *out = In; |
| 9060 | return 0; |
| 9061 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9062 | isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9063 | if (isinstance == -1) { |
| 9064 | return 1; |
| 9065 | } |
| 9066 | if (isinstance) { |
| 9067 | *out = NotIn; |
| 9068 | return 0; |
| 9069 | } |
| 9070 | |
| 9071 | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
| 9072 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9073 | } |
| 9074 | |
| 9075 | int |
| 9076 | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
| 9077 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9078 | PyObject* tmp = NULL; |
| 9079 | expr_ty target; |
| 9080 | expr_ty iter; |
| 9081 | asdl_seq* ifs; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9082 | int is_async; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9083 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9084 | if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9085 | return 1; |
| 9086 | } |
| 9087 | if (tmp == NULL) { |
| 9088 | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
| 9089 | return 1; |
| 9090 | } |
| 9091 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9092 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9093 | res = obj2ast_expr(tmp, &target, arena); |
| 9094 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9095 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9096 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9097 | if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9098 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9099 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9100 | if (tmp == NULL) { |
| 9101 | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
| 9102 | return 1; |
| 9103 | } |
| 9104 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9105 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9106 | res = obj2ast_expr(tmp, &iter, arena); |
| 9107 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9108 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9110 | if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9111 | return 1; |
| 9112 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9113 | if (tmp == NULL) { |
| 9114 | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
| 9115 | return 1; |
| 9116 | } |
| 9117 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9118 | int res; |
| 9119 | Py_ssize_t len; |
| 9120 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9121 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9122 | 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] | 9123 | goto failed; |
| 9124 | } |
| 9125 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9126 | ifs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9127 | if (ifs == NULL) goto failed; |
| 9128 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9129 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9130 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9131 | Py_INCREF(tmp2); |
| 9132 | res = obj2ast_expr(tmp2, &val, arena); |
| 9133 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9134 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9135 | if (len != PyList_GET_SIZE(tmp)) { |
| 9136 | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
| 9137 | goto failed; |
| 9138 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9139 | asdl_seq_SET(ifs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9140 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9141 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9142 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9143 | if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9144 | return 1; |
| 9145 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9146 | if (tmp == NULL) { |
| 9147 | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
| 9148 | return 1; |
| 9149 | } |
| 9150 | else { |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9151 | int res; |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9152 | res = obj2ast_int(tmp, &is_async, arena); |
| 9153 | if (res != 0) goto failed; |
| 9154 | Py_CLEAR(tmp); |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 9155 | } |
| 9156 | *out = comprehension(target, iter, ifs, is_async, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9157 | return 0; |
| 9158 | failed: |
| 9159 | Py_XDECREF(tmp); |
| 9160 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9161 | } |
| 9162 | |
| 9163 | int |
| 9164 | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
| 9165 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9166 | int isinstance; |
Neal Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 9167 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9168 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9169 | PyObject *tp; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9170 | int lineno; |
| 9171 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9172 | int end_lineno; |
| 9173 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9174 | |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9175 | if (obj == Py_None) { |
| 9176 | *out = NULL; |
| 9177 | return 0; |
| 9178 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9179 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9180 | return 1; |
| 9181 | } |
| 9182 | if (tmp == NULL) { |
| 9183 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
| 9184 | return 1; |
| 9185 | } |
| 9186 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9187 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9188 | res = obj2ast_int(tmp, &lineno, arena); |
| 9189 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9190 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9191 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9192 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9193 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9194 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9195 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9196 | if (tmp == NULL) { |
| 9197 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
| 9198 | return 1; |
| 9199 | } |
| 9200 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9201 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9202 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9203 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9204 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9205 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9206 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9207 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9208 | return 1; |
| 9209 | } |
| 9210 | if (tmp == NULL || tmp == Py_None) { |
| 9211 | Py_CLEAR(tmp); |
| 9212 | end_lineno = 0; |
| 9213 | } |
| 9214 | else { |
| 9215 | int res; |
| 9216 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9217 | if (res != 0) goto failed; |
| 9218 | Py_CLEAR(tmp); |
| 9219 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9220 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9221 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9222 | return 1; |
| 9223 | } |
| 9224 | if (tmp == NULL || tmp == Py_None) { |
| 9225 | Py_CLEAR(tmp); |
| 9226 | end_col_offset = 0; |
| 9227 | } |
| 9228 | else { |
| 9229 | int res; |
| 9230 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9231 | if (res != 0) goto failed; |
| 9232 | Py_CLEAR(tmp); |
| 9233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9234 | tp = astmodulestate_global->ExceptHandler_type; |
| 9235 | isinstance = PyObject_IsInstance(obj, tp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9236 | if (isinstance == -1) { |
| 9237 | return 1; |
| 9238 | } |
| 9239 | if (isinstance) { |
| 9240 | expr_ty type; |
| 9241 | identifier name; |
| 9242 | asdl_seq* body; |
| 9243 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9244 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9245 | return 1; |
| 9246 | } |
| 9247 | if (tmp == NULL || tmp == Py_None) { |
| 9248 | Py_CLEAR(tmp); |
| 9249 | type = NULL; |
| 9250 | } |
| 9251 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9252 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9253 | res = obj2ast_expr(tmp, &type, arena); |
| 9254 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9255 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9256 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9257 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9258 | return 1; |
| 9259 | } |
| 9260 | if (tmp == NULL || tmp == Py_None) { |
| 9261 | Py_CLEAR(tmp); |
| 9262 | name = NULL; |
| 9263 | } |
| 9264 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9265 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9266 | res = obj2ast_identifier(tmp, &name, arena); |
| 9267 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9268 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9269 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9270 | if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9271 | return 1; |
| 9272 | } |
| 9273 | if (tmp == NULL) { |
| 9274 | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
| 9275 | return 1; |
| 9276 | } |
| 9277 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9278 | int res; |
| 9279 | Py_ssize_t len; |
| 9280 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9281 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9282 | 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] | 9283 | goto failed; |
| 9284 | } |
| 9285 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9286 | body = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9287 | if (body == NULL) goto failed; |
| 9288 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9289 | stmt_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9290 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9291 | Py_INCREF(tmp2); |
| 9292 | res = obj2ast_stmt(tmp2, &val, arena); |
| 9293 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9294 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9295 | if (len != PyList_GET_SIZE(tmp)) { |
| 9296 | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
| 9297 | goto failed; |
| 9298 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9299 | asdl_seq_SET(body, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9300 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9301 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9302 | } |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9303 | *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno, |
| 9304 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9305 | if (*out == NULL) goto failed; |
| 9306 | return 0; |
| 9307 | } |
| 9308 | |
| 9309 | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
| 9310 | failed: |
| 9311 | Py_XDECREF(tmp); |
| 9312 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9313 | } |
| 9314 | |
| 9315 | int |
| 9316 | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
| 9317 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9318 | PyObject* tmp = NULL; |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9319 | asdl_seq* posonlyargs; |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9320 | asdl_seq* args; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9321 | arg_ty vararg; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9322 | asdl_seq* kwonlyargs; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9323 | asdl_seq* kw_defaults; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9324 | arg_ty kwarg; |
| 9325 | asdl_seq* defaults; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9326 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9327 | if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) < |
| 9328 | 0) { |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9329 | return 1; |
| 9330 | } |
| 9331 | if (tmp == NULL) { |
| 9332 | PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments"); |
| 9333 | return 1; |
| 9334 | } |
| 9335 | else { |
| 9336 | int res; |
| 9337 | Py_ssize_t len; |
| 9338 | Py_ssize_t i; |
| 9339 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9340 | 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] | 9341 | goto failed; |
| 9342 | } |
| 9343 | len = PyList_GET_SIZE(tmp); |
| 9344 | posonlyargs = _Py_asdl_seq_new(len, arena); |
| 9345 | if (posonlyargs == NULL) goto failed; |
| 9346 | for (i = 0; i < len; i++) { |
| 9347 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9348 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9349 | Py_INCREF(tmp2); |
| 9350 | res = obj2ast_arg(tmp2, &val, arena); |
| 9351 | Py_DECREF(tmp2); |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9352 | if (res != 0) goto failed; |
| 9353 | if (len != PyList_GET_SIZE(tmp)) { |
| 9354 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration"); |
| 9355 | goto failed; |
| 9356 | } |
| 9357 | asdl_seq_SET(posonlyargs, i, val); |
| 9358 | } |
| 9359 | Py_CLEAR(tmp); |
| 9360 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9361 | if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) { |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9362 | return 1; |
| 9363 | } |
| 9364 | if (tmp == NULL) { |
| 9365 | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
| 9366 | return 1; |
| 9367 | } |
| 9368 | else { |
| 9369 | int res; |
| 9370 | Py_ssize_t len; |
| 9371 | Py_ssize_t i; |
| 9372 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9373 | 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] | 9374 | goto failed; |
| 9375 | } |
| 9376 | len = PyList_GET_SIZE(tmp); |
| 9377 | args = _Py_asdl_seq_new(len, arena); |
| 9378 | if (args == NULL) goto failed; |
| 9379 | for (i = 0; i < len; i++) { |
| 9380 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9381 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9382 | Py_INCREF(tmp2); |
| 9383 | res = obj2ast_arg(tmp2, &val, arena); |
| 9384 | Py_DECREF(tmp2); |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9385 | if (res != 0) goto failed; |
| 9386 | if (len != PyList_GET_SIZE(tmp)) { |
| 9387 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
| 9388 | goto failed; |
| 9389 | } |
| 9390 | asdl_seq_SET(args, i, val); |
| 9391 | } |
| 9392 | Py_CLEAR(tmp); |
| 9393 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9394 | if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9395 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9396 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9397 | if (tmp == NULL || tmp == Py_None) { |
| 9398 | Py_CLEAR(tmp); |
| 9399 | vararg = NULL; |
| 9400 | } |
| 9401 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9402 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9403 | res = obj2ast_arg(tmp, &vararg, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9404 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9405 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9406 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9407 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0) |
| 9408 | { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9409 | return 1; |
| 9410 | } |
| 9411 | if (tmp == NULL) { |
| 9412 | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
| 9413 | return 1; |
| 9414 | } |
| 9415 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9416 | int res; |
| 9417 | Py_ssize_t len; |
| 9418 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9419 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9420 | 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] | 9421 | goto failed; |
| 9422 | } |
| 9423 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9424 | kwonlyargs = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9425 | if (kwonlyargs == NULL) goto failed; |
| 9426 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9427 | arg_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9428 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9429 | Py_INCREF(tmp2); |
| 9430 | res = obj2ast_arg(tmp2, &val, arena); |
| 9431 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9432 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9433 | if (len != PyList_GET_SIZE(tmp)) { |
| 9434 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
| 9435 | goto failed; |
| 9436 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9437 | asdl_seq_SET(kwonlyargs, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9438 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9439 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9440 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9441 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) < |
| 9442 | 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9443 | return 1; |
| 9444 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9445 | if (tmp == NULL) { |
| 9446 | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
| 9447 | return 1; |
| 9448 | } |
| 9449 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9450 | int res; |
| 9451 | Py_ssize_t len; |
| 9452 | Py_ssize_t i; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9453 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9454 | 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] | 9455 | goto failed; |
| 9456 | } |
| 9457 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9458 | kw_defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9459 | if (kw_defaults == NULL) goto failed; |
| 9460 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9461 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9462 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9463 | Py_INCREF(tmp2); |
| 9464 | res = obj2ast_expr(tmp2, &val, arena); |
| 9465 | Py_DECREF(tmp2); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9466 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9467 | if (len != PyList_GET_SIZE(tmp)) { |
| 9468 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
| 9469 | goto failed; |
| 9470 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9471 | asdl_seq_SET(kw_defaults, i, val); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9472 | } |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9473 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9474 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9475 | if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9476 | return 1; |
| 9477 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9478 | if (tmp == NULL || tmp == Py_None) { |
| 9479 | Py_CLEAR(tmp); |
| 9480 | kwarg = NULL; |
| 9481 | } |
| 9482 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9483 | int res; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9484 | res = obj2ast_arg(tmp, &kwarg, arena); |
| 9485 | if (res != 0) goto failed; |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9486 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9487 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9488 | if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9489 | return 1; |
| 9490 | } |
| 9491 | if (tmp == NULL) { |
| 9492 | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
| 9493 | return 1; |
| 9494 | } |
| 9495 | else { |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9496 | int res; |
| 9497 | Py_ssize_t len; |
| 9498 | Py_ssize_t i; |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9499 | if (!PyList_Check(tmp)) { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9500 | 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] | 9501 | goto failed; |
| 9502 | } |
| 9503 | len = PyList_GET_SIZE(tmp); |
Antoine Pitrou | d01d396e | 2013-10-12 22:52:43 +0200 | [diff] [blame] | 9504 | defaults = _Py_asdl_seq_new(len, arena); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9505 | if (defaults == NULL) goto failed; |
| 9506 | for (i = 0; i < len; i++) { |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9507 | expr_ty val; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 9508 | PyObject *tmp2 = PyList_GET_ITEM(tmp, i); |
| 9509 | Py_INCREF(tmp2); |
| 9510 | res = obj2ast_expr(tmp2, &val, arena); |
| 9511 | Py_DECREF(tmp2); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9512 | if (res != 0) goto failed; |
Serhiy Storchaka | cf38060 | 2016-10-07 21:51:28 +0300 | [diff] [blame] | 9513 | if (len != PyList_GET_SIZE(tmp)) { |
| 9514 | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
| 9515 | goto failed; |
| 9516 | } |
Yuan Chao Chou | 2af565b | 2017-08-04 10:53:12 -0700 | [diff] [blame] | 9517 | asdl_seq_SET(defaults, i, val); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9518 | } |
Victor Stinner | b318990 | 2013-07-27 00:04:42 +0200 | [diff] [blame] | 9519 | Py_CLEAR(tmp); |
Victor Stinner | ee4b59c | 2013-07-27 00:01:35 +0200 | [diff] [blame] | 9520 | } |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 9521 | *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 9522 | defaults, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9523 | return 0; |
| 9524 | failed: |
| 9525 | Py_XDECREF(tmp); |
| 9526 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9527 | } |
| 9528 | |
| 9529 | int |
| 9530 | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
| 9531 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9532 | PyObject* tmp = NULL; |
| 9533 | identifier arg; |
| 9534 | expr_ty annotation; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9535 | string type_comment; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9536 | int lineno; |
| 9537 | int col_offset; |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9538 | int end_lineno; |
| 9539 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9540 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9541 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9542 | return 1; |
| 9543 | } |
| 9544 | if (tmp == NULL) { |
| 9545 | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
| 9546 | return 1; |
| 9547 | } |
| 9548 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9549 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9550 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9551 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9552 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9553 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9554 | if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0) |
| 9555 | { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9556 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9557 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9558 | if (tmp == NULL || tmp == Py_None) { |
| 9559 | Py_CLEAR(tmp); |
| 9560 | annotation = NULL; |
| 9561 | } |
| 9562 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9563 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9564 | res = obj2ast_expr(tmp, &annotation, arena); |
| 9565 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9566 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9567 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9568 | if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) < |
| 9569 | 0) { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9570 | return 1; |
| 9571 | } |
| 9572 | if (tmp == NULL || tmp == Py_None) { |
| 9573 | Py_CLEAR(tmp); |
| 9574 | type_comment = NULL; |
| 9575 | } |
| 9576 | else { |
| 9577 | int res; |
| 9578 | res = obj2ast_string(tmp, &type_comment, arena); |
| 9579 | if (res != 0) goto failed; |
| 9580 | Py_CLEAR(tmp); |
| 9581 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9582 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9583 | return 1; |
| 9584 | } |
| 9585 | if (tmp == NULL) { |
| 9586 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
| 9587 | return 1; |
| 9588 | } |
| 9589 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9590 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9591 | res = obj2ast_int(tmp, &lineno, arena); |
| 9592 | if (res != 0) goto failed; |
| 9593 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9594 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9595 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9596 | { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9597 | return 1; |
| 9598 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9599 | if (tmp == NULL) { |
| 9600 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
| 9601 | return 1; |
| 9602 | } |
| 9603 | else { |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9604 | int res; |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9605 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9606 | if (res != 0) goto failed; |
| 9607 | Py_CLEAR(tmp); |
Victor Stinner | c106c68 | 2015-11-06 17:01:48 +0100 | [diff] [blame] | 9608 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9609 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9610 | { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9611 | return 1; |
| 9612 | } |
| 9613 | if (tmp == NULL || tmp == Py_None) { |
| 9614 | Py_CLEAR(tmp); |
| 9615 | end_lineno = 0; |
| 9616 | } |
| 9617 | else { |
| 9618 | int res; |
| 9619 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9620 | if (res != 0) goto failed; |
| 9621 | Py_CLEAR(tmp); |
| 9622 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9623 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9624 | < 0) { |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 9625 | return 1; |
| 9626 | } |
| 9627 | if (tmp == NULL || tmp == Py_None) { |
| 9628 | Py_CLEAR(tmp); |
| 9629 | end_col_offset = 0; |
| 9630 | } |
| 9631 | else { |
| 9632 | int res; |
| 9633 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9634 | if (res != 0) goto failed; |
| 9635 | Py_CLEAR(tmp); |
| 9636 | } |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9637 | *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno, |
| 9638 | end_col_offset, arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9639 | return 0; |
| 9640 | failed: |
| 9641 | Py_XDECREF(tmp); |
| 9642 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9643 | } |
| 9644 | |
| 9645 | int |
| 9646 | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
| 9647 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9648 | PyObject* tmp = NULL; |
| 9649 | identifier arg; |
| 9650 | expr_ty value; |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9651 | int lineno; |
| 9652 | int col_offset; |
| 9653 | int end_lineno; |
| 9654 | int end_col_offset; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9655 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9656 | if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9657 | return 1; |
| 9658 | } |
| 9659 | if (tmp == NULL || tmp == Py_None) { |
| 9660 | Py_CLEAR(tmp); |
| 9661 | arg = NULL; |
| 9662 | } |
| 9663 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9664 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9665 | res = obj2ast_identifier(tmp, &arg, arena); |
| 9666 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9667 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9668 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9669 | if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9670 | return 1; |
| 9671 | } |
| 9672 | if (tmp == NULL) { |
| 9673 | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
| 9674 | return 1; |
| 9675 | } |
| 9676 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9677 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9678 | res = obj2ast_expr(tmp, &value, arena); |
| 9679 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9680 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9681 | } |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 9682 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) { |
| 9683 | return 1; |
| 9684 | } |
| 9685 | if (tmp == NULL) { |
| 9686 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword"); |
| 9687 | return 1; |
| 9688 | } |
| 9689 | else { |
| 9690 | int res; |
| 9691 | res = obj2ast_int(tmp, &lineno, arena); |
| 9692 | if (res != 0) goto failed; |
| 9693 | Py_CLEAR(tmp); |
| 9694 | } |
| 9695 | if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0) |
| 9696 | { |
| 9697 | return 1; |
| 9698 | } |
| 9699 | if (tmp == NULL) { |
| 9700 | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword"); |
| 9701 | return 1; |
| 9702 | } |
| 9703 | else { |
| 9704 | int res; |
| 9705 | res = obj2ast_int(tmp, &col_offset, arena); |
| 9706 | if (res != 0) goto failed; |
| 9707 | Py_CLEAR(tmp); |
| 9708 | } |
| 9709 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0) |
| 9710 | { |
| 9711 | return 1; |
| 9712 | } |
| 9713 | if (tmp == NULL || tmp == Py_None) { |
| 9714 | Py_CLEAR(tmp); |
| 9715 | end_lineno = 0; |
| 9716 | } |
| 9717 | else { |
| 9718 | int res; |
| 9719 | res = obj2ast_int(tmp, &end_lineno, arena); |
| 9720 | if (res != 0) goto failed; |
| 9721 | Py_CLEAR(tmp); |
| 9722 | } |
| 9723 | if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp) |
| 9724 | < 0) { |
| 9725 | return 1; |
| 9726 | } |
| 9727 | if (tmp == NULL || tmp == Py_None) { |
| 9728 | Py_CLEAR(tmp); |
| 9729 | end_col_offset = 0; |
| 9730 | } |
| 9731 | else { |
| 9732 | int res; |
| 9733 | res = obj2ast_int(tmp, &end_col_offset, arena); |
| 9734 | if (res != 0) goto failed; |
| 9735 | Py_CLEAR(tmp); |
| 9736 | } |
| 9737 | *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset, |
| 9738 | arena); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9739 | return 0; |
| 9740 | failed: |
| 9741 | Py_XDECREF(tmp); |
| 9742 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9743 | } |
| 9744 | |
| 9745 | int |
| 9746 | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
| 9747 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9748 | PyObject* tmp = NULL; |
| 9749 | identifier name; |
| 9750 | identifier asname; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9751 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9752 | if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9753 | return 1; |
| 9754 | } |
| 9755 | if (tmp == NULL) { |
| 9756 | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
| 9757 | return 1; |
| 9758 | } |
| 9759 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9760 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9761 | res = obj2ast_identifier(tmp, &name, arena); |
| 9762 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9763 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9764 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9765 | if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) { |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9766 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9767 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9768 | if (tmp == NULL || tmp == Py_None) { |
| 9769 | Py_CLEAR(tmp); |
| 9770 | asname = NULL; |
| 9771 | } |
| 9772 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9773 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9774 | res = obj2ast_identifier(tmp, &asname, arena); |
| 9775 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9776 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9777 | } |
| 9778 | *out = alias(name, asname, arena); |
| 9779 | return 0; |
| 9780 | failed: |
| 9781 | Py_XDECREF(tmp); |
| 9782 | return 1; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9783 | } |
| 9784 | |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9785 | int |
| 9786 | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
| 9787 | { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9788 | PyObject* tmp = NULL; |
| 9789 | expr_ty context_expr; |
| 9790 | expr_ty optional_vars; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9791 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9792 | if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) < |
| 9793 | 0) { |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9794 | return 1; |
| 9795 | } |
| 9796 | if (tmp == NULL) { |
| 9797 | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
| 9798 | return 1; |
| 9799 | } |
| 9800 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9801 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9802 | res = obj2ast_expr(tmp, &context_expr, arena); |
| 9803 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9804 | Py_CLEAR(tmp); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9805 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9806 | if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) < |
| 9807 | 0) { |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9808 | return 1; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9809 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 9810 | if (tmp == NULL || tmp == Py_None) { |
| 9811 | Py_CLEAR(tmp); |
| 9812 | optional_vars = NULL; |
| 9813 | } |
| 9814 | else { |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9815 | int res; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9816 | res = obj2ast_expr(tmp, &optional_vars, arena); |
| 9817 | if (res != 0) goto failed; |
Victor Stinner | 1acc129 | 2013-07-27 00:03:47 +0200 | [diff] [blame] | 9818 | Py_CLEAR(tmp); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9819 | } |
| 9820 | *out = withitem(context_expr, optional_vars, arena); |
| 9821 | return 0; |
| 9822 | failed: |
| 9823 | Py_XDECREF(tmp); |
| 9824 | return 1; |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 9825 | } |
| 9826 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9827 | int |
| 9828 | obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena) |
| 9829 | { |
| 9830 | int isinstance; |
| 9831 | |
| 9832 | PyObject *tmp = NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9833 | PyObject *tp; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9834 | |
| 9835 | if (obj == Py_None) { |
| 9836 | *out = NULL; |
| 9837 | return 0; |
| 9838 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9839 | tp = astmodulestate_global->TypeIgnore_type; |
| 9840 | isinstance = PyObject_IsInstance(obj, tp); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9841 | if (isinstance == -1) { |
| 9842 | return 1; |
| 9843 | } |
| 9844 | if (isinstance) { |
| 9845 | int lineno; |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9846 | string tag; |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9847 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9848 | if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) |
| 9849 | { |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9850 | return 1; |
| 9851 | } |
| 9852 | if (tmp == NULL) { |
| 9853 | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore"); |
| 9854 | return 1; |
| 9855 | } |
| 9856 | else { |
| 9857 | int res; |
| 9858 | res = obj2ast_int(tmp, &lineno, arena); |
| 9859 | if (res != 0) goto failed; |
| 9860 | Py_CLEAR(tmp); |
| 9861 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9862 | if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) { |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 9863 | return 1; |
| 9864 | } |
| 9865 | if (tmp == NULL) { |
| 9866 | PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore"); |
| 9867 | return 1; |
| 9868 | } |
| 9869 | else { |
| 9870 | int res; |
| 9871 | res = obj2ast_string(tmp, &tag, arena); |
| 9872 | if (res != 0) goto failed; |
| 9873 | Py_CLEAR(tmp); |
| 9874 | } |
| 9875 | *out = TypeIgnore(lineno, tag, arena); |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9876 | if (*out == NULL) goto failed; |
| 9877 | return 0; |
| 9878 | } |
| 9879 | |
| 9880 | PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj); |
| 9881 | failed: |
| 9882 | Py_XDECREF(tmp); |
| 9883 | return 1; |
| 9884 | } |
| 9885 | |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 9886 | |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9887 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 9888 | PyInit__ast(void) |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 9889 | { |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9890 | PyObject *m; |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9891 | if (!init_types()) return NULL; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9892 | m = PyState_FindModule(&_astmodule); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 9893 | if (!m) return NULL; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9894 | if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) { |
| 9895 | goto error; |
| 9896 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9897 | Py_INCREF(astmodulestate(m)->AST_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9898 | if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) { |
| 9899 | goto error; |
| 9900 | } |
| 9901 | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) { |
| 9902 | goto error; |
| 9903 | } |
| 9904 | if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) { |
| 9905 | goto error; |
| 9906 | } |
| 9907 | if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) { |
| 9908 | goto error; |
| 9909 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9910 | Py_INCREF(astmodulestate(m)->mod_type); |
| 9911 | if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9912 | 0) { |
| 9913 | goto error; |
| 9914 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9915 | Py_INCREF(astmodulestate(m)->Module_type); |
| 9916 | if (PyModule_AddObject(m, "Interactive", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9917 | astmodulestate_global->Interactive_type) < 0) { |
| 9918 | goto error; |
| 9919 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9920 | Py_INCREF(astmodulestate(m)->Interactive_type); |
| 9921 | if (PyModule_AddObject(m, "Expression", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9922 | astmodulestate_global->Expression_type) < 0) { |
| 9923 | goto error; |
| 9924 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9925 | Py_INCREF(astmodulestate(m)->Expression_type); |
| 9926 | if (PyModule_AddObject(m, "FunctionType", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9927 | astmodulestate_global->FunctionType_type) < 0) { |
| 9928 | goto error; |
| 9929 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9930 | Py_INCREF(astmodulestate(m)->FunctionType_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9931 | if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) { |
| 9932 | goto error; |
| 9933 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9934 | Py_INCREF(astmodulestate(m)->stmt_type); |
| 9935 | if (PyModule_AddObject(m, "FunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9936 | astmodulestate_global->FunctionDef_type) < 0) { |
| 9937 | goto error; |
| 9938 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9939 | Py_INCREF(astmodulestate(m)->FunctionDef_type); |
| 9940 | if (PyModule_AddObject(m, "AsyncFunctionDef", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9941 | astmodulestate_global->AsyncFunctionDef_type) < 0) { |
| 9942 | goto error; |
| 9943 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9944 | Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type); |
| 9945 | if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9946 | < 0) { |
| 9947 | goto error; |
| 9948 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9949 | Py_INCREF(astmodulestate(m)->ClassDef_type); |
| 9950 | if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9951 | 0) { |
| 9952 | goto error; |
| 9953 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9954 | Py_INCREF(astmodulestate(m)->Return_type); |
| 9955 | if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9956 | 0) { |
| 9957 | goto error; |
| 9958 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9959 | Py_INCREF(astmodulestate(m)->Delete_type); |
| 9960 | if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9961 | 0) { |
| 9962 | goto error; |
| 9963 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9964 | Py_INCREF(astmodulestate(m)->Assign_type); |
| 9965 | if (PyModule_AddObject(m, "AugAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9966 | astmodulestate_global->AugAssign_type) < 0) { |
| 9967 | goto error; |
| 9968 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9969 | Py_INCREF(astmodulestate(m)->AugAssign_type); |
| 9970 | if (PyModule_AddObject(m, "AnnAssign", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9971 | astmodulestate_global->AnnAssign_type) < 0) { |
| 9972 | goto error; |
| 9973 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9974 | Py_INCREF(astmodulestate(m)->AnnAssign_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9975 | if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) { |
| 9976 | goto error; |
| 9977 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9978 | Py_INCREF(astmodulestate(m)->For_type); |
| 9979 | if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9980 | < 0) { |
| 9981 | goto error; |
| 9982 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9983 | Py_INCREF(astmodulestate(m)->AsyncFor_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9984 | if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) { |
| 9985 | goto error; |
| 9986 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9987 | Py_INCREF(astmodulestate(m)->While_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9988 | if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) { |
| 9989 | goto error; |
| 9990 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9991 | Py_INCREF(astmodulestate(m)->If_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9992 | if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) { |
| 9993 | goto error; |
| 9994 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 9995 | Py_INCREF(astmodulestate(m)->With_type); |
| 9996 | if (PyModule_AddObject(m, "AsyncWith", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 9997 | astmodulestate_global->AsyncWith_type) < 0) { |
| 9998 | goto error; |
| 9999 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10000 | Py_INCREF(astmodulestate(m)->AsyncWith_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10001 | if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) { |
| 10002 | goto error; |
| 10003 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10004 | Py_INCREF(astmodulestate(m)->Raise_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10005 | if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) { |
| 10006 | goto error; |
| 10007 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10008 | Py_INCREF(astmodulestate(m)->Try_type); |
| 10009 | if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10010 | 0) { |
| 10011 | goto error; |
| 10012 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10013 | Py_INCREF(astmodulestate(m)->Assert_type); |
| 10014 | if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10015 | 0) { |
| 10016 | goto error; |
| 10017 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10018 | Py_INCREF(astmodulestate(m)->Import_type); |
| 10019 | if (PyModule_AddObject(m, "ImportFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10020 | astmodulestate_global->ImportFrom_type) < 0) { |
| 10021 | goto error; |
| 10022 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10023 | Py_INCREF(astmodulestate(m)->ImportFrom_type); |
| 10024 | if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10025 | 0) { |
| 10026 | goto error; |
| 10027 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10028 | Py_INCREF(astmodulestate(m)->Global_type); |
| 10029 | if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10030 | < 0) { |
| 10031 | goto error; |
| 10032 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10033 | Py_INCREF(astmodulestate(m)->Nonlocal_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10034 | if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) { |
| 10035 | goto error; |
| 10036 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10037 | Py_INCREF(astmodulestate(m)->Expr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10038 | if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) { |
| 10039 | goto error; |
| 10040 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10041 | Py_INCREF(astmodulestate(m)->Pass_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10042 | if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) { |
| 10043 | goto error; |
| 10044 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10045 | Py_INCREF(astmodulestate(m)->Break_type); |
| 10046 | if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10047 | < 0) { |
| 10048 | goto error; |
| 10049 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10050 | Py_INCREF(astmodulestate(m)->Continue_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10051 | if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) { |
| 10052 | goto error; |
| 10053 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10054 | Py_INCREF(astmodulestate(m)->expr_type); |
| 10055 | if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10056 | 0) { |
| 10057 | goto error; |
| 10058 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10059 | Py_INCREF(astmodulestate(m)->BoolOp_type); |
| 10060 | if (PyModule_AddObject(m, "NamedExpr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10061 | astmodulestate_global->NamedExpr_type) < 0) { |
| 10062 | goto error; |
| 10063 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10064 | Py_INCREF(astmodulestate(m)->NamedExpr_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10065 | if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) { |
| 10066 | goto error; |
| 10067 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10068 | Py_INCREF(astmodulestate(m)->BinOp_type); |
| 10069 | if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10070 | 0) { |
| 10071 | goto error; |
| 10072 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10073 | Py_INCREF(astmodulestate(m)->UnaryOp_type); |
| 10074 | if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10075 | 0) { |
| 10076 | goto error; |
| 10077 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10078 | Py_INCREF(astmodulestate(m)->Lambda_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10079 | if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) { |
| 10080 | goto error; |
| 10081 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10082 | Py_INCREF(astmodulestate(m)->IfExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10083 | if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) { |
| 10084 | goto error; |
| 10085 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10086 | Py_INCREF(astmodulestate(m)->Dict_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10087 | if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) { |
| 10088 | goto error; |
| 10089 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10090 | Py_INCREF(astmodulestate(m)->Set_type); |
| 10091 | if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10092 | < 0) { |
| 10093 | goto error; |
| 10094 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10095 | Py_INCREF(astmodulestate(m)->ListComp_type); |
| 10096 | if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10097 | 0) { |
| 10098 | goto error; |
| 10099 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10100 | Py_INCREF(astmodulestate(m)->SetComp_type); |
| 10101 | if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10102 | < 0) { |
| 10103 | goto error; |
| 10104 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10105 | Py_INCREF(astmodulestate(m)->DictComp_type); |
| 10106 | if (PyModule_AddObject(m, "GeneratorExp", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10107 | astmodulestate_global->GeneratorExp_type) < 0) { |
| 10108 | goto error; |
| 10109 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10110 | Py_INCREF(astmodulestate(m)->GeneratorExp_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10111 | if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) { |
| 10112 | goto error; |
| 10113 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10114 | Py_INCREF(astmodulestate(m)->Await_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10115 | if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) { |
| 10116 | goto error; |
| 10117 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10118 | Py_INCREF(astmodulestate(m)->Yield_type); |
| 10119 | if (PyModule_AddObject(m, "YieldFrom", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10120 | astmodulestate_global->YieldFrom_type) < 0) { |
| 10121 | goto error; |
| 10122 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10123 | Py_INCREF(astmodulestate(m)->YieldFrom_type); |
| 10124 | if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10125 | 0) { |
| 10126 | goto error; |
| 10127 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10128 | Py_INCREF(astmodulestate(m)->Compare_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10129 | if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) { |
| 10130 | goto error; |
| 10131 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10132 | Py_INCREF(astmodulestate(m)->Call_type); |
| 10133 | if (PyModule_AddObject(m, "FormattedValue", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10134 | astmodulestate_global->FormattedValue_type) < 0) { |
| 10135 | goto error; |
| 10136 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10137 | Py_INCREF(astmodulestate(m)->FormattedValue_type); |
| 10138 | if (PyModule_AddObject(m, "JoinedStr", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10139 | astmodulestate_global->JoinedStr_type) < 0) { |
| 10140 | goto error; |
| 10141 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10142 | Py_INCREF(astmodulestate(m)->JoinedStr_type); |
| 10143 | if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10144 | < 0) { |
| 10145 | goto error; |
| 10146 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10147 | Py_INCREF(astmodulestate(m)->Constant_type); |
| 10148 | if (PyModule_AddObject(m, "Attribute", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10149 | astmodulestate_global->Attribute_type) < 0) { |
| 10150 | goto error; |
| 10151 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10152 | Py_INCREF(astmodulestate(m)->Attribute_type); |
| 10153 | if (PyModule_AddObject(m, "Subscript", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10154 | astmodulestate_global->Subscript_type) < 0) { |
| 10155 | goto error; |
| 10156 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10157 | Py_INCREF(astmodulestate(m)->Subscript_type); |
| 10158 | if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10159 | 0) { |
| 10160 | goto error; |
| 10161 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10162 | Py_INCREF(astmodulestate(m)->Starred_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10163 | if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) { |
| 10164 | goto error; |
| 10165 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10166 | Py_INCREF(astmodulestate(m)->Name_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10167 | if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) { |
| 10168 | goto error; |
| 10169 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10170 | Py_INCREF(astmodulestate(m)->List_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10171 | if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) { |
| 10172 | goto error; |
| 10173 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10174 | Py_INCREF(astmodulestate(m)->Tuple_type); |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 10175 | if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) { |
| 10176 | goto error; |
| 10177 | } |
| 10178 | Py_INCREF(astmodulestate(m)->Slice_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10179 | if (PyModule_AddObject(m, "expr_context", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10180 | astmodulestate_global->expr_context_type) < 0) { |
| 10181 | goto error; |
| 10182 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10183 | Py_INCREF(astmodulestate(m)->expr_context_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10184 | if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) { |
| 10185 | goto error; |
| 10186 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10187 | Py_INCREF(astmodulestate(m)->Load_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10188 | if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) { |
| 10189 | goto error; |
| 10190 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10191 | Py_INCREF(astmodulestate(m)->Store_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10192 | if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) { |
| 10193 | goto error; |
| 10194 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10195 | Py_INCREF(astmodulestate(m)->Del_type); |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10196 | if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10197 | 0) { |
| 10198 | goto error; |
| 10199 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10200 | Py_INCREF(astmodulestate(m)->boolop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10201 | if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) { |
| 10202 | goto error; |
| 10203 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10204 | Py_INCREF(astmodulestate(m)->And_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10205 | if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) { |
| 10206 | goto error; |
| 10207 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10208 | Py_INCREF(astmodulestate(m)->Or_type); |
| 10209 | if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10210 | < 0) { |
| 10211 | goto error; |
| 10212 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10213 | Py_INCREF(astmodulestate(m)->operator_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10214 | if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) { |
| 10215 | goto error; |
| 10216 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10217 | Py_INCREF(astmodulestate(m)->Add_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10218 | if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) { |
| 10219 | goto error; |
| 10220 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10221 | Py_INCREF(astmodulestate(m)->Sub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10222 | if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) { |
| 10223 | goto error; |
| 10224 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10225 | Py_INCREF(astmodulestate(m)->Mult_type); |
| 10226 | if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10227 | 0) { |
| 10228 | goto error; |
| 10229 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10230 | Py_INCREF(astmodulestate(m)->MatMult_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10231 | if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) { |
| 10232 | goto error; |
| 10233 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10234 | Py_INCREF(astmodulestate(m)->Div_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10235 | if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) { |
| 10236 | goto error; |
| 10237 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10238 | Py_INCREF(astmodulestate(m)->Mod_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10239 | if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) { |
| 10240 | goto error; |
| 10241 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10242 | Py_INCREF(astmodulestate(m)->Pow_type); |
| 10243 | if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10244 | 0) { |
| 10245 | goto error; |
| 10246 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10247 | Py_INCREF(astmodulestate(m)->LShift_type); |
| 10248 | if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10249 | 0) { |
| 10250 | goto error; |
| 10251 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10252 | Py_INCREF(astmodulestate(m)->RShift_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10253 | if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) { |
| 10254 | goto error; |
| 10255 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10256 | Py_INCREF(astmodulestate(m)->BitOr_type); |
| 10257 | if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10258 | 0) { |
| 10259 | goto error; |
| 10260 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10261 | Py_INCREF(astmodulestate(m)->BitXor_type); |
| 10262 | if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10263 | 0) { |
| 10264 | goto error; |
| 10265 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10266 | Py_INCREF(astmodulestate(m)->BitAnd_type); |
| 10267 | if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10268 | < 0) { |
| 10269 | goto error; |
| 10270 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10271 | Py_INCREF(astmodulestate(m)->FloorDiv_type); |
| 10272 | if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10273 | 0) { |
| 10274 | goto error; |
| 10275 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10276 | Py_INCREF(astmodulestate(m)->unaryop_type); |
| 10277 | if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10278 | 0) { |
| 10279 | goto error; |
| 10280 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10281 | Py_INCREF(astmodulestate(m)->Invert_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10282 | if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) { |
| 10283 | goto error; |
| 10284 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10285 | Py_INCREF(astmodulestate(m)->Not_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10286 | if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) { |
| 10287 | goto error; |
| 10288 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10289 | Py_INCREF(astmodulestate(m)->UAdd_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10290 | if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) { |
| 10291 | goto error; |
| 10292 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10293 | Py_INCREF(astmodulestate(m)->USub_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10294 | if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) { |
| 10295 | goto error; |
| 10296 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10297 | Py_INCREF(astmodulestate(m)->cmpop_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10298 | if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) { |
| 10299 | goto error; |
| 10300 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10301 | Py_INCREF(astmodulestate(m)->Eq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10302 | if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) { |
| 10303 | goto error; |
| 10304 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10305 | Py_INCREF(astmodulestate(m)->NotEq_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10306 | if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) { |
| 10307 | goto error; |
| 10308 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10309 | Py_INCREF(astmodulestate(m)->Lt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10310 | if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) { |
| 10311 | goto error; |
| 10312 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10313 | Py_INCREF(astmodulestate(m)->LtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10314 | if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) { |
| 10315 | goto error; |
| 10316 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10317 | Py_INCREF(astmodulestate(m)->Gt_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10318 | if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) { |
| 10319 | goto error; |
| 10320 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10321 | Py_INCREF(astmodulestate(m)->GtE_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10322 | if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) { |
| 10323 | goto error; |
| 10324 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10325 | Py_INCREF(astmodulestate(m)->Is_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10326 | if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) { |
| 10327 | goto error; |
| 10328 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10329 | Py_INCREF(astmodulestate(m)->IsNot_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10330 | if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) { |
| 10331 | goto error; |
| 10332 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10333 | Py_INCREF(astmodulestate(m)->In_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10334 | if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) { |
| 10335 | goto error; |
| 10336 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10337 | Py_INCREF(astmodulestate(m)->NotIn_type); |
| 10338 | if (PyModule_AddObject(m, "comprehension", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10339 | astmodulestate_global->comprehension_type) < 0) { |
| 10340 | goto error; |
| 10341 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10342 | Py_INCREF(astmodulestate(m)->comprehension_type); |
| 10343 | if (PyModule_AddObject(m, "excepthandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10344 | astmodulestate_global->excepthandler_type) < 0) { |
| 10345 | goto error; |
| 10346 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10347 | Py_INCREF(astmodulestate(m)->excepthandler_type); |
| 10348 | if (PyModule_AddObject(m, "ExceptHandler", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10349 | astmodulestate_global->ExceptHandler_type) < 0) { |
| 10350 | goto error; |
| 10351 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10352 | Py_INCREF(astmodulestate(m)->ExceptHandler_type); |
| 10353 | if (PyModule_AddObject(m, "arguments", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10354 | astmodulestate_global->arguments_type) < 0) { |
| 10355 | goto error; |
| 10356 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10357 | Py_INCREF(astmodulestate(m)->arguments_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10358 | if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) { |
| 10359 | goto error; |
| 10360 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10361 | Py_INCREF(astmodulestate(m)->arg_type); |
| 10362 | if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) < |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10363 | 0) { |
| 10364 | goto error; |
| 10365 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10366 | Py_INCREF(astmodulestate(m)->keyword_type); |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10367 | if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) { |
| 10368 | goto error; |
| 10369 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10370 | Py_INCREF(astmodulestate(m)->alias_type); |
| 10371 | if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type) |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10372 | < 0) { |
| 10373 | goto error; |
| 10374 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10375 | Py_INCREF(astmodulestate(m)->withitem_type); |
| 10376 | if (PyModule_AddObject(m, "type_ignore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10377 | astmodulestate_global->type_ignore_type) < 0) { |
| 10378 | goto error; |
| 10379 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10380 | Py_INCREF(astmodulestate(m)->type_ignore_type); |
| 10381 | if (PyModule_AddObject(m, "TypeIgnore", |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10382 | astmodulestate_global->TypeIgnore_type) < 0) { |
| 10383 | goto error; |
| 10384 | } |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10385 | Py_INCREF(astmodulestate(m)->TypeIgnore_type); |
Victor Stinner | ce72e1c | 2013-07-27 00:00:36 +0200 | [diff] [blame] | 10386 | return m; |
Brandt Bucher | d2f9667 | 2020-02-06 06:45:46 -0800 | [diff] [blame] | 10387 | error: |
| 10388 | Py_DECREF(m); |
| 10389 | return NULL; |
Martin v. Löwis | 577b5b9 | 2006-02-27 15:23:19 +0000 | [diff] [blame] | 10390 | } |
| 10391 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10392 | |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10393 | PyObject* PyAST_mod2obj(mod_ty t) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10394 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10395 | if (!init_types()) |
| 10396 | return NULL; |
Martin v. Löwis | bd260da | 2006-02-26 19:42:26 +0000 | [diff] [blame] | 10397 | return ast2obj_mod(t); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10398 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10399 | |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10400 | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
| 10401 | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10402 | { |
Benjamin Peterson | c2f665e | 2014-02-10 22:19:02 -0500 | [diff] [blame] | 10403 | PyObject *req_type[3]; |
Serhiy Storchaka | 43c9731 | 2019-09-10 13:02:30 +0300 | [diff] [blame] | 10404 | const char * const req_name[] = {"Module", "Expression", "Interactive"}; |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10405 | int isinstance; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10406 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 10407 | if (PySys_Audit("compile", "OO", ast, Py_None) < 0) { |
| 10408 | return NULL; |
| 10409 | } |
| 10410 | |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10411 | req_type[0] = astmodulestate_global->Module_type; |
| 10412 | req_type[1] = astmodulestate_global->Expression_type; |
| 10413 | req_type[2] = astmodulestate_global->Interactive_type; |
Benjamin Peterson | 42ec031 | 2014-02-10 22:41:40 -0500 | [diff] [blame] | 10414 | |
Guido van Rossum | 3a32e3b | 2019-02-01 11:37:34 -0800 | [diff] [blame] | 10415 | assert(0 <= mode && mode <= 2); |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10416 | |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10417 | if (!init_types()) |
| 10418 | return NULL; |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10419 | |
Benjamin Peterson | 0496c9e | 2009-12-13 01:24:58 +0000 | [diff] [blame] | 10420 | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
| 10421 | if (isinstance == -1) |
| 10422 | return NULL; |
| 10423 | if (!isinstance) { |
Neal Norwitz | db4115f | 2008-03-31 04:20:05 +0000 | [diff] [blame] | 10424 | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10425 | req_name[mode], _PyType_Name(Py_TYPE(ast))); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10426 | return NULL; |
| 10427 | } |
Dong-hee Na | a05fcd3 | 2019-10-10 16:41:26 +0900 | [diff] [blame] | 10428 | |
| 10429 | mod_ty res = NULL; |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10430 | if (obj2ast_mod(ast, &res, arena) != 0) |
| 10431 | return NULL; |
| 10432 | else |
| 10433 | return res; |
| 10434 | } |
| 10435 | |
| 10436 | int PyAST_Check(PyObject* obj) |
| 10437 | { |
Victor Stinner | bdf630c | 2013-07-17 00:17:15 +0200 | [diff] [blame] | 10438 | if (!init_types()) |
| 10439 | return -1; |
Dino Viehland | ac46eb4 | 2019-09-11 10:16:34 -0700 | [diff] [blame] | 10440 | return PyObject_IsInstance(obj, astmodulestate_global->AST_type); |
Martin v. Löwis | 618dc5e | 2008-03-30 20:03:44 +0000 | [diff] [blame] | 10441 | } |
| 10442 | |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 10443 | |