From: <fwi...@us...> - 2008-08-13 00:30:40
|
Revision: 5164 http://jython.svn.sourceforge.net/jython/?rev=5164&view=rev Author: fwierzbicki Date: 2008-08-13 00:30:38 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Before this check-in there was an AST inconsistency with CPython. To pick one example, CPython's AST for --1 is (USub(-1)) and Jython is (Usub(Usub(1)). This fixes that inconsistency. Modified Paths: -------------- branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-12 22:58:47 UTC (rev 5163) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 00:30:38 UTC (rev 5164) @@ -4,6 +4,10 @@ import org.antlr.runtime.Token; import org.python.core.Py; +import org.python.core.PyComplex; +import org.python.core.PyFloat; +import org.python.core.PyInteger; +import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyUnicode; @@ -85,7 +89,6 @@ public class GrammarActions { private ErrorHandler errorHandler = null; - public GrammarActions() { } @@ -448,10 +451,31 @@ exprType negate(PythonTree t, exprType o) { if (o instanceof Num) { Num num = (Num)o; - if (num.n instanceof PyObject) { - num.n = ((PyObject)num.n).__neg__(); + if (num.n instanceof PyInteger) { + int v = ((PyInteger)num.n).getValue(); + if (v > 0) { + num.n = new PyInteger(-v); + return num; + } + } else if (num.n instanceof PyLong) { + BigInteger v = ((PyLong)num.n).getValue(); + if (v.compareTo(BigInteger.ZERO) == 1) { + num.n = new PyLong(v.negate()); + return num; + } + } else if (num.n instanceof PyFloat) { + double v = ((PyFloat)num.n).getValue(); + if (v > 0) { + num.n = new PyFloat(-v); + return num; + } + } else if (num.n instanceof PyComplex) { + double v = ((PyComplex)num.n).imag; + if (v > 0) { + num.n = new PyComplex(0,-v); + return num; + } } - return num; } return new UnaryOp(t, unaryopType.USub, o); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |