From: <fwi...@us...> - 2009-01-08 02:21:22
|
Revision: 5876 http://jython.svn.sourceforge.net/jython/?rev=5876&view=rev Author: fwierzbicki Date: 2009-01-08 02:21:17 +0000 (Thu, 08 Jan 2009) Log Message: ----------- Merged revisions 5875 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5875 | fwierzbicki | 2009-01-07 21:08:58 -0500 (Wed, 07 Jan 2009) | 4 lines Change to Raise and ExceptHandler so that Python sees the properly named "type" field, but the getters and setters are mangled to getExceptType so PyObject's getType method is not in conflict. ........ Modified Paths: -------------- branches/jy3k/ast/Python.asdl branches/jy3k/ast/asdl_antlr.py branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java branches/jy3k/src/org/python/compiler/CodeCompiler.java Property Changed: ---------------- branches/jy3k/ Property changes on: branches/jy3k ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5872 + /trunk/jython:1-5875 Modified: branches/jy3k/ast/Python.asdl =================================================================== --- branches/jy3k/ast/Python.asdl 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/ast/Python.asdl 2009-01-08 02:21:17 UTC (rev 5876) @@ -101,8 +101,7 @@ comprehension = (expr target, expr iter, expr* ifs) -- not sure what to call the first argument for raise and except - -- changed to 'type' to excepttype for Jython - excepthandler = ExceptHandler(expr? excepttype, identifier? name, stmt* body) + excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) attributes (int lineno, int col_offset) arguments = (arg* args, identifier? vararg, expr? varargannotation, Modified: branches/jy3k/ast/asdl_antlr.py =================================================================== --- branches/jy3k/ast/asdl_antlr.py 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/ast/asdl_antlr.py 2009-01-08 02:21:17 UTC (rev 5876) @@ -484,7 +484,7 @@ self.emit('{%s}, %s);' % (fpargs, len(fields)), depth + 2) i = 0 for f in fields: - self.emit("set%s(ap.getPyObject(%s));" % (str(f.name).capitalize(), + self.emit("set%s(ap.getPyObject(%s));" % (self.processFieldName(f.name), str(i)), depth+1) i += 1 if str(name) in ('stmt', 'expr', 'excepthandler'): @@ -506,8 +506,7 @@ fpargs = ", ".join(["PyObject %s" % f.name for f in fields]) self.emit("public %s(%s) {" % (clsname, fpargs), depth) for f in fields: - self.emit("set%s(%s);" % (str(f.name).capitalize(), - f.name), depth+1) + self.emit("set%s(%s);" % (self.processFieldName(f.name), f.name), depth+1) self.emit("}", depth) self.emit("", 0) @@ -539,6 +538,14 @@ self.emit("", 0) + #This is mainly a kludge to turn get/setType -> get/setExceptType because + #getType conflicts with a method on PyObject. + def processFieldName(self, name): + name = str(name).capitalize() + if name == "Type": + name = "ExceptType" + return name + def visitField(self, field, depth): self.emit("private %s;" % self.fieldDef(field), depth) self.emit("public %s getInternal%s() {" % (self.javaType(field), @@ -546,7 +553,7 @@ self.emit("return %s;" % field.name, depth+1) self.emit("}", depth) self.emit('@ExposedGet(name = "%s")' % field.name, depth) - self.emit("public PyObject get%s() {" % (str(field.name).capitalize()), depth) + self.emit("public PyObject get%s() {" % self.processFieldName(field.name), depth) if field.seq: self.emit("return new AstList(%s, AstAdapters.%sAdapter);" % (field.name, field.type), depth+1) else: @@ -567,8 +574,7 @@ #self.emit("return Py.None;", depth+1) self.emit("}", depth) self.emit('@ExposedSet(name = "%s")' % field.name, depth) - self.emit("public void set%s(PyObject %s) {" % (str(field.name).capitalize(), - field.name), depth) + self.emit("public void set%s(PyObject %s) {" % (self.processFieldName(field.name), field.name), depth) if field.seq: #self.emit("this.%s = new %s(" % (field.name, self.javaType(field)), depth+1) self.emit("this.%s = AstAdapters.py2%sList(%s);" % (field.name, str(field.type), field.name), depth+1) Modified: branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java =================================================================== --- branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/src/org/python/antlr/ast/ExceptHandler.java 2009-01-08 02:21:17 UTC (rev 5876) @@ -28,17 +28,17 @@ @ExposedType(name = "_ast.ExceptHandler", base = AST.class) public class ExceptHandler extends excepthandler { public static final PyType TYPE = PyType.fromClass(ExceptHandler.class); - private expr excepttype; - public expr getInternalExcepttype() { - return excepttype; + private expr type; + public expr getInternalType() { + return type; } - @ExposedGet(name = "excepttype") - public PyObject getExcepttype() { - return excepttype; + @ExposedGet(name = "type") + public PyObject getExceptType() { + return type; } - @ExposedSet(name = "excepttype") - public void setExcepttype(PyObject excepttype) { - this.excepttype = AstAdapters.py2expr(excepttype); + @ExposedSet(name = "type") + public void setExceptType(PyObject type) { + this.type = AstAdapters.py2expr(type); } private String name; @@ -70,7 +70,7 @@ private final static PyString[] fields = - new PyString[] {new PyString("excepttype"), new PyString("name"), new PyString("body")}; + new PyString[] {new PyString("type"), new PyString("name"), new PyString("body")}; @ExposedGet(name = "_fields") public PyString[] get_fields() { return fields; } @@ -89,8 +89,8 @@ @ExposedMethod public void ExceptHandler___init__(PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("ExceptHandler", args, keywords, new String[] - {"excepttype", "name", "body", "lineno", "col_offset"}, 3); - setExcepttype(ap.getPyObject(0)); + {"type", "name", "body", "lineno", "col_offset"}, 3); + setExceptType(ap.getPyObject(0)); setName(ap.getPyObject(1)); setBody(ap.getPyObject(2)); int lin = ap.getInt(3, -1); @@ -105,16 +105,16 @@ } - public ExceptHandler(PyObject excepttype, PyObject name, PyObject body) { - setExcepttype(excepttype); + public ExceptHandler(PyObject type, PyObject name, PyObject body) { + setExceptType(type); setName(name); setBody(body); } - public ExceptHandler(Token token, expr excepttype, String name, java.util.List<stmt> body) { + public ExceptHandler(Token token, expr type, String name, java.util.List<stmt> body) { super(token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; this.body = body; if (body == null) { @@ -125,11 +125,11 @@ } } - public ExceptHandler(Integer ttype, Token token, expr excepttype, String name, - java.util.List<stmt> body) { + public ExceptHandler(Integer ttype, Token token, expr type, String name, java.util.List<stmt> + body) { super(ttype, token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; this.body = body; if (body == null) { @@ -140,10 +140,10 @@ } } - public ExceptHandler(PythonTree tree, expr excepttype, String name, java.util.List<stmt> body) { + public ExceptHandler(PythonTree tree, expr type, String name, java.util.List<stmt> body) { super(tree); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; this.body = body; if (body == null) { @@ -161,8 +161,8 @@ public String toStringTree() { StringBuffer sb = new StringBuffer("ExceptHandler("); - sb.append("excepttype="); - sb.append(dumpThis(excepttype)); + sb.append("type="); + sb.append(dumpThis(type)); sb.append(","); sb.append("name="); sb.append(dumpThis(name)); @@ -179,8 +179,8 @@ } public void traverse(VisitorIF visitor) throws Exception { - if (excepttype != null) - excepttype.accept(visitor); + if (type != null) + type.accept(visitor); if (body != null) { for (PythonTree t : body) { if (t != null) Modified: branches/jy3k/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-08 02:08:58 UTC (rev 5875) +++ branches/jy3k/src/org/python/compiler/CodeCompiler.java 2009-01-08 02:21:17 UTC (rev 5876) @@ -1041,10 +1041,10 @@ //setline(name); Label end_of_self = new Label(); - if (handler.getInternalExcepttype() != null) { + if (handler.getInternalType() != null) { code.aload(exc); //get specific exception - visit(handler.getInternalExcepttype()); + visit(handler.getInternalType()); code.invokestatic("org/python/core/Py", "matchException", "(" + $pyExc + $pyObj + ")Z"); code.ifeq(end_of_self); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |