summaryrefslogtreecommitdiff
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2006-04-04 04:00:23 +0000
committerJeremy Hylton <jeremy@alum.mit.edu>2006-04-04 04:00:23 +0000
commitfd0a654fa9ef5097caaf2948a6967c357a7964c0 (patch)
treedda2b62758a16d957407181b8a4a9bbec4b0beb1 /Python/Python-ast.c
parent3bbfd9761b50446e7e945a0713bc625e4e8b46ae (diff)
downloadcpython-fd0a654fa9ef5097caaf2948a6967c357a7964c0.tar.gz
Add lineno, col_offset to excephandler to enable future fix for
tracing/line number table in except blocks. Reflow long lines introduced by col_offset changes. Update test_ast to handle new fields in excepthandler. As note in Python.asdl says, we might want to rethink how attributes are handled. Perhaps they should be the same as other fields, with the primary difference being how they are defined for all types within a sum. Also fix asdl_c so that constructors with int fields don't fail when passed a zero value.
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r--Python/Python-ast.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index d981af861c..8b9400b32d 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -331,6 +331,8 @@ static char *excepthandler_fields[]={
"type",
"name",
"body",
+ "lineno",
+ "col_offset",
};
static PyTypeObject *arguments_type;
static PyObject* ast2obj_arguments(void*);
@@ -712,7 +714,7 @@ static int init_types(void)
comprehension_fields, 3);
if (!comprehension_type) return 0;
excepthandler_type = make_type("excepthandler", AST_type,
- excepthandler_fields, 3);
+ excepthandler_fields, 5);
if (!excepthandler_type) return 0;
arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
if (!arguments_type) return 0;
@@ -1843,7 +1845,8 @@ comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, PyArena *arena)
}
excepthandler_ty
-excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
+excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
+ col_offset, PyArena *arena)
{
excepthandler_ty p;
p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
@@ -1854,6 +1857,8 @@ excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena)
p->type = type;
p->name = name;
p->body = body;
+ p->lineno = lineno;
+ p->col_offset = col_offset;
return p;
}
@@ -2917,6 +2922,16 @@ ast2obj_excepthandler(void* _o)
if (PyObject_SetAttrString(result, "body", value) == -1)
goto failed;
Py_DECREF(value);
+ value = ast2obj_int(o->lineno);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "lineno", value) == -1)
+ goto failed;
+ Py_DECREF(value);
+ value = ast2obj_int(o->col_offset);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "col_offset", value) == -1)
+ goto failed;
+ Py_DECREF(value);
return result;
failed:
Py_XDECREF(value);
@@ -3033,7 +3048,7 @@ init_ast(void)
if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
return;
- if (PyModule_AddStringConstant(m, "__version__", "42753") < 0)
+ if (PyModule_AddStringConstant(m, "__version__", "") < 0)
return;
if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)