enum _mod_kind {Module_kind=1, Interactive_kind=2, Expression_kind=3,
- FunctionType_kind=4, Suite_kind=5};
+ FunctionType_kind=4};
struct _mod {
enum _mod_kind kind;
union {
expr_ty returns;
} FunctionType;
- struct {
- asdl_seq *body;
- } Suite;
-
} v;
};
mod_ty _Py_Expression(expr_ty body, PyArena *arena);
#define FunctionType(a0, a1, a2) _Py_FunctionType(a0, a1, a2)
mod_ty _Py_FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena);
-#define Suite(a0, a1) _Py_Suite(a0, a1)
-mod_ty _Py_Suite(asdl_seq * body, PyArena *arena);
#define FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body,
asdl_seq * decorator_list, expr_ty returns, string
module Python
{
- mod = Module(stmt* body, type_ignore *type_ignores)
+ mod = Module(stmt* body, type_ignore* type_ignores)
| Interactive(stmt* body)
| Expression(expr body)
| FunctionType(expr* argtypes, expr returns)
- -- not really an actual node but useful in Jython's typesystem.
- | Suite(stmt* body)
-
stmt = FunctionDef(identifier name, arguments args,
stmt* body, expr* decorator_list, expr? returns,
string? type_comment)
| Expr(expr value)
| Pass | Break | Continue
- -- XXX Jython will be different
-- col_offset is the byte offset in the utf8 string the parser uses
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
PyObject *Sub_singleton;
PyObject *Sub_type;
PyObject *Subscript_type;
- PyObject *Suite_type;
PyObject *Try_type;
PyObject *Tuple_type;
PyObject *TypeIgnore_type;
Py_CLEAR(astmodulestate(module)->Sub_singleton);
Py_CLEAR(astmodulestate(module)->Sub_type);
Py_CLEAR(astmodulestate(module)->Subscript_type);
- Py_CLEAR(astmodulestate(module)->Suite_type);
Py_CLEAR(astmodulestate(module)->Try_type);
Py_CLEAR(astmodulestate(module)->Tuple_type);
Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
Py_VISIT(astmodulestate(module)->Sub_singleton);
Py_VISIT(astmodulestate(module)->Sub_type);
Py_VISIT(astmodulestate(module)->Subscript_type);
- Py_VISIT(astmodulestate(module)->Suite_type);
Py_VISIT(astmodulestate(module)->Try_type);
Py_VISIT(astmodulestate(module)->Tuple_type);
Py_VISIT(astmodulestate(module)->TypeIgnore_type);
"argtypes",
"returns",
};
-static const char * const Suite_fields[]={
- "body",
-};
static const char * const stmt_attributes[] = {
"lineno",
"col_offset",
state->FunctionType_type = make_type("FunctionType", state->mod_type,
FunctionType_fields, 2);
if (!state->FunctionType_type) return 0;
- state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1);
- if (!state->Suite_type) return 0;
state->stmt_type = make_type("stmt", state->AST_type, NULL, 0);
if (!state->stmt_type) return 0;
if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
return p;
}
-mod_ty
-Suite(asdl_seq * body, PyArena *arena)
-{
- mod_ty p;
- p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
- if (!p)
- return NULL;
- p->kind = Suite_kind;
- p->v.Suite.body = body;
- return p;
-}
-
stmt_ty
FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
decorator_list, expr_ty returns, string type_comment, int lineno,
goto failed;
Py_DECREF(value);
break;
- case Suite_kind:
- tp = (PyTypeObject *)astmodulestate_global->Suite_type;
- result = PyType_GenericNew(tp, NULL, NULL);
- if (!result) goto failed;
- value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
- if (!value) goto failed;
- if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
- goto failed;
- Py_DECREF(value);
- break;
}
return result;
failed:
if (*out == NULL) goto failed;
return 0;
}
- tp = astmodulestate_global->Suite_type;
- isinstance = PyObject_IsInstance(obj, tp);
- if (isinstance == -1) {
- return 1;
- }
- if (isinstance) {
- asdl_seq* body;
-
- if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
- return 1;
- }
- if (tmp == NULL) {
- PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
- return 1;
- }
- else {
- int res;
- Py_ssize_t len;
- Py_ssize_t i;
- if (!PyList_Check(tmp)) {
- PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
- goto failed;
- }
- len = PyList_GET_SIZE(tmp);
- body = _Py_asdl_seq_new(len, arena);
- if (body == NULL) goto failed;
- for (i = 0; i < len; i++) {
- stmt_ty val;
- PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
- Py_INCREF(tmp2);
- res = obj2ast_stmt(tmp2, &val, arena);
- Py_DECREF(tmp2);
- if (res != 0) goto failed;
- if (len != PyList_GET_SIZE(tmp)) {
- PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
- goto failed;
- }
- asdl_seq_SET(body, i, val);
- }
- Py_CLEAR(tmp);
- }
- *out = Suite(body, arena);
- if (*out == NULL) goto failed;
- return 0;
- }
PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
failed:
goto error;
}
Py_INCREF(astmodulestate(m)->FunctionType_type);
- if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0) {
- goto error;
- }
- Py_INCREF(astmodulestate(m)->Suite_type);
if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
goto error;
}