diff -r d638b2c5ef28 Lib/test/test_ast.py --- a/Lib/test/test_ast.py Sat Oct 21 12:24:14 2017 +0100 +++ b/Lib/test/test_ast.py Fri Oct 27 10:41:45 2017 -0400 @@ -1,4 +1,4 @@ -import sys, itertools, unittest +import sys, itertools, unittest, traceback from test import test_support import ast @@ -290,6 +290,19 @@ self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None)) self.assertRaises(ValueError, ast.literal_eval, 'foo()') + def test_uses_lineno(self): + node = ast.Module(body=[ast.Expr(value=ast.Name(id='x', ctx=ast.Load()),lineno=42)]) + node = ast.fix_missing_locations(node) + exc = None + try: + exec compile(node,'','exec') + except: + exc = traceback.format_tb(sys.exc_info()[2]) + assert exc is not None + + # can only check the last line of the stack trace: + self.assertEqual(exc[-1],' File "", line 42, in \n') + def test_main(): #XXX: AST pickling is left as a TODO for now. diff -r d638b2c5ef28 src/org/python/antlr/ParseException.java --- a/src/org/python/antlr/ParseException.java Sat Oct 21 12:24:14 2017 +0100 +++ b/src/org/python/antlr/ParseException.java Fri Oct 27 10:41:45 2017 -0400 @@ -35,7 +35,7 @@ * n must not be null to use this constructor */ public ParseException(String message, PythonTree n) { - this(message, n.getLine(), n.getCharPositionInLine()); + this(message, n.getLineno(), n.getCol_offset()); this.node = n; this.token = n.getToken(); } diff -r d638b2c5ef28 src/org/python/antlr/PythonTree.java --- a/src/org/python/antlr/PythonTree.java Sat Oct 21 12:24:14 2017 +0100 +++ b/src/org/python/antlr/PythonTree.java Fri Oct 27 10:41:45 2017 -0400 @@ -78,7 +78,7 @@ return node.getText(); } - public int getLine() { + protected int getLine() { if (node.getToken()==null || node.getToken().getLine()==0) { if ( getChildCount()>0 ) { return getChild(0).getLine(); @@ -88,7 +88,7 @@ return node.getToken().getLine(); } - public int getCharPositionInLine() { + protected int getCharPositionInLine() { Token token = node.getToken(); if (token==null || token.getCharPositionInLine()==-1) { if (getChildCount()>0) { @@ -105,6 +105,14 @@ return token.getCharPositionInLine(); } + public int getLineno() { + return getLine(); + } + + public int getCol_offset() { + return getCharPositionInLine(); + } + public int getTokenStartIndex() { return node.getTokenStartIndex(); } diff -r d638b2c5ef28 src/org/python/compiler/CodeCompiler.java --- a/src/org/python/compiler/CodeCompiler.java Sat Oct 21 12:24:14 2017 +0100 +++ b/src/org/python/compiler/CodeCompiler.java Fri Oct 27 10:41:45 2017 -0400 @@ -183,7 +183,7 @@ } public void setline(PythonTree node) throws Exception { - setline(node.getLine()); + setline(node.getLineno()); } public void set(PythonTree node) throws Exception { @@ -509,7 +509,7 @@ scope.setup_closure(); scope.dump(); module.codeConstant(new Suite(node, node.getInternalBody()), name, true, className, false, - false, node.getLine(), scope, cflags).get(code); + false, node.getLineno(), scope, cflags).get(code); Str docStr = getDocStr(node.getInternalBody()); if (docStr != null) { @@ -2168,7 +2168,7 @@ code.ldc("append"); code.invokevirtual(p(PyObject.class), "__getattr__", sig(PyObject.class, String.class)); - String tmp_append = "_[" + node.getLine() + "_" + node.getCharPositionInLine() + "]"; + String tmp_append = "_[" + node.getLineno() + "_" + node.getCol_offset() + "]"; java.util.List args = new ArrayList(); args.add(node.getInternalElt()); @@ -2312,7 +2312,7 @@ scope.setup_closure(); scope.dump(); - module.codeConstant(retSuite, name, true, className, false, false, node.getLine(), scope, + module.codeConstant(retSuite, name, true, className, false, false, node.getLineno(), scope, cflags).get(code); if (!makeClosure(scope)) { @@ -2387,7 +2387,7 @@ // Make code object out of suite module.codeConstant(new Suite(node, node.getInternalBody()), name, false, name, - getDocStr(node.getInternalBody()), true, false, node.getLine(), scope, cflags).get( + getDocStr(node.getInternalBody()), true, false, node.getLineno(), scope, cflags).get( code); // Make class out of name, bases, and code @@ -2608,7 +2608,7 @@ java.util.List bod = new ArrayList(); bod.add(n); module.codeConstant(new Suite(node, bod), "", true, className, false, false, - node.getLine(), scope, cflags).get(code); + node.getLineno(), scope, cflags).get(code); code.aconst_null(); if (!makeClosure(scope)) { @@ -2681,7 +2681,7 @@ java.util.List bod = new ArrayList(); bod.add(n); module.codeConstant(new Suite(node, bod), "", true, className, false, false, - node.getLine(), scope, cflags).get(code); + node.getLineno(), scope, cflags).get(code); code.aconst_null(); if (!makeClosure(scope)) { diff -r d638b2c5ef28 src/org/python/compiler/Module.java --- a/src/org/python/compiler/Module.java Sat Oct 21 12:24:14 2017 +0100 +++ b/src/org/python/compiler/Module.java Fri Oct 27 10:41:45 2017 -0400 @@ -685,7 +685,7 @@ if (!err) { try { Py.warning(Py.SyntaxWarning, msg, (sfilename != null) ? sfilename : "?", - node.getLine(), null, Py.None); + node.getLineno(), null, Py.None); return; } catch (PyException e) { if (!e.match(Py.SyntaxWarning)) { diff -r d638b2c5ef28 src/org/python/compiler/ScopesCompiler.java --- a/src/org/python/compiler/ScopesCompiler.java Sat Oct 21 12:24:14 2017 +0100 +++ b/src/org/python/compiler/ScopesCompiler.java Fri Oct 27 10:41:45 2017 -0400 @@ -285,7 +285,7 @@ @Override public Object visitListComp(ListComp node) throws Exception { - String tmp = "_[" + node.getLine() + "_" + node.getCharPositionInLine() + String tmp = "_[" + node.getLineno() + "_" + node.getCol_offset() + "]"; cur.addBound(tmp); traverse(node); @@ -328,7 +328,7 @@ visit(generators.get(0).getInternalIter()); } String bound_exp = "_(x)"; - String tmp = "_(" + node.getLine() + "_" + node.getCharPositionInLine() + String tmp = "_(" + node.getLineno() + "_" + node.getCol_offset() + ")"; def(tmp); ArgListCompiler ac = new ArgListCompiler(); diff -r d638b2c5ef28 src/org/python/core/ParserFacade.java --- a/src/org/python/core/ParserFacade.java Sat Oct 21 12:24:14 2017 +0100 +++ b/src/org/python/core/ParserFacade.java Fri Oct 27 10:41:45 2017 -0400 @@ -84,8 +84,8 @@ int line=e.line; int col=e.charPositionInLine; if (node != null) { - line = node.getLine(); - col = node.getCharPositionInLine(); + line = node.getLineno(); + col = node.getCol_offset(); } String text= getLine(reader, line); String msg = e.getMessage();