parse.y (patch_method_invocation): Pick the correct enclosing context when creating...
authorAlexandre Petit-Bianco <apbianco@cygnus.com>
Tue, 5 Dec 2000 07:08:56 +0000 (07:08 +0000)
committerAlexandre Petit-Bianco <apbianco@gcc.gnu.org>
Tue, 5 Dec 2000 07:08:56 +0000 (23:08 -0800)
2000-12-04  Alexandre Petit-Bianco  <apbianco@cygnus.com>

* parse.y (patch_method_invocation): Pick the correct enclosing
context when creating inner class instances.
Fixes gcj/332.

(http://gcc.gnu.org/ml/gcc-patches/2000-12/msg00217.html)

From-SVN: r38026

gcc/java/ChangeLog
gcc/java/parse.y

index 69e257bbcb3be2e599efc1bc23e58b56388b115f..69044f8506a0694aefbb97d6d25ae02f512d91da 100644 (file)
@@ -1,3 +1,9 @@
+2000-12-04  Alexandre Petit-Bianco  <apbianco@cygnus.com>
+
+       * parse.y (patch_method_invocation): Pick the correct enclosing
+       context when creating inner class instances.
+       Fixes gcj/332.
+
 2000-11-26  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * gjavah.c (version), jcf-dump.c (version), jv-scan.c (version):
index c411054b789c9ca1496136c40bfefe7413ab9b8a..d89ace421cc9e475f8315b924c6b2f4434b5a8db 100644 (file)
@@ -9997,7 +9997,33 @@ patch_method_invocation (patch, primary, where, is_static, ret_decl)
 
       /* Secretly pass the current_this/primary as a second argument */
       if (primary || current_this)
-       args = tree_cons (NULL_TREE, (primary ? primary : current_this), args);
+       {
+         tree extra_arg;
+         tree this_type = (current_this ?
+                           TREE_TYPE (TREE_TYPE (current_this)) : NULL_TREE);
+         /* Method's (list) enclosing context */
+         tree mec = DECL_CONTEXT (TYPE_NAME (DECL_CONTEXT (list)));
+         /* If we have a primary, use it. */
+         if (primary)
+           extra_arg = primary;
+         /* The current `this' is an inner class but isn't a direct
+            enclosing context for the inner class we're trying to
+            create. Build an access to the proper enclosing context
+            and use it. */
+         else if (current_this && PURE_INNER_CLASS_TYPE_P (this_type)
+                  && this_type != TREE_TYPE (mec))
+           {
+
+             extra_arg = build_access_to_thisn (current_class,
+                                                TREE_TYPE (mec), 0);
+             extra_arg = java_complete_tree (extra_arg);
+           }
+         /* Otherwise, just use the current `this' as an enclosing
+             context. */
+         else
+           extra_arg = current_this;
+         args = tree_cons (NULL_TREE, extra_arg, args);
+       }
       else
        args = tree_cons (NULL_TREE, integer_zero_node, args);
     }