summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 94e04b1..1b5e18f 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -934,13 +934,20 @@ PyObject* PyAST_mod2obj(mod_ty t)
return ast2obj_mod(t);
}
-mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena)
+/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
+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"};
+ assert(0 <= mode && mode <= 2);
+
init_types();
- if (!PyObject_IsInstance(ast, (PyObject*)mod_type)) {
- PyErr_SetString(PyExc_TypeError, "expected either Module, Interactive "
- "or Expression node");
+
+ if (!PyObject_IsInstance(ast, req_type[mode])) {
+ PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
+ req_name[mode], Py_TYPE(ast)->tp_name);
return NULL;
}
if (obj2ast_mod(ast, &res, arena) != 0)
@@ -997,8 +1004,8 @@ def main(srcfile):
)
c.visit(mod)
f.write("PyObject* PyAST_mod2obj(mod_ty t);\n")
- print >>f, "mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena);"
- print >>f, "int PyAST_Check(PyObject* obj);"
+ f.write("mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode);\n")
+ f.write("int PyAST_Check(PyObject* obj);\n")
f.close()
if SRC_DIR: