comparison Python/Python-ast.c @ 82732:7c5c678e4164

unify some ast.argument's attrs; change Attribute column offset (closes #16795) Patch from Sven Brauch.
author Benjamin Peterson <benjamin@python.org>
date Mon, 18 Mar 2013 10:48:58 -0700
parents 7d69d04522e3
children c8ccc0519247
comparison
equal deleted inserted replaced
82731:30530f6c24bb 82732:7c5c678e4164
410 "body", 410 "body",
411 }; 411 };
412 static PyTypeObject *arguments_type; 412 static PyTypeObject *arguments_type;
413 static PyObject* ast2obj_arguments(void*); 413 static PyObject* ast2obj_arguments(void*);
414 _Py_IDENTIFIER(vararg); 414 _Py_IDENTIFIER(vararg);
415 _Py_IDENTIFIER(varargannotation);
416 _Py_IDENTIFIER(kwonlyargs); 415 _Py_IDENTIFIER(kwonlyargs);
416 _Py_IDENTIFIER(kw_defaults);
417 _Py_IDENTIFIER(kwarg); 417 _Py_IDENTIFIER(kwarg);
418 _Py_IDENTIFIER(kwargannotation);
419 _Py_IDENTIFIER(defaults); 418 _Py_IDENTIFIER(defaults);
420 _Py_IDENTIFIER(kw_defaults);
421 static char *arguments_fields[]={ 419 static char *arguments_fields[]={
422 "args", 420 "args",
423 "vararg", 421 "vararg",
424 "varargannotation",
425 "kwonlyargs", 422 "kwonlyargs",
423 "kw_defaults",
426 "kwarg", 424 "kwarg",
427 "kwargannotation",
428 "defaults", 425 "defaults",
429 "kw_defaults",
430 }; 426 };
431 static PyTypeObject *arg_type; 427 static PyTypeObject *arg_type;
432 static PyObject* ast2obj_arg(void*); 428 static PyObject* ast2obj_arg(void*);
429 static char *arg_attributes[] = {
430 "lineno",
431 "col_offset",
432 };
433 _Py_IDENTIFIER(arg); 433 _Py_IDENTIFIER(arg);
434 _Py_IDENTIFIER(annotation); 434 _Py_IDENTIFIER(annotation);
435 static char *arg_fields[]={ 435 static char *arg_fields[]={
436 "arg", 436 "arg",
437 "annotation", 437 "annotation",
1054 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); 1054 NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL);
1055 if (!NotIn_singleton) return 0; 1055 if (!NotIn_singleton) return 0;
1056 comprehension_type = make_type("comprehension", &AST_type, 1056 comprehension_type = make_type("comprehension", &AST_type,
1057 comprehension_fields, 3); 1057 comprehension_fields, 3);
1058 if (!comprehension_type) return 0; 1058 if (!comprehension_type) return 0;
1059 if (!add_attributes(comprehension_type, NULL, 0)) return 0;
1059 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); 1060 excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0);
1060 if (!excepthandler_type) return 0; 1061 if (!excepthandler_type) return 0;
1061 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) 1062 if (!add_attributes(excepthandler_type, excepthandler_attributes, 2))
1062 return 0; 1063 return 0;
1063 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, 1064 ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
1064 ExceptHandler_fields, 3); 1065 ExceptHandler_fields, 3);
1065 if (!ExceptHandler_type) return 0; 1066 if (!ExceptHandler_type) return 0;
1066 arguments_type = make_type("arguments", &AST_type, arguments_fields, 8); 1067 arguments_type = make_type("arguments", &AST_type, arguments_fields, 6);
1067 if (!arguments_type) return 0; 1068 if (!arguments_type) return 0;
1069 if (!add_attributes(arguments_type, NULL, 0)) return 0;
1068 arg_type = make_type("arg", &AST_type, arg_fields, 2); 1070 arg_type = make_type("arg", &AST_type, arg_fields, 2);
1069 if (!arg_type) return 0; 1071 if (!arg_type) return 0;
1072 if (!add_attributes(arg_type, arg_attributes, 2)) return 0;
1070 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); 1073 keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
1071 if (!keyword_type) return 0; 1074 if (!keyword_type) return 0;
1075 if (!add_attributes(keyword_type, NULL, 0)) return 0;
1072 alias_type = make_type("alias", &AST_type, alias_fields, 2); 1076 alias_type = make_type("alias", &AST_type, alias_fields, 2);
1073 if (!alias_type) return 0; 1077 if (!alias_type) return 0;
1078 if (!add_attributes(alias_type, NULL, 0)) return 0;
1074 withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); 1079 withitem_type = make_type("withitem", &AST_type, withitem_fields, 2);
1075 if (!withitem_type) return 0; 1080 if (!withitem_type) return 0;
1081 if (!add_attributes(withitem_type, NULL, 0)) return 0;
1076 initialized = 1; 1082 initialized = 1;
1077 return 1; 1083 return 1;
1078 } 1084 }
1079 1085
1080 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); 1086 static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
2211 p->col_offset = col_offset; 2217 p->col_offset = col_offset;
2212 return p; 2218 return p;
2213 } 2219 }
2214 2220
2215 arguments_ty 2221 arguments_ty
2216 arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation, 2222 arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq *
2217 asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation, 2223 kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena)
2218 asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
2219 { 2224 {
2220 arguments_ty p; 2225 arguments_ty p;
2221 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); 2226 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
2222 if (!p) 2227 if (!p)
2223 return NULL; 2228 return NULL;
2224 p->args = args; 2229 p->args = args;
2225 p->vararg = vararg; 2230 p->vararg = vararg;
2226 p->varargannotation = varargannotation;
2227 p->kwonlyargs = kwonlyargs; 2231 p->kwonlyargs = kwonlyargs;
2232 p->kw_defaults = kw_defaults;
2228 p->kwarg = kwarg; 2233 p->kwarg = kwarg;
2229 p->kwargannotation = kwargannotation;
2230 p->defaults = defaults; 2234 p->defaults = defaults;
2231 p->kw_defaults = kw_defaults;
2232 return p; 2235 return p;
2233 } 2236 }
2234 2237
2235 arg_ty 2238 arg_ty
2236 arg(identifier arg, expr_ty annotation, PyArena *arena) 2239 arg(identifier arg, expr_ty annotation, PyArena *arena)
3411 value = ast2obj_list(o->args, ast2obj_arg); 3414 value = ast2obj_list(o->args, ast2obj_arg);
3412 if (!value) goto failed; 3415 if (!value) goto failed;
3413 if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) 3416 if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
3414 goto failed; 3417 goto failed;
3415 Py_DECREF(value); 3418 Py_DECREF(value);
3416 value = ast2obj_identifier(o->vararg); 3419 value = ast2obj_arg(o->vararg);
3417 if (!value) goto failed; 3420 if (!value) goto failed;
3418 if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) 3421 if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1)
3419 goto failed;
3420 Py_DECREF(value);
3421 value = ast2obj_expr(o->varargannotation);
3422 if (!value) goto failed;
3423 if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1)
3424 goto failed; 3422 goto failed;
3425 Py_DECREF(value); 3423 Py_DECREF(value);
3426 value = ast2obj_list(o->kwonlyargs, ast2obj_arg); 3424 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
3427 if (!value) goto failed; 3425 if (!value) goto failed;
3428 if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) 3426 if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1)
3429 goto failed; 3427 goto failed;
3430 Py_DECREF(value); 3428 Py_DECREF(value);
3431 value = ast2obj_identifier(o->kwarg); 3429 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3430 if (!value) goto failed;
3431 if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1)
3432 goto failed;
3433 Py_DECREF(value);
3434 value = ast2obj_arg(o->kwarg);
3432 if (!value) goto failed; 3435 if (!value) goto failed;
3433 if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) 3436 if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1)
3434 goto failed;
3435 Py_DECREF(value);
3436 value = ast2obj_expr(o->kwargannotation);
3437 if (!value) goto failed;
3438 if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1)
3439 goto failed; 3437 goto failed;
3440 Py_DECREF(value); 3438 Py_DECREF(value);
3441 value = ast2obj_list(o->defaults, ast2obj_expr); 3439 value = ast2obj_list(o->defaults, ast2obj_expr);
3442 if (!value) goto failed; 3440 if (!value) goto failed;
3443 if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) 3441 if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1)
3444 goto failed;
3445 Py_DECREF(value);
3446 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
3447 if (!value) goto failed;
3448 if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1)
3449 goto failed; 3442 goto failed;
3450 Py_DECREF(value); 3443 Py_DECREF(value);
3451 return result; 3444 return result;
3452 failed: 3445 failed:
3453 Py_XDECREF(value); 3446 Py_XDECREF(value);
3473 goto failed; 3466 goto failed;
3474 Py_DECREF(value); 3467 Py_DECREF(value);
3475 value = ast2obj_expr(o->annotation); 3468 value = ast2obj_expr(o->annotation);
3476 if (!value) goto failed; 3469 if (!value) goto failed;
3477 if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) 3470 if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
3471 goto failed;
3472 Py_DECREF(value);
3473 value = ast2obj_int(o->lineno);
3474 if (!value) goto failed;
3475 if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
3476 goto failed;
3477 Py_DECREF(value);
3478 value = ast2obj_int(o->col_offset);
3479 if (!value) goto failed;
3480 if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
3478 goto failed; 3481 goto failed;
3479 Py_DECREF(value); 3482 Py_DECREF(value);
3480 return result; 3483 return result;
3481 failed: 3484 failed:
3482 Py_XDECREF(value); 3485 Py_XDECREF(value);
3841 tmp = NULL; 3844 tmp = NULL;
3842 } else { 3845 } else {
3843 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); 3846 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
3844 return 1; 3847 return 1;
3845 } 3848 }
3846 if (_PyObject_HasAttrId(obj, &PyId_returns)) { 3849 if (_PyObject_HasAttrId(obj, &PyId_returns) && _PyObject_GetAttrId(obj, &PyId_returns) != Py_None) {
3847 int res; 3850 int res;
3848 tmp = _PyObject_GetAttrId(obj, &PyId_returns); 3851 tmp = _PyObject_GetAttrId(obj, &PyId_returns);
3849 if (tmp == NULL) goto failed; 3852 if (tmp == NULL) goto failed;
3850 res = obj2ast_expr(tmp, &returns, arena); 3853 res = obj2ast_expr(tmp, &returns, arena);
3851 if (res != 0) goto failed; 3854 if (res != 0) goto failed;
3932 tmp = NULL; 3935 tmp = NULL;
3933 } else { 3936 } else {
3934 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); 3937 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
3935 return 1; 3938 return 1;
3936 } 3939 }
3937 if (_PyObject_HasAttrId(obj, &PyId_starargs)) { 3940 if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) {
3938 int res; 3941 int res;
3939 tmp = _PyObject_GetAttrId(obj, &PyId_starargs); 3942 tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
3940 if (tmp == NULL) goto failed; 3943 if (tmp == NULL) goto failed;
3941 res = obj2ast_expr(tmp, &starargs, arena); 3944 res = obj2ast_expr(tmp, &starargs, arena);
3942 if (res != 0) goto failed; 3945 if (res != 0) goto failed;
3943 Py_XDECREF(tmp); 3946 Py_XDECREF(tmp);
3944 tmp = NULL; 3947 tmp = NULL;
3945 } else { 3948 } else {
3946 starargs = NULL; 3949 starargs = NULL;
3947 } 3950 }
3948 if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { 3951 if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) {
3949 int res; 3952 int res;
3950 tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); 3953 tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
3951 if (tmp == NULL) goto failed; 3954 if (tmp == NULL) goto failed;
3952 res = obj2ast_expr(tmp, &kwargs, arena); 3955 res = obj2ast_expr(tmp, &kwargs, arena);
3953 if (res != 0) goto failed; 3956 if (res != 0) goto failed;
4016 return 1; 4019 return 1;
4017 } 4020 }
4018 if (isinstance) { 4021 if (isinstance) {
4019 expr_ty value; 4022 expr_ty value;
4020 4023
4021 if (_PyObject_HasAttrId(obj, &PyId_value)) { 4024 if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) {
4022 int res; 4025 int res;
4023 tmp = _PyObject_GetAttrId(obj, &PyId_value); 4026 tmp = _PyObject_GetAttrId(obj, &PyId_value);
4024 if (tmp == NULL) goto failed; 4027 if (tmp == NULL) goto failed;
4025 res = obj2ast_expr(tmp, &value, arena); 4028 res = obj2ast_expr(tmp, &value, arena);
4026 if (res != 0) goto failed; 4029 if (res != 0) goto failed;
4474 } 4477 }
4475 if (isinstance) { 4478 if (isinstance) {
4476 expr_ty exc; 4479 expr_ty exc;
4477 expr_ty cause; 4480 expr_ty cause;
4478 4481
4479 if (_PyObject_HasAttrId(obj, &PyId_exc)) { 4482 if (_PyObject_HasAttrId(obj, &PyId_exc) && _PyObject_GetAttrId(obj, &PyId_exc) != Py_None) {
4480 int res; 4483 int res;
4481 tmp = _PyObject_GetAttrId(obj, &PyId_exc); 4484 tmp = _PyObject_GetAttrId(obj, &PyId_exc);
4482 if (tmp == NULL) goto failed; 4485 if (tmp == NULL) goto failed;
4483 res = obj2ast_expr(tmp, &exc, arena); 4486 res = obj2ast_expr(tmp, &exc, arena);
4484 if (res != 0) goto failed; 4487 if (res != 0) goto failed;
4485 Py_XDECREF(tmp); 4488 Py_XDECREF(tmp);
4486 tmp = NULL; 4489 tmp = NULL;
4487 } else { 4490 } else {
4488 exc = NULL; 4491 exc = NULL;
4489 } 4492 }
4490 if (_PyObject_HasAttrId(obj, &PyId_cause)) { 4493 if (_PyObject_HasAttrId(obj, &PyId_cause) && _PyObject_GetAttrId(obj, &PyId_cause) != Py_None) {
4491 int res; 4494 int res;
4492 tmp = _PyObject_GetAttrId(obj, &PyId_cause); 4495 tmp = _PyObject_GetAttrId(obj, &PyId_cause);
4493 if (tmp == NULL) goto failed; 4496 if (tmp == NULL) goto failed;
4494 res = obj2ast_expr(tmp, &cause, arena); 4497 res = obj2ast_expr(tmp, &cause, arena);
4495 if (res != 0) goto failed; 4498 if (res != 0) goto failed;
4635 tmp = NULL; 4638 tmp = NULL;
4636 } else { 4639 } else {
4637 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); 4640 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
4638 return 1; 4641 return 1;
4639 } 4642 }
4640 if (_PyObject_HasAttrId(obj, &PyId_msg)) { 4643 if (_PyObject_HasAttrId(obj, &PyId_msg) && _PyObject_GetAttrId(obj, &PyId_msg) != Py_None) {
4641 int res; 4644 int res;
4642 tmp = _PyObject_GetAttrId(obj, &PyId_msg); 4645 tmp = _PyObject_GetAttrId(obj, &PyId_msg);
4643 if (tmp == NULL) goto failed; 4646 if (tmp == NULL) goto failed;
4644 res = obj2ast_expr(tmp, &msg, arena); 4647 res = obj2ast_expr(tmp, &msg, arena);
4645 if (res != 0) goto failed; 4648 if (res != 0) goto failed;
4695 if (isinstance) { 4698 if (isinstance) {
4696 identifier module; 4699 identifier module;
4697 asdl_seq* names; 4700 asdl_seq* names;
4698 int level; 4701 int level;
4699 4702
4700 if (_PyObject_HasAttrId(obj, &PyId_module)) { 4703 if (_PyObject_HasAttrId(obj, &PyId_module) && _PyObject_GetAttrId(obj, &PyId_module) != Py_None) {
4701 int res; 4704 int res;
4702 tmp = _PyObject_GetAttrId(obj, &PyId_module); 4705 tmp = _PyObject_GetAttrId(obj, &PyId_module);
4703 if (tmp == NULL) goto failed; 4706 if (tmp == NULL) goto failed;
4704 res = obj2ast_identifier(tmp, &module, arena); 4707 res = obj2ast_identifier(tmp, &module, arena);
4705 if (res != 0) goto failed; 4708 if (res != 0) goto failed;
4731 tmp = NULL; 4734 tmp = NULL;
4732 } else { 4735 } else {
4733 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); 4736 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
4734 return 1; 4737 return 1;
4735 } 4738 }
4736 if (_PyObject_HasAttrId(obj, &PyId_level)) { 4739 if (_PyObject_HasAttrId(obj, &PyId_level) && _PyObject_GetAttrId(obj, &PyId_level) != Py_None) {
4737 int res; 4740 int res;
4738 tmp = _PyObject_GetAttrId(obj, &PyId_level); 4741 tmp = _PyObject_GetAttrId(obj, &PyId_level);
4739 if (tmp == NULL) goto failed; 4742 if (tmp == NULL) goto failed;
4740 res = obj2ast_int(tmp, &level, arena); 4743 res = obj2ast_int(tmp, &level, arena);
4741 if (res != 0) goto failed; 4744 if (res != 0) goto failed;
5450 return 1; 5453 return 1;
5451 } 5454 }
5452 if (isinstance) { 5455 if (isinstance) {
5453 expr_ty value; 5456 expr_ty value;
5454 5457
5455 if (_PyObject_HasAttrId(obj, &PyId_value)) { 5458 if (_PyObject_HasAttrId(obj, &PyId_value) && _PyObject_GetAttrId(obj, &PyId_value) != Py_None) {
5456 int res; 5459 int res;
5457 tmp = _PyObject_GetAttrId(obj, &PyId_value); 5460 tmp = _PyObject_GetAttrId(obj, &PyId_value);
5458 if (tmp == NULL) goto failed; 5461 if (tmp == NULL) goto failed;
5459 res = obj2ast_expr(tmp, &value, arena); 5462 res = obj2ast_expr(tmp, &value, arena);
5460 if (res != 0) goto failed; 5463 if (res != 0) goto failed;
5637 tmp = NULL; 5640 tmp = NULL;
5638 } else { 5641 } else {
5639 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); 5642 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
5640 return 1; 5643 return 1;
5641 } 5644 }
5642 if (_PyObject_HasAttrId(obj, &PyId_starargs)) { 5645 if (_PyObject_HasAttrId(obj, &PyId_starargs) && _PyObject_GetAttrId(obj, &PyId_starargs) != Py_None) {
5643 int res; 5646 int res;
5644 tmp = _PyObject_GetAttrId(obj, &PyId_starargs); 5647 tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
5645 if (tmp == NULL) goto failed; 5648 if (tmp == NULL) goto failed;
5646 res = obj2ast_expr(tmp, &starargs, arena); 5649 res = obj2ast_expr(tmp, &starargs, arena);
5647 if (res != 0) goto failed; 5650 if (res != 0) goto failed;
5648 Py_XDECREF(tmp); 5651 Py_XDECREF(tmp);
5649 tmp = NULL; 5652 tmp = NULL;
5650 } else { 5653 } else {
5651 starargs = NULL; 5654 starargs = NULL;
5652 } 5655 }
5653 if (_PyObject_HasAttrId(obj, &PyId_kwargs)) { 5656 if (_PyObject_HasAttrId(obj, &PyId_kwargs) && _PyObject_GetAttrId(obj, &PyId_kwargs) != Py_None) {
5654 int res; 5657 int res;
5655 tmp = _PyObject_GetAttrId(obj, &PyId_kwargs); 5658 tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
5656 if (tmp == NULL) goto failed; 5659 if (tmp == NULL) goto failed;
5657 res = obj2ast_expr(tmp, &kwargs, arena); 5660 res = obj2ast_expr(tmp, &kwargs, arena);
5658 if (res != 0) goto failed; 5661 if (res != 0) goto failed;
6119 if (isinstance) { 6122 if (isinstance) {
6120 expr_ty lower; 6123 expr_ty lower;
6121 expr_ty upper; 6124 expr_ty upper;
6122 expr_ty step; 6125 expr_ty step;
6123 6126
6124 if (_PyObject_HasAttrId(obj, &PyId_lower)) { 6127 if (_PyObject_HasAttrId(obj, &PyId_lower) && _PyObject_GetAttrId(obj, &PyId_lower) != Py_None) {
6125 int res; 6128 int res;
6126 tmp = _PyObject_GetAttrId(obj, &PyId_lower); 6129 tmp = _PyObject_GetAttrId(obj, &PyId_lower);
6127 if (tmp == NULL) goto failed; 6130 if (tmp == NULL) goto failed;
6128 res = obj2ast_expr(tmp, &lower, arena); 6131 res = obj2ast_expr(tmp, &lower, arena);
6129 if (res != 0) goto failed; 6132 if (res != 0) goto failed;
6130 Py_XDECREF(tmp); 6133 Py_XDECREF(tmp);
6131 tmp = NULL; 6134 tmp = NULL;
6132 } else { 6135 } else {
6133 lower = NULL; 6136 lower = NULL;
6134 } 6137 }
6135 if (_PyObject_HasAttrId(obj, &PyId_upper)) { 6138 if (_PyObject_HasAttrId(obj, &PyId_upper) && _PyObject_GetAttrId(obj, &PyId_upper) != Py_None) {
6136 int res; 6139 int res;
6137 tmp = _PyObject_GetAttrId(obj, &PyId_upper); 6140 tmp = _PyObject_GetAttrId(obj, &PyId_upper);
6138 if (tmp == NULL) goto failed; 6141 if (tmp == NULL) goto failed;
6139 res = obj2ast_expr(tmp, &upper, arena); 6142 res = obj2ast_expr(tmp, &upper, arena);
6140 if (res != 0) goto failed; 6143 if (res != 0) goto failed;
6141 Py_XDECREF(tmp); 6144 Py_XDECREF(tmp);
6142 tmp = NULL; 6145 tmp = NULL;
6143 } else { 6146 } else {
6144 upper = NULL; 6147 upper = NULL;
6145 } 6148 }
6146 if (_PyObject_HasAttrId(obj, &PyId_step)) { 6149 if (_PyObject_HasAttrId(obj, &PyId_step) && _PyObject_GetAttrId(obj, &PyId_step) != Py_None) {
6147 int res; 6150 int res;
6148 tmp = _PyObject_GetAttrId(obj, &PyId_step); 6151 tmp = _PyObject_GetAttrId(obj, &PyId_step);
6149 if (tmp == NULL) goto failed; 6152 if (tmp == NULL) goto failed;
6150 res = obj2ast_expr(tmp, &step, arena); 6153 res = obj2ast_expr(tmp, &step, arena);
6151 if (res != 0) goto failed; 6154 if (res != 0) goto failed;
6596 if (isinstance) { 6599 if (isinstance) {
6597 expr_ty type; 6600 expr_ty type;
6598 identifier name; 6601 identifier name;
6599 asdl_seq* body; 6602 asdl_seq* body;
6600 6603
6601 if (_PyObject_HasAttrId(obj, &PyId_type)) { 6604 if (_PyObject_HasAttrId(obj, &PyId_type) && _PyObject_GetAttrId(obj, &PyId_type) != Py_None) {
6602 int res; 6605 int res;
6603 tmp = _PyObject_GetAttrId(obj, &PyId_type); 6606 tmp = _PyObject_GetAttrId(obj, &PyId_type);
6604 if (tmp == NULL) goto failed; 6607 if (tmp == NULL) goto failed;
6605 res = obj2ast_expr(tmp, &type, arena); 6608 res = obj2ast_expr(tmp, &type, arena);
6606 if (res != 0) goto failed; 6609 if (res != 0) goto failed;
6607 Py_XDECREF(tmp); 6610 Py_XDECREF(tmp);
6608 tmp = NULL; 6611 tmp = NULL;
6609 } else { 6612 } else {
6610 type = NULL; 6613 type = NULL;
6611 } 6614 }
6612 if (_PyObject_HasAttrId(obj, &PyId_name)) { 6615 if (_PyObject_HasAttrId(obj, &PyId_name) && _PyObject_GetAttrId(obj, &PyId_name) != Py_None) {
6613 int res; 6616 int res;
6614 tmp = _PyObject_GetAttrId(obj, &PyId_name); 6617 tmp = _PyObject_GetAttrId(obj, &PyId_name);
6615 if (tmp == NULL) goto failed; 6618 if (tmp == NULL) goto failed;
6616 res = obj2ast_identifier(tmp, &name, arena); 6619 res = obj2ast_identifier(tmp, &name, arena);
6617 if (res != 0) goto failed; 6620 if (res != 0) goto failed;
6660 int 6663 int
6661 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) 6664 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
6662 { 6665 {
6663 PyObject* tmp = NULL; 6666 PyObject* tmp = NULL;
6664 asdl_seq* args; 6667 asdl_seq* args;
6665 identifier vararg; 6668 arg_ty vararg;
6666 expr_ty varargannotation;
6667 asdl_seq* kwonlyargs; 6669 asdl_seq* kwonlyargs;
6668 identifier kwarg; 6670 asdl_seq* kw_defaults;
6669 expr_ty kwargannotation; 6671 arg_ty kwarg;
6670 asdl_seq* defaults; 6672 asdl_seq* defaults;
6671 asdl_seq* kw_defaults;
6672 6673
6673 if (_PyObject_HasAttrId(obj, &PyId_args)) { 6674 if (_PyObject_HasAttrId(obj, &PyId_args)) {
6674 int res; 6675 int res;
6675 Py_ssize_t len; 6676 Py_ssize_t len;
6676 Py_ssize_t i; 6677 Py_ssize_t i;
6693 tmp = NULL; 6694 tmp = NULL;
6694 } else { 6695 } else {
6695 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); 6696 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
6696 return 1; 6697 return 1;
6697 } 6698 }
6698 if (_PyObject_HasAttrId(obj, &PyId_vararg)) { 6699 if (_PyObject_HasAttrId(obj, &PyId_vararg) && _PyObject_GetAttrId(obj, &PyId_vararg) != Py_None) {
6699 int res; 6700 int res;
6700 tmp = _PyObject_GetAttrId(obj, &PyId_vararg); 6701 tmp = _PyObject_GetAttrId(obj, &PyId_vararg);
6701 if (tmp == NULL) goto failed; 6702 if (tmp == NULL) goto failed;
6702 res = obj2ast_identifier(tmp, &vararg, arena); 6703 res = obj2ast_arg(tmp, &vararg, arena);
6703 if (res != 0) goto failed; 6704 if (res != 0) goto failed;
6704 Py_XDECREF(tmp); 6705 Py_XDECREF(tmp);
6705 tmp = NULL; 6706 tmp = NULL;
6706 } else { 6707 } else {
6707 vararg = NULL; 6708 vararg = NULL;
6708 }
6709 if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) {
6710 int res;
6711 tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation);
6712 if (tmp == NULL) goto failed;
6713 res = obj2ast_expr(tmp, &varargannotation, arena);
6714 if (res != 0) goto failed;
6715 Py_XDECREF(tmp);
6716 tmp = NULL;
6717 } else {
6718 varargannotation = NULL;
6719 } 6709 }
6720 if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { 6710 if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) {
6721 int res; 6711 int res;
6722 Py_ssize_t len; 6712 Py_ssize_t len;
6723 Py_ssize_t i; 6713 Py_ssize_t i;
6740 tmp = NULL; 6730 tmp = NULL;
6741 } else { 6731 } else {
6742 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); 6732 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
6743 return 1; 6733 return 1;
6744 } 6734 }
6745 if (_PyObject_HasAttrId(obj, &PyId_kwarg)) { 6735 if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) {
6736 int res;
6737 Py_ssize_t len;
6738 Py_ssize_t i;
6739 tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults);
6740 if (tmp == NULL) goto failed;
6741 if (!PyList_Check(tmp)) {
6742 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6743 goto failed;
6744 }
6745 len = PyList_GET_SIZE(tmp);
6746 kw_defaults = asdl_seq_new(len, arena);
6747 if (kw_defaults == NULL) goto failed;
6748 for (i = 0; i < len; i++) {
6749 expr_ty value;
6750 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6751 if (res != 0) goto failed;
6752 asdl_seq_SET(kw_defaults, i, value);
6753 }
6754 Py_XDECREF(tmp);
6755 tmp = NULL;
6756 } else {
6757 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
6758 return 1;
6759 }
6760 if (_PyObject_HasAttrId(obj, &PyId_kwarg) && _PyObject_GetAttrId(obj, &PyId_kwarg) != Py_None) {
6746 int res; 6761 int res;
6747 tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); 6762 tmp = _PyObject_GetAttrId(obj, &PyId_kwarg);
6748 if (tmp == NULL) goto failed; 6763 if (tmp == NULL) goto failed;
6749 res = obj2ast_identifier(tmp, &kwarg, arena); 6764 res = obj2ast_arg(tmp, &kwarg, arena);
6750 if (res != 0) goto failed; 6765 if (res != 0) goto failed;
6751 Py_XDECREF(tmp); 6766 Py_XDECREF(tmp);
6752 tmp = NULL; 6767 tmp = NULL;
6753 } else { 6768 } else {
6754 kwarg = NULL; 6769 kwarg = NULL;
6755 }
6756 if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) {
6757 int res;
6758 tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation);
6759 if (tmp == NULL) goto failed;
6760 res = obj2ast_expr(tmp, &kwargannotation, arena);
6761 if (res != 0) goto failed;
6762 Py_XDECREF(tmp);
6763 tmp = NULL;
6764 } else {
6765 kwargannotation = NULL;
6766 } 6770 }
6767 if (_PyObject_HasAttrId(obj, &PyId_defaults)) { 6771 if (_PyObject_HasAttrId(obj, &PyId_defaults)) {
6768 int res; 6772 int res;
6769 Py_ssize_t len; 6773 Py_ssize_t len;
6770 Py_ssize_t i; 6774 Py_ssize_t i;
6787 tmp = NULL; 6791 tmp = NULL;
6788 } else { 6792 } else {
6789 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); 6793 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
6790 return 1; 6794 return 1;
6791 } 6795 }
6792 if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { 6796 *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg,
6793 int res; 6797 defaults, arena);
6794 Py_ssize_t len;
6795 Py_ssize_t i;
6796 tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults);
6797 if (tmp == NULL) goto failed;
6798 if (!PyList_Check(tmp)) {
6799 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
6800 goto failed;
6801 }
6802 len = PyList_GET_SIZE(tmp);
6803 kw_defaults = asdl_seq_new(len, arena);
6804 if (kw_defaults == NULL) goto failed;
6805 for (i = 0; i < len; i++) {
6806 expr_ty value;
6807 res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
6808 if (res != 0) goto failed;
6809 asdl_seq_SET(kw_defaults, i, value);
6810 }
6811 Py_XDECREF(tmp);
6812 tmp = NULL;
6813 } else {
6814 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
6815 return 1;
6816 }
6817 *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg,
6818 kwargannotation, defaults, kw_defaults, arena);
6819 return 0; 6798 return 0;
6820 failed: 6799 failed:
6821 Py_XDECREF(tmp); 6800 Py_XDECREF(tmp);
6822 return 1; 6801 return 1;
6823 } 6802 }
6839 tmp = NULL; 6818 tmp = NULL;
6840 } else { 6819 } else {
6841 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); 6820 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
6842 return 1; 6821 return 1;
6843 } 6822 }
6844 if (_PyObject_HasAttrId(obj, &PyId_annotation)) { 6823 if (_PyObject_HasAttrId(obj, &PyId_annotation) && _PyObject_GetAttrId(obj, &PyId_annotation) != Py_None) {
6845 int res; 6824 int res;
6846 tmp = _PyObject_GetAttrId(obj, &PyId_annotation); 6825 tmp = _PyObject_GetAttrId(obj, &PyId_annotation);
6847 if (tmp == NULL) goto failed; 6826 if (tmp == NULL) goto failed;
6848 res = obj2ast_expr(tmp, &annotation, arena); 6827 res = obj2ast_expr(tmp, &annotation, arena);
6849 if (res != 0) goto failed; 6828 if (res != 0) goto failed;
6914 tmp = NULL; 6893 tmp = NULL;
6915 } else { 6894 } else {
6916 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); 6895 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
6917 return 1; 6896 return 1;
6918 } 6897 }
6919 if (_PyObject_HasAttrId(obj, &PyId_asname)) { 6898 if (_PyObject_HasAttrId(obj, &PyId_asname) && _PyObject_GetAttrId(obj, &PyId_asname) != Py_None) {
6920 int res; 6899 int res;
6921 tmp = _PyObject_GetAttrId(obj, &PyId_asname); 6900 tmp = _PyObject_GetAttrId(obj, &PyId_asname);
6922 if (tmp == NULL) goto failed; 6901 if (tmp == NULL) goto failed;
6923 res = obj2ast_identifier(tmp, &asname, arena); 6902 res = obj2ast_identifier(tmp, &asname, arena);
6924 if (res != 0) goto failed; 6903 if (res != 0) goto failed;
6951 tmp = NULL; 6930 tmp = NULL;
6952 } else { 6931 } else {
6953 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); 6932 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
6954 return 1; 6933 return 1;
6955 } 6934 }
6956 if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) { 6935 if (_PyObject_HasAttrId(obj, &PyId_optional_vars) && _PyObject_GetAttrId(obj, &PyId_optional_vars) != Py_None) {
6957 int res; 6936 int res;
6958 tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); 6937 tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars);
6959 if (tmp == NULL) goto failed; 6938 if (tmp == NULL) goto failed;
6960 res = obj2ast_expr(tmp, &optional_vars, arena); 6939 res = obj2ast_expr(tmp, &optional_vars, arena);
6961 if (res != 0) goto failed; 6940 if (res != 0) goto failed;