Right direction?

Peter Ahé peter at ahe.dk
Sat May 26 10:07:26 PDT 2007


Now it is a binary file which means that I cannot view it without
adding a few steps.  Here are some tips for sending a patch:

* make sure that you call it something meaningful, for example,
void-method-cascading-v0.1.patch, not file.patch, etc.

* make sure that your mail sender does not wrap the the patch (I think
you can do this by attaching it as a text file)

* make sure that it is displayed inline.

* experiment by sending emails to yourself, not the list ;-)

The best I can do in Gmail is add .txt to the filename.  I have
attached the result.

Cheers,
Peter

On 5/26/07, Matthias Ernst <ernst.matthias at gmail.com> wrote:
> On 5/26/07, Peter Ahé <peter at ahe.dk> wrote:
> > Your patch is line wrapped.  Could you try to resend it as an attachment?
> >
> > Cheers,
> > Peter
>
>
> That should be better. Sorry for that.
>
> Matthias
>
>
-------------- next part --------------
--- comp/Attr.java.orig.txt	2007-05-26 13:55:53.000000000 +0200
+++ comp/Attr.java	2007-05-26 14:15:51.000000000 +0200
@@ -1315,6 +1315,18 @@
                               restype.tsym);
             }
 
+            // as a special case, o.m() where m is a void method, has type of o
+            if(restype == Symtab.voidType && !isStatic(TreeInfo.symbol(tree.meth))) {
+                if(tree.meth.tag != JCTree.SELECT) {
+                    log.warning(tree.meth.pos(), "Cannot (yet) cascade unqualified method call");
+                } else {
+                    JCExpression receiver = ((JCFieldAccess) tree.meth).selected;
+                    restype = receiver.type;
+                }
+            }
+
+          
+
             // Check that value of resulting type is admissible in the
             // current context.  Also, capture the return type
             result = check(tree, capture(restype), VAL, pkind, pt);
--- comp/TransTypes.java.orig.txt	2007-05-26 13:56:46.000000000 +0200
+++ comp/TransTypes.java	2007-05-26 14:15:51.000000000 +0200
@@ -25,19 +25,23 @@
 
 package com.sun.tools.javac.comp;
 
-import java.util.*;
-
+import static com.sun.tools.javac.code.Flags.*;
+import static com.sun.tools.javac.code.Kinds.*;
 import com.sun.tools.javac.code.*;
-import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.tree.*;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Symbol.MethodSymbol;
+import com.sun.tools.javac.code.Symbol.TypeSymbol;
+import static com.sun.tools.javac.code.TypeTags.*;
+import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.tree.JCTree.*;
+import com.sun.tools.javac.tree.TreeInfo;
+import com.sun.tools.javac.tree.TreeMaker;
+import com.sun.tools.javac.tree.TreeTranslator;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
-import com.sun.tools.javac.util.List;
 
-import static com.sun.tools.javac.code.Flags.*;
-import static com.sun.tools.javac.code.Kinds.*;
-import static com.sun.tools.javac.code.TypeTags.*;
+import java.util.HashMap;
+import java.util.Map;
 
 /** This pass translates Generic Java to conventional Java.
  *
@@ -583,7 +587,8 @@
         tree.args = translateArgs(tree.args, argtypes, tree.varargsElement);
 
         // Insert casts of method invocation results as needed.
-        result = retype(tree, mt.getReturnType(), pt);
+        // mernst: do not use mt.resType as cascading may have changed it
+        result = retype(tree, types.erasure(tree.type), pt);
     }
 
     public void visitNewClass(JCNewClass tree) {
--- jvm/Gen.java.orig.txt	2007-05-26 14:00:07.000000000 +0200
+++ jvm/Gen.java	2007-05-26 14:16:38.000000000 +0200
@@ -1664,14 +1664,24 @@
  *************************************************************************/
 
     public void visitApply(JCMethodInvocation tree) {
+
 	// Generate code for method.
 	Item m = genExpr(tree.meth, methodType);
+
+        // in case of a cascade, duplicate the receiver
+        boolean cascaded = ((MethodType)tree.meth.type).restype == Symtab.voidType && tree.type != Symtab.voidType;
+        Item stackItem = cascaded ? items.makeStackItem(tree.type) : null;
+        if(cascaded) stackItem.duplicate();
+
 	// Generate code for all arguments, where the expected types are
 	// the parameters of the method's external type (that is, any implicit
 	// outer instance of a super(...) call appears as first parameter).
 	genArgs(tree.args,
 		TreeInfo.symbol(tree.meth).externalType(types).getParameterTypes());
 	result = m.invoke();
+
+        // in case of a cascade, the receiver is top of stack now
+        if(cascaded) result = stackItem;
     }
 
     public void visitConditional(JCConditional tree) {


More information about the compiler-dev mailing list