From: <fwi...@us...> - 2008-09-03 15:24:37
|
Revision: 5287 http://jython.svn.sourceforge.net/jython/?rev=5287&view=rev Author: fwierzbicki Date: 2008-09-03 15:24:20 +0000 (Wed, 03 Sep 2008) Log Message: ----------- Small cleanup of compiler package. Mainly remove unused imports and rename local vars that shadow member vars. Modified Paths: -------------- trunk/jython/src/org/python/compiler/AdapterMaker.java trunk/jython/src/org/python/compiler/ArgListCompiler.java trunk/jython/src/org/python/compiler/ClassFile.java trunk/jython/src/org/python/compiler/Code.java trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/compiler/Constant.java trunk/jython/src/org/python/compiler/JavaMaker.java trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/compiler/ProxyMaker.java trunk/jython/src/org/python/compiler/ScopeInfo.java trunk/jython/src/org/python/compiler/ScopesCompiler.java Modified: trunk/jython/src/org/python/compiler/AdapterMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/AdapterMaker.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/AdapterMaker.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -4,11 +4,9 @@ import java.io.OutputStream; import java.lang.reflect.Method; -import java.util.Set; import java.util.HashSet; import org.python.objectweb.asm.Label; -import org.python.objectweb.asm.MethodVisitor; import org.python.objectweb.asm.Opcodes; @@ -41,12 +39,14 @@ return pm.myClass; } + @Override public void doConstants() throws Exception { for (String name : names) { classfile.addField(name, "Lorg/python/core/PyObject;", Opcodes.ACC_PUBLIC); } } + @Override public void addMethod(Method method, int access) throws Exception { Class<?>[] parameters = method.getParameterTypes(); Class<?> ret = method.getReturnType(); Modified: trunk/jython/src/org/python/compiler/ArgListCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/ArgListCompiler.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/ArgListCompiler.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -79,6 +79,7 @@ } } + @Override public Object visitName(Name node) throws Exception { //FIXME: do we need Store and Param, or just Param? if (node.ctx != expr_contextType.Store && node.ctx != expr_contextType.Param) { @@ -93,6 +94,7 @@ return node.id; } + @Override public Object visitTuple(Tuple node) throws Exception { StringBuffer name = new StringBuffer("("); int n = node.elts.length; Modified: trunk/jython/src/org/python/compiler/ClassFile.java =================================================================== --- trunk/jython/src/org/python/compiler/ClassFile.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/ClassFile.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -2,7 +2,6 @@ package org.python.compiler; import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -11,7 +10,6 @@ import java.util.List; import org.python.objectweb.asm.AnnotationVisitor; -import org.python.objectweb.asm.Attribute; import org.python.objectweb.asm.ClassWriter; import org.python.objectweb.asm.FieldVisitor; import org.python.objectweb.asm.MethodVisitor; Modified: trunk/jython/src/org/python/compiler/Code.java =================================================================== --- trunk/jython/src/org/python/compiler/Code.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/Code.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -211,7 +211,7 @@ } break; case 'L': - while (c[++i] != ';') {;} + while (c[++i] != ';') {} default: if (ret) stack++; else stack--; Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -69,12 +69,9 @@ import org.python.antlr.ast.TryFinally; import org.python.antlr.ast.Tuple; import org.python.antlr.ast.UnaryOp; -import org.python.antlr.ast.Unicode; import org.python.antlr.ast.While; import org.python.antlr.ast.With; import org.python.antlr.ast.Yield; -import org.python.antlr.ast.aliasType; -import org.python.antlr.ast.argumentsType; import org.python.antlr.ast.cmpopType; import org.python.antlr.ast.comprehensionType; import org.python.antlr.ast.excepthandlerType; @@ -83,10 +80,7 @@ import org.python.antlr.ast.keywordType; import org.python.antlr.ast.modType; import org.python.antlr.ast.operatorType; -import org.python.antlr.ast.sliceType; import org.python.antlr.ast.stmtType; -import org.python.antlr.ast.unaryopType; -import org.python.core.PyFrame; public class CodeCompiler extends Visitor implements Opcodes, ClassConstants //, PythonGrammarTreeConstants { @@ -288,11 +282,13 @@ } } + @Override public Object visitInteractive(Interactive node) throws Exception { traverse(node); return null; } + @Override public Object visitModule(org.python.antlr.ast.Module suite) throws Exception { @@ -315,6 +311,7 @@ return null; } + @Override public Object visitExpression(Expression node) throws Exception { if (my_scope.generator && node.body != null) { module.error("'return' with argument inside generator", @@ -389,6 +386,7 @@ return true; } + @Override public Object visitFunctionDef(FunctionDef node) throws Exception { String name = getName(node.name); @@ -788,15 +786,15 @@ loadFrame(); code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); } else { - String[] names = new String[node.names.length]; + String[] fromNames = new String[node.names.length]; String[] asnames = new String[node.names.length]; for (int i = 0; i < node.names.length; i++) { - names[i] = node.names[i].name; + fromNames[i] = node.names[i].name; asnames[i] = node.names[i].asname; if (asnames[i] == null) - asnames[i] = names[i]; + asnames[i] = fromNames[i]; } - makeStrings(code, names, names.length); + makeStrings(code, fromNames, fromNames.length); loadFrame(); code.invokestatic("org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyFrame + ")" + $pyObjArr); @@ -1353,6 +1351,7 @@ return null; } + @Override public Object visitUnaryOp(UnaryOp node) throws Exception { visit(node.operand); String name = null; @@ -1366,6 +1365,7 @@ return null; } + @Override public Object visitAugAssign(AugAssign node) throws Exception { setline(node); @@ -1466,6 +1466,7 @@ } + @Override public Object visitCall(Call node) throws Exception { String[] keys = new String[node.keywords.length]; exprType[] values = new exprType[node.args.length + keys.length]; @@ -1582,6 +1583,7 @@ } + @Override public Object visitSubscript(Subscript node) throws Exception { if (node.slice instanceof Slice) { return Slice(node, (Slice) node.slice); @@ -1617,11 +1619,13 @@ return null; } + @Override public Object visitIndex(Index node) throws Exception { traverse(node); return null; } + @Override public Object visitExtSlice(ExtSlice node) throws Exception { code.new_("org/python/core/PyTuple"); code.dup(); @@ -1630,6 +1634,7 @@ return null; } + @Override public Object visitAttribute(Attribute node) throws Exception { expr_contextType ctx = node.ctx; @@ -1688,6 +1693,7 @@ return null; } + @Override public Object visitTuple(Tuple node) throws Exception { /* if (mode ==AUGSET) throw new ParseException( @@ -1703,6 +1709,7 @@ return null; } + @Override public Object visitList(List node) throws Exception { if (node.ctx == expr_contextType.Store) return seqSet(node.elts); if (node.ctx == expr_contextType.Del) return seqDel(node.elts); @@ -1714,6 +1721,7 @@ return null; } + @Override public Object visitListComp(ListComp node) throws Exception { code.new_("org/python/core/PyList"); @@ -1747,6 +1755,7 @@ return null; } + @Override public Object visitDict(Dict node) throws Exception { code.new_("org/python/core/PyDictionary"); @@ -1761,12 +1770,14 @@ return null; } + @Override public Object visitRepr(Repr node) throws Exception { visit(node.value); code.invokevirtual("org/python/core/PyObject", "__repr__", "()" + $pyStr); return null; } + @Override public Object visitLambda(Lambda node) throws Exception { String name = "<lambda>"; @@ -1801,11 +1812,13 @@ } + @Override public Object visitEllipsis(Ellipsis node) throws Exception { code.getstatic("org/python/core/Py", "Ellipsis", "Lorg/python/core/PyObject;"); return null; } + @Override public Object visitSlice(Slice node) throws Exception { code.new_("org/python/core/PySlice"); @@ -1817,6 +1830,7 @@ return null; } + @Override public Object visitClassDef(ClassDef node) throws Exception { setline(node); @@ -1881,6 +1895,7 @@ code.invokevirtual("org/python/core/PyFrame", "getglobal", "(" + $str + ")" + $pyObj); } + @Override public Object visitName(Name node) throws Exception { String name; if (fast_locals) @@ -1985,6 +2000,7 @@ return null; } + @Override public Object visitStr(Str node) throws Exception { PyString s = (PyString)node.s; if (s instanceof PyUnicode) { @@ -1995,6 +2011,7 @@ return null; } + @Override public Object visitGeneratorExp(GeneratorExp node) throws Exception { String bound_exp = "_(x)"; String tmp_append ="_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; @@ -2170,6 +2187,7 @@ return null; } + @Override protected Object unhandled_node(PythonTree node) throws Exception { throw new Exception("Unhandled node " + node); } Modified: trunk/jython/src/org/python/compiler/Constant.java =================================================================== --- trunk/jython/src/org/python/compiler/Constant.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/Constant.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -4,7 +4,6 @@ import java.io.IOException; -import org.python.objectweb.asm.MethodVisitor; import org.python.objectweb.asm.Opcodes; abstract class Constant implements Opcodes{ Modified: trunk/jython/src/org/python/compiler/JavaMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/JavaMaker.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/JavaMaker.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -4,7 +4,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import org.python.objectweb.asm.Opcodes; import org.python.core.PyObject; public class JavaMaker extends ProxyMaker implements ClassConstants { @@ -25,6 +24,7 @@ this.methods = methods; } + @Override public void addConstructor(String name, Class<?>[] parameters, Class<?> ret, @@ -40,6 +40,7 @@ code.visitInsn(RETURN); } + @Override public void addProxy() throws Exception { if (methods != null) super.addProxy(); @@ -58,6 +59,7 @@ } + @Override public void addMethod(Method method, int access) throws Exception { if (Modifier.isAbstract(access)) { // Maybe throw an exception here??? Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/Module.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -37,10 +37,12 @@ c.putstatic(module.classfile.name, name, $pyInteger); } + @Override public int hashCode() { return value; } + @Override public boolean equals(Object o) { if (o instanceof PyIntegerConstant) return ((PyIntegerConstant)o).value == value; @@ -68,10 +70,12 @@ c.putstatic(module.classfile.name, name, $pyFloat); } + @Override public int hashCode() { return (int)value; } + @Override public boolean equals(Object o) { if (o instanceof PyFloatConstant) return ((PyFloatConstant)o).value == value; @@ -99,10 +103,12 @@ c.putstatic(module.classfile.name, name, $pyComplex); } + @Override public int hashCode() { return (int)value; } + @Override public boolean equals(Object o) { if (o instanceof PyComplexConstant) return ((PyComplexConstant)o).value == value; @@ -130,10 +136,12 @@ c.putstatic(module.classfile.name, name, $pyStr); } + @Override public int hashCode() { return value.hashCode(); } + @Override public boolean equals(Object o) { if (o instanceof PyStringConstant) return ((PyStringConstant)o).value.equals(value); @@ -161,10 +169,12 @@ c.putstatic(module.classfile.name, name, $pyUnicode); } + @Override public int hashCode() { return value.hashCode(); } + @Override public boolean equals(Object o) { if (o instanceof PyUnicodeConstant) return ((PyUnicodeConstant)o).value.equals(value); @@ -192,10 +202,12 @@ c.putstatic(module.classfile.name, name, $pyLong); } + @Override public int hashCode() { return value.hashCode(); } + @Override public boolean equals(Object o) { if (o instanceof PyLongConstant) return ((PyLongConstant)o).value.equals(value); @@ -220,7 +232,7 @@ public int moreflags; - public PyCodeConstant() { ; + public PyCodeConstant() { } public void get(Code c) throws IOException { Modified: trunk/jython/src/org/python/compiler/ProxyMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -34,17 +34,17 @@ public static Map<Class<?>, Integer> types=fillTypes(); public static Map<Class<?>, Integer> fillTypes() { - Map<Class<?>, Integer> types = new HashMap<Class<?>, Integer>(); - types.put(Boolean.TYPE, tBoolean); - types.put(Byte.TYPE, tByte); - types.put(Short.TYPE, tShort); - types.put(Integer.TYPE, tInteger); - types.put(Long.TYPE, tLong); - types.put(Float.TYPE, tFloat); - types.put(Double.TYPE, tDouble); - types.put(Character.TYPE, tCharacter); - types.put(Void.TYPE, tVoid); - return types; + Map<Class<?>, Integer> typeMap = new HashMap<Class<?>, Integer>(); + typeMap.put(Boolean.TYPE, tBoolean); + typeMap.put(Byte.TYPE, tByte); + typeMap.put(Short.TYPE, tShort); + typeMap.put(Integer.TYPE, tInteger); + typeMap.put(Long.TYPE, tLong); + typeMap.put(Float.TYPE, tFloat); + typeMap.put(Double.TYPE, tDouble); + typeMap.put(Character.TYPE, tCharacter); + typeMap.put(Void.TYPE, tVoid); + return typeMap; } public static int getType(Class<?> c) { @@ -440,14 +440,14 @@ Label callPython = new Label(); code.ifnonnull(callPython); - String superclass = mapClass(method.getDeclaringClass()); + String superClass = mapClass(method.getDeclaringClass()); - callSuper(code, name, superclass, parameters, ret, sig); + callSuper(code, name, superClass, parameters, ret, sig); code.label(callPython); code.aload(tmp); callMethod(code, name, parameters, ret, method.getExceptionTypes()); - addSuperMethod("super__"+name, name, superclass, parameters, + addSuperMethod("super__"+name, name, superClass, parameters, ret, sig, access); } else { if (!isAdapter) { @@ -512,9 +512,9 @@ if (sc != null) addMethods(sc, t); - Class<?>[] interfaces = c.getInterfaces(); - for (int j=0; j<interfaces.length; j++) { - addMethods(interfaces[j], t); + Class<?>[] ifaces = c.getInterfaces(); + for (int j=0; j<ifaces.length; j++) { + addMethods(ifaces[j], t); } } @@ -562,14 +562,14 @@ Class<?>[] parameters = method.getParameterTypes(); Class<?> ret = method.getReturnType(); String sig = makeSignature(parameters, ret); - String superclass = mapClass(method.getDeclaringClass()); + String superClass = mapClass(method.getDeclaringClass()); String superName = method.getName(); String methodName = superName; if (Modifier.isFinal(access)) { methodName = "super__" + superName; access &= ~Modifier.FINAL; } - addSuperMethod(methodName, superName, superclass, parameters, + addSuperMethod(methodName, superName, superClass, parameters, ret, sig, access); } @@ -656,8 +656,8 @@ code.aload(0); code.ldc("__supernames__"); - String[] names = supernames.toArray(new String[n]); - CodeCompiler.makeStrings(code, names, n); + String[] nameArray = supernames.toArray(new String[n]); + CodeCompiler.makeStrings(code, nameArray, n); code.invokestatic("org/python/core/Py", "java2py", "(" + $obj + ")" + $pyObj); code.invokevirtual("org/python/core/PyObject", "__setitem__", "(" + $str + $pyObj + ")V"); code.return_(); Modified: trunk/jython/src/org/python/compiler/ScopeInfo.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -2,7 +2,9 @@ package org.python.compiler; -import java.util.*; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; import org.python.antlr.PythonTree; public class ScopeInfo extends Object implements ScopeConstants { @@ -257,6 +259,7 @@ } + @Override public String toString() { return "ScopeInfo[" + scope_name + " " + kind + "]@" + System.identityHashCode(this); Modified: trunk/jython/src/org/python/compiler/ScopesCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopesCompiler.java 2008-09-03 09:21:25 UTC (rev 5286) +++ trunk/jython/src/org/python/compiler/ScopesCompiler.java 2008-09-03 15:24:20 UTC (rev 5287) @@ -66,6 +66,7 @@ } } + @Override public Object visitInteractive(Interactive node) throws Exception { beginScope("<single-top>", TOPSCOPE, node, null); suite(node.body); @@ -73,6 +74,7 @@ return null; } + @Override public Object visitModule(org.python.antlr.ast.Module node) throws Exception { @@ -82,6 +84,7 @@ return null; } + @Override public Object visitExpression(Expression node) throws Exception { beginScope("<eval-top>", TOPSCOPE, node, null); visit(new Return(node, node.body)); @@ -93,6 +96,7 @@ cur.addBound(name); } + @Override public Object visitFunctionDef(FunctionDef node) throws Exception { def(node.name); ArgListCompiler ac = new ArgListCompiler(); @@ -117,6 +121,7 @@ return null; } + @Override public Object visitLambda(Lambda node) throws Exception { ArgListCompiler ac = new ArgListCompiler(); ac.visitArgs(node.args); @@ -144,6 +149,7 @@ visit(stmts[i]); } + @Override public Object visitImport(Import node) throws Exception { for (int i = 0; i < node.names.length; i++) { if (node.names[i].asname != null) { @@ -159,6 +165,7 @@ return null; } + @Override public Object visitImportFrom(ImportFrom node) throws Exception { Future.checkFromFuture(node); // future stmt support int n = node.names.length; @@ -176,6 +183,7 @@ return null; } + @Override public Object visitGlobal(Global node) throws Exception { int n = node.names.length; for (int i = 0; i < n; i++) { @@ -202,6 +210,7 @@ return null; } + @Override public Object visitExec(Exec node) throws Exception { cur.exec = true; if (node.globals == null && node.locals == null) { @@ -211,6 +220,7 @@ return null; } + @Override public Object visitClassDef(ClassDef node) throws Exception { def(node.name); int n = node.bases.length; @@ -223,6 +233,7 @@ return null; } + @Override public Object visitName(Name node) throws Exception { String name = node.id; if (node.ctx != expr_contextType.Load) { @@ -236,6 +247,7 @@ return null; } + @Override public Object visitListComp(ListComp node) throws Exception { String tmp ="_[" + node.getLine() + "_" + node.getCharPositionInLine() + "]"; cur.addBound(tmp); @@ -243,6 +255,7 @@ return null; } + @Override public Object visitYield(Yield node) throws Exception { cur.generator = true; cur.yield_count++; @@ -250,6 +263,7 @@ return null; } + @Override public Object visitGeneratorExp(GeneratorExp node) throws Exception { String bound_exp = "_(x)"; String tmp ="_(" + node.getLine() + "_" + node.getCharPositionInLine() + ")"; @@ -269,6 +283,7 @@ return null; } + @Override public Object visitWith(With node) throws Exception { cur.max_with_count++; traverse(node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |