parse.y (build_outer_field_access): New local `decl_ctx', use it.
authorAlexandre Petit-Bianco <apbianco@cygnus.com>
Thu, 23 Nov 2000 06:04:16 +0000 (06:04 +0000)
committerAlexandre Petit-Bianco <apbianco@gcc.gnu.org>
Thu, 23 Nov 2000 06:04:16 +0000 (22:04 -0800)
2000-11-22  Alexandre Petit-Bianco  <apbianco@cygnus.com>

* parse.y (build_outer_field_access): New local `decl_ctx', use
it. Check for field's context and current class immediate outer
context inheritance.
(outer_field_access_p): Consider fields inherited from the last
enclosing context.
(build_access_to_thisn): Stop at the last enclosing context if
necessary.
Fixes gcj/367.

(http://gcc.gnu.org/ml/gcc-patches/2000-11/msg01335.html)

From-SVN: r37689

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

index d40670c1478d7d75deb83ec8984da62bef4e1ae8..02b70d01ad689a2c632b5695d86f8bb2aab9d97d 100644 (file)
@@ -1,3 +1,14 @@
+2000-11-22  Alexandre Petit-Bianco  <apbianco@cygnus.com>
+
+       * parse.y (build_outer_field_access): New local `decl_ctx', use
+       it. Check for field's context and current class immediate outer
+       context inheritance.
+       (outer_field_access_p): Consider fields inherited from the last
+       enclosing context.
+       (build_access_to_thisn): Stop at the last enclosing context if
+       necessary.
+       Fixes gcj/367.
+
 Thu Nov 23 02:19:14 2000  J"orn Rennecke <amylaar@redhat.com>
 
        * Make-lang.in (jvspec.o): Depend on $(CONFIG_H).
index 60d5077c32babee6cc99c7572b4fe9678cd9e3dc..c411054b789c9ca1496136c40bfefe7413ab9b8a 100644 (file)
@@ -7837,11 +7837,13 @@ build_outer_field_access (id, decl)
 {
   tree access = NULL_TREE;
   tree ctx = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current_class)));
+  tree decl_ctx = DECL_CONTEXT (decl);
 
-  /* If decl's class is the direct outer class of the current_class,
-     build the access as `this$<n>.<field>'. Note that we will break
-     the `private' barrier if we're not emitting bytecodes. */
-  if (ctx == DECL_CONTEXT (decl) 
+  /* If the immediate enclosing context of the current class is the
+     field decl's class or inherits from it; build the access as
+     `this$<n>.<field>'. Note that we will break the `private' barrier
+     if we're not emitting bytecodes. */
+  if ((ctx == decl_ctx || inherits_from_p (ctx, decl_ctx))
       && (!FIELD_PRIVATE (decl) || !flag_emit_class_files ))
     {
       tree thisn = build_current_thisn (current_class);
@@ -7857,14 +7859,14 @@ build_outer_field_access (id, decl)
       /* Now we chain the required number of calls to the access$0 to
         get a hold to the enclosing instance we need, and then we
         build the field access. */
-      access = build_access_to_thisn (current_class, DECL_CONTEXT (decl), lc);
+      access = build_access_to_thisn (current_class, decl_ctx, lc);
 
       /* If the field is private and we're generating bytecode, then
          we generate an access method */
       if (FIELD_PRIVATE (decl) && flag_emit_class_files )
        {
          tree name = build_outer_field_access_methods (decl);
-         access = build_outer_field_access_expr (lc, DECL_CONTEXT (decl),
+         access = build_outer_field_access_expr (lc, decl_ctx,
                                                  name, access, NULL_TREE);
        }
       /* Otherwise we use `access$(this$<j>). ... access$(this$<i>).<field>'.
@@ -7898,8 +7900,15 @@ outer_field_access_p (type, decl)
     {
       if (type == DECL_CONTEXT (decl))
        return 1;
+
       if (!DECL_CONTEXT (TYPE_NAME (type)))
-       break;
+       {
+         /* Before we give up, see whether the field is inherited from
+            the enclosing context we're considering. */
+         if (inherits_from_p (type, DECL_CONTEXT (decl)))
+           return 1;
+         break;
+       }
     }
 
   return 0;
@@ -8221,8 +8230,13 @@ build_access_to_thisn (from, to, lc)
          access = build_method_invocation (access0_wfl, access);
          access = make_qualified_primary (cn, access, lc);
        }
-      
-      from = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (from)));
+
+      /* if FROM isn't an inter class, that's fine, we've done
+         enough. What we're looking for can be accessed from there. */
+      from = DECL_CONTEXT (TYPE_NAME (from));
+      if (!from)
+       break;
+      from = TREE_TYPE (from);
     }
   return access;
 }