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
commit2f327c14eb998e8796a3775aa6a7aade14e97004 (patch)
tree3de98142ca2b873c0cfb25f630c7dda2d90f96fa /Python/Python-ast.c
parentcb30f97bd3bdea2e884e8faec23751b39db4c0b3 (diff)
downloadcpython-git-2f327c14eb998e8796a3775aa6a7aade14e97004.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)