]> source.dussan.org Git - javassist.git/commitdiff
made javassist.expr.MethodCall#replace correctly work
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 10 Oct 2003 06:15:50 +0000 (06:15 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 10 Oct 2003 06:15:50 +0000 (06:15 +0000)
with super's method calls.

git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@53 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/compiler/Javac.java
src/main/javassist/compiler/JvstCodeGen.java
src/main/javassist/compiler/MemberCodeGen.java
src/main/javassist/expr/Cast.java
src/main/javassist/expr/FieldAccess.java
src/main/javassist/expr/Instanceof.java
src/main/javassist/expr/MethodCall.java

index e0bf34288cc997f7854652dcab822d780ed04910..44c3ff111206f61a144a1e68f4664f88c996c550 100644 (file)
@@ -383,6 +383,39 @@ public class Javac {
         gen.setProceedHandler(h, proceedName);
     }
 
+    /**
+     * Prepares to use $proceed() representing a private/super's method.
+     * If the return type of $proceed() is void, null is pushed on the
+     * stack.  This method is for methods invoked by INVOKESPECIAL.
+     *
+     * @param target    an expression specifying the target object.
+     *                          if null, "this" is the target.
+     * @param classname            the class name declaring the method.
+     * @param methodname    the method name.
+     * @param descriptor    the method descriptor.
+     */
+    public void recordSpecialProceed(String target, String classname,
+                                     String methodname, String descriptor)
+        throws CompileError
+    {
+        Parser p = new Parser(new Lex(target));
+        final ASTree texpr = p.parseExpression(stable);
+        final String cname = classname;
+        final String method = methodname;
+        final String desc = descriptor;
+
+        ProceedHandler h = new ProceedHandler() {
+                public void doit(JvstCodeGen gen, Bytecode b, ASTList args)
+                    throws CompileError
+                {
+                    gen.compileInvokeSpecial(texpr,
+                                             cname, method, desc, args);
+                }
+            };
+
+        gen.setProceedHandler(h, proceedName);
+    }
+
     /**
      * Prepares to use $proceed().
      */
index 40d39a1197268431ab964f0446982f54f92226a0..5081ea1e685c834755888aa21ca5f0281ac3a6f3 100644 (file)
@@ -306,15 +306,15 @@ public class JvstCodeGen extends MemberCodeGen {
     }
 
     /*
-    public int atMethodArgsLength(ASTList args) {
+    public int getMethodArgsLength(ASTList args) {
         if (!isParamListName(args))
-            return super.atMethodArgsLength(args);
+            return super.getMethodArgsLength(args);
 
         return paramTypeList.length;
     }
     */
 
-    public int atMethodArgsLength(ASTList args) {
+    public int getMethodArgsLength(ASTList args) {
         String pname = paramListName;
         int n = 0;
         while (args != null) {
@@ -391,6 +391,22 @@ public class JvstCodeGen extends MemberCodeGen {
     }
     */
 
+    /* called by Javac#recordSpecialProceed().
+     */
+    void compileInvokeSpecial(ASTree target, String classname,
+                              String methodname, String descriptor,
+                              ASTList args)
+        throws CompileError
+    {
+        target.accept(this);
+        int nargs = getMethodArgsLength(args);
+        atMethodArgs(args, new int[nargs], new int[nargs],
+                     new String[nargs]);
+        bytecode.addInvokespecial(classname, methodname, descriptor);
+        setReturnType(descriptor, false, false);
+        addNullIfVoid();
+    }
+
     /*
      * Makes it valid to write "return <expr>;" for a void method.
      */
index c97855f3deca8e6892d3120cba698d3f183dc3c8..92e299f01adf921b3b4620f1dd16520c24c2bd29 100644 (file)
@@ -315,7 +315,7 @@ public class MemberCodeGen extends CodeGen {
                         int aload0pos)
         throws CompileError
     {
-        int nargs = atMethodArgsLength(args);
+        int nargs = getMethodArgsLength(args);
         int[] types = new int[nargs];
         int[] dims = new int[nargs];
         String[] cnames = new String[nargs];
@@ -386,7 +386,7 @@ public class MemberCodeGen extends CodeGen {
         setReturnType(desc, isStatic, popTarget);
     }
 
-    public int atMethodArgsLength(ASTList args) {
+    public int getMethodArgsLength(ASTList args) {
         return ASTList.length(args);
     }
 
@@ -404,8 +404,7 @@ public class MemberCodeGen extends CodeGen {
         }
     }
 
-    private void setReturnType(String desc, boolean isStatic,
-                               boolean popTarget)
+    void setReturnType(String desc, boolean isStatic, boolean popTarget)
         throws CompileError
     {
         int i = desc.indexOf(')');
index 9003503bb4437847dead564eb4a5d75bd3edac96..5dcbbb41ab3c38f6e929b572087aa7b72565ed3e 100644 (file)
@@ -138,7 +138,7 @@ public class Cast extends Expr {
         public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
             throws CompileError
         {
-            if (gen.atMethodArgsLength(args) != 1)
+            if (gen.getMethodArgsLength(args) != 1)
                 throw new CompileError(Javac.proceedName
                         + "() cannot take more than one parameter "
                         + "for cast");
index 6a7e912067dfbfa9bee290258cb831af2ca356ee..0a9cfeb1b92d11b5d95d9e52a8e24425a42e316e 100644 (file)
@@ -260,7 +260,7 @@ public class FieldAccess extends Expr {
         public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
             throws CompileError
         {
-            if (gen.atMethodArgsLength(args) != 1)
+            if (gen.getMethodArgsLength(args) != 1)
                 throw new CompileError(Javac.proceedName
                         + "() cannot take more than one parameter "
                         + "for field writing");
index c9ae913897967ca18c729c3a4750fed12946c58d..9743c84105297a97fc54f8cdb661adb93bad7350 100644 (file)
@@ -141,7 +141,7 @@ public class Instanceof extends Expr {
         public void doit(JvstCodeGen gen, Bytecode bytecode, ASTList args)
             throws CompileError
         {
-            if (gen.atMethodArgsLength(args) != 1)
+            if (gen.getMethodArgsLength(args) != 1)
                 throw new CompileError(Javac.proceedName
                         + "() cannot take more than one parameter "
                         + "for instanceof");
index 9eee7fe9928ff20b0500a49d38ba968300160bcc..80b35f155f5cd326e763f9291055c0d330e9d0a9 100644 (file)
@@ -198,6 +198,9 @@ public class MethodCall extends Expr {
             int retVar = jc.recordReturnType(retType, true);
             if (c == INVOKESTATIC)
                 jc.recordStaticProceed(classname, methodname);
+            else if (c == INVOKESPECIAL)
+                jc.recordSpecialProceed(Javac.param0Name, classname,
+                                        methodname, signature);
             else
                 jc.recordProceed(Javac.param0Name, methodname);