summaryrefslogtreecommitdiff
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r--Python/Python-ast.c2433
1 files changed, 1029 insertions, 1404 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index e6f1e58252..6cf99ec5ad 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -1,6 +1,13 @@
/* File automatically generated by Parser/asdl_c.py. */
-#include <stddef.h>
+
+/*
+ __version__ 82160.
+
+ This module must be committed separately after each AST grammar change;
+ The __version__ number is set to the revision number of the commit
+ containing the grammar change.
+*/
#include "Python.h"
#include "Python-ast.h"
@@ -9,7 +16,6 @@ static PyTypeObject AST_type;
static PyTypeObject *mod_type;
static PyObject* ast2obj_mod(void*);
static PyTypeObject *Module_type;
-_Py_IDENTIFIER(body);
static char *Module_fields[]={
"body",
};
@@ -26,46 +32,30 @@ static char *Suite_fields[]={
"body",
};
static PyTypeObject *stmt_type;
-_Py_IDENTIFIER(lineno);
-_Py_IDENTIFIER(col_offset);
static char *stmt_attributes[] = {
"lineno",
"col_offset",
};
static PyObject* ast2obj_stmt(void*);
static PyTypeObject *FunctionDef_type;
-_Py_IDENTIFIER(name);
-_Py_IDENTIFIER(args);
-_Py_IDENTIFIER(decorator_list);
-_Py_IDENTIFIER(returns);
static char *FunctionDef_fields[]={
"name",
"args",
"body",
"decorator_list",
- "returns",
};
static PyTypeObject *ClassDef_type;
-_Py_IDENTIFIER(bases);
-_Py_IDENTIFIER(keywords);
-_Py_IDENTIFIER(starargs);
-_Py_IDENTIFIER(kwargs);
static char *ClassDef_fields[]={
"name",
"bases",
- "keywords",
- "starargs",
- "kwargs",
"body",
"decorator_list",
};
static PyTypeObject *Return_type;
-_Py_IDENTIFIER(value);
static char *Return_fields[]={
"value",
};
static PyTypeObject *Delete_type;
-_Py_IDENTIFIER(targets);
static char *Delete_fields[]={
"targets",
};
@@ -75,16 +65,18 @@ static char *Assign_fields[]={
"value",
};
static PyTypeObject *AugAssign_type;
-_Py_IDENTIFIER(target);
-_Py_IDENTIFIER(op);
static char *AugAssign_fields[]={
"target",
"op",
"value",
};
+static PyTypeObject *Print_type;
+static char *Print_fields[]={
+ "dest",
+ "values",
+ "nl",
+};
static PyTypeObject *For_type;
-_Py_IDENTIFIER(iter);
-_Py_IDENTIFIER(orelse);
static char *For_fields[]={
"target",
"iter",
@@ -92,7 +84,6 @@ static char *For_fields[]={
"orelse",
};
static PyTypeObject *While_type;
-_Py_IDENTIFIER(test);
static char *While_fields[]={
"test",
"body",
@@ -105,54 +96,53 @@ static char *If_fields[]={
"orelse",
};
static PyTypeObject *With_type;
-_Py_IDENTIFIER(items);
static char *With_fields[]={
- "items",
+ "context_expr",
+ "optional_vars",
"body",
};
static PyTypeObject *Raise_type;
-_Py_IDENTIFIER(exc);
-_Py_IDENTIFIER(cause);
static char *Raise_fields[]={
- "exc",
- "cause",
+ "type",
+ "inst",
+ "tback",
};
-static PyTypeObject *Try_type;
-_Py_IDENTIFIER(handlers);
-_Py_IDENTIFIER(finalbody);
-static char *Try_fields[]={
+static PyTypeObject *TryExcept_type;
+static char *TryExcept_fields[]={
"body",
"handlers",
"orelse",
+};
+static PyTypeObject *TryFinally_type;
+static char *TryFinally_fields[]={
+ "body",
"finalbody",
};
static PyTypeObject *Assert_type;
-_Py_IDENTIFIER(msg);
static char *Assert_fields[]={
"test",
"msg",
};
static PyTypeObject *Import_type;
-_Py_IDENTIFIER(names);
static char *Import_fields[]={
"names",
};
static PyTypeObject *ImportFrom_type;
-_Py_IDENTIFIER(module);
-_Py_IDENTIFIER(level);
static char *ImportFrom_fields[]={
"module",
"names",
"level",
};
+static PyTypeObject *Exec_type;
+static char *Exec_fields[]={
+ "body",
+ "globals",
+ "locals",
+};
static PyTypeObject *Global_type;
static char *Global_fields[]={
"names",
};
-static PyTypeObject *Nonlocal_type;
-static char *Nonlocal_fields[]={
- "names",
-};
static PyTypeObject *Expr_type;
static char *Expr_fields[]={
"value",
@@ -167,21 +157,17 @@ static char *expr_attributes[] = {
};
static PyObject* ast2obj_expr(void*);
static PyTypeObject *BoolOp_type;
-_Py_IDENTIFIER(values);
static char *BoolOp_fields[]={
"op",
"values",
};
static PyTypeObject *BinOp_type;
-_Py_IDENTIFIER(left);
-_Py_IDENTIFIER(right);
static char *BinOp_fields[]={
"left",
"op",
"right",
};
static PyTypeObject *UnaryOp_type;
-_Py_IDENTIFIER(operand);
static char *UnaryOp_fields[]={
"op",
"operand",
@@ -198,19 +184,15 @@ static char *IfExp_fields[]={
"orelse",
};
static PyTypeObject *Dict_type;
-_Py_IDENTIFIER(keys);
static char *Dict_fields[]={
"keys",
"values",
};
static PyTypeObject *Set_type;
-_Py_IDENTIFIER(elts);
static char *Set_fields[]={
"elts",
};
static PyTypeObject *ListComp_type;
-_Py_IDENTIFIER(elt);
-_Py_IDENTIFIER(generators);
static char *ListComp_fields[]={
"elt",
"generators",
@@ -221,7 +203,6 @@ static char *SetComp_fields[]={
"generators",
};
static PyTypeObject *DictComp_type;
-_Py_IDENTIFIER(key);
static char *DictComp_fields[]={
"key",
"value",
@@ -236,20 +217,13 @@ static PyTypeObject *Yield_type;
static char *Yield_fields[]={
"value",
};
-static PyTypeObject *YieldFrom_type;
-static char *YieldFrom_fields[]={
- "value",
-};
static PyTypeObject *Compare_type;
-_Py_IDENTIFIER(ops);
-_Py_IDENTIFIER(comparators);
static char *Compare_fields[]={
"left",
"ops",
"comparators",
};
static PyTypeObject *Call_type;
-_Py_IDENTIFIER(func);
static char *Call_fields[]={
"func",
"args",
@@ -257,43 +231,31 @@ static char *Call_fields[]={
"starargs",
"kwargs",
};
+static PyTypeObject *Repr_type;
+static char *Repr_fields[]={
+ "value",
+};
static PyTypeObject *Num_type;
-_Py_IDENTIFIER(n);
static char *Num_fields[]={
"n",
};
static PyTypeObject *Str_type;
-_Py_IDENTIFIER(s);
static char *Str_fields[]={
"s",
};
-static PyTypeObject *Bytes_type;
-static char *Bytes_fields[]={
- "s",
-};
-static PyTypeObject *Ellipsis_type;
static PyTypeObject *Attribute_type;
-_Py_IDENTIFIER(attr);
-_Py_IDENTIFIER(ctx);
static char *Attribute_fields[]={
"value",
"attr",
"ctx",
};
static PyTypeObject *Subscript_type;
-_Py_IDENTIFIER(slice);
static char *Subscript_fields[]={
"value",
"slice",
"ctx",
};
-static PyTypeObject *Starred_type;
-static char *Starred_fields[]={
- "value",
- "ctx",
-};
static PyTypeObject *Name_type;
-_Py_IDENTIFIER(id);
static char *Name_fields[]={
"id",
"ctx",
@@ -320,17 +282,14 @@ static PyTypeObject *AugStore_type;
static PyTypeObject *Param_type;
static PyTypeObject *slice_type;
static PyObject* ast2obj_slice(void*);
+static PyTypeObject *Ellipsis_type;
static PyTypeObject *Slice_type;
-_Py_IDENTIFIER(lower);
-_Py_IDENTIFIER(upper);
-_Py_IDENTIFIER(step);
static char *Slice_fields[]={
"lower",
"upper",
"step",
};
static PyTypeObject *ExtSlice_type;
-_Py_IDENTIFIER(dims);
static char *ExtSlice_fields[]={
"dims",
};
@@ -386,7 +345,6 @@ static PyTypeObject *In_type;
static PyTypeObject *NotIn_type;
static PyTypeObject *comprehension_type;
static PyObject* ast2obj_comprehension(void*);
-_Py_IDENTIFIER(ifs);
static char *comprehension_fields[]={
"target",
"iter",
@@ -399,7 +357,6 @@ static char *excepthandler_attributes[] = {
};
static PyObject* ast2obj_excepthandler(void*);
static PyTypeObject *ExceptHandler_type;
-_Py_IDENTIFIER(type);
static char *ExceptHandler_fields[]={
"type",
"name",
@@ -407,30 +364,11 @@ static char *ExceptHandler_fields[]={
};
static PyTypeObject *arguments_type;
static PyObject* ast2obj_arguments(void*);
-_Py_IDENTIFIER(vararg);
-_Py_IDENTIFIER(varargannotation);
-_Py_IDENTIFIER(kwonlyargs);
-_Py_IDENTIFIER(kwarg);
-_Py_IDENTIFIER(kwargannotation);
-_Py_IDENTIFIER(defaults);
-_Py_IDENTIFIER(kw_defaults);
static char *arguments_fields[]={
"args",
"vararg",
- "varargannotation",
- "kwonlyargs",
"kwarg",
- "kwargannotation",
"defaults",
- "kw_defaults",
-};
-static PyTypeObject *arg_type;
-static PyObject* ast2obj_arg(void*);
-_Py_IDENTIFIER(arg);
-_Py_IDENTIFIER(annotation);
-static char *arg_fields[]={
- "arg",
- "annotation",
};
static PyTypeObject *keyword_type;
static PyObject* ast2obj_keyword(void*);
@@ -440,54 +378,19 @@ static char *keyword_fields[]={
};
static PyTypeObject *alias_type;
static PyObject* ast2obj_alias(void*);
-_Py_IDENTIFIER(asname);
static char *alias_fields[]={
"name",
"asname",
};
-static PyTypeObject *withitem_type;
-static PyObject* ast2obj_withitem(void*);
-_Py_IDENTIFIER(context_expr);
-_Py_IDENTIFIER(optional_vars);
-static char *withitem_fields[]={
- "context_expr",
- "optional_vars",
-};
-typedef struct {
- PyObject_HEAD
- PyObject *dict;
-} AST_object;
-
-static void
-ast_dealloc(AST_object *self)
-{
- Py_CLEAR(self->dict);
- Py_TYPE(self)->tp_free(self);
-}
-
-static int
-ast_traverse(AST_object *self, visitproc visit, void *arg)
-{
- Py_VISIT(self->dict);
- return 0;
-}
-
-static void
-ast_clear(AST_object *self)
-{
- Py_CLEAR(self->dict);
-}
-
static int
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
{
- _Py_IDENTIFIER(_fields);
Py_ssize_t i, numfields = 0;
int res = -1;
PyObject *key, *value, *fields;
- fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields);
+ fields = PyObject_GetAttrString((PyObject*)Py_TYPE(self), "_fields");
if (!fields)
PyErr_Clear();
if (fields) {
@@ -537,8 +440,7 @@ static PyObject *
ast_type_reduce(PyObject *self, PyObject *unused)
{
PyObject *res;
- _Py_IDENTIFIER(__dict__);
- PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__);
+ PyObject *dict = PyObject_GetAttrString(self, "__dict__");
if (dict == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError))
PyErr_Clear();
@@ -558,21 +460,16 @@ static PyMethodDef ast_type_methods[] = {
{NULL}
};
-static PyGetSetDef ast_type_getsets[] = {
- {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
- {NULL}
-};
-
static PyTypeObject AST_type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"_ast.AST",
- sizeof(AST_object),
+ sizeof(PyObject),
0,
- (destructor)ast_dealloc, /* tp_dealloc */
+ 0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_reserved */
+ 0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -583,26 +480,26 @@ static PyTypeObject AST_type = {
PyObject_GenericGetAttr, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
0, /* tp_doc */
- (traverseproc)ast_traverse, /* tp_traverse */
- (inquiry)ast_clear, /* tp_clear */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
ast_type_methods, /* tp_methods */
0, /* tp_members */
- ast_type_getsets, /* tp_getset */
+ 0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
- offsetof(AST_object, dict),/* tp_dictoffset */
+ 0, /* tp_dictoffset */
(initproc)ast_type_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
- PyObject_GC_Del, /* tp_free */
+ PyObject_Del, /* tp_free */
};
@@ -613,7 +510,7 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
fnames = PyTuple_New(num_fields);
if (!fnames) return NULL;
for (i = 0; i < num_fields; i++) {
- PyObject *field = PyUnicode_FromString(fields[i]);
+ PyObject *field = PyString_FromString(fields[i]);
if (!field) {
Py_DECREF(fnames);
return NULL;
@@ -629,19 +526,18 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
{
int i, result;
- _Py_IDENTIFIER(_attributes);
PyObject *s, *l = PyTuple_New(num_fields);
if (!l)
return 0;
for (i = 0; i < num_fields; i++) {
- s = PyUnicode_FromString(attrs[i]);
+ s = PyString_FromString(attrs[i]);
if (!s) {
Py_DECREF(l);
return 0;
}
PyTuple_SET_ITEM(l, i, s);
}
- result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0;
+ result = PyObject_SetAttrString((PyObject*)type, "_attributes", l) >= 0;
Py_DECREF(l);
return result;
}
@@ -650,7 +546,7 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
{
- Py_ssize_t i, n = asdl_seq_LEN(seq);
+ int i, n = asdl_seq_LEN(seq);
PyObject *result = PyList_New(n);
PyObject *value;
if (!result)
@@ -675,11 +571,14 @@ static PyObject* ast2obj_object(void *o)
}
#define ast2obj_identifier ast2obj_object
#define ast2obj_string ast2obj_object
-#define ast2obj_bytes ast2obj_object
+static PyObject* ast2obj_bool(bool b)
+{
+ return PyBool_FromLong(b);
+}
static PyObject* ast2obj_int(long b)
{
- return PyLong_FromLong(b);
+ return PyInt_FromLong(b);
}
/* Conversion Python -> AST */
@@ -697,8 +596,9 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
{
- if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
- PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
+ if (!PyString_CheckExact(obj) && obj != Py_None) {
+ PyErr_Format(PyExc_TypeError,
+ "AST identifier must be of type str");
return 1;
}
return obj2ast_object(obj, out, arena);
@@ -706,17 +606,9 @@ static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
{
- if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
- PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
- return 1;
- }
- return obj2ast_object(obj, out, arena);
-}
-
-static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena)
-{
- if (!PyBytes_CheckExact(obj)) {
- PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes");
+ if (!PyString_CheckExact(obj) && !PyUnicode_CheckExact(obj)) {
+ PyErr_SetString(PyExc_TypeError,
+ "AST string must be of type str or unicode");
return 1;
}
return obj2ast_object(obj, out, arena);
@@ -725,8 +617,12 @@ static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena)
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
{
int i;
- if (!PyLong_Check(obj)) {
- PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
+ if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
+ PyObject *s = PyObject_Repr(obj);
+ if (s == NULL) return 1;
+ PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s",
+ PyString_AS_STRING(s));
+ Py_DECREF(s);
return 1;
}
@@ -737,6 +633,21 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
return 0;
}
+static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
+{
+ if (!PyBool_Check(obj)) {
+ PyObject *s = PyObject_Repr(obj);
+ if (s == NULL) return 1;
+ PyErr_Format(PyExc_ValueError, "invalid boolean value: %.400s",
+ PyString_AS_STRING(s));
+ Py_DECREF(s);
+ return 1;
+ }
+
+ *out = (obj == Py_True);
+ return 0;
+}
+
static int add_ast_fields(void)
{
PyObject *empty_tuple, *d;
@@ -777,9 +688,9 @@ static int init_types(void)
if (!stmt_type) return 0;
if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
FunctionDef_type = make_type("FunctionDef", stmt_type,
- FunctionDef_fields, 5);
+ FunctionDef_fields, 4);
if (!FunctionDef_type) return 0;
- ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 7);
+ ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4);
if (!ClassDef_type) return 0;
Return_type = make_type("Return", stmt_type, Return_fields, 1);
if (!Return_type) return 0;
@@ -789,18 +700,23 @@ static int init_types(void)
if (!Assign_type) return 0;
AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
if (!AugAssign_type) return 0;
+ Print_type = make_type("Print", stmt_type, Print_fields, 3);
+ if (!Print_type) return 0;
For_type = make_type("For", stmt_type, For_fields, 4);
if (!For_type) return 0;
While_type = make_type("While", stmt_type, While_fields, 3);
if (!While_type) return 0;
If_type = make_type("If", stmt_type, If_fields, 3);
if (!If_type) return 0;
- With_type = make_type("With", stmt_type, With_fields, 2);
+ With_type = make_type("With", stmt_type, With_fields, 3);
if (!With_type) return 0;
- Raise_type = make_type("Raise", stmt_type, Raise_fields, 2);
+ Raise_type = make_type("Raise", stmt_type, Raise_fields, 3);
if (!Raise_type) return 0;
- Try_type = make_type("Try", stmt_type, Try_fields, 4);
- if (!Try_type) return 0;
+ TryExcept_type = make_type("TryExcept", stmt_type, TryExcept_fields, 3);
+ if (!TryExcept_type) return 0;
+ TryFinally_type = make_type("TryFinally", stmt_type, TryFinally_fields,
+ 2);
+ if (!TryFinally_type) return 0;
Assert_type = make_type("Assert", stmt_type, Assert_fields, 2);
if (!Assert_type) return 0;
Import_type = make_type("Import", stmt_type, Import_fields, 1);
@@ -808,10 +724,10 @@ static int init_types(void)
ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields,
3);
if (!ImportFrom_type) return 0;
+ Exec_type = make_type("Exec", stmt_type, Exec_fields, 3);
+ if (!Exec_type) return 0;
Global_type = make_type("Global", stmt_type, Global_fields, 1);
if (!Global_type) return 0;
- Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1);
- if (!Nonlocal_type) return 0;
Expr_type = make_type("Expr", stmt_type, Expr_fields, 1);
if (!Expr_type) return 0;
Pass_type = make_type("Pass", stmt_type, NULL, 0);
@@ -848,26 +764,20 @@ static int init_types(void)
if (!GeneratorExp_type) return 0;
Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
if (!Yield_type) return 0;
- YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1);
- if (!YieldFrom_type) return 0;
Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
if (!Compare_type) return 0;
Call_type = make_type("Call", expr_type, Call_fields, 5);
if (!Call_type) return 0;
+ Repr_type = make_type("Repr", expr_type, Repr_fields, 1);
+ if (!Repr_type) return 0;
Num_type = make_type("Num", expr_type, Num_fields, 1);
if (!Num_type) return 0;
Str_type = make_type("Str", expr_type, Str_fields, 1);
if (!Str_type) return 0;
- Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
- if (!Bytes_type) return 0;
- Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
- if (!Ellipsis_type) return 0;
Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
if (!Attribute_type) return 0;
Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
if (!Subscript_type) return 0;
- Starred_type = make_type("Starred", expr_type, Starred_fields, 2);
- if (!Starred_type) return 0;
Name_type = make_type("Name", expr_type, Name_fields, 2);
if (!Name_type) return 0;
List_type = make_type("List", expr_type, List_fields, 2);
@@ -904,6 +814,8 @@ static int init_types(void)
slice_type = make_type("slice", &AST_type, NULL, 0);
if (!slice_type) return 0;
if (!add_attributes(slice_type, NULL, 0)) return 0;
+ Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
+ if (!Ellipsis_type) return 0;
Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
if (!Slice_type) return 0;
ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
@@ -1044,16 +956,12 @@ static int init_types(void)
ExceptHandler_type = make_type("ExceptHandler", excepthandler_type,
ExceptHandler_fields, 3);
if (!ExceptHandler_type) return 0;
- arguments_type = make_type("arguments", &AST_type, arguments_fields, 8);
+ arguments_type = make_type("arguments", &AST_type, arguments_fields, 4);
if (!arguments_type) return 0;
- arg_type = make_type("arg", &AST_type, arg_fields, 2);
- if (!arg_type) return 0;
keyword_type = make_type("keyword", &AST_type, keyword_fields, 2);
if (!keyword_type) return 0;
alias_type = make_type("alias", &AST_type, alias_fields, 2);
if (!alias_type) return 0;
- withitem_type = make_type("withitem", &AST_type, withitem_fields, 2);
- if (!withitem_type) return 0;
initialized = 1;
return 1;
}
@@ -1073,10 +981,8 @@ static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
arena);
static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
-static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
-static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
mod_ty
Module(asdl_seq * body, PyArena *arena)
@@ -1133,8 +1039,7 @@ Suite(asdl_seq * body, PyArena *arena)
stmt_ty
FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
- decorator_list, expr_ty returns, int lineno, int col_offset,
- PyArena *arena)
+ decorator_list, int lineno, int col_offset, PyArena *arena)
{
stmt_ty p;
if (!name) {
@@ -1155,16 +1060,14 @@ FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
p->v.FunctionDef.args = args;
p->v.FunctionDef.body = body;
p->v.FunctionDef.decorator_list = decorator_list;
- p->v.FunctionDef.returns = returns;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
}
stmt_ty
-ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
- starargs, expr_ty kwargs, asdl_seq * body, asdl_seq * decorator_list,
- int lineno, int col_offset, PyArena *arena)
+ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq *
+ decorator_list, int lineno, int col_offset, PyArena *arena)
{
stmt_ty p;
if (!name) {
@@ -1178,9 +1081,6 @@ ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
p->kind = ClassDef_kind;
p->v.ClassDef.name = name;
p->v.ClassDef.bases = bases;
- p->v.ClassDef.keywords = keywords;
- p->v.ClassDef.starargs = starargs;
- p->v.ClassDef.kwargs = kwargs;
p->v.ClassDef.body = body;
p->v.ClassDef.decorator_list = decorator_list;
p->lineno = lineno;
@@ -1270,6 +1170,23 @@ AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
}
stmt_ty
+Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
+ PyArena *arena)
+{
+ stmt_ty p;
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
+ if (!p)
+ return NULL;
+ p->kind = Print_kind;
+ p->v.Print.dest = dest;
+ p->v.Print.values = values;
+ p->v.Print.nl = nl;
+ p->lineno = lineno;
+ p->col_offset = col_offset;
+ return p;
+}
+
+stmt_ty
For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
lineno, int col_offset, PyArena *arena)
{
@@ -1342,15 +1259,21 @@ If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
}
stmt_ty
-With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena
- *arena)
+With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body, int lineno,
+ int col_offset, PyArena *arena)
{
stmt_ty p;
+ if (!context_expr) {
+ PyErr_SetString(PyExc_ValueError,
+ "field context_expr is required for With");
+ return NULL;
+ }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
p->kind = With_kind;
- p->v.With.items = items;
+ p->v.With.context_expr = context_expr;
+ p->v.With.optional_vars = optional_vars;
p->v.With.body = body;
p->lineno = lineno;
p->col_offset = col_offset;
@@ -1358,33 +1281,50 @@ With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena
}
stmt_ty
-Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena)
+Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int col_offset,
+ PyArena *arena)
{
stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
p->kind = Raise_kind;
- p->v.Raise.exc = exc;
- p->v.Raise.cause = cause;
+ p->v.Raise.type = type;
+ p->v.Raise.inst = inst;
+ p->v.Raise.tback = tback;
+ p->lineno = lineno;
+ p->col_offset = col_offset;
+ return p;
+}
+
+stmt_ty
+TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, int lineno,
+ int col_offset, PyArena *arena)
+{
+ stmt_ty p;
+ p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
+ if (!p)
+ return NULL;
+ p->kind = TryExcept_kind;
+ p->v.TryExcept.body = body;
+ p->v.TryExcept.handlers = handlers;
+ p->v.TryExcept.orelse = orelse;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
}
stmt_ty
-Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
- finalbody, int lineno, int col_offset, PyArena *arena)
+TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int col_offset,
+ PyArena *arena)
{
stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
- p->kind = Try_kind;
- p->v.Try.body = body;
- p->v.Try.handlers = handlers;
- p->v.Try.orelse = orelse;
- p->v.Try.finalbody = finalbody;
+ p->kind = TryFinally_kind;
+ p->v.TryFinally.body = body;
+ p->v.TryFinally.finalbody = finalbody;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
@@ -1442,28 +1382,36 @@ ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
}
stmt_ty
-Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
+Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int col_offset,
+ PyArena *arena)
{
stmt_ty p;
+ if (!body) {
+ PyErr_SetString(PyExc_ValueError,
+ "field body is required for Exec");
+ return NULL;
+ }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
- p->kind = Global_kind;
- p->v.Global.names = names;
+ p->kind = Exec_kind;
+ p->v.Exec.body = body;
+ p->v.Exec.globals = globals;
+ p->v.Exec.locals = locals;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
}
stmt_ty
-Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
+Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena)
{
stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
- p->kind = Nonlocal_kind;
- p->v.Nonlocal.names = names;
+ p->kind = Global_kind;
+ p->v.Global.names = names;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
@@ -1799,25 +1747,6 @@ Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
}
expr_ty
-YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena)
-{
- expr_ty p;
- if (!value) {
- PyErr_SetString(PyExc_ValueError,
- "field value is required for YieldFrom");
- return NULL;
- }
- p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
- if (!p)
- return NULL;
- p->kind = YieldFrom_kind;
- p->v.YieldFrom.value = value;
- p->lineno = lineno;
- p->col_offset = col_offset;
- return p;
-}
-
-expr_ty
Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
int col_offset, PyArena *arena)
{
@@ -1864,70 +1793,57 @@ Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs,
}
expr_ty
-Num(object n, int lineno, int col_offset, PyArena *arena)
+Repr(expr_ty value, int lineno, int col_offset, PyArena *arena)
{
expr_ty p;
- if (!n) {
+ if (!value) {
PyErr_SetString(PyExc_ValueError,
- "field n is required for Num");
+ "field value is required for Repr");
return NULL;
}
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
- p->kind = Num_kind;
- p->v.Num.n = n;
+ p->kind = Repr_kind;
+ p->v.Repr.value = value;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
}
expr_ty
-Str(string s, int lineno, int col_offset, PyArena *arena)
+Num(object n, int lineno, int col_offset, PyArena *arena)
{
expr_ty p;
- if (!s) {
+ if (!n) {
PyErr_SetString(PyExc_ValueError,
- "field s is required for Str");
+ "field n is required for Num");
return NULL;
}
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
- p->kind = Str_kind;
- p->v.Str.s = s;
+ p->kind = Num_kind;
+ p->v.Num.n = n;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
}
expr_ty
-Bytes(bytes s, int lineno, int col_offset, PyArena *arena)
+Str(string s, int lineno, int col_offset, PyArena *arena)
{
expr_ty p;
if (!s) {
PyErr_SetString(PyExc_ValueError,
- "field s is required for Bytes");
+ "field s is required for Str");
return NULL;
}
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
- p->kind = Bytes_kind;
- p->v.Bytes.s = s;
- p->lineno = lineno;
- p->col_offset = col_offset;
- return p;
-}
-
-expr_ty
-Ellipsis(int lineno, int col_offset, PyArena *arena)
-{
- expr_ty p;
- p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
- if (!p)
- return NULL;
- p->kind = Ellipsis_kind;
+ p->kind = Str_kind;
+ p->v.Str.s = s;
p->lineno = lineno;
p->col_offset = col_offset;
return p;
@@ -1998,32 +1914,6 @@ Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
}
expr_ty
-Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena
- *arena)
-{
- expr_ty p;
- if (!value) {
- PyErr_SetString(PyExc_ValueError,
- "field value is required for Starred");
- return NULL;
- }
- if (!ctx) {
- PyErr_SetString(PyExc_ValueError,
- "field ctx is required for Starred");
- return NULL;
- }
- p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
- if (!p)
- return NULL;
- p->kind = Starred_kind;
- p->v.Starred.value = value;
- p->v.Starred.ctx = ctx;
- p->lineno = lineno;
- p->col_offset = col_offset;
- return p;
-}
-
-expr_ty
Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena
*arena)
{
@@ -2092,6 +1982,17 @@ Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena
}
slice_ty
+Ellipsis(PyArena *arena)
+{
+ slice_ty p;
+ p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
+ if (!p)
+ return NULL;
+ p->kind = Ellipsis_kind;
+ return p;
+}
+
+slice_ty
Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
{
slice_ty p;
@@ -2158,7 +2059,7 @@ comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
}
excepthandler_ty
-ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
+ExceptHandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
col_offset, PyArena *arena)
{
excepthandler_ty p;
@@ -2175,9 +2076,8 @@ ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
}
arguments_ty
-arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
- asdl_seq * kwonlyargs, identifier kwarg, expr_ty kwargannotation,
- asdl_seq * defaults, asdl_seq * kw_defaults, PyArena *arena)
+arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
+ defaults, PyArena *arena)
{
arguments_ty p;
p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
@@ -2185,29 +2085,8 @@ arguments(asdl_seq * args, identifier vararg, expr_ty varargannotation,
return NULL;
p->args = args;
p->vararg = vararg;
- p->varargannotation = varargannotation;
- p->kwonlyargs = kwonlyargs;
p->kwarg = kwarg;
- p->kwargannotation = kwargannotation;
p->defaults = defaults;
- p->kw_defaults = kw_defaults;
- return p;
-}
-
-arg_ty
-arg(identifier arg, expr_ty annotation, PyArena *arena)
-{
- arg_ty p;
- if (!arg) {
- PyErr_SetString(PyExc_ValueError,
- "field arg is required for arg");
- return NULL;
- }
- p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
- if (!p)
- return NULL;
- p->arg = arg;
- p->annotation = annotation;
return p;
}
@@ -2250,23 +2129,6 @@ alias(identifier name, identifier asname, PyArena *arena)
return p;
}
-withitem_ty
-withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
-{
- withitem_ty p;
- if (!context_expr) {
- PyErr_SetString(PyExc_ValueError,
- "field context_expr is required for withitem");
- return NULL;
- }
- p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
- if (!p)
- return NULL;
- p->context_expr = context_expr;
- p->optional_vars = optional_vars;
- return p;
-}
-
PyObject*
ast2obj_mod(void* _o)
@@ -2284,7 +2146,7 @@ ast2obj_mod(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2293,7 +2155,7 @@ ast2obj_mod(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2302,7 +2164,7 @@ ast2obj_mod(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Expression.body);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2311,7 +2173,7 @@ ast2obj_mod(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2339,69 +2201,49 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_identifier(o->v.FunctionDef.name);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
+ if (PyObject_SetAttrString(result, "name", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_arguments(o->v.FunctionDef.args);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
+ if (PyObject_SetAttrString(result, "args", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.FunctionDef.decorator_list,
ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) ==
+ if (PyObject_SetAttrString(result, "decorator_list", value) ==
-1)
goto failed;
Py_DECREF(value);
- value = ast2obj_expr(o->v.FunctionDef.returns);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1)
- goto failed;
- Py_DECREF(value);
break;
case ClassDef_kind:
result = PyType_GenericNew(ClassDef_type, NULL, NULL);
if (!result) goto failed;
value = ast2obj_identifier(o->v.ClassDef.name);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
+ if (PyObject_SetAttrString(result, "name", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_expr(o->v.ClassDef.starargs);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_expr(o->v.ClassDef.kwargs);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1)
+ if (PyObject_SetAttrString(result, "bases", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.ClassDef.decorator_list,
ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) ==
+ if (PyObject_SetAttrString(result, "decorator_list", value) ==
-1)
goto failed;
Py_DECREF(value);
@@ -2411,7 +2253,7 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Return.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2420,7 +2262,7 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
+ if (PyObject_SetAttrString(result, "targets", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2429,12 +2271,12 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1)
+ if (PyObject_SetAttrString(result, "targets", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.Assign.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2443,17 +2285,36 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.AugAssign.target);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
+ if (PyObject_SetAttrString(result, "target", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_operator(o->v.AugAssign.op);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
+ if (PyObject_SetAttrString(result, "op", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.AugAssign.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ break;
+ case Print_kind:
+ result = PyType_GenericNew(Print_type, NULL, NULL);
+ if (!result) goto failed;
+ value = ast2obj_expr(o->v.Print.dest);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "dest", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_list(o->v.Print.values, ast2obj_expr);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "values", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_bool(o->v.Print.nl);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "nl", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2462,22 +2323,22 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.For.target);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
+ if (PyObject_SetAttrString(result, "target", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.For.iter);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
+ if (PyObject_SetAttrString(result, "iter", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.For.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2486,17 +2347,17 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.While.test);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
+ if (PyObject_SetAttrString(result, "test", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.While.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2505,69 +2366,90 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.If.test);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
+ if (PyObject_SetAttrString(result, "test", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.If.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)
goto failed;
Py_DECREF(value);
break;
case With_kind:
result = PyType_GenericNew(With_type, NULL, NULL);
if (!result) goto failed;
- value = ast2obj_list(o->v.With.items, ast2obj_withitem);
+ value = ast2obj_expr(o->v.With.context_expr);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "context_expr", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_expr(o->v.With.optional_vars);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_items, value) == -1)
+ if (PyObject_SetAttrString(result, "optional_vars", value) ==
+ -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.With.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
break;
case Raise_kind:
result = PyType_GenericNew(Raise_type, NULL, NULL);
if (!result) goto failed;
- value = ast2obj_expr(o->v.Raise.exc);
+ value = ast2obj_expr(o->v.Raise.type);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1)
+ if (PyObject_SetAttrString(result, "type", value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_expr(o->v.Raise.cause);
+ value = ast2obj_expr(o->v.Raise.inst);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1)
+ if (PyObject_SetAttrString(result, "inst", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_expr(o->v.Raise.tback);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "tback", value) == -1)
goto failed;
Py_DECREF(value);
break;
- case Try_kind:
- result = PyType_GenericNew(Try_type, NULL, NULL);
+ case TryExcept_kind:
+ result = PyType_GenericNew(TryExcept_type, NULL, NULL);
if (!result) goto failed;
- value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
+ value = ast2obj_list(o->v.TryExcept.body, ast2obj_stmt);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "body", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_list(o->v.TryExcept.handlers,
+ ast2obj_excepthandler);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "handlers", value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
+ value = ast2obj_list(o->v.TryExcept.orelse, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1)
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
+ break;
+ case TryFinally_kind:
+ result = PyType_GenericNew(TryFinally_type, NULL, NULL);
+ if (!result) goto failed;
+ value = ast2obj_list(o->v.TryFinally.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
+ value = ast2obj_list(o->v.TryFinally.finalbody, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1)
+ if (PyObject_SetAttrString(result, "finalbody", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2576,12 +2458,12 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Assert.test);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
+ if (PyObject_SetAttrString(result, "test", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.Assert.msg);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1)
+ if (PyObject_SetAttrString(result, "msg", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2590,7 +2472,7 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Import.names, ast2obj_alias);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
+ if (PyObject_SetAttrString(result, "names", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2599,35 +2481,45 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_identifier(o->v.ImportFrom.module);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_module, value) == -1)
+ if (PyObject_SetAttrString(result, "module", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
+ if (PyObject_SetAttrString(result, "names", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_int(o->v.ImportFrom.level);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_level, value) == -1)
+ if (PyObject_SetAttrString(result, "level", value) == -1)
goto failed;
Py_DECREF(value);
break;
- case Global_kind:
- result = PyType_GenericNew(Global_type, NULL, NULL);
+ case Exec_kind:
+ result = PyType_GenericNew(Exec_type, NULL, NULL);
if (!result) goto failed;
- value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
+ value = ast2obj_expr(o->v.Exec.body);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "body", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_expr(o->v.Exec.globals);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "globals", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_expr(o->v.Exec.locals);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
+ if (PyObject_SetAttrString(result, "locals", value) == -1)
goto failed;
Py_DECREF(value);
break;
- case Nonlocal_kind:
- result = PyType_GenericNew(Nonlocal_type, NULL, NULL);
+ case Global_kind:
+ result = PyType_GenericNew(Global_type, NULL, NULL);
if (!result) goto failed;
- value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
+ value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_names, value) == -1)
+ if (PyObject_SetAttrString(result, "names", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2636,7 +2528,7 @@ ast2obj_stmt(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Expr.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2655,12 +2547,12 @@ ast2obj_stmt(void* _o)
}
value = ast2obj_int(o->lineno);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
+ if (PyObject_SetAttrString(result, "lineno", value) < 0)
goto failed;
Py_DECREF(value);
value = ast2obj_int(o->col_offset);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
+ if (PyObject_SetAttrString(result, "col_offset", value) < 0)
goto failed;
Py_DECREF(value);
return result;
@@ -2686,12 +2578,12 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_boolop(o->v.BoolOp.op);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
+ if (PyObject_SetAttrString(result, "op", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
+ if (PyObject_SetAttrString(result, "values", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2700,17 +2592,17 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.BinOp.left);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
+ if (PyObject_SetAttrString(result, "left", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_operator(o->v.BinOp.op);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
+ if (PyObject_SetAttrString(result, "op", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.BinOp.right);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_right, value) == -1)
+ if (PyObject_SetAttrString(result, "right", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2719,12 +2611,12 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_unaryop(o->v.UnaryOp.op);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_op, value) == -1)
+ if (PyObject_SetAttrString(result, "op", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.UnaryOp.operand);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1)
+ if (PyObject_SetAttrString(result, "operand", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2733,12 +2625,12 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_arguments(o->v.Lambda.args);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
+ if (PyObject_SetAttrString(result, "args", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.Lambda.body);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2747,17 +2639,17 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.IfExp.test);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_test, value) == -1)
+ if (PyObject_SetAttrString(result, "test", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.IfExp.body);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.IfExp.orelse);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1)
+ if (PyObject_SetAttrString(result, "orelse", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2766,12 +2658,12 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1)
+ if (PyObject_SetAttrString(result, "keys", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_values, value) == -1)
+ if (PyObject_SetAttrString(result, "values", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2780,7 +2672,7 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
+ if (PyObject_SetAttrString(result, "elts", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2789,13 +2681,13 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.ListComp.elt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
+ if (PyObject_SetAttrString(result, "elt", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.ListComp.generators,
ast2obj_comprehension);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
+ if (PyObject_SetAttrString(result, "generators", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2804,13 +2696,13 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.SetComp.elt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
+ if (PyObject_SetAttrString(result, "elt", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.SetComp.generators,
ast2obj_comprehension);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
+ if (PyObject_SetAttrString(result, "generators", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2819,18 +2711,18 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.DictComp.key);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_key, value) == -1)
+ if (PyObject_SetAttrString(result, "key", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.DictComp.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.DictComp.generators,
ast2obj_comprehension);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
+ if (PyObject_SetAttrString(result, "generators", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2839,13 +2731,13 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.GeneratorExp.elt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1)
+ if (PyObject_SetAttrString(result, "elt", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.GeneratorExp.generators,
ast2obj_comprehension);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
+ if (PyObject_SetAttrString(result, "generators", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2854,16 +2746,7 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Yield.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
- goto failed;
- Py_DECREF(value);
- break;
- case YieldFrom_kind:
- result = PyType_GenericNew(YieldFrom_type, NULL, NULL);
- if (!result) goto failed;
- value = ast2obj_expr(o->v.YieldFrom.value);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2872,23 +2755,23 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Compare.left);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_left, value) == -1)
+ if (PyObject_SetAttrString(result, "left", value) == -1)
goto failed;
Py_DECREF(value);
{
- Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
+ int i, n = asdl_seq_LEN(o->v.Compare.ops);
value = PyList_New(n);
if (!value) goto failed;
for(i = 0; i < n; i++)
PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
}
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1)
+ if (PyObject_SetAttrString(result, "ops", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1)
+ if (PyObject_SetAttrString(result, "comparators", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2897,27 +2780,36 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Call.func);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_func, value) == -1)
+ if (PyObject_SetAttrString(result, "func", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.Call.args, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
+ if (PyObject_SetAttrString(result, "args", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1)
+ if (PyObject_SetAttrString(result, "keywords", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.Call.starargs);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_starargs, value) == -1)
+ if (PyObject_SetAttrString(result, "starargs", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.Call.kwargs);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kwargs, value) == -1)
+ if (PyObject_SetAttrString(result, "kwargs", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ break;
+ case Repr_kind:
+ result = PyType_GenericNew(Repr_type, NULL, NULL);
+ if (!result) goto failed;
+ value = ast2obj_expr(o->v.Repr.value);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2926,7 +2818,7 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_object(o->v.Num.n);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_n, value) == -1)
+ if (PyObject_SetAttrString(result, "n", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2935,39 +2827,26 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_string(o->v.Str.s);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_s, value) == -1)
+ if (PyObject_SetAttrString(result, "s", value) == -1)
goto failed;
Py_DECREF(value);
break;
- case Bytes_kind:
- result = PyType_GenericNew(Bytes_type, NULL, NULL);
- if (!result) goto failed;
- value = ast2obj_bytes(o->v.Bytes.s);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_s, value) == -1)
- goto failed;
- Py_DECREF(value);
- break;
- case Ellipsis_kind:
- result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
- if (!result) goto failed;
- break;
case Attribute_kind:
result = PyType_GenericNew(Attribute_type, NULL, NULL);
if (!result) goto failed;
value = ast2obj_expr(o->v.Attribute.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_identifier(o->v.Attribute.attr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1)
+ if (PyObject_SetAttrString(result, "attr", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr_context(o->v.Attribute.ctx);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -2976,31 +2855,17 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Subscript.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_slice(o->v.Subscript.slice);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1)
+ if (PyObject_SetAttrString(result, "slice", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr_context(o->v.Subscript.ctx);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
- goto failed;
- Py_DECREF(value);
- break;
- case Starred_kind:
- result = PyType_GenericNew(Starred_type, NULL, NULL);
- if (!result) goto failed;
- value = ast2obj_expr(o->v.Starred.value);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_expr_context(o->v.Starred.ctx);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -3009,12 +2874,12 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_identifier(o->v.Name.id);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_id, value) == -1)
+ if (PyObject_SetAttrString(result, "id", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr_context(o->v.Name.ctx);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -3023,12 +2888,12 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.List.elts, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
+ if (PyObject_SetAttrString(result, "elts", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr_context(o->v.List.ctx);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -3037,24 +2902,24 @@ ast2obj_expr(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1)
+ if (PyObject_SetAttrString(result, "elts", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr_context(o->v.Tuple.ctx);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1)
+ if (PyObject_SetAttrString(result, "ctx", value) == -1)
goto failed;
Py_DECREF(value);
break;
}
value = ast2obj_int(o->lineno);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
+ if (PyObject_SetAttrString(result, "lineno", value) < 0)
goto failed;
Py_DECREF(value);
value = ast2obj_int(o->col_offset);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
+ if (PyObject_SetAttrString(result, "col_offset", value) < 0)
goto failed;
Py_DECREF(value);
return result;
@@ -3102,22 +2967,26 @@ ast2obj_slice(void* _o)
}
switch (o->kind) {
+ case Ellipsis_kind:
+ result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
+ if (!result) goto failed;
+ break;
case Slice_kind:
result = PyType_GenericNew(Slice_type, NULL, NULL);
if (!result) goto failed;
value = ast2obj_expr(o->v.Slice.lower);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1)
+ if (PyObject_SetAttrString(result, "lower", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.Slice.upper);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1)
+ if (PyObject_SetAttrString(result, "upper", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->v.Slice.step);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_step, value) == -1)
+ if (PyObject_SetAttrString(result, "step", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -3126,7 +2995,7 @@ ast2obj_slice(void* _o)
if (!result) goto failed;
value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1)
+ if (PyObject_SetAttrString(result, "dims", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -3135,7 +3004,7 @@ ast2obj_slice(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.Index.value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
break;
@@ -3281,17 +3150,17 @@ ast2obj_comprehension(void* _o)
if (!result) return NULL;
value = ast2obj_expr(o->target);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_target, value) == -1)
+ if (PyObject_SetAttrString(result, "target", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->iter);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1)
+ if (PyObject_SetAttrString(result, "iter", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->ifs, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1)
+ if (PyObject_SetAttrString(result, "ifs", value) == -1)
goto failed;
Py_DECREF(value);
return result;
@@ -3317,29 +3186,29 @@ ast2obj_excepthandler(void* _o)
if (!result) goto failed;
value = ast2obj_expr(o->v.ExceptHandler.type);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_type, value) == -1)
+ if (PyObject_SetAttrString(result, "type", value) == -1)
goto failed;
Py_DECREF(value);
- value = ast2obj_identifier(o->v.ExceptHandler.name);
+ value = ast2obj_expr(o->v.ExceptHandler.name);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
+ if (PyObject_SetAttrString(result, "name", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_body, value) == -1)
+ if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
break;
}
value = ast2obj_int(o->lineno);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0)
+ if (PyObject_SetAttrString(result, "lineno", value) < 0)
goto failed;
Py_DECREF(value);
value = ast2obj_int(o->col_offset);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0)
+ if (PyObject_SetAttrString(result, "col_offset", value) < 0)
goto failed;
Py_DECREF(value);
return result;
@@ -3361,73 +3230,24 @@ ast2obj_arguments(void* _o)
result = PyType_GenericNew(arguments_type, NULL, NULL);
if (!result) return NULL;
- value = ast2obj_list(o->args, ast2obj_arg);
+ value = ast2obj_list(o->args, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_args, value) == -1)
+ if (PyObject_SetAttrString(result, "args", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_identifier(o->vararg);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_expr(o->varargannotation);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_varargannotation, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1)
+ if (PyObject_SetAttrString(result, "vararg", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_identifier(o->kwarg);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_expr(o->kwargannotation);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kwargannotation, value) == -1)
+ if (PyObject_SetAttrString(result, "kwarg", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_list(o->defaults, ast2obj_expr);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_list(o->kw_defaults, ast2obj_expr);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1)
- goto failed;
- Py_DECREF(value);
- return result;
-failed:
- Py_XDECREF(value);
- Py_XDECREF(result);
- return NULL;
-}
-
-PyObject*
-ast2obj_arg(void* _o)
-{
- arg_ty o = (arg_ty)_o;
- PyObject *result = NULL, *value = NULL;
- if (!o) {
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- result = PyType_GenericNew(arg_type, NULL, NULL);
- if (!result) return NULL;
- value = ast2obj_identifier(o->arg);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_expr(o->annotation);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1)
+ if (PyObject_SetAttrString(result, "defaults", value) == -1)
goto failed;
Py_DECREF(value);
return result;
@@ -3451,12 +3271,12 @@ ast2obj_keyword(void* _o)
if (!result) return NULL;
value = ast2obj_identifier(o->arg);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1)
+ if (PyObject_SetAttrString(result, "arg", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_expr(o->value);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
+ if (PyObject_SetAttrString(result, "value", value) == -1)
goto failed;
Py_DECREF(value);
return result;
@@ -3480,41 +3300,12 @@ ast2obj_alias(void* _o)
if (!result) return NULL;
value = ast2obj_identifier(o->name);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_name, value) == -1)
+ if (PyObject_SetAttrString(result, "name", value) == -1)
goto failed;
Py_DECREF(value);
value = ast2obj_identifier(o->asname);
if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1)
- goto failed;
- Py_DECREF(value);
- return result;
-failed:
- Py_XDECREF(value);
- Py_XDECREF(result);
- return NULL;
-}
-
-PyObject*
-ast2obj_withitem(void* _o)
-{
- withitem_ty o = (withitem_ty)_o;
- PyObject *result = NULL, *value = NULL;
- if (!o) {
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- result = PyType_GenericNew(withitem_type, NULL, NULL);
- if (!result) return NULL;
- value = ast2obj_expr(o->context_expr);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1)
- goto failed;
- Py_DECREF(value);
- value = ast2obj_expr(o->optional_vars);
- if (!value) goto failed;
- if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1)
+ if (PyObject_SetAttrString(result, "asname", value) == -1)
goto failed;
Py_DECREF(value);
return result;
@@ -3528,9 +3319,9 @@ failed:
int
obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
- PyObject *tmp = NULL;
if (obj == Py_None) {
*out = NULL;
@@ -3543,11 +3334,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
if (isinstance) {
asdl_seq* body;
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3579,11 +3370,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
if (isinstance) {
asdl_seq* body;
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3615,9 +3406,9 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
if (isinstance) {
expr_ty body;
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &body, arena);
if (res != 0) goto failed;
@@ -3638,11 +3429,11 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
if (isinstance) {
asdl_seq* body;
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3668,8 +3459,10 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
- failed:
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyString_AS_STRING(tmp));
+failed:
Py_XDECREF(tmp);
return 1;
}
@@ -3677,9 +3470,9 @@ obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
int
obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
- PyObject *tmp = NULL;
int lineno;
int col_offset;
@@ -3687,9 +3480,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
*out = NULL;
return 0;
}
- if (_PyObject_HasAttrId(obj, &PyId_lineno)) {
+ if (PyObject_HasAttrString(obj, "lineno")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_lineno);
+ tmp = PyObject_GetAttrString(obj, "lineno");
if (tmp == NULL) goto failed;
res = obj2ast_int(tmp, &lineno, arena);
if (res != 0) goto failed;
@@ -3699,9 +3492,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_col_offset)) {
+ if (PyObject_HasAttrString(obj, "col_offset")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_col_offset);
+ tmp = PyObject_GetAttrString(obj, "col_offset");
if (tmp == NULL) goto failed;
res = obj2ast_int(tmp, &col_offset, arena);
if (res != 0) goto failed;
@@ -3720,11 +3513,10 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
arguments_ty args;
asdl_seq* body;
asdl_seq* decorator_list;
- expr_ty returns;
- if (_PyObject_HasAttrId(obj, &PyId_name)) {
+ if (PyObject_HasAttrString(obj, "name")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_name);
+ tmp = PyObject_GetAttrString(obj, "name");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &name, arena);
if (res != 0) goto failed;
@@ -3734,9 +3526,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_args)) {
+ if (PyObject_HasAttrString(obj, "args")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_args);
+ tmp = PyObject_GetAttrString(obj, "args");
if (tmp == NULL) goto failed;
res = obj2ast_arguments(tmp, &args, arena);
if (res != 0) goto failed;
@@ -3746,11 +3538,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3771,11 +3563,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) {
+ if (PyObject_HasAttrString(obj, "decorator_list")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list);
+ tmp = PyObject_GetAttrString(obj, "decorator_list");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3796,19 +3588,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_returns)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_returns);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &returns, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- returns = NULL;
- }
- *out = FunctionDef(name, args, body, decorator_list, returns,
- lineno, col_offset, arena);
+ *out = FunctionDef(name, args, body, decorator_list, lineno,
+ col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
@@ -3819,15 +3600,12 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (isinstance) {
identifier name;
asdl_seq* bases;
- asdl_seq* keywords;
- expr_ty starargs;
- expr_ty kwargs;
asdl_seq* body;
asdl_seq* decorator_list;
- if (_PyObject_HasAttrId(obj, &PyId_name)) {
+ if (PyObject_HasAttrString(obj, "name")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_name);
+ tmp = PyObject_GetAttrString(obj, "name");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &name, arena);
if (res != 0) goto failed;
@@ -3837,11 +3615,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_bases)) {
+ if (PyObject_HasAttrString(obj, "bases")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_bases);
+ tmp = PyObject_GetAttrString(obj, "bases");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3862,58 +3640,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_keywords)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_keywords);
- if (tmp == NULL) goto failed;
- if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
- goto failed;
- }
- len = PyList_GET_SIZE(tmp);
- keywords = asdl_seq_new(len, arena);
- if (keywords == NULL) goto failed;
- for (i = 0; i < len; i++) {
- keyword_ty value;
- res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
- if (res != 0) goto failed;
- asdl_seq_SET(keywords, i, value);
- }
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
- return 1;
- }
- if (_PyObject_HasAttrId(obj, &PyId_starargs)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &starargs, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- starargs = NULL;
- }
- if (_PyObject_HasAttrId(obj, &PyId_kwargs)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &kwargs, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- kwargs = NULL;
- }
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3934,11 +3665,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) {
+ if (PyObject_HasAttrString(obj, "decorator_list")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list);
+ tmp = PyObject_GetAttrString(obj, "decorator_list");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -3959,8 +3690,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
return 1;
}
- *out = ClassDef(name, bases, keywords, starargs, kwargs, body,
- decorator_list, lineno, col_offset, arena);
+ *out = ClassDef(name, bases, body, decorator_list, lineno,
+ col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
@@ -3971,9 +3702,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -3993,11 +3724,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (isinstance) {
asdl_seq* targets;
- if (_PyObject_HasAttrId(obj, &PyId_targets)) {
+ if (PyObject_HasAttrString(obj, "targets")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_targets);
+ tmp = PyObject_GetAttrString(obj, "targets");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4030,11 +3761,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
asdl_seq* targets;
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_targets)) {
+ if (PyObject_HasAttrString(obj, "targets")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_targets);
+ tmp = PyObject_GetAttrString(obj, "targets");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4055,9 +3786,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -4080,9 +3811,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
operator_ty op;
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_target)) {
+ if (PyObject_HasAttrString(obj, "target")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_target);
+ tmp = PyObject_GetAttrString(obj, "target");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &target, arena);
if (res != 0) goto failed;
@@ -4092,9 +3823,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_op)) {
+ if (PyObject_HasAttrString(obj, "op")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_op);
+ tmp = PyObject_GetAttrString(obj, "op");
if (tmp == NULL) goto failed;
res = obj2ast_operator(tmp, &op, arena);
if (res != 0) goto failed;
@@ -4104,9 +3835,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -4120,6 +3851,67 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (*out == NULL) goto failed;
return 0;
}
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Print_type);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (isinstance) {
+ expr_ty dest;
+ asdl_seq* values;
+ bool nl;
+
+ if (PyObject_HasAttrString(obj, "dest")) {
+ int res;
+ tmp = PyObject_GetAttrString(obj, "dest");
+ if (tmp == NULL) goto failed;
+ res = obj2ast_expr(tmp, &dest, arena);
+ if (res != 0) goto failed;
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ dest = NULL;
+ }
+ if (PyObject_HasAttrString(obj, "values")) {
+ int res;
+ Py_ssize_t len;
+ Py_ssize_t i;
+ tmp = PyObject_GetAttrString(obj, "values");
+ if (tmp == NULL) goto failed;
+ if (!PyList_Check(tmp)) {
+ PyErr_Format(PyExc_TypeError, "Print field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
+ goto failed;
+ }
+ len = PyList_GET_SIZE(tmp);
+ values = asdl_seq_new(len, arena);
+ if (values == NULL) goto failed;
+ for (i = 0; i < len; i++) {
+ expr_ty value;
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
+ if (res != 0) goto failed;
+ asdl_seq_SET(values, i, value);
+ }
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Print");
+ return 1;
+ }
+ if (PyObject_HasAttrString(obj, "nl")) {
+ int res;
+ tmp = PyObject_GetAttrString(obj, "nl");
+ if (tmp == NULL) goto failed;
+ res = obj2ast_bool(tmp, &nl, arena);
+ if (res != 0) goto failed;
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "required field \"nl\" missing from Print");
+ return 1;
+ }
+ *out = Print(dest, values, nl, lineno, col_offset, arena);
+ if (*out == NULL) goto failed;
+ return 0;
+ }
isinstance = PyObject_IsInstance(obj, (PyObject*)For_type);
if (isinstance == -1) {
return 1;
@@ -4130,9 +3922,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
asdl_seq* body;
asdl_seq* orelse;
- if (_PyObject_HasAttrId(obj, &PyId_target)) {
+ if (PyObject_HasAttrString(obj, "target")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_target);
+ tmp = PyObject_GetAttrString(obj, "target");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &target, arena);
if (res != 0) goto failed;
@@ -4142,9 +3934,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_iter)) {
+ if (PyObject_HasAttrString(obj, "iter")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_iter);
+ tmp = PyObject_GetAttrString(obj, "iter");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &iter, arena);
if (res != 0) goto failed;
@@ -4154,11 +3946,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4179,11 +3971,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
+ if (PyObject_HasAttrString(obj, "orelse")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
+ tmp = PyObject_GetAttrString(obj, "orelse");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4218,9 +4010,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
asdl_seq* body;
asdl_seq* orelse;
- if (_PyObject_HasAttrId(obj, &PyId_test)) {
+ if (PyObject_HasAttrString(obj, "test")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_test);
+ tmp = PyObject_GetAttrString(obj, "test");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &test, arena);
if (res != 0) goto failed;
@@ -4230,11 +4022,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4255,11 +4047,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
+ if (PyObject_HasAttrString(obj, "orelse")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
+ tmp = PyObject_GetAttrString(obj, "orelse");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4293,9 +4085,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
asdl_seq* body;
asdl_seq* orelse;
- if (_PyObject_HasAttrId(obj, &PyId_test)) {
+ if (PyObject_HasAttrString(obj, "test")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_test);
+ tmp = PyObject_GetAttrString(obj, "test");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &test, arena);
if (res != 0) goto failed;
@@ -4305,11 +4097,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4330,11 +4122,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
+ if (PyObject_HasAttrString(obj, "orelse")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
+ tmp = PyObject_GetAttrString(obj, "orelse");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4364,39 +4156,38 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
return 1;
}
if (isinstance) {
- asdl_seq* items;
+ expr_ty context_expr;
+ expr_ty optional_vars;
asdl_seq* body;
- if (_PyObject_HasAttrId(obj, &PyId_items)) {
+ if (PyObject_HasAttrString(obj, "context_expr")) {
int res;
- Py_ssize_t len;
- Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_items);
+ tmp = PyObject_GetAttrString(obj, "context_expr");
if (tmp == NULL) goto failed;
- if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name);
- goto failed;
- }
- len = PyList_GET_SIZE(tmp);
- items = asdl_seq_new(len, arena);
- if (items == NULL) goto failed;
- for (i = 0; i < len; i++) {
- withitem_ty value;
- res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena);
- if (res != 0) goto failed;
- asdl_seq_SET(items, i, value);
- }
+ res = obj2ast_expr(tmp, &context_expr, arena);
+ if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
+ PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from With");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "optional_vars")) {
+ int res;
+ tmp = PyObject_GetAttrString(obj, "optional_vars");
+ if (tmp == NULL) goto failed;
+ res = obj2ast_expr(tmp, &optional_vars, arena);
+ if (res != 0) goto failed;
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ optional_vars = NULL;
+ }
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4417,7 +4208,8 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
return 1;
}
- *out = With(items, body, lineno, col_offset, arena);
+ *out = With(context_expr, optional_vars, body, lineno,
+ col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
@@ -4426,36 +4218,48 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
return 1;
}
if (isinstance) {
- expr_ty exc;
- expr_ty cause;
+ expr_ty type;
+ expr_ty inst;
+ expr_ty tback;
- if (_PyObject_HasAttrId(obj, &PyId_exc)) {
+ if (PyObject_HasAttrString(obj, "type")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_exc);
+ tmp = PyObject_GetAttrString(obj, "type");
if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &exc, arena);
+ res = obj2ast_expr(tmp, &type, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- exc = NULL;
+ type = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_cause)) {
+ if (PyObject_HasAttrString(obj, "inst")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_cause);
+ tmp = PyObject_GetAttrString(obj, "inst");
if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &cause, arena);
+ res = obj2ast_expr(tmp, &inst, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- cause = NULL;
+ inst = NULL;
}
- *out = Raise(exc, cause, lineno, col_offset, arena);
+ if (PyObject_HasAttrString(obj, "tback")) {
+ int res;
+ tmp = PyObject_GetAttrString(obj, "tback");
+ if (tmp == NULL) goto failed;
+ res = obj2ast_expr(tmp, &tback, arena);
+ if (res != 0) goto failed;
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ tback = NULL;
+ }
+ *out = Raise(type, inst, tback, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type);
+ isinstance = PyObject_IsInstance(obj, (PyObject*)TryExcept_type);
if (isinstance == -1) {
return 1;
}
@@ -4463,16 +4267,15 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
asdl_seq* body;
asdl_seq* handlers;
asdl_seq* orelse;
- asdl_seq* finalbody;
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
+ PyErr_Format(PyExc_TypeError, "TryExcept field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
goto failed;
}
len = PyList_GET_SIZE(tmp);
@@ -4487,17 +4290,17 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryExcept");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_handlers)) {
+ if (PyObject_HasAttrString(obj, "handlers")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_handlers);
+ tmp = PyObject_GetAttrString(obj, "handlers");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
+ PyErr_Format(PyExc_TypeError, "TryExcept field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name);
goto failed;
}
len = PyList_GET_SIZE(tmp);
@@ -4512,17 +4315,17 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
+ PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from TryExcept");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
+ if (PyObject_HasAttrString(obj, "orelse")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
+ tmp = PyObject_GetAttrString(obj, "orelse");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
+ PyErr_Format(PyExc_TypeError, "TryExcept field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name);
goto failed;
}
len = PyList_GET_SIZE(tmp);
@@ -4537,17 +4340,55 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
+ PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from TryExcept");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_finalbody)) {
+ *out = TryExcept(body, handlers, orelse, lineno, col_offset,
+ arena);
+ if (*out == NULL) goto failed;
+ return 0;
+ }
+ isinstance = PyObject_IsInstance(obj, (PyObject*)TryFinally_type);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (isinstance) {
+ asdl_seq* body;
+ asdl_seq* finalbody;
+
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_finalbody);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
+ PyErr_Format(PyExc_TypeError, "TryFinally field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
+ goto failed;
+ }
+ len = PyList_GET_SIZE(tmp);
+ body = asdl_seq_new(len, arena);
+ if (body == NULL) goto failed;
+ for (i = 0; i < len; i++) {
+ stmt_ty value;
+ res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
+ if (res != 0) goto failed;
+ asdl_seq_SET(body, i, value);
+ }
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from TryFinally");
+ return 1;
+ }
+ if (PyObject_HasAttrString(obj, "finalbody")) {
+ int res;
+ Py_ssize_t len;
+ Py_ssize_t i;
+ tmp = PyObject_GetAttrString(obj, "finalbody");
+ if (tmp == NULL) goto failed;
+ if (!PyList_Check(tmp)) {
+ PyErr_Format(PyExc_TypeError, "TryFinally field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name);
goto failed;
}
len = PyList_GET_SIZE(tmp);
@@ -4562,11 +4403,10 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
+ PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from TryFinally");
return 1;
}
- *out = Try(body, handlers, orelse, finalbody, lineno,
- col_offset, arena);
+ *out = TryFinally(body, finalbody, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
@@ -4578,9 +4418,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
expr_ty test;
expr_ty msg;
- if (_PyObject_HasAttrId(obj, &PyId_test)) {
+ if (PyObject_HasAttrString(obj, "test")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_test);
+ tmp = PyObject_GetAttrString(obj, "test");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &test, arena);
if (res != 0) goto failed;
@@ -4590,9 +4430,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_msg)) {
+ if (PyObject_HasAttrString(obj, "msg")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_msg);
+ tmp = PyObject_GetAttrString(obj, "msg");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &msg, arena);
if (res != 0) goto failed;
@@ -4612,11 +4452,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (isinstance) {
asdl_seq* names;
- if (_PyObject_HasAttrId(obj, &PyId_names)) {
+ if (PyObject_HasAttrString(obj, "names")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_names);
+ tmp = PyObject_GetAttrString(obj, "names");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4650,9 +4490,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
asdl_seq* names;
int level;
- if (_PyObject_HasAttrId(obj, &PyId_module)) {
+ if (PyObject_HasAttrString(obj, "module")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_module);
+ tmp = PyObject_GetAttrString(obj, "module");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &module, arena);
if (res != 0) goto failed;
@@ -4661,11 +4501,11 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
} else {
module = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_names)) {
+ if (PyObject_HasAttrString(obj, "names")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_names);
+ tmp = PyObject_GetAttrString(obj, "names");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4686,9 +4526,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_level)) {
+ if (PyObject_HasAttrString(obj, "level")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_level);
+ tmp = PyObject_GetAttrString(obj, "level");
if (tmp == NULL) goto failed;
res = obj2ast_int(tmp, &level, arena);
if (res != 0) goto failed;
@@ -4702,57 +4542,68 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Exec_type);
if (isinstance == -1) {
return 1;
}
if (isinstance) {
- asdl_seq* names;
+ expr_ty body;
+ expr_ty globals;
+ expr_ty locals;
- if (_PyObject_HasAttrId(obj, &PyId_names)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
- Py_ssize_t len;
- Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_names);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
- if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
- goto failed;
- }
- len = PyList_GET_SIZE(tmp);
- names = asdl_seq_new(len, arena);
- if (names == NULL) goto failed;
- for (i = 0; i < len; i++) {
- identifier value;
- res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
- if (res != 0) goto failed;
- asdl_seq_SET(names, i, value);
- }
+ res = obj2ast_expr(tmp, &body, arena);
+ if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
+ PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Exec");
return 1;
}
- *out = Global(names, lineno, col_offset, arena);
+ if (PyObject_HasAttrString(obj, "globals")) {
+ int res;
+ tmp = PyObject_GetAttrString(obj, "globals");
+ if (tmp == NULL) goto failed;
+ res = obj2ast_expr(tmp, &globals, arena);
+ if (res != 0) goto failed;
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ globals = NULL;
+ }
+ if (PyObject_HasAttrString(obj, "locals")) {
+ int res;
+ tmp = PyObject_GetAttrString(obj, "locals");
+ if (tmp == NULL) goto failed;
+ res = obj2ast_expr(tmp, &locals, arena);
+ if (res != 0) goto failed;
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ locals = NULL;
+ }
+ *out = Exec(body, globals, locals, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type);
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type);
if (isinstance == -1) {
return 1;
}
if (isinstance) {
asdl_seq* names;
- if (_PyObject_HasAttrId(obj, &PyId_names)) {
+ if (PyObject_HasAttrString(obj, "names")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_names);
+ tmp = PyObject_GetAttrString(obj, "names");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
+ PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name);
goto failed;
}
len = PyList_GET_SIZE(tmp);
@@ -4767,10 +4618,10 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
+ PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
return 1;
}
- *out = Nonlocal(names, lineno, col_offset, arena);
+ *out = Global(names, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
@@ -4781,9 +4632,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -4828,8 +4679,10 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
- failed:
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyString_AS_STRING(tmp));
+failed:
Py_XDECREF(tmp);
return 1;
}
@@ -4837,9 +4690,9 @@ obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
int
obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
- PyObject *tmp = NULL;
int lineno;
int col_offset;
@@ -4847,9 +4700,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
*out = NULL;
return 0;
}
- if (_PyObject_HasAttrId(obj, &PyId_lineno)) {
+ if (PyObject_HasAttrString(obj, "lineno")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_lineno);
+ tmp = PyObject_GetAttrString(obj, "lineno");
if (tmp == NULL) goto failed;
res = obj2ast_int(tmp, &lineno, arena);
if (res != 0) goto failed;
@@ -4859,9 +4712,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_col_offset)) {
+ if (PyObject_HasAttrString(obj, "col_offset")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_col_offset);
+ tmp = PyObject_GetAttrString(obj, "col_offset");
if (tmp == NULL) goto failed;
res = obj2ast_int(tmp, &col_offset, arena);
if (res != 0) goto failed;
@@ -4879,9 +4732,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
boolop_ty op;
asdl_seq* values;
- if (_PyObject_HasAttrId(obj, &PyId_op)) {
+ if (PyObject_HasAttrString(obj, "op")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_op);
+ tmp = PyObject_GetAttrString(obj, "op");
if (tmp == NULL) goto failed;
res = obj2ast_boolop(tmp, &op, arena);
if (res != 0) goto failed;
@@ -4891,11 +4744,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_values)) {
+ if (PyObject_HasAttrString(obj, "values")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_values);
+ tmp = PyObject_GetAttrString(obj, "values");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -4929,9 +4782,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
operator_ty op;
expr_ty right;
- if (_PyObject_HasAttrId(obj, &PyId_left)) {
+ if (PyObject_HasAttrString(obj, "left")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_left);
+ tmp = PyObject_GetAttrString(obj, "left");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &left, arena);
if (res != 0) goto failed;
@@ -4941,9 +4794,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_op)) {
+ if (PyObject_HasAttrString(obj, "op")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_op);
+ tmp = PyObject_GetAttrString(obj, "op");
if (tmp == NULL) goto failed;
res = obj2ast_operator(tmp, &op, arena);
if (res != 0) goto failed;
@@ -4953,9 +4806,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_right)) {
+ if (PyObject_HasAttrString(obj, "right")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_right);
+ tmp = PyObject_GetAttrString(obj, "right");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &right, arena);
if (res != 0) goto failed;
@@ -4977,9 +4830,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
unaryop_ty op;
expr_ty operand;
- if (_PyObject_HasAttrId(obj, &PyId_op)) {
+ if (PyObject_HasAttrString(obj, "op")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_op);
+ tmp = PyObject_GetAttrString(obj, "op");
if (tmp == NULL) goto failed;
res = obj2ast_unaryop(tmp, &op, arena);
if (res != 0) goto failed;
@@ -4989,9 +4842,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_operand)) {
+ if (PyObject_HasAttrString(obj, "operand")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_operand);
+ tmp = PyObject_GetAttrString(obj, "operand");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &operand, arena);
if (res != 0) goto failed;
@@ -5013,9 +4866,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
arguments_ty args;
expr_ty body;
- if (_PyObject_HasAttrId(obj, &PyId_args)) {
+ if (PyObject_HasAttrString(obj, "args")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_args);
+ tmp = PyObject_GetAttrString(obj, "args");
if (tmp == NULL) goto failed;
res = obj2ast_arguments(tmp, &args, arena);
if (res != 0) goto failed;
@@ -5025,9 +4878,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &body, arena);
if (res != 0) goto failed;
@@ -5050,9 +4903,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
expr_ty body;
expr_ty orelse;
- if (_PyObject_HasAttrId(obj, &PyId_test)) {
+ if (PyObject_HasAttrString(obj, "test")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_test);
+ tmp = PyObject_GetAttrString(obj, "test");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &test, arena);
if (res != 0) goto failed;
@@ -5062,9 +4915,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &body, arena);
if (res != 0) goto failed;
@@ -5074,9 +4927,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_orelse)) {
+ if (PyObject_HasAttrString(obj, "orelse")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_orelse);
+ tmp = PyObject_GetAttrString(obj, "orelse");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &orelse, arena);
if (res != 0) goto failed;
@@ -5098,11 +4951,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
asdl_seq* keys;
asdl_seq* values;
- if (_PyObject_HasAttrId(obj, &PyId_keys)) {
+ if (PyObject_HasAttrString(obj, "keys")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_keys);
+ tmp = PyObject_GetAttrString(obj, "keys");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5123,11 +4976,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_values)) {
+ if (PyObject_HasAttrString(obj, "values")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_values);
+ tmp = PyObject_GetAttrString(obj, "values");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5159,11 +5012,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
if (isinstance) {
asdl_seq* elts;
- if (_PyObject_HasAttrId(obj, &PyId_elts)) {
+ if (PyObject_HasAttrString(obj, "elts")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_elts);
+ tmp = PyObject_GetAttrString(obj, "elts");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5196,9 +5049,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
expr_ty elt;
asdl_seq* generators;
- if (_PyObject_HasAttrId(obj, &PyId_elt)) {
+ if (PyObject_HasAttrString(obj, "elt")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_elt);
+ tmp = PyObject_GetAttrString(obj, "elt");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &elt, arena);
if (res != 0) goto failed;
@@ -5208,11 +5061,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_generators)) {
+ if (PyObject_HasAttrString(obj, "generators")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_generators);
+ tmp = PyObject_GetAttrString(obj, "generators");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5245,9 +5098,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
expr_ty elt;
asdl_seq* generators;
- if (_PyObject_HasAttrId(obj, &PyId_elt)) {
+ if (PyObject_HasAttrString(obj, "elt")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_elt);
+ tmp = PyObject_GetAttrString(obj, "elt");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &elt, arena);
if (res != 0) goto failed;
@@ -5257,11 +5110,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_generators)) {
+ if (PyObject_HasAttrString(obj, "generators")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_generators);
+ tmp = PyObject_GetAttrString(obj, "generators");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5295,9 +5148,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
expr_ty value;
asdl_seq* generators;
- if (_PyObject_HasAttrId(obj, &PyId_key)) {
+ if (PyObject_HasAttrString(obj, "key")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_key);
+ tmp = PyObject_GetAttrString(obj, "key");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &key, arena);
if (res != 0) goto failed;
@@ -5307,9 +5160,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -5319,11 +5172,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_generators)) {
+ if (PyObject_HasAttrString(obj, "generators")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_generators);
+ tmp = PyObject_GetAttrString(obj, "generators");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5357,9 +5210,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
expr_ty elt;
asdl_seq* generators;
- if (_PyObject_HasAttrId(obj, &PyId_elt)) {
+ if (PyObject_HasAttrString(obj, "elt")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_elt);
+ tmp = PyObject_GetAttrString(obj, "elt");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &elt, arena);
if (res != 0) goto failed;
@@ -5369,11 +5222,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_generators)) {
+ if (PyObject_HasAttrString(obj, "generators")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_generators);
+ tmp = PyObject_GetAttrString(obj, "generators");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5405,9 +5258,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -5420,29 +5273,6 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type);
- if (isinstance == -1) {
- return 1;
- }
- if (isinstance) {
- expr_ty value;
-
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &value, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
- return 1;
- }
- *out = YieldFrom(value, lineno, col_offset, arena);
- if (*out == NULL) goto failed;
- return 0;
- }
isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
if (isinstance == -1) {
return 1;
@@ -5452,9 +5282,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
asdl_int_seq* ops;
asdl_seq* comparators;
- if (_PyObject_HasAttrId(obj, &PyId_left)) {
+ if (PyObject_HasAttrString(obj, "left")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_left);
+ tmp = PyObject_GetAttrString(obj, "left");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &left, arena);
if (res != 0) goto failed;
@@ -5464,11 +5294,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_ops)) {
+ if (PyObject_HasAttrString(obj, "ops")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_ops);
+ tmp = PyObject_GetAttrString(obj, "ops");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5489,11 +5319,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_comparators)) {
+ if (PyObject_HasAttrString(obj, "comparators")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_comparators);
+ tmp = PyObject_GetAttrString(obj, "comparators");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5530,9 +5360,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
expr_ty starargs;
expr_ty kwargs;
- if (_PyObject_HasAttrId(obj, &PyId_func)) {
+ if (PyObject_HasAttrString(obj, "func")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_func);
+ tmp = PyObject_GetAttrString(obj, "func");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &func, arena);
if (res != 0) goto failed;
@@ -5542,11 +5372,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_args)) {
+ if (PyObject_HasAttrString(obj, "args")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_args);
+ tmp = PyObject_GetAttrString(obj, "args");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5567,11 +5397,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_keywords)) {
+ if (PyObject_HasAttrString(obj, "keywords")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_keywords);
+ tmp = PyObject_GetAttrString(obj, "keywords");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5592,9 +5422,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_starargs)) {
+ if (PyObject_HasAttrString(obj, "starargs")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_starargs);
+ tmp = PyObject_GetAttrString(obj, "starargs");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &starargs, arena);
if (res != 0) goto failed;
@@ -5603,9 +5433,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
} else {
starargs = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwargs)) {
+ if (PyObject_HasAttrString(obj, "kwargs")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_kwargs);
+ tmp = PyObject_GetAttrString(obj, "kwargs");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &kwargs, arena);
if (res != 0) goto failed;
@@ -5619,82 +5449,72 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Repr_type);
if (isinstance == -1) {
return 1;
}
if (isinstance) {
- object n;
+ expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_n)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_n);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
- res = obj2ast_object(tmp, &n, arena);
+ res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
+ PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Repr");
return 1;
}
- *out = Num(n, lineno, col_offset, arena);
+ *out = Repr(value, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type);
if (isinstance == -1) {
return 1;
}
if (isinstance) {
- string s;
+ object n;
- if (_PyObject_HasAttrId(obj, &PyId_s)) {
+ if (PyObject_HasAttrString(obj, "n")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_s);
+ tmp = PyObject_GetAttrString(obj, "n");
if (tmp == NULL) goto failed;
- res = obj2ast_string(tmp, &s, arena);
+ res = obj2ast_object(tmp, &n, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
+ PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num");
return 1;
}
- *out = Str(s, lineno, col_offset, arena);
+ *out = Num(n, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type);
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type);
if (isinstance == -1) {
return 1;
}
if (isinstance) {
- bytes s;
+ string s;
- if (_PyObject_HasAttrId(obj, &PyId_s)) {
+ if (PyObject_HasAttrString(obj, "s")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_s);
+ tmp = PyObject_GetAttrString(obj, "s");
if (tmp == NULL) goto failed;
- res = obj2ast_bytes(tmp, &s, arena);
+ res = obj2ast_string(tmp, &s, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
- PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes");
+ PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str");
return 1;
}
- *out = Bytes(s, lineno, col_offset, arena);
- if (*out == NULL) goto failed;
- return 0;
- }
- isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
- if (isinstance == -1) {
- return 1;
- }
- if (isinstance) {
-
- *out = Ellipsis(lineno, col_offset, arena);
+ *out = Str(s, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
@@ -5707,9 +5527,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
identifier attr;
expr_context_ty ctx;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -5719,9 +5539,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_attr)) {
+ if (PyObject_HasAttrString(obj, "attr")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_attr);
+ tmp = PyObject_GetAttrString(obj, "attr");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &attr, arena);
if (res != 0) goto failed;
@@ -5731,9 +5551,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
+ if (PyObject_HasAttrString(obj, "ctx")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
+ tmp = PyObject_GetAttrString(obj, "ctx");
if (tmp == NULL) goto failed;
res = obj2ast_expr_context(tmp, &ctx, arena);
if (res != 0) goto failed;
@@ -5756,9 +5576,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
slice_ty slice;
expr_context_ty ctx;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -5768,9 +5588,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_slice)) {
+ if (PyObject_HasAttrString(obj, "slice")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_slice);
+ tmp = PyObject_GetAttrString(obj, "slice");
if (tmp == NULL) goto failed;
res = obj2ast_slice(tmp, &slice, arena);
if (res != 0) goto failed;
@@ -5780,9 +5600,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
+ if (PyObject_HasAttrString(obj, "ctx")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
+ tmp = PyObject_GetAttrString(obj, "ctx");
if (tmp == NULL) goto failed;
res = obj2ast_expr_context(tmp, &ctx, arena);
if (res != 0) goto failed;
@@ -5796,42 +5616,6 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
if (*out == NULL) goto failed;
return 0;
}
- isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type);
- if (isinstance == -1) {
- return 1;
- }
- if (isinstance) {
- expr_ty value;
- expr_context_ty ctx;
-
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &value, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
- return 1;
- }
- if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr_context(tmp, &ctx, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
- return 1;
- }
- *out = Starred(value, ctx, lineno, col_offset, arena);
- if (*out == NULL) goto failed;
- return 0;
- }
isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type);
if (isinstance == -1) {
return 1;
@@ -5840,9 +5624,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
identifier id;
expr_context_ty ctx;
- if (_PyObject_HasAttrId(obj, &PyId_id)) {
+ if (PyObject_HasAttrString(obj, "id")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_id);
+ tmp = PyObject_GetAttrString(obj, "id");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &id, arena);
if (res != 0) goto failed;
@@ -5852,9 +5636,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
+ if (PyObject_HasAttrString(obj, "ctx")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
+ tmp = PyObject_GetAttrString(obj, "ctx");
if (tmp == NULL) goto failed;
res = obj2ast_expr_context(tmp, &ctx, arena);
if (res != 0) goto failed;
@@ -5876,11 +5660,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
asdl_seq* elts;
expr_context_ty ctx;
- if (_PyObject_HasAttrId(obj, &PyId_elts)) {
+ if (PyObject_HasAttrString(obj, "elts")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_elts);
+ tmp = PyObject_GetAttrString(obj, "elts");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5901,9 +5685,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
+ if (PyObject_HasAttrString(obj, "ctx")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
+ tmp = PyObject_GetAttrString(obj, "ctx");
if (tmp == NULL) goto failed;
res = obj2ast_expr_context(tmp, &ctx, arena);
if (res != 0) goto failed;
@@ -5925,11 +5709,11 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
asdl_seq* elts;
expr_context_ty ctx;
- if (_PyObject_HasAttrId(obj, &PyId_elts)) {
+ if (PyObject_HasAttrString(obj, "elts")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_elts);
+ tmp = PyObject_GetAttrString(obj, "elts");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -5950,9 +5734,9 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_ctx)) {
+ if (PyObject_HasAttrString(obj, "ctx")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_ctx);
+ tmp = PyObject_GetAttrString(obj, "ctx");
if (tmp == NULL) goto failed;
res = obj2ast_expr_context(tmp, &ctx, arena);
if (res != 0) goto failed;
@@ -5967,8 +5751,10 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
- failed:
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyString_AS_STRING(tmp));
+failed:
Py_XDECREF(tmp);
return 1;
}
@@ -5976,6 +5762,7 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
int
obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
@@ -6027,21 +5814,35 @@ obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyString_AS_STRING(tmp));
+failed:
+ Py_XDECREF(tmp);
return 1;
}
int
obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
- PyObject *tmp = NULL;
if (obj == Py_None) {
*out = NULL;
return 0;
}
+ isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type);
+ if (isinstance == -1) {
+ return 1;
+ }
+ if (isinstance) {
+
+ *out = Ellipsis(arena);
+ if (*out == NULL) goto failed;
+ return 0;
+ }
isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type);
if (isinstance == -1) {
return 1;
@@ -6051,9 +5852,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
expr_ty upper;
expr_ty step;
- if (_PyObject_HasAttrId(obj, &PyId_lower)) {
+ if (PyObject_HasAttrString(obj, "lower")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_lower);
+ tmp = PyObject_GetAttrString(obj, "lower");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &lower, arena);
if (res != 0) goto failed;
@@ -6062,9 +5863,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
} else {
lower = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_upper)) {
+ if (PyObject_HasAttrString(obj, "upper")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_upper);
+ tmp = PyObject_GetAttrString(obj, "upper");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &upper, arena);
if (res != 0) goto failed;
@@ -6073,9 +5874,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
} else {
upper = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_step)) {
+ if (PyObject_HasAttrString(obj, "step")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_step);
+ tmp = PyObject_GetAttrString(obj, "step");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &step, arena);
if (res != 0) goto failed;
@@ -6095,11 +5896,11 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
if (isinstance) {
asdl_seq* dims;
- if (_PyObject_HasAttrId(obj, &PyId_dims)) {
+ if (PyObject_HasAttrString(obj, "dims")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_dims);
+ tmp = PyObject_GetAttrString(obj, "dims");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -6131,9 +5932,9 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
if (isinstance) {
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -6148,8 +5949,10 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
- failed:
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyString_AS_STRING(tmp));
+failed:
Py_XDECREF(tmp);
return 1;
}
@@ -6157,6 +5960,7 @@ obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
int
obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
@@ -6176,13 +5980,18 @@ obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyString_AS_STRING(tmp));
+failed:
+ Py_XDECREF(tmp);
return 1;
}
int
obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
@@ -6282,13 +6091,18 @@ obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyString_AS_STRING(tmp));
+failed:
+ Py_XDECREF(tmp);
return 1;
}
int
obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
@@ -6324,13 +6138,18 @@ obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyString_AS_STRING(tmp));
+failed:
+ Py_XDECREF(tmp);
return 1;
}
int
obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
@@ -6414,7 +6233,11 @@ obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyString_AS_STRING(tmp));
+failed:
+ Py_XDECREF(tmp);
return 1;
}
@@ -6426,9 +6249,9 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
expr_ty iter;
asdl_seq* ifs;
- if (_PyObject_HasAttrId(obj, &PyId_target)) {
+ if (PyObject_HasAttrString(obj, "target")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_target);
+ tmp = PyObject_GetAttrString(obj, "target");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &target, arena);
if (res != 0) goto failed;
@@ -6438,9 +6261,9 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_iter)) {
+ if (PyObject_HasAttrString(obj, "iter")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_iter);
+ tmp = PyObject_GetAttrString(obj, "iter");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &iter, arena);
if (res != 0) goto failed;
@@ -6450,11 +6273,11 @@ obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_ifs)) {
+ if (PyObject_HasAttrString(obj, "ifs")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_ifs);
+ tmp = PyObject_GetAttrString(obj, "ifs");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -6485,9 +6308,9 @@ failed:
int
obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
{
+ PyObject* tmp = NULL;
int isinstance;
- PyObject *tmp = NULL;
int lineno;
int col_offset;
@@ -6495,9 +6318,9 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
*out = NULL;
return 0;
}
- if (_PyObject_HasAttrId(obj, &PyId_lineno)) {
+ if (PyObject_HasAttrString(obj, "lineno")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_lineno);
+ tmp = PyObject_GetAttrString(obj, "lineno");
if (tmp == NULL) goto failed;
res = obj2ast_int(tmp, &lineno, arena);
if (res != 0) goto failed;
@@ -6507,9 +6330,9 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_col_offset)) {
+ if (PyObject_HasAttrString(obj, "col_offset")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_col_offset);
+ tmp = PyObject_GetAttrString(obj, "col_offset");
if (tmp == NULL) goto failed;
res = obj2ast_int(tmp, &col_offset, arena);
if (res != 0) goto failed;
@@ -6525,12 +6348,12 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
}
if (isinstance) {
expr_ty type;
- identifier name;
+ expr_ty name;
asdl_seq* body;
- if (_PyObject_HasAttrId(obj, &PyId_type)) {
+ if (PyObject_HasAttrString(obj, "type")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_type);
+ tmp = PyObject_GetAttrString(obj, "type");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &type, arena);
if (res != 0) goto failed;
@@ -6539,22 +6362,22 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
} else {
type = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_name)) {
+ if (PyObject_HasAttrString(obj, "name")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_name);
+ tmp = PyObject_GetAttrString(obj, "name");
if (tmp == NULL) goto failed;
- res = obj2ast_identifier(tmp, &name, arena);
+ res = obj2ast_expr(tmp, &name, arena);
if (res != 0) goto failed;
Py_XDECREF(tmp);
tmp = NULL;
} else {
name = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_body)) {
+ if (PyObject_HasAttrString(obj, "body")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_body);
+ tmp = PyObject_GetAttrString(obj, "body");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -6581,8 +6404,10 @@ obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
return 0;
}
- PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
- failed:
+ tmp = PyObject_Repr(obj);
+ if (tmp == NULL) goto failed;
+ PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyString_AS_STRING(tmp));
+failed:
Py_XDECREF(tmp);
return 1;
}
@@ -6593,18 +6418,14 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
PyObject* tmp = NULL;
asdl_seq* args;
identifier vararg;
- expr_ty varargannotation;
- asdl_seq* kwonlyargs;
identifier kwarg;
- expr_ty kwargannotation;
asdl_seq* defaults;
- asdl_seq* kw_defaults;
- if (_PyObject_HasAttrId(obj, &PyId_args)) {
+ if (PyObject_HasAttrString(obj, "args")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_args);
+ tmp = PyObject_GetAttrString(obj, "args");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -6614,8 +6435,8 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
args = asdl_seq_new(len, arena);
if (args == NULL) goto failed;
for (i = 0; i < len; i++) {
- arg_ty value;
- res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena);
+ expr_ty value;
+ res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
asdl_seq_SET(args, i, value);
}
@@ -6625,9 +6446,9 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_vararg)) {
+ if (PyObject_HasAttrString(obj, "vararg")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_vararg);
+ tmp = PyObject_GetAttrString(obj, "vararg");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &vararg, arena);
if (res != 0) goto failed;
@@ -6636,45 +6457,9 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
} else {
vararg = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_varargannotation)) {
+ if (PyObject_HasAttrString(obj, "kwarg")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_varargannotation);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &varargannotation, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- varargannotation = NULL;
- }
- if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs);
- if (tmp == NULL) goto failed;
- if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name);
- goto failed;
- }
- len = PyList_GET_SIZE(tmp);
- kwonlyargs = asdl_seq_new(len, arena);
- if (kwonlyargs == NULL) goto failed;
- for (i = 0; i < len; i++) {
- arg_ty value;
- res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena);
- if (res != 0) goto failed;
- asdl_seq_SET(kwonlyargs, i, value);
- }
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
- return 1;
- }
- if (_PyObject_HasAttrId(obj, &PyId_kwarg)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_kwarg);
+ tmp = PyObject_GetAttrString(obj, "kwarg");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &kwarg, arena);
if (res != 0) goto failed;
@@ -6683,22 +6468,11 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
} else {
kwarg = NULL;
}
- if (_PyObject_HasAttrId(obj, &PyId_kwargannotation)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_kwargannotation);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &kwargannotation, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- kwargannotation = NULL;
- }
- if (_PyObject_HasAttrId(obj, &PyId_defaults)) {
+ if (PyObject_HasAttrString(obj, "defaults")) {
int res;
Py_ssize_t len;
Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_defaults);
+ tmp = PyObject_GetAttrString(obj, "defaults");
if (tmp == NULL) goto failed;
if (!PyList_Check(tmp)) {
PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
@@ -6719,70 +6493,7 @@ obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults);
- if (tmp == NULL) goto failed;
- if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name);
- goto failed;
- }
- len = PyList_GET_SIZE(tmp);
- kw_defaults = asdl_seq_new(len, arena);
- if (kw_defaults == NULL) goto failed;
- for (i = 0; i < len; i++) {
- expr_ty value;
- res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
- if (res != 0) goto failed;
- asdl_seq_SET(kw_defaults, i, value);
- }
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
- return 1;
- }
- *out = arguments(args, vararg, varargannotation, kwonlyargs, kwarg,
- kwargannotation, defaults, kw_defaults, arena);
- return 0;
-failed:
- Py_XDECREF(tmp);
- return 1;
-}
-
-int
-obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
-{
- PyObject* tmp = NULL;
- identifier arg;
- expr_ty annotation;
-
- if (_PyObject_HasAttrId(obj, &PyId_arg)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_arg);
- if (tmp == NULL) goto failed;
- res = obj2ast_identifier(tmp, &arg, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
- return 1;
- }
- if (_PyObject_HasAttrId(obj, &PyId_annotation)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_annotation);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &annotation, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- annotation = NULL;
- }
- *out = arg(arg, annotation, arena);
+ *out = arguments(args, vararg, kwarg, defaults, arena);
return 0;
failed:
Py_XDECREF(tmp);
@@ -6796,9 +6507,9 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
identifier arg;
expr_ty value;
- if (_PyObject_HasAttrId(obj, &PyId_arg)) {
+ if (PyObject_HasAttrString(obj, "arg")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_arg);
+ tmp = PyObject_GetAttrString(obj, "arg");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &arg, arena);
if (res != 0) goto failed;
@@ -6808,9 +6519,9 @@ obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from keyword");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_value)) {
+ if (PyObject_HasAttrString(obj, "value")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_value);
+ tmp = PyObject_GetAttrString(obj, "value");
if (tmp == NULL) goto failed;
res = obj2ast_expr(tmp, &value, arena);
if (res != 0) goto failed;
@@ -6834,9 +6545,9 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
identifier name;
identifier asname;
- if (_PyObject_HasAttrId(obj, &PyId_name)) {
+ if (PyObject_HasAttrString(obj, "name")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_name);
+ tmp = PyObject_GetAttrString(obj, "name");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &name, arena);
if (res != 0) goto failed;
@@ -6846,9 +6557,9 @@ obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
return 1;
}
- if (_PyObject_HasAttrId(obj, &PyId_asname)) {
+ if (PyObject_HasAttrString(obj, "asname")) {
int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_asname);
+ tmp = PyObject_GetAttrString(obj, "asname");
if (tmp == NULL) goto failed;
res = obj2ast_identifier(tmp, &asname, arena);
if (res != 0) goto failed;
@@ -6864,261 +6575,167 @@ failed:
return 1;
}
-int
-obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
-{
- PyObject* tmp = NULL;
- expr_ty context_expr;
- expr_ty optional_vars;
-
- if (_PyObject_HasAttrId(obj, &PyId_context_expr)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_context_expr);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &context_expr, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
- return 1;
- }
- if (_PyObject_HasAttrId(obj, &PyId_optional_vars)) {
- int res;
- tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars);
- if (tmp == NULL) goto failed;
- res = obj2ast_expr(tmp, &optional_vars, arena);
- if (res != 0) goto failed;
- Py_XDECREF(tmp);
- tmp = NULL;
- } else {
- optional_vars = NULL;
- }
- *out = withitem(context_expr, optional_vars, arena);
- return 0;
-failed:
- Py_XDECREF(tmp);
- return 1;
-}
-
-static struct PyModuleDef _astmodule = {
- PyModuleDef_HEAD_INIT, "_ast"
-};
PyMODINIT_FUNC
-PyInit__ast(void)
+init_ast(void)
{
PyObject *m, *d;
- if (!init_types()) return NULL;
- m = PyModule_Create(&_astmodule);
- if (!m) return NULL;
+ if (!init_types()) return;
+ m = Py_InitModule3("_ast", NULL, NULL);
+ if (!m) return;
d = PyModule_GetDict(m);
- if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return
- NULL;
+ if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return
- NULL;
+ return;
+ if (PyModule_AddStringConstant(m, "__version__", "82160") < 0)
+ return;
+ if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)
- < 0) return NULL;
+ < 0) return;
if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) <
- 0) return NULL;
- if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return
- NULL;
+ 0) return;
+ if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return;
+ if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return;
if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type)
- < 0) return NULL;
+ < 0) return;
if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
- 0) return NULL;
- if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return
- NULL;
+ 0) return;
+ if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
+ if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
+ if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
+ if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
+ if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
+ if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;
+ if (PyDict_SetItemString(d, "TryExcept", (PyObject*)TryExcept_type) <
+ 0) return;
+ if (PyDict_SetItemString(d, "TryFinally", (PyObject*)TryFinally_type) <
+ 0) return;
if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) <
- 0) return NULL;
+ 0) return;
+ if (PyDict_SetItemString(d, "Exec", (PyObject*)Exec_type) < 0) return;
if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return;
+ if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return;
+ if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return;
if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return;
if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return;
if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return;
+ if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return;
+ if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return;
if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "GeneratorExp",
- (PyObject*)GeneratorExp_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) <
- 0) return NULL;
+ (PyObject*)GeneratorExp_type) < 0) return;
+ if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return;
if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
- return NULL;
+ return;
+ if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
+ if (PyDict_SetItemString(d, "Repr", (PyObject*)Repr_type) < 0) return;
+ if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
+ if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
- 0) return NULL;
+ 0) return;
if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
- 0) return NULL;
- if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return
- NULL;
+ 0) return;
+ if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
+ if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return;
+ if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return;
if (PyDict_SetItemString(d, "expr_context",
- (PyObject*)expr_context_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return
- NULL;
+ (PyObject*)expr_context_type) < 0) return;
+ if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return;
+ if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return;
+ if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return;
if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
+ if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
+ if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
+ return;
+ if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL;
+ return;
+ if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return;
+ if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return;
if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return;
+ if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return;
+ if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return;
+ if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return;
+ if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return;
+ if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return;
if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return;
if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0)
- return NULL;
+ return;
if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL;
- if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return
- NULL;
+ return;
+ if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return;
+ if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return;
+ if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return;
+ if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return;
+ if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return;
+ if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return;
+ if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return;
+ if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return;
+ if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return;
+ if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return;
+ if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return;
+ if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return;
+ if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return;
+ if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return;
if (PyDict_SetItemString(d, "comprehension",
- (PyObject*)comprehension_type) < 0) return NULL;
+ (PyObject*)comprehension_type) < 0) return;
if (PyDict_SetItemString(d, "excepthandler",
- (PyObject*)excepthandler_type) < 0) return NULL;
+ (PyObject*)excepthandler_type) < 0) return;
if (PyDict_SetItemString(d, "ExceptHandler",
- (PyObject*)ExceptHandler_type) < 0) return NULL;
+ (PyObject*)ExceptHandler_type) < 0) return;
if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) <
- 0) return NULL;
- if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return
- NULL;
+ 0) return;
if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0)
- return NULL;
- if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return
- NULL;
- if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0)
- return NULL;
- return m;
+ return;
+ if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return;
}
@@ -7132,10 +6749,18 @@ PyObject* PyAST_mod2obj(mod_ty t)
mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
{
mod_ty res;
- PyObject *req_type[] = {(PyObject*)Module_type, (PyObject*)Expression_type,
- (PyObject*)Interactive_type};
- char *req_name[] = {"Module", "Expression", "Interactive"};
+ PyObject *req_type[3];
+ char *req_name[3];
int isinstance;
+
+ req_type[0] = (PyObject*)Module_type;
+ req_type[1] = (PyObject*)Expression_type;
+ req_type[2] = (PyObject*)Interactive_type;
+
+ req_name[0] = "Module";
+ req_name[1] = "Expression";
+ req_name[2] = "Interactive";
+
assert(0 <= mode && mode <= 2);
init_types();