Revision: 6709
http://jython.svn.sourceforge.net/jython/?rev=6709&view=rev
Author: cgroves
Date: 2009-08-22 23:06:08 +0000 (Sat, 22 Aug 2009)
Log Message:
-----------
Keep track of added constructors for subclass overriding
Modified Paths:
--------------
branches/customizable-proxymaker/src/org/python/compiler/Code.java
branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java
branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java
Modified: branches/customizable-proxymaker/src/org/python/compiler/Code.java
===================================================================
--- branches/customizable-proxymaker/src/org/python/compiler/Code.java 2009-08-22 23:05:15 UTC (rev 6708)
+++ branches/customizable-proxymaker/src/org/python/compiler/Code.java 2009-08-22 23:06:08 UTC (rev 6709)
@@ -9,7 +9,7 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
-class Code implements MethodVisitor, Opcodes {
+public class Code implements MethodVisitor, Opcodes {
MethodVisitor mv;
String sig;
String locals[];
@@ -17,7 +17,7 @@
int argcount;
int returnLocal;
BitSet finallyLocals = new java.util.BitSet();
-
+
//XXX: I'd really like to get sig and access out of here since MethodVistitor
// should already have this information.
public Code(MethodVisitor mv, String sig, int access) {
@@ -28,7 +28,7 @@
argcount = nlocals;
locals = new String[nlocals+128];
}
-
+
public int getLocal(String type) {
//Could optimize this to skip arguments?
for(int l = argcount; l<nlocals; l++) {
@@ -225,7 +225,7 @@
public void aaload() {
mv.visitInsn(AALOAD);
}
-
+
public void aastore() {
mv.visitInsn(AASTORE);
}
@@ -293,7 +293,7 @@
public void dup2() {
mv.visitInsn(DUP2);
}
-
+
public void dup_x1() {
mv.visitInsn(DUP_X1);
}
@@ -313,7 +313,7 @@
public void fconst_0() {
mv.visitInsn(FCONST_0);
}
-
+
public void fload(int index) {
mv.visitVarInsn(FLOAD, index);
}
@@ -333,7 +333,7 @@
public void goto_(Label label) {
mv.visitJumpInsn(GOTO, label);
}
-
+
public void iconst(int value) {
if (value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE) {
switch (value) {
@@ -372,31 +372,31 @@
public void iconst_m1() {
mv.visitInsn(ICONST_M1);
}
-
+
public void iconst_0() {
mv.visitInsn(ICONST_0);
}
-
+
public void iconst_1() {
mv.visitInsn(ICONST_1);
}
-
+
public void iconst_2() {
mv.visitInsn(ICONST_2);
}
-
+
public void iconst_3() {
mv.visitInsn(ICONST_3);
}
-
+
public void iconst_4() {
mv.visitInsn(ICONST_4);
}
-
+
public void iconst_5() {
mv.visitInsn(ICONST_5);
}
-
+
public void ifeq(Label label) {
mv.visitJumpInsn(IFEQ, label);
}
@@ -404,7 +404,7 @@
public void ifle(Label label) {
mv.visitJumpInsn(IFLE, label);
}
-
+
public void ifne(Label label) {
mv.visitJumpInsn(IFNE, label);
}
@@ -416,31 +416,31 @@
public void ifnonnull(Label label) {
mv.visitJumpInsn(IFNONNULL, label);
}
-
+
public void if_acmpne(Label label) {
mv.visitJumpInsn(IF_ACMPNE, label);
}
-
+
public void if_acmpeq(Label label) {
mv.visitJumpInsn(IF_ACMPEQ, label);
}
-
+
public void if_icmple(Label label) {
mv.visitJumpInsn(IF_ICMPLE, label);
}
-
+
public void if_icmpgt(Label label) {
mv.visitJumpInsn(IF_ICMPGT, label);
}
-
+
public void if_icmplt(Label label) {
mv.visitJumpInsn(IF_ICMPLT, label);
}
-
+
public void if_icmpne(Label label) {
mv.visitJumpInsn(IF_ICMPNE, label);
}
-
+
public void if_icmpeq(Label label) {
mv.visitJumpInsn(IF_ICMPEQ, label);
}
@@ -476,15 +476,15 @@
public void invokestatic(String owner, String name, String type) {
mv.visitMethodInsn(INVOKESTATIC, owner, name, type);
}
-
+
public void invokevirtual(String owner, String name, String type) {
mv.visitMethodInsn(INVOKEVIRTUAL, owner, name, type);
}
-
+
public void ireturn() {
mv.visitInsn(IRETURN);
}
-
+
public void istore(int index) {
mv.visitVarInsn(ISTORE, index);
}
@@ -506,7 +506,7 @@
String value = (String) cst;
final int len = value.length();
// 65535 / 4 (max utf-8 expansion for non BMP characters)
- final int maxlen = 16000;
+ final int maxlen = 16000;
if (len > maxlen) {
new_("java/lang/StringBuilder");
@@ -553,7 +553,7 @@
public void pop() {
mv.visitInsn(POP);
}
-
+
public void pop2() {
mv.visitInsn(POP2);
}
@@ -561,11 +561,11 @@
public void putstatic(String owner, String name, String type) {
mv.visitFieldInsn(PUTSTATIC, owner, name, type);
}
-
+
public void putfield(String owner, String name, String type) {
mv.visitFieldInsn(PUTFIELD, owner, name, type);
}
-
+
public void ret(int index) {
mv.visitVarInsn(RET, index);
}
@@ -581,7 +581,7 @@
public void swap() {
mv.visitInsn(SWAP);
}
-
+
public void swap2() {
dup2_x2();
pop2();
@@ -594,7 +594,7 @@
public void trycatch(Label start, Label end, Label handlerStart, String type) {
mv.visitTryCatchBlock(start, end, handlerStart, type);
}
-
+
public void setline(int line) {
mv.visitLineNumber(line, new Label());
}
Modified: branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java
===================================================================
--- branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java 2009-08-22 23:05:15 UTC (rev 6708)
+++ branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java 2009-08-22 23:06:08 UTC (rev 6709)
@@ -28,14 +28,11 @@
}
@Override
- public void addConstructor(String name,
- Class<?>[] parameters,
- Class<?> ret,
- String sig,
- int access) {
+ public void addConstructor(Class<?>[] parameters, int access) {
/* Need a fancy constructor for the Java side of things */
+ String sig = makeSig(Void.TYPE, parameters);
Code code = classfile.addMethod("<init>", sig, access);
- callSuper(code, "<init>", name, parameters, null, sig);
+ callSuper(code, "<init>", mapClass(superclass), parameters, Void.TYPE, false);
callInitProxy(parameters, code);
}
Modified: branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java
===================================================================
--- branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java 2009-08-22 23:05:15 UTC (rev 6708)
+++ branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java 2009-08-22 23:06:08 UTC (rev 6709)
@@ -126,8 +126,7 @@
String name,
String superclass,
Class<?>[] parameters,
- Class<?> ret,
- String sig) {
+ Class<?> ret, boolean doReturn) {
code.aload(0);
int local_index;
@@ -160,9 +159,11 @@
break;
}
}
- code.invokespecial(superclass, name, sig);
+ code.invokespecial(superclass, name, makeSig(ret, parameters));
- doReturn(code, ret);
+ if (doReturn) {
+ doReturn(code, ret);
+ }
}
protected void doJavaCall(Code code, String name, String type, String jcallName) {
@@ -376,8 +377,7 @@
int access,
Class<?> declaringClass) {
names.add(name);
- String sig = makeSig(ret, parameters);
- Code code = classfile.addMethod(name, sig, access);
+ Code code = classfile.addMethod(name, makeSig(ret, parameters), access);
code.aload(0);
code.ldc(name);
if (declaringClass != null) {
@@ -389,11 +389,11 @@
Label callPython = new Label();
code.ifnonnull(callPython);
String superClass = mapClass(declaringClass);
- callSuper(code, name, superClass, parameters, ret, sig);
+ callSuper(code, name, superClass, parameters, ret, true);
code.label(callPython);
code.aload(tmp);
callMethod(code, name, parameters, ret, exceptions);
- addSuperMethod("super__" + name, name, superClass, parameters, ret, sig, access);
+ addSuperMethod("super__" + name, name, superClass, parameters, ret, access);
} else {
code.invokestatic("org/python/compiler/ProxyMaker", "findPython",
makeSig($pyObj, $pyProxy, $str));
@@ -454,6 +454,17 @@
}
}
+ protected static class ConstructorDescr extends MethodDescr {
+
+ public ConstructorDescr(Constructor<?> cons) {
+ this(cons.getParameterTypes(), cons.getExceptionTypes());
+ }
+
+ public ConstructorDescr(Class<?>[] parameters, Class<?>[] exceptions) {
+ super("<init>", Void.TYPE, parameters, exceptions);
+ }
+ }
+
protected void addMethods(Class<?> c, Set<MethodDescr> t) {
for (Method method : c.getDeclaredMethods()) {
@@ -501,21 +512,18 @@
}
/** Adds a constructor that calls through to superclass. */
- protected void addConstructor(String superclassName,
- Class<?>[] parameters,
- Class<?> ret,
- String sig,
- int access) {
+ protected void addConstructor(Class<?>[] parameters, int access) {
+ String sig = makeSig(Void.TYPE, parameters);
Code code = classfile.addMethod("<init>", sig, access);
- callSuper(code, "<init>", superclassName, parameters, Void.TYPE, sig);
+ callSuper(code, "<init>", mapClass(superclass), parameters, Void.TYPE, true);
}
/**
* Adds constructors from this proxy's superclass.
*/
- protected void addConstructors() {
+ protected Set<ConstructorDescr> addConstructors() {
+ Set<ConstructorDescr> added = Generic.set();
Constructor<?>[] constructors = superclass.getDeclaredConstructors();
- String superclassName = mapClass(superclass);
for (Constructor<?> constructor : constructors) {
int access = constructor.getModifiers();
if (Modifier.isPrivate(access)) {
@@ -527,10 +535,10 @@
if (Modifier.isProtected(access)) {
access = access & ~Modifier.PROTECTED | Modifier.PUBLIC;
}
- Class<?>[] parameters = constructor.getParameterTypes();
- addConstructor(superclassName, parameters, Void.TYPE, makeSig(Void.TYPE, parameters),
- access);
+ addConstructor(constructor.getParameterTypes(), access);
+ added.add(new ConstructorDescr(constructor));
}
+ return added;
}
// Super methods are added for the following three reasons:
@@ -557,17 +565,15 @@
methodName = "super__" + superName;
access &= ~Modifier.FINAL;
}
- addSuperMethod(methodName, superName, superClass, parameters, ret,
- makeSig(ret, parameters), access);
+ addSuperMethod(methodName, superName, superClass, parameters, ret, access);
}
protected void addSuperMethod(String methodName,
- String superName,
- String declClass,
- Class<?>[] parameters,
- Class<?> ret,
- String sig,
- int access) {
+ String superName,
+ String declClass,
+ Class<?>[] parameters,
+ Class<?> ret,
+ int access) {
if (methodName.startsWith("super__")) {
/* rationale: JC java-class, P proxy-class subclassing JC
in order to avoid infinite recursion P should define super__foo
@@ -585,8 +591,8 @@
}
}
supernames.add(methodName);
- Code code = classfile.addMethod(methodName, sig, access);
- callSuper(code, superName, declClass, parameters, ret, sig);
+ Code code = classfile.addMethod(methodName, makeSig(ret, parameters), access);
+ callSuper(code, superName, declClass, parameters, ret, true);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|