| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Jython
Revision: 5287
Author: fwierzbicki
Date: 03 Sep 2008 11:24:20
Changes:Small cleanup of compiler package. Mainly remove unused imports and rename
local vars that shadow member vars.
| ... | ...@@ -4,7 +4,6 @@ | |
| 4 | 4 | |
| 5 | 5 | import java.io.IOException; |
| 6 | 6 | |
| 7 | import org.python.objectweb.asm.MethodVisitor; | |
| 8 | 7 | import org.python.objectweb.asm.Opcodes; |
| 9 | 8 | |
| 10 | 9 | abstract class Constant implements Opcodes{ |
| ... | ...@@ -211,7 +211,7 @@ | |
| 211 | 211 | } |
| 212 | 212 | break; |
| 213 | 213 | case 'L': |
| 214 | while (c[++i] != ';') {;} | |
| 214 | while (c[++i] != ';') {} | |
| 215 | 215 | default: |
| 216 | 216 | if (ret) stack++; |
| 217 | 217 | else stack--; |
| ... | ...@@ -4,11 +4,9 @@ | |
| 4 | 4 | |
| 5 | 5 | import java.io.OutputStream; |
| 6 | 6 | import java.lang.reflect.Method; |
| 7 | import java.util.Set; | |
| 8 | 7 | import java.util.HashSet; |
| 9 | 8 | |
| 10 | 9 | import org.python.objectweb.asm.Label; |
| 11 | import org.python.objectweb.asm.MethodVisitor; | |
| 12 | 10 | import org.python.objectweb.asm.Opcodes; |
| 13 | 11 | |
| 14 | 12 | |
| ... | ...@@ -41,12 +39,14 @@ | |
| 41 | 39 | return pm.myClass; |
| 42 | 40 | } |
| 43 | 41 | |
| 42 | @Override | |
| 44 | 43 | public void doConstants() throws Exception { |
| 45 | 44 | for (String name : names) { |
| 46 | 45 | classfile.addField(name, "Lorg/python/core/PyObject;", Opcodes.ACC_PUBLIC); |
| 47 | 46 | } |
| 48 | 47 | } |
| 49 | 48 | |
| 49 | @Override | |
| 50 | 50 | public void addMethod(Method method, int access) throws Exception { |
| 51 | 51 | Class<?>[] parameters = method.getParameterTypes(); |
| 52 | 52 | Class<?> ret = method.getReturnType(); |
| ... | ...@@ -79,6 +79,7 @@ | |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | @Override | |
| 82 | 83 | public Object visitName(Name node) throws Exception { |
| 83 | 84 | //FIXME: do we need Store and Param, or just Param? |
| 84 | 85 | if (node.ctx != expr_contextType.Store && node.ctx != expr_contextType.Param) { |
| ... | ...@@ -93,6 +94,7 @@ | |
| 93 | 94 | return node.id; |
| 94 | 95 | } |
| 95 | 96 | |
| 97 | @Override | |
| 96 | 98 | public Object visitTuple(Tuple node) throws Exception { |
| 97 | 99 | StringBuffer name = new StringBuffer("("); |
| 98 | 100 | int n = node.elts.length; |
| ... | ...@@ -4,7 +4,6 @@ | |
| 4 | 4 | import java.lang.reflect.Method; |
| 5 | 5 | import java.lang.reflect.Modifier; |
| 6 | 6 | |
| 7 | import org.python.objectweb.asm.Opcodes; | |
| 8 | 7 | import org.python.core.PyObject; |
| 9 | 8 | |
| 10 | 9 | public class JavaMaker extends ProxyMaker implements ClassConstants { |
| ... | ...@@ -25,6 +24,7 @@ | |
| 25 | 24 | this.methods = methods; |
| 26 | 25 | } |
| 27 | 26 | |
| 27 | @Override | |
| 28 | 28 | public void addConstructor(String name, |
| 29 | 29 | Class<?>[] parameters, |
| 30 | 30 | Class<?> ret, |
| ... | ...@@ -40,6 +40,7 @@ | |
| 40 | 40 | code.visitInsn(RETURN); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | @Override | |
| 43 | 44 | public void addProxy() throws Exception { |
| 44 | 45 | if (methods != null) |
| 45 | 46 | super.addProxy(); |
| ... | ...@@ -58,6 +59,7 @@ | |
| 58 | 59 | |
| 59 | 60 | } |
| 60 | 61 | |
| 62 | @Override | |
| 61 | 63 | public void addMethod(Method method, int access) throws Exception { |
| 62 | 64 | if (Modifier.isAbstract(access)) { |
| 63 | 65 | // Maybe throw an exception here??? |
| ... | ...@@ -34,17 +34,17 @@ | |
| 34 | 34 | public static Map<Class<?>, Integer> types=fillTypes(); |
| 35 | 35 | |
| 36 | 36 | public static Map<Class<?>, Integer> fillTypes() { |
| 37 | Map<Class<?>, Integer> types = new HashMap<Class<?>, Integer>(); | |
| 38 | types.put(Boolean.TYPE, tBoolean); | |
| 39 | types.put(Byte.TYPE, tByte); | |
| 40 | types.put(Short.TYPE, tShort); | |
| 41 | types.put(Integer.TYPE, tInteger); | |
| 42 | types.put(Long.TYPE, tLong); | |
| 43 | types.put(Float.TYPE, tFloat); | |
| 44 | types.put(Double.TYPE, tDouble); | |
| 45 | types.put(Character.TYPE, tCharacter); | |
| 46 | types.put(Void.TYPE, tVoid); | |
| 47 | return types; | |
| 37 | Map<Class<?>, Integer> typeMap = new HashMap<Class<?>, Integer>(); | |
| 38 | typeMap.put(Boolean.TYPE, tBoolean); | |
| 39 | typeMap.put(Byte.TYPE, tByte); | |
| 40 | typeMap.put(Short.TYPE, tShort); | |
| 41 | typeMap.put(Integer.TYPE, tInteger); | |
| 42 | typeMap.put(Long.TYPE, tLong); | |
| 43 | typeMap.put(Float.TYPE, tFloat); | |
| 44 | typeMap.put(Double.TYPE, tDouble); | |
| 45 | typeMap.put(Character.TYPE, tCharacter); | |
| 46 | typeMap.put(Void.TYPE, tVoid); | |
| 47 | return typeMap; | |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public static int getType(Class<?> c) { |
| ... | ...@@ -440,14 +440,14 @@ | |
| 440 | 440 | Label callPython = new Label(); |
| 441 | 441 | code.ifnonnull(callPython); |
| 442 | 442 | |
| 443 | String superclass = mapClass(method.getDeclaringClass()); | |
| 443 | String superClass = mapClass(method.getDeclaringClass()); | |
| 444 | 444 | |
| 445 | callSuper(code, name, superclass, parameters, ret, sig); | |
| 445 | callSuper(code, name, superClass, parameters, ret, sig); | |
| 446 | 446 | code.label(callPython); |
| 447 | 447 | code.aload(tmp); |
| 448 | 448 | callMethod(code, name, parameters, ret, method.getExceptionTypes()); |
| 449 | 449 | |
| 450 | addSuperMethod("super__"+name, name, superclass, parameters, | |
| 450 | addSuperMethod("super__"+name, name, superClass, parameters, | |
| 451 | 451 | ret, sig, access); |
| 452 | 452 | } else { |
| 453 | 453 | if (!isAdapter) { |
| ... | ...@@ -512,9 +512,9 @@ | |
| 512 | 512 | if (sc != null) |
| 513 | 513 | addMethods(sc, t); |
| 514 | 514 | |
| 515 | Class<?>[] interfaces = c.getInterfaces(); | |
| 516 | for (int j=0; j<interfaces.length; j++) { | |
| 517 | addMethods(interfaces[j], t); | |
| 515 | Class<?>[] ifaces = c.getInterfaces(); | |
| 516 | for (int j=0; j<ifaces.length; j++) { | |
| 517 | addMethods(ifaces[j], t); | |
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | |
| ... | ...@@ -562,14 +562,14 @@ | |
| 562 | 562 | Class<?>[] parameters = method.getParameterTypes(); |
| 563 | 563 | Class<?> ret = method.getReturnType(); |
| 564 | 564 | String sig = makeSignature(parameters, ret); |
| 565 | String superclass = mapClass(method.getDeclaringClass()); | |
| 565 | String superClass = mapClass(method.getDeclaringClass()); | |
| 566 | 566 | String superName = method.getName(); |
| 567 | 567 | String methodName = superName; |
| 568 | 568 | if (Modifier.isFinal(access)) { |
| 569 | 569 | methodName = "super__" + superName; |
| 570 | 570 | access &= ~Modifier.FINAL; |
| 571 | 571 | } |
| 572 | addSuperMethod(methodName, superName, superclass, parameters, | |
| 572 | addSuperMethod(methodName, superName, superClass, parameters, | |
| 573 | 573 | ret, sig, access); |
| 574 | 574 | } |
| 575 | 575 | |
| ... | ...@@ -656,8 +656,8 @@ | |
| 656 | 656 | code.aload(0); |
| 657 | 657 | code.ldc("__supernames__"); |
| 658 | 658 | |
| 659 | String[] names = supernames.toArray(new String[n]); | |
| 660 | CodeCompiler.makeStrings(code, names, n); | |
| 659 | String[] nameArray = supernames.toArray(new String[n]); | |
| 660 | CodeCompiler.makeStrings(code, nameArray, n); | |
| 661 | 661 | code.invokestatic("org/python/core/Py", "java2py", "(" + $obj + ")" + $pyObj); |
| 662 | 662 | code.invokevirtual("org/python/core/PyObject", "__setitem__", "(" + $str + $pyObj + ")V"); |
| 663 | 663 | code.return_(); |
| ... | ...@@ -2,7 +2,6 @@ | |
| 2 | 2 | |
| 3 | 3 | package org.python.compiler; |
| 4 | 4 | import java.io.ByteArrayOutputStream; |
| 5 | import java.io.DataOutputStream; | |
| 6 | 5 | import java.io.FileOutputStream; |
| 7 | 6 | import java.io.IOException; |
| 8 | 7 | import java.io.OutputStream; |
| ... | ...@@ -11,7 +10,6 @@ | |
| 11 | 10 | import java.util.List; |
| 12 | 11 | |
| 13 | 12 | import org.python.objectweb.asm.AnnotationVisitor; |
| 14 | import org.python.objectweb.asm.Attribute; | |
| 15 | 13 | import org.python.objectweb.asm.ClassWriter; |
| 16 | 14 | import org.python.objectweb.asm.FieldVisitor; |
| 17 | 15 | import org.python.objectweb.asm.MethodVisitor; |
| ... | ...@@ -69,12 +69,9 @@ | |
| 69 | 69 | import org.python.antlr.ast.TryFinally; |
| 70 | 70 | import org.python.antlr.ast.Tuple; |
| 71 | 71 | import org.python.antlr.ast.UnaryOp; |
| 72 | import org.python.antlr.ast.Unicode; | |
| 73 | 72 | import org.python.antlr.ast.While; |
| 74 | 73 | import org.python.antlr.ast.With; |
| 75 | 74 | import org.python.antlr.ast.Yield; |
| 76 | import org.python.antlr.ast.aliasType; | |
| 77 | import org.python.antlr.ast.argumentsType; | |
| 78 | 75 | import org.python.antlr.ast.cmpopType; |
| 79 | 76 | import org.python.antlr.ast.comprehensionType; |
| 80 | 77 | import org.python.antlr.ast.excepthandlerType; |
| ... | ...@@ -83,10 +80,7 @@ | |
| 83 | 80 | import org.python.antlr.ast.keywordType; |
| 84 | 81 | import org.python.antlr.ast.modType; |
| 85 | 82 | import org.python.antlr.ast.operatorType; |
| 86 | import org.python.antlr.ast.sliceType; | |
| 87 | 83 | import org.python.antlr.ast.stmtType; |
| 88 | import org.python.antlr.ast.unaryopType; | |
| 89 | import org.python.core.PyFrame; | |
| 90 | 84 | |
| 91 | 85 | public class CodeCompiler extends Visitor implements Opcodes, ClassConstants //, PythonGrammarTreeConstants |
| 92 | 86 | { |
| ... | ...@@ -288,11 +282,13 @@ | |
| 288 | 282 | } |
| 289 | 283 | } |
| 290 | 284 | |
| 285 | @Override | |
| 291 | 286 | public Object visitInteractive(Interactive node) throws Exception { |
| 292 | 287 | traverse(node); |
| 293 | 288 | return null; |
| 294 | 289 | } |
| 295 | 290 | |
| 291 | @Override | |
| 296 | 292 | public Object visitModule(org.python.antlr.ast.Module suite) |
| 297 | 293 | throws Exception |
| 298 | 294 | { |
| ... | ...@@ -315,6 +311,7 @@ | |
| 315 | 311 | return null; |
| 316 | 312 | } |
| 317 | 313 | |
| 314 | @Override | |
| 318 | 315 | public Object visitExpression(Expression node) throws Exception { |
| 319 | 316 | if (my_scope.generator && node.body != null) { |
| 320 | 317 | module.error("'return' with argument inside generator", |
| ... | ...@@ -389,6 +386,7 @@ | |
| 389 | 386 | return true; |
| 390 | 387 | } |
| 391 | 388 | |
| 389 | @Override | |
| 392 | 390 | public Object visitFunctionDef(FunctionDef node) throws Exception { |
| 393 | 391 | String name = getName(node.name); |
| 394 | 392 | |
| ... | ...@@ -788,15 +786,15 @@ | |
| 788 | 786 | loadFrame(); |
| 789 | 787 | code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); |
| 790 | 788 | } else { |
| 791 | String[] names = new String[node.names.length]; | |
| 789 | String[] fromNames = new String[node.names.length]; | |
| 792 | 790 | String[] asnames = new String[node.names.length]; |
| 793 | 791 | for (int i = 0; i < node.names.length; i++) { |
| 794 | names[i] = node.names[i].name; | |
| 792 | fromNames[i] = node.names[i].name; | |
| 795 | 793 | asnames[i] = node.names[i].asname; |
| 796 | 794 | if (asnames[i] == null) |
| 797 | asnames[i] = names[i]; | |
| 795 | asnames[i] = fromNames[i]; | |
| 798 | 796 | } |
| 799 | makeStrings(code, names, names.length); | |
| 797 | makeStrings(code, fromNames, fromNames.length); | |
| 800 | 798 | |
| 801 | 799 | loadFrame(); |
| 802 | 800 | code.invokestatic("org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyFrame + ")" + $pyObjArr); |
| ... | ...@@ -1353,6 +1351,7 @@ | |
| 1353 | 1351 | return null; |
| 1354 | 1352 | } |
| 1355 | 1353 | |
| 1354 | @Override | |
| 1356 | 1355 | public Object visitUnaryOp(UnaryOp node) throws Exception { |
| 1357 | 1356 | visit(node.operand); |
| 1358 | 1357 | String name = null; |
| ... | ...@@ -1366,6 +1365,7 @@ | |
| 1366 | 1365 | return null; |
| 1367 | 1366 | } |
| 1368 | 1367 | |
| 1368 | @Override | |
| 1369 | 1369 | public Object visitAugAssign(AugAssign node) throws Exception { |
| 1370 | 1370 | setline(node); |
| 1371 | 1371 | |
| ... | ...@@ -1466,6 +1466,7 @@ | |
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | 1468 | |
| 1469 | @Override | |
| 1469 | 1470 | public Object visitCall(Call node) throws Exception { |
| 1470 | 1471 | String[] keys = new String[node.keywords.length]; |
| 1471 | 1472 | exprType[] values = new exprType[node.args.length + keys.length]; |
| ... | ...@@ -1582,6 +1583,7 @@ | |
| 1582 | 1583 | |
| 1583 | 1584 | } |
| 1584 | 1585 | |
| 1586 | @Override | |
| 1585 | 1587 | public Object visitSubscript(Subscript node) throws Exception { |
| 1586 | 1588 | if (node.slice instanceof Slice) { |
| 1587 | 1589 | return Slice(node, (Slice) node.slice); |
| ... | ...@@ -1617,11 +1619,13 @@ | |
| 1617 | 1619 | return null; |
| 1618 | 1620 | } |
| 1619 | 1621 | |
| 1622 | @Override | |
| 1620 | 1623 | public Object visitIndex(Index node) throws Exception { |
| 1621 | 1624 | traverse(node); |
| 1622 | 1625 | return null; |
| 1623 | 1626 | } |
| 1624 | 1627 | |
| 1628 | @Override | |
| 1625 | 1629 | public Object visitExtSlice(ExtSlice node) throws Exception { |
| 1626 | 1630 | code.new_("org/python/core/PyTuple"); |
| 1627 | 1631 | code.dup(); |
| ... | ...@@ -1630,6 +1634,7 @@ | |
| 1630 | 1634 | return null; |
| 1631 | 1635 | } |
| 1632 | 1636 | |
| 1637 | @Override | |
| 1633 | 1638 | public Object visitAttribute(Attribute node) throws Exception { |
| 1634 | 1639 | |
| 1635 | 1640 | expr_contextType ctx = node.ctx; |
| ... | ...@@ -1688,6 +1693,7 @@ | |
| 1688 | 1693 | return null; |
| 1689 | 1694 | } |
| 1690 | 1695 | |
| 1696 | @Override | |
| 1691 | 1697 | public Object visitTuple(Tuple node) throws Exception { |
| 1692 | 1698 | /* if (mode ==AUGSET) |
| 1693 | 1699 | throw new ParseException( |
| ... | ...@@ -1703,6 +1709,7 @@ | |
| 1703 | 1709 | return null; |
| 1704 | 1710 | } |
| 1705 | 1711 | |
| 1712 | @Override | |
| 1706 | 1713 | public Object visitList(List node) throws Exception { |
| 1707 | 1714 | if (node.ctx == expr_contextType.Store) return seqSet(node.elts); |
| 1708 | 1715 | if (node.ctx == expr_contextType.Del) return seqDel(node.elts); |
| ... | ...@@ -1714,6 +1721,7 @@ | |
| 1714 | 1721 | return null; |
| 1715 | 1722 | } |
| 1716 | 1723 | |
| 1724 | @Override | |
| 1717 | 1725 | public Object visitListComp(ListComp node) throws Exception { |
| 1718 | 1726 | code.new_("org/python/core/PyList"); |
| 1719 | 1727 | |
| ... | ...@@ -1747,6 +1755,7 @@ | |
| 1747 | 1755 | return null; |
| 1748 | 1756 | } |
| 1749 | 1757 | |
| 1758 | @Override | |
| 1750 | 1759 | public Object visitDict(Dict node) throws Exception { |
| 1751 | 1760 | code.new_("org/python/core/PyDictionary"); |
| 1752 | 1761 | |
| ... | ...@@ -1761,12 +1770,14 @@ | |
| 1761 | 1770 | return null; |
| 1762 | 1771 | } |
| 1763 | 1772 | |
| 1773 | @Override | |
| 1764 | 1774 | public Object visitRepr(Repr node) throws Exception { |
| 1765 | 1775 | visit(node.value); |
| 1766 | 1776 | code.invokevirtual("org/python/core/PyObject", "__repr__", "()" + $pyStr); |
| 1767 | 1777 | return null; |
| 1768 | 1778 | } |
| 1769 | 1779 | |
| 1780 | @Override | |
| 1770 | 1781 | public Object visitLambda(Lambda node) throws Exception { |
| 1771 | 1782 | String name = "<lambda>"; |
| 1772 | 1783 | |
| ... | ...@@ -1801,11 +1812,13 @@ | |
| 1801 | 1812 | } |
| 1802 | 1813 | |
| 1803 | 1814 | |
| 1815 | @Override | |
| 1804 | 1816 | public Object visitEllipsis(Ellipsis node) throws Exception { |
| 1805 | 1817 | code.getstatic("org/python/core/Py", "Ellipsis", "Lorg/python/core/PyObject;"); |
| 1806 | 1818 | return null; |
| 1807 | 1819 | } |
| 1808 | 1820 | |
| 1821 | @Override | |
| 1809 | 1822 | public Object visitSlice(Slice node) throws Exception { |
| 1810 | 1823 | code.new_("org/python/core/PySlice"); |
| 1811 | 1824 | |
| ... | ...@@ -1817,6 +1830,7 @@ | |
| 1817 | 1830 | return null; |
| 1818 | 1831 | } |
| 1819 | 1832 | |
| 1833 | @Override | |
| 1820 | 1834 | public Object visitClassDef(ClassDef node) throws Exception { |
| 1821 | 1835 | setline(node); |
| 1822 | 1836 | |
| ... | ...@@ -1881,6 +1895,7 @@ | |
| 1881 | 1895 | code.invokevirtual("org/python/core/PyFrame", "getglobal", "(" + $str + ")" + $pyObj); |
| 1882 | 1896 | } |
| 1883 | 1897 | |
| 1898 | @Override | |
| 1884 | 1899 | public Object visitName(Name node) throws Exception { |
| 1885 | 1900 | String name; |
| 1886 | 1901 | if (fast_locals) |
| ... | ...@@ -1985,6 +2000,7 @@ | |
| 1985 | 2000 | return null; |
| 1986 | 2001 | } |
| 1987 | 2002 | |
| 2003 | @Override | |
| 1988 | 2004 | public Object visitStr(Str node) throws Exception { |
| 1989 | 2005 | PyString s = (PyString)node.s; |
| 1990 | 2006 | if (s instanceof PyUnicode) { |
| ... | ...@@ -1995,6 +2011,7 @@ | |
| 1995 | 2011 | return null; |
| 1996 | 2012 | } |
| 1997 | 2013 | |
| 2014 | @Override | |
| 1998 | 2015 | public Object visitGeneratorExp(GeneratorExp node) throws Exception { |
| 1999 | 2016 | String bound_exp = "_(x)"; |
| 2000 | 2017 | String tmp_append ="_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; |
| ... | ...@@ -2170,6 +2187,7 @@ | |
| 2170 | 2187 | return null; |
| 2171 | 2188 | } |
| 2172 | 2189 | |
| 2190 | @Override | |
| 2173 | 2191 | protected Object unhandled_node(PythonTree node) throws Exception { |
| 2174 | 2192 | throw new Exception("Unhandled node " + node); |
| 2175 | 2193 | } |
| ... | ...@@ -37,10 +37,12 @@ | |
| 37 | 37 | c.putstatic(module.classfile.name, name, $pyInteger); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | @Override | |
| 40 | 41 | public int hashCode() { |
| 41 | 42 | return value; |
| 42 | 43 | } |
| 43 | 44 | |
| 45 | @Override | |
| 44 | 46 | public boolean equals(Object o) { |
| 45 | 47 | if (o instanceof PyIntegerConstant) |
| 46 | 48 | return ((PyIntegerConstant)o).value == value; |
| ... | ...@@ -68,10 +70,12 @@ | |
| 68 | 70 | c.putstatic(module.classfile.name, name, $pyFloat); |
| 69 | 71 | } |
| 70 | 72 | |
| 73 | @Override | |
| 71 | 74 | public int hashCode() { |
| 72 | 75 | return (int)value; |
| 73 | 76 | } |
| 74 | 77 | |
| 78 | @Override | |
| 75 | 79 | public boolean equals(Object o) { |
| 76 | 80 | if (o instanceof PyFloatConstant) |
| 77 | 81 | return ((PyFloatConstant)o).value == value; |
| ... | ...@@ -99,10 +103,12 @@ | |
| 99 | 103 | c.putstatic(module.classfile.name, name, $pyComplex); |
| 100 | 104 | } |
| 101 | 105 | |
| 106 | @Override | |
| 102 | 107 | public int hashCode() { |
| 103 | 108 | return (int)value; |
| 104 | 109 | } |
| 105 | 110 | |
| 111 | @Override | |
| 106 | 112 | public boolean equals(Object o) { |
| 107 | 113 | if (o instanceof PyComplexConstant) |
| 108 | 114 | return ((PyComplexConstant)o).value == value; |
| ... | ...@@ -130,10 +136,12 @@ | |
| 130 | 136 | c.putstatic(module.classfile.name, name, $pyStr); |
| 131 | 137 | } |
| 132 | 138 | |
| 139 | @Override | |
| 133 | 140 | public int hashCode() { |
| 134 | 141 | return value.hashCode(); |
| 135 | 142 | } |
| 136 | 143 | |
| 144 | @Override | |
| 137 | 145 | public boolean equals(Object o) { |
| 138 | 146 | if (o instanceof PyStringConstant) |
| 139 | 147 | return ((PyStringConstant)o).value.equals(value); |
| ... | ...@@ -161,10 +169,12 @@ | |
| 161 | 169 | c.putstatic(module.classfile.name, name, $pyUnicode); |
| 162 | 170 | } |
| 163 | 171 | |
| 172 | @Override | |
| 164 | 173 | public int hashCode() { |
| 165 | 174 | return value.hashCode(); |
| 166 | 175 | } |
| 167 | 176 | |
| 177 | @Override | |
| 168 | 178 | public boolean equals(Object o) { |
| 169 | 179 | if (o instanceof PyUnicodeConstant) |
| 170 | 180 | return ((PyUnicodeConstant)o).value.equals(value); |
| ... | ...@@ -192,10 +202,12 @@ | |
| 192 | 202 | c.putstatic(module.classfile.name, name, $pyLong); |
| 193 | 203 | } |
| 194 | 204 | |
| 205 | @Override | |
| 195 | 206 | public int hashCode() { |
| 196 | 207 | return value.hashCode(); |
| 197 | 208 | } |
| 198 | 209 | |
| 210 | @Override | |
| 199 | 211 | public boolean equals(Object o) { |
| 200 | 212 | if (o instanceof PyLongConstant) |
| 201 | 213 | return ((PyLongConstant)o).value.equals(value); |
| ... | ...@@ -220,7 +232,7 @@ | |
| 220 | 232 | |
| 221 | 233 | public int moreflags; |
| 222 | 234 | |
| 223 | public PyCodeConstant() { ; | |
| 235 | public PyCodeConstant() { | |
| 224 | 236 | } |
| 225 | 237 | |
| 226 | 238 | public void get(Code c) throws IOException { |
| ... | ...@@ -2,7 +2,9 @@ | |
| 2 | 2 | |
| 3 | 3 | package org.python.compiler; |
| 4 | 4 | |
| 5 | import java.util.*; | |
| 5 | import java.util.Enumeration; | |
| 6 | import java.util.Hashtable; | |
| 7 | import java.util.Vector; | |
| 6 | 8 | import org.python.antlr.PythonTree; |
| 7 | 9 | |
| 8 | 10 | public class ScopeInfo extends Object implements ScopeConstants { |
| ... | ...@@ -257,6 +259,7 @@ | |
| 257 | 259 | |
| 258 | 260 | } |
| 259 | 261 | |
| 262 | @Override | |
| 260 | 263 | public String toString() { |
| 261 | 264 | return "ScopeInfo[" + scope_name + " " + kind + "]@" + |
| 262 | 265 | System.identityHashCode(this); |
| ... | ...@@ -66,6 +66,7 @@ | |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | @Override | |
| 69 | 70 | public Object visitInteractive(Interactive node) throws Exception { |
| 70 | 71 | beginScope("<single-top>", TOPSCOPE, node, null); |
| 71 | 72 | suite(node.body); |
| ... | ...@@ -73,6 +74,7 @@ | |
| 73 | 74 | return null; |
| 74 | 75 | } |
| 75 | 76 | |
| 77 | @Override | |
| 76 | 78 | public Object visitModule(org.python.antlr.ast.Module node) |
| 77 | 79 | throws Exception |
| 78 | 80 | { |
| ... | ...@@ -82,6 +84,7 @@ | |
| 82 | 84 | return null; |
| 83 | 85 | } |
| 84 | 86 | |
| 87 | @Override | |
| 85 | 88 | public Object visitExpression(Expression node) throws Exception { |
| 86 | 89 | beginScope("<eval-top>", TOPSCOPE, node, null); |
| 87 | 90 | visit(new Return(node, node.body)); |
| ... | ...@@ -93,6 +96,7 @@ | |
| 93 | 96 | cur.addBound(name); |
| 94 | 97 | } |
| 95 | 98 | |
| 99 | @Override | |
| 96 | 100 | public Object visitFunctionDef(FunctionDef node) throws Exception { |
| 97 | 101 | def(node.name); |
| 98 | 102 | ArgListCompiler ac = new ArgListCompiler(); |
| ... | ...@@ -117,6 +121,7 @@ | |
| 117 | 121 | return null; |
| 118 | 122 | } |
| 119 | 123 | |
| 124 | @Override | |
| 120 | 125 | public Object visitLambda(Lambda node) throws Exception { |
| 121 | 126 | ArgListCompiler ac = new ArgListCompiler(); |
| 122 | 127 | ac.visitArgs(node.args); |
| ... | ...@@ -144,6 +149,7 @@ | |
| 144 | 149 | visit(stmts[i]); |
| 145 | 150 | } |
| 146 | 151 | |
| 152 | @Override | |
| 147 | 153 | public Object visitImport(Import node) throws Exception { |
| 148 | 154 | for (int i = 0; i < node.names.length; i++) { |
| 149 | 155 | if (node.names[i].asname != null) { |
| ... | ...@@ -159,6 +165,7 @@ | |
| 159 | 165 | return null; |
| 160 | 166 | } |
| 161 | 167 | |
| 168 | @Override | |
| 162 | 169 | public Object visitImportFrom(ImportFrom node) throws Exception { |
| 163 | 170 | Future.checkFromFuture(node); // future stmt support |
| 164 | 171 | int n = node.names.length; |
| ... | ...@@ -176,6 +183,7 @@ | |
| 176 | 183 | return null; |
| 177 | 184 | } |
| 178 | 185 | |
| 186 | @Override | |
| 179 | 187 | public Object visitGlobal(Global node) throws Exception { |
| 180 | 188 | int n = node.names.length; |
| 181 | 189 | for (int i = 0; i < n; i++) { |
| ... | ...@@ -202,6 +210,7 @@ | |
| 202 | 210 | return null; |
| 203 | 211 | } |
| 204 | 212 | |
| 213 | @Override | |
| 205 | 214 | public Object visitExec(Exec node) throws Exception { |
| 206 | 215 | cur.exec = true; |
| 207 | 216 | if (node.globals == null && node.locals == null) { |
| ... | ...@@ -211,6 +220,7 @@ | |
| 211 | 220 | return null; |
| 212 | 221 | } |
| 213 | 222 | |
| 223 | @Override | |
| 214 | 224 | public Object visitClassDef(ClassDef node) throws Exception { |
| 215 | 225 | def(node.name); |
| 216 | 226 | int n = node.bases.length; |
| ... | ...@@ -223,6 +233,7 @@ | |
| 223 | 233 | return null; |
| 224 | 234 | } |
| 225 | 235 | |
| 236 | @Override | |
| 226 | 237 | public Object visitName(Name node) throws Exception { |
| 227 | 238 | String name = node.id; |
| 228 | 239 | if (node.ctx != expr_contextType.Load) { |
| ... | ...@@ -236,6 +247,7 @@ | |
| 236 | 247 | return null; |
| 237 | 248 | } |
| 238 | 249 | |
| 250 | @Override | |
| 239 | 251 | public Object visitListComp(ListComp node) throws Exception { |
| 240 | 252 | String tmp ="_[" + node.getLine() + "_" + node.getCharPositionInLine() + "]"; |
| 241 | 253 | cur.addBound(tmp); |
| ... | ...@@ -243,6 +255,7 @@ | |
| 243 | 255 | return null; |
| 244 | 256 | } |
| 245 | 257 | |
| 258 | @Override | |
| 246 | 259 | public Object visitYield(Yield node) throws Exception { |
| 247 | 260 | cur.generator = true; |
| 248 | 261 | cur.yield_count++; |
| ... | ...@@ -250,6 +263,7 @@ | |
| 250 | 263 | return null; |
| 251 | 264 | } |
| 252 | 265 | |
| 266 | @Override | |
| 253 | 267 | public Object visitGeneratorExp(GeneratorExp node) throws Exception { |
| 254 | 268 | String bound_exp = "_(x)"; |
| 255 | 269 | String tmp ="_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; |
| ... | ...@@ -269,6 +283,7 @@ | |
| 269 | 283 | return null; |
| 270 | 284 | } |
| 271 | 285 | |
| 286 | @Override | |
| 272 | 287 | public Object visitWith(With node) throws Exception { |
| 273 | 288 | cur.max_with_count++; |
| 274 | 289 | traverse(node); |