Mercurial > cpython-lru_cache-weakref
diff Python/Python-ast.c @ 37453:16a64e394602 legacy-trunk
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.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Tue, 04 Apr 2006 04:00:23 +0000 |
| parents | dfc33ec7f73a |
| children | a9470eb637f1 |
line wrap: on
line diff
--- a/Python/Python-ast.c Tue Apr 04 03:05:44 2006 +0000 +++ b/Python/Python-ast.c Tue Apr 04 04:00:23 2006 +0000 @@ -331,6 +331,8 @@ "type", "name", "body", + "lineno", + "col_offset", }; static PyTypeObject *arguments_type; static PyObject* ast2obj_arguments(void*); @@ -712,7 +714,7 @@ 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 @@ } 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 @@ p->type = type; p->name = name; p->body = body; + p->lineno = lineno; + p->col_offset = col_offset; return p; } @@ -2917,6 +2922,16 @@ 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 @@ 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)
