From: <fwi...@us...> - 2009-01-08 02:09:02
|
Revision: 5875 http://jython.svn.sourceforge.net/jython/?rev=5875&view=rev Author: fwierzbicki Date: 2009-01-08 02:08:58 +0000 (Thu, 08 Jan 2009) Log Message: ----------- 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: -------------- trunk/jython/ast/Python.asdl trunk/jython/ast/asdl_antlr.py trunk/jython/src/org/python/antlr/ast/ExceptHandler.java trunk/jython/src/org/python/antlr/ast/Raise.java trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/ast/Python.asdl =================================================================== --- trunk/jython/ast/Python.asdl 2009-01-08 00:34:35 UTC (rev 5874) +++ trunk/jython/ast/Python.asdl 2009-01-08 02:08:58 UTC (rev 5875) @@ -28,8 +28,7 @@ | With(expr context_expr, expr? optional_vars, stmt* body) -- 'type' is a bad name - -- changed to 'type' to excepttype for Jython - | Raise(expr? excepttype, expr? inst, expr? tback) + | Raise(expr? type, expr? inst, expr? tback) | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse) | TryFinally(stmt* body, stmt* finalbody) | Assert(expr test, expr? msg) @@ -99,8 +98,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, expr? name, stmt* body) + excepthandler = ExceptHandler(expr? type, expr? name, stmt* body) attributes (int lineno, int col_offset) arguments = (expr* args, identifier? vararg, Modified: trunk/jython/ast/asdl_antlr.py =================================================================== --- trunk/jython/ast/asdl_antlr.py 2009-01-08 00:34:35 UTC (rev 5874) +++ trunk/jython/ast/asdl_antlr.py 2009-01-08 02:08:58 UTC (rev 5875) @@ -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: trunk/jython/src/org/python/antlr/ast/ExceptHandler.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExceptHandler.java 2009-01-08 00:34:35 UTC (rev 5874) +++ trunk/jython/src/org/python/antlr/ast/ExceptHandler.java 2009-01-08 02:08:58 UTC (rev 5875) @@ -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 expr name; @@ -69,7 +69,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; } @@ -88,8 +88,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); @@ -104,16 +104,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, expr name, java.util.List<stmt> body) { + public ExceptHandler(Token token, expr type, expr name, java.util.List<stmt> body) { super(token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; addChild(name); this.body = body; @@ -125,11 +125,11 @@ } } - public ExceptHandler(Integer ttype, Token token, expr excepttype, expr name, - java.util.List<stmt> body) { + public ExceptHandler(Integer ttype, Token token, expr type, expr name, java.util.List<stmt> + body) { super(ttype, token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; addChild(name); this.body = body; @@ -141,10 +141,10 @@ } } - public ExceptHandler(PythonTree tree, expr excepttype, expr name, java.util.List<stmt> body) { + public ExceptHandler(PythonTree tree, expr type, expr name, java.util.List<stmt> body) { super(tree); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.name = name; addChild(name); this.body = body; @@ -163,8 +163,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)); @@ -181,8 +181,8 @@ } public void traverse(VisitorIF visitor) throws Exception { - if (excepttype != null) - excepttype.accept(visitor); + if (type != null) + type.accept(visitor); if (name != null) name.accept(visitor); if (body != null) { Modified: trunk/jython/src/org/python/antlr/ast/Raise.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Raise.java 2009-01-08 00:34:35 UTC (rev 5874) +++ trunk/jython/src/org/python/antlr/ast/Raise.java 2009-01-08 02:08:58 UTC (rev 5875) @@ -28,17 +28,17 @@ @ExposedType(name = "_ast.Raise", base = AST.class) public class Raise extends stmt { public static final PyType TYPE = PyType.fromClass(Raise.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 expr inst; @@ -69,7 +69,7 @@ private final static PyString[] fields = - new PyString[] {new PyString("excepttype"), new PyString("inst"), new PyString("tback")}; + new PyString[] {new PyString("type"), new PyString("inst"), new PyString("tback")}; @ExposedGet(name = "_fields") public PyString[] get_fields() { return fields; } @@ -88,8 +88,8 @@ @ExposedMethod public void Raise___init__(PyObject[] args, String[] keywords) { ArgParser ap = new ArgParser("Raise", args, keywords, new String[] - {"excepttype", "inst", "tback", "lineno", "col_offset"}, 3); - setExcepttype(ap.getPyObject(0)); + {"type", "inst", "tback", "lineno", "col_offset"}, 3); + setExceptType(ap.getPyObject(0)); setInst(ap.getPyObject(1)); setTback(ap.getPyObject(2)); int lin = ap.getInt(3, -1); @@ -104,36 +104,36 @@ } - public Raise(PyObject excepttype, PyObject inst, PyObject tback) { - setExcepttype(excepttype); + public Raise(PyObject type, PyObject inst, PyObject tback) { + setExceptType(type); setInst(inst); setTback(tback); } - public Raise(Token token, expr excepttype, expr inst, expr tback) { + public Raise(Token token, expr type, expr inst, expr tback) { super(token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.inst = inst; addChild(inst); this.tback = tback; addChild(tback); } - public Raise(Integer ttype, Token token, expr excepttype, expr inst, expr tback) { + public Raise(Integer ttype, Token token, expr type, expr inst, expr tback) { super(ttype, token); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.inst = inst; addChild(inst); this.tback = tback; addChild(tback); } - public Raise(PythonTree tree, expr excepttype, expr inst, expr tback) { + public Raise(PythonTree tree, expr type, expr inst, expr tback) { super(tree); - this.excepttype = excepttype; - addChild(excepttype); + this.type = type; + addChild(type); this.inst = inst; addChild(inst); this.tback = tback; @@ -147,8 +147,8 @@ public String toStringTree() { StringBuffer sb = new StringBuffer("Raise("); - sb.append("excepttype="); - sb.append(dumpThis(excepttype)); + sb.append("type="); + sb.append(dumpThis(type)); sb.append(","); sb.append("inst="); sb.append(dumpThis(inst)); @@ -165,8 +165,8 @@ } public void traverse(VisitorIF visitor) throws Exception { - if (excepttype != null) - excepttype.accept(visitor); + if (type != null) + type.accept(visitor); if (inst != null) inst.accept(visitor); if (tback != null) Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-01-08 00:34:35 UTC (rev 5874) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-01-08 02:08:58 UTC (rev 5875) @@ -751,10 +751,10 @@ @Override public Object visitRaise(Raise node) throws Exception { setline(node); - if (node.getInternalExcepttype() != null) { visit(node.getInternalExcepttype()); stackProduce(); } + if (node.getInternalType() != null) { visit(node.getInternalType()); stackProduce(); } if (node.getInternalInst() != null) { visit(node.getInternalInst()); stackProduce(); } if (node.getInternalTback() != null) { visit(node.getInternalTback()); stackProduce(); } - if (node.getInternalExcepttype() == null) { + if (node.getInternalType() == null) { code.invokestatic("org/python/core/Py", "makeException", "()" + $pyExc); } else if (node.getInternalInst() == null) { stackConsume(); @@ -1117,10 +1117,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. |