/* Conversion Python -> AST */
-static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
+static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj,
+ PyObject** out,
+ const char* Py_UNUSED(field), PyArena* arena)
{
if (obj == Py_None)
obj = NULL;
return 0;
}
-static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
+static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj,
+ PyObject** out,
+ const char* Py_UNUSED(field), PyArena* arena)
{
if (_PyArena_AddPyObject(arena, obj) < 0) {
*out = NULL;
return 0;
}
-static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
+static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
{
if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
- PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string object", field);
return -1;
}
- return obj2ast_object(state, obj, out, arena);
+ return obj2ast_object(state, obj, out, field, arena);
}
-static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
+static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, const char* field, PyArena* arena)
{
if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
- PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting a string or bytes object", field);
return -1;
}
- return obj2ast_object(state, obj, out, arena);
+ return obj2ast_object(state, obj, out, field, arena);
}
-static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
+static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, const char* field, PyArena* arena)
{
int i;
if (!PyLong_Check(obj)) {
- PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
+ PyErr_Format(PyExc_ValueError, "field \"%s\" got an invalid integer value: %R", field, obj);
return -1;
}
}
static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
- PyArena* arena);
+ const char* field, PyArena* arena);
static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
- PyArena* arena);
+ const char* field, PyArena* arena);
static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
- PyArena* arena);
+ const char* field, PyArena* arena);
static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
- expr_context_ty* out, PyArena* arena);
+ expr_context_ty* out, const char* field,
+ PyArena* arena);
static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
- out, PyArena* arena);
+ out, const char* field, PyArena* arena);
static int obj2ast_operator(struct ast_state *state, PyObject* obj,
- operator_ty* out, PyArena* arena);
+ operator_ty* out, const char* field, PyArena*
+ arena);
static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
- out, PyArena* arena);
+ out, const char* field, PyArena* arena);
static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
- PyArena* arena);
+ const char* field, PyArena* arena);
static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
- comprehension_ty* out, PyArena* arena);
+ comprehension_ty* out, const char* field,
+ PyArena* arena);
static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
- excepthandler_ty* out, PyArena* arena);
+ excepthandler_ty* out, const char* field,
+ PyArena* arena);
static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
- arguments_ty* out, PyArena* arena);
+ arguments_ty* out, const char* field, PyArena*
+ arena);
static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
- PyArena* arena);
+ const char* field, PyArena* arena);
static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
- out, PyArena* arena);
+ out, const char* field, PyArena* arena);
static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
- PyArena* arena);
+ const char* field, PyArena* arena);
static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
- withitem_ty* out, PyArena* arena);
+ withitem_ty* out, const char* field, PyArena*
+ arena);
static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
- match_case_ty* out, PyArena* arena);
+ match_case_ty* out, const char* field, PyArena*
+ arena);
static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
- out, PyArena* arena);
+ out, const char* field, PyArena* arena);
static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
- type_ignore_ty* out, PyArena* arena);
+ type_ignore_ty* out, const char* field, PyArena*
+ arena);
static int obj2ast_type_param(struct ast_state *state, PyObject* obj,
- type_param_ty* out, PyArena* arena);
+ type_param_ty* out, const char* field, PyArena*
+ arena);
mod_ty
_PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
int
-obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
+obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, const char*
+ field, PyArena* arena)
{
int isinstance;
*out = NULL;
return 0;
}
+ tp = state->mod_type;
+ isinstance = PyObject_IsInstance(obj, tp);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (!isinstance && field != NULL) {
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'mod', got '%s'", field, _PyType_Name(Py_TYPE(obj)));
+ return 1;
+ }
tp = state->Module_type;
isinstance = PyObject_IsInstance(obj, tp);
if (isinstance == -1) {
if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
goto failed;
}
- res = obj2ast_type_ignore(state, tmp2, &val, arena);
+ res = obj2ast_type_ignore(state, tmp2, &val, "type_ignores", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &body, arena);
+ res = obj2ast_expr(state, tmp, &body, "body", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "argtypes", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &returns, arena);
+ res = obj2ast_expr(state, tmp, &returns, "returns", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
}
int
-obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
- arena)
+obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, const char*
+ field, PyArena* arena)
{
int isinstance;
*out = NULL;
return 0;
}
+ tp = state->stmt_type;
+ isinstance = PyObject_IsInstance(obj, tp);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (!isinstance && field != NULL) {
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'stmt', got '%s'", field, _PyType_Name(Py_TYPE(obj)));
+ return 1;
+ }
if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
return -1;
}
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
goto failed;
}
- res = obj2ast_arguments(state, tmp, &args, arena);
+ res = obj2ast_arguments(state, tmp, &args, "args", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &returns, arena);
+ res = obj2ast_expr(state, tmp, &returns, "returns", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
goto failed;
}
- res = obj2ast_type_param(state, tmp2, &val, arena);
+ res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
goto failed;
}
- res = obj2ast_arguments(state, tmp, &args, arena);
+ res = obj2ast_arguments(state, tmp, &args, "args", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &returns, arena);
+ res = obj2ast_expr(state, tmp, &returns, "returns", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
goto failed;
}
- res = obj2ast_type_param(state, tmp2, &val, arena);
+ res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "bases", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
goto failed;
}
- res = obj2ast_keyword(state, tmp2, &val, arena);
+ res = obj2ast_keyword(state, tmp2, &val, "keywords", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "decorator_list", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
goto failed;
}
- res = obj2ast_type_param(state, tmp2, &val, arena);
+ res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "targets", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "targets", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &name, arena);
+ res = obj2ast_expr(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
goto failed;
}
- res = obj2ast_type_param(state, tmp2, &val, arena);
+ res = obj2ast_type_param(state, tmp2, &val, "type_params", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &target, arena);
+ res = obj2ast_expr(state, tmp, &target, "target", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
goto failed;
}
- res = obj2ast_operator(state, tmp, &op, arena);
+ res = obj2ast_operator(state, tmp, &op, "op", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &target, arena);
+ res = obj2ast_expr(state, tmp, &target, "target", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &annotation, arena);
+ res = obj2ast_expr(state, tmp, &annotation, "annotation", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &simple, arena);
+ res = obj2ast_int(state, tmp, &simple, "simple", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &target, arena);
+ res = obj2ast_expr(state, tmp, &target, "target", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &iter, arena);
+ res = obj2ast_expr(state, tmp, &iter, "iter", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &target, arena);
+ res = obj2ast_expr(state, tmp, &target, "target", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &iter, arena);
+ res = obj2ast_expr(state, tmp, &iter, "iter", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &test, arena);
+ res = obj2ast_expr(state, tmp, &test, "test", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &test, arena);
+ res = obj2ast_expr(state, tmp, &test, "test", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
goto failed;
}
- res = obj2ast_withitem(state, tmp2, &val, arena);
+ res = obj2ast_withitem(state, tmp2, &val, "items", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
goto failed;
}
- res = obj2ast_withitem(state, tmp2, &val, arena);
+ res = obj2ast_withitem(state, tmp2, &val, "items", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &subject, arena);
+ res = obj2ast_expr(state, tmp, &subject, "subject", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
goto failed;
}
- res = obj2ast_match_case(state, tmp2, &val, arena);
+ res = obj2ast_match_case(state, tmp2, &val, "cases", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &exc, arena);
+ res = obj2ast_expr(state, tmp, &exc, "exc", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &cause, arena);
+ res = obj2ast_expr(state, tmp, &cause, "cause", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
goto failed;
}
- res = obj2ast_excepthandler(state, tmp2, &val, arena);
+ res = obj2ast_excepthandler(state, tmp2, &val, "handlers", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "finalbody", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
goto failed;
}
- res = obj2ast_excepthandler(state, tmp2, &val, arena);
+ res = obj2ast_excepthandler(state, tmp2, &val, "handlers", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "orelse", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "finalbody", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &test, arena);
+ res = obj2ast_expr(state, tmp, &test, "test", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &msg, arena);
+ res = obj2ast_expr(state, tmp, &msg, "msg", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
goto failed;
}
- res = obj2ast_alias(state, tmp2, &val, arena);
+ res = obj2ast_alias(state, tmp2, &val, "names", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &is_lazy, arena);
+ res = obj2ast_int(state, tmp, &is_lazy, "is_lazy", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &module, arena);
+ res = obj2ast_identifier(state, tmp, &module, "module", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
goto failed;
}
- res = obj2ast_alias(state, tmp2, &val, arena);
+ res = obj2ast_alias(state, tmp2, &val, "names", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &level, arena);
+ res = obj2ast_int(state, tmp, &level, "level", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &is_lazy, arena);
+ res = obj2ast_int(state, tmp, &is_lazy, "is_lazy", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp2, &val, arena);
+ res = obj2ast_identifier(state, tmp2, &val, "names", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp2, &val, arena);
+ res = obj2ast_identifier(state, tmp2, &val, "names", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
}
int
-obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
- arena)
+obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, const char*
+ field, PyArena* arena)
{
int isinstance;
*out = NULL;
return 0;
}
+ tp = state->expr_type;
+ isinstance = PyObject_IsInstance(obj, tp);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (!isinstance && field != NULL) {
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'expr', got '%s'", field, _PyType_Name(Py_TYPE(obj)));
+ return 1;
+ }
if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
return -1;
}
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
goto failed;
}
- res = obj2ast_boolop(state, tmp, &op, arena);
+ res = obj2ast_boolop(state, tmp, &op, "op", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "values", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &target, arena);
+ res = obj2ast_expr(state, tmp, &target, "target", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &left, arena);
+ res = obj2ast_expr(state, tmp, &left, "left", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
goto failed;
}
- res = obj2ast_operator(state, tmp, &op, arena);
+ res = obj2ast_operator(state, tmp, &op, "op", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &right, arena);
+ res = obj2ast_expr(state, tmp, &right, "right", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
goto failed;
}
- res = obj2ast_unaryop(state, tmp, &op, arena);
+ res = obj2ast_unaryop(state, tmp, &op, "op", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &operand, arena);
+ res = obj2ast_expr(state, tmp, &operand, "operand", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
goto failed;
}
- res = obj2ast_arguments(state, tmp, &args, arena);
+ res = obj2ast_arguments(state, tmp, &args, "args", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &body, arena);
+ res = obj2ast_expr(state, tmp, &body, "body", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &test, arena);
+ res = obj2ast_expr(state, tmp, &test, "test", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &body, arena);
+ res = obj2ast_expr(state, tmp, &body, "body", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &orelse, arena);
+ res = obj2ast_expr(state, tmp, &orelse, "orelse", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "keys", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "values", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "elts", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &elt, arena);
+ res = obj2ast_expr(state, tmp, &elt, "elt", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
goto failed;
}
- res = obj2ast_comprehension(state, tmp2, &val, arena);
+ res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &elt, arena);
+ res = obj2ast_expr(state, tmp, &elt, "elt", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
goto failed;
}
- res = obj2ast_comprehension(state, tmp2, &val, arena);
+ res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &key, arena);
+ res = obj2ast_expr(state, tmp, &key, "key", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
goto failed;
}
- res = obj2ast_comprehension(state, tmp2, &val, arena);
+ res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &elt, arena);
+ res = obj2ast_expr(state, tmp, &elt, "elt", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
goto failed;
}
- res = obj2ast_comprehension(state, tmp2, &val, arena);
+ res = obj2ast_comprehension(state, tmp2, &val, "generators", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &left, arena);
+ res = obj2ast_expr(state, tmp, &left, "left", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
goto failed;
}
- res = obj2ast_cmpop(state, tmp2, &val, arena);
+ res = obj2ast_cmpop(state, tmp2, &val, "ops", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "comparators", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &func, arena);
+ res = obj2ast_expr(state, tmp, &func, "func", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "args", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
goto failed;
}
- res = obj2ast_keyword(state, tmp2, &val, arena);
+ res = obj2ast_keyword(state, tmp2, &val, "keywords", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &conversion, arena);
+ res = obj2ast_int(state, tmp, &conversion, "conversion", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &format_spec, arena);
+ res = obj2ast_expr(state, tmp, &format_spec, "format_spec", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
goto failed;
}
- res = obj2ast_constant(state, tmp, &str, arena);
+ res = obj2ast_constant(state, tmp, &str, "str", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &conversion, arena);
+ res = obj2ast_int(state, tmp, &conversion, "conversion", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Interpolation' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &format_spec, arena);
+ res = obj2ast_expr(state, tmp, &format_spec, "format_spec", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "values", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'TemplateStr' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "values", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
goto failed;
}
- res = obj2ast_constant(state, tmp, &value, arena);
+ res = obj2ast_constant(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &kind, arena);
+ res = obj2ast_string(state, tmp, &kind, "kind", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &attr, arena);
+ res = obj2ast_identifier(state, tmp, &attr, "attr", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
goto failed;
}
- res = obj2ast_expr_context(state, tmp, &ctx, arena);
+ res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &slice, arena);
+ res = obj2ast_expr(state, tmp, &slice, "slice", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
goto failed;
}
- res = obj2ast_expr_context(state, tmp, &ctx, arena);
+ res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
goto failed;
}
- res = obj2ast_expr_context(state, tmp, &ctx, arena);
+ res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &id, arena);
+ res = obj2ast_identifier(state, tmp, &id, "id", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
goto failed;
}
- res = obj2ast_expr_context(state, tmp, &ctx, arena);
+ res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "elts", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
goto failed;
}
- res = obj2ast_expr_context(state, tmp, &ctx, arena);
+ res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "elts", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
goto failed;
}
- res = obj2ast_expr_context(state, tmp, &ctx, arena);
+ res = obj2ast_expr_context(state, tmp, &ctx, "ctx", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &lower, arena);
+ res = obj2ast_expr(state, tmp, &lower, "lower", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &upper, arena);
+ res = obj2ast_expr(state, tmp, &upper, "upper", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &step, arena);
+ res = obj2ast_expr(state, tmp, &step, "step", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
int
obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
- out, PyArena* arena)
+ out, const char* field, PyArena* arena)
{
int isinstance;
}
int
-obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
- arena)
+obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, const
+ char* field, PyArena* arena)
{
int isinstance;
int
obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
- PyArena* arena)
+ const char* field, PyArena* arena)
{
int isinstance;
}
int
-obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
- PyArena* arena)
+obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out, const
+ char* field, PyArena* arena)
{
int isinstance;
}
int
-obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
- arena)
+obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, const
+ char* field, PyArena* arena)
{
int isinstance;
int
obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
- out, PyArena* arena)
+ out, const char* field, PyArena* arena)
{
PyObject* tmp = NULL;
expr_ty target;
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &target, arena);
+ res = obj2ast_expr(state, tmp, &target, "target", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &iter, arena);
+ res = obj2ast_expr(state, tmp, &iter, "iter", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "ifs", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &is_async, arena);
+ res = obj2ast_int(state, tmp, &is_async, "is_async", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
int
obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
- out, PyArena* arena)
+ out, const char* field, PyArena* arena)
{
int isinstance;
*out = NULL;
return 0;
}
+ tp = state->excepthandler_type;
+ isinstance = PyObject_IsInstance(obj, tp);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (!isinstance && field != NULL) {
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'excepthandler', got '%s'", field, _PyType_Name(Py_TYPE(obj)));
+ return 1;
+ }
if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
return -1;
}
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &type, arena);
+ res = obj2ast_expr(state, tmp, &type, "type", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
int
obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
- PyArena* arena)
+ const char* field, PyArena* arena)
{
PyObject* tmp = NULL;
asdl_arg_seq* posonlyargs;
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
goto failed;
}
- res = obj2ast_arg(state, tmp2, &val, arena);
+ res = obj2ast_arg(state, tmp2, &val, "posonlyargs", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
goto failed;
}
- res = obj2ast_arg(state, tmp2, &val, arena);
+ res = obj2ast_arg(state, tmp2, &val, "args", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
goto failed;
}
- res = obj2ast_arg(state, tmp, &vararg, arena);
+ res = obj2ast_arg(state, tmp, &vararg, "vararg", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
goto failed;
}
- res = obj2ast_arg(state, tmp2, &val, arena);
+ res = obj2ast_arg(state, tmp2, &val, "kwonlyargs", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "kw_defaults", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
goto failed;
}
- res = obj2ast_arg(state, tmp, &kwarg, arena);
+ res = obj2ast_arg(state, tmp, &kwarg, "kwarg", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "defaults", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
}
int
-obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
+obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, const char*
+ field, PyArena* arena)
{
PyObject* tmp = NULL;
identifier arg;
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &arg, arena);
+ res = obj2ast_identifier(state, tmp, &arg, "arg", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &annotation, arena);
+ res = obj2ast_expr(state, tmp, &annotation, "annotation", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &type_comment, arena);
+ res = obj2ast_string(state, tmp, &type_comment, "type_comment", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
}
int
-obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
- PyArena* arena)
+obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out, const
+ char* field, PyArena* arena)
{
PyObject* tmp = NULL;
identifier arg;
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &arg, arena);
+ res = obj2ast_identifier(state, tmp, &arg, "arg", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
}
int
-obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
- arena)
+obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, const
+ char* field, PyArena* arena)
{
PyObject* tmp = NULL;
identifier name;
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &asname, arena);
+ res = obj2ast_identifier(state, tmp, &asname, "asname", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
int
obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
- PyArena* arena)
+ const char* field, PyArena* arena)
{
PyObject* tmp = NULL;
expr_ty context_expr;
if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &context_expr, arena);
+ res = obj2ast_expr(state, tmp, &context_expr, "context_expr", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &optional_vars, arena);
+ res = obj2ast_expr(state, tmp, &optional_vars, "optional_vars", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
int
obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
- PyArena* arena)
+ const char* field, PyArena* arena)
{
PyObject* tmp = NULL;
pattern_ty pattern;
if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
goto failed;
}
- res = obj2ast_pattern(state, tmp, &pattern, arena);
+ res = obj2ast_pattern(state, tmp, &pattern, "pattern", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &guard, arena);
+ res = obj2ast_expr(state, tmp, &guard, "guard", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
goto failed;
}
- res = obj2ast_stmt(state, tmp2, &val, arena);
+ res = obj2ast_stmt(state, tmp2, &val, "body", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
}
int
-obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
- PyArena* arena)
+obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out, const
+ char* field, PyArena* arena)
{
int isinstance;
*out = NULL;
return 0;
}
+ tp = state->pattern_type;
+ isinstance = PyObject_IsInstance(obj, tp);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (!isinstance && field != NULL) {
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'pattern', got '%s'", field, _PyType_Name(Py_TYPE(obj)));
+ return 1;
+ }
if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
return -1;
}
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &value, arena);
+ res = obj2ast_expr(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
goto failed;
}
- res = obj2ast_constant(state, tmp, &value, arena);
+ res = obj2ast_constant(state, tmp, &value, "value", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
goto failed;
}
- res = obj2ast_pattern(state, tmp2, &val, arena);
+ res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp2, &val, arena);
+ res = obj2ast_expr(state, tmp2, &val, "keys", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
goto failed;
}
- res = obj2ast_pattern(state, tmp2, &val, arena);
+ res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &rest, arena);
+ res = obj2ast_identifier(state, tmp, &rest, "rest", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &cls, arena);
+ res = obj2ast_expr(state, tmp, &cls, "cls", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
goto failed;
}
- res = obj2ast_pattern(state, tmp2, &val, arena);
+ res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp2, &val, arena);
+ res = obj2ast_identifier(state, tmp2, &val, "kwd_attrs", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
goto failed;
}
- res = obj2ast_pattern(state, tmp2, &val, arena);
+ res = obj2ast_pattern(state, tmp2, &val, "kwd_patterns", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
goto failed;
}
- res = obj2ast_pattern(state, tmp, &pattern, arena);
+ res = obj2ast_pattern(state, tmp, &pattern, "pattern", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
goto failed;
}
- res = obj2ast_pattern(state, tmp2, &val, arena);
+ res = obj2ast_pattern(state, tmp2, &val, "patterns", arena);
_Py_LeaveRecursiveCall();
Py_DECREF(tmp2);
if (res != 0) goto failed;
int
obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
- out, PyArena* arena)
+ out, const char* field, PyArena* arena)
{
int isinstance;
*out = NULL;
return 0;
}
+ tp = state->type_ignore_type;
+ isinstance = PyObject_IsInstance(obj, tp);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (!isinstance && field != NULL) {
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'type_ignore', got '%s'", field, _PyType_Name(Py_TYPE(obj)));
+ return 1;
+ }
tp = state->TypeIgnore_type;
isinstance = PyObject_IsInstance(obj, tp);
if (isinstance == -1) {
if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
goto failed;
}
- res = obj2ast_string(state, tmp, &tag, arena);
+ res = obj2ast_string(state, tmp, &tag, "tag", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
int
obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out,
- PyArena* arena)
+ const char* field, PyArena* arena)
{
int isinstance;
*out = NULL;
return 0;
}
+ tp = state->type_param_type;
+ isinstance = PyObject_IsInstance(obj, tp);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (!isinstance && field != NULL) {
+ PyErr_Format(PyExc_TypeError, "field '%s' was expecting node of type 'type_param', got '%s'", field, _PyType_Name(Py_TYPE(obj)));
+ return 1;
+ }
if (PyObject_GetOptionalAttr(obj, state->lineno, &tmp) < 0) {
return -1;
}
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &lineno, arena);
+ res = obj2ast_int(state, tmp, &lineno, "lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &col_offset, arena);
+ res = obj2ast_int(state, tmp, &col_offset, "col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_lineno, arena);
+ res = obj2ast_int(state, tmp, &end_lineno, "end_lineno", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
goto failed;
}
- res = obj2ast_int(state, tmp, &end_col_offset, arena);
+ res = obj2ast_int(state, tmp, &end_col_offset, "end_col_offset", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &bound, arena);
+ res = obj2ast_expr(state, tmp, &bound, "bound", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &default_value, arena);
+ res = obj2ast_expr(state, tmp, &default_value, "default_value",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &default_value, arena);
+ res = obj2ast_expr(state, tmp, &default_value, "default_value",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
goto failed;
}
- res = obj2ast_identifier(state, tmp, &name, arena);
+ res = obj2ast_identifier(state, tmp, &name, "name", arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
goto failed;
}
- res = obj2ast_expr(state, tmp, &default_value, arena);
+ res = obj2ast_expr(state, tmp, &default_value, "default_value",
+ arena);
_Py_LeaveRecursiveCall();
if (res != 0) goto failed;
Py_CLEAR(tmp);
}
mod_ty res = NULL;
- if (obj2ast_mod(state, ast, &res, arena) != 0)
+ if (obj2ast_mod(state, ast, &res, NULL, arena) != 0)
return NULL;
else
return res;