parse.y (resolve_field_access): Initialize class if field is found in another static...
authorTom Tromey <tromey@redhat.com>
Tue, 11 Mar 2003 20:37:02 +0000 (20:37 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Tue, 11 Mar 2003 20:37:02 +0000 (20:37 +0000)
* parse.y (resolve_field_access): Initialize class if field is
found in another static field.
* expr.c (build_class_init): Don't optimize out initialization of
implemented interface.

From-SVN: r64185

gcc/java/ChangeLog
gcc/java/expr.c
gcc/java/parse.y

index e0eed8ce43047840c32acd0ae6b5c38bf6b41097..0c9bc9b182af6adf26b0297ba10cfd5d6a2420d0 100644 (file)
@@ -1,3 +1,10 @@
+2003-03-11  Tom Tromey  <tromey@redhat.com>
+
+       * parse.y (resolve_field_access): Initialize class if field is
+       found in another static field.
+       * expr.c (build_class_init): Don't optimize out initialization of
+       implemented interface.
+
 2003-03-11  Andrew Haley  <aph@redhat.com>
 
        * jcf-io.c (caching_stat): Initialize origsep to remove compiler
index 48e67dfe2278dc1ab0f84ccb4ba39c4a8b7d26a7..11748238fd751c37e29ee790d32d4d464413109b 100644 (file)
@@ -1672,7 +1672,14 @@ tree
 build_class_init (tree clas, tree expr)
 {
   tree init;
-  if (inherits_from_p (current_class, clas))
+
+  /* An optimization: if CLAS is a superclass of the class we're
+     compiling, we don't need to initialize it.  However, if CLAS is
+     an interface, it won't necessarily be initialized, even if we
+     implement it.  */
+  if ((! CLASS_INTERFACE (TYPE_NAME (clas))
+       && inherits_from_p (current_class, clas))
+      || current_class == clas)
     return expr;
 
   if (always_initialize_class_p)
index 5c28ce7bd20a3b9b95daf2a6af38d7256f417e81..82293edfc724a139badf3d4fc288223c0258dc7c 100644 (file)
@@ -9301,6 +9301,19 @@ resolve_field_access (tree qual_wfl, tree *field_decl, tree *field_type)
        return error_mark_node;
       if (is_static)
        field_ref = maybe_build_class_init_for_field (decl, field_ref);
+
+      /* If we're looking at a static field, we may need to generate a
+        class initialization for it.  This can happen when the access
+        looks like `field.ref', where `field' is a static field in an
+        interface we implement.  */
+      if (!flag_emit_class_files
+         && !flag_emit_xref
+         && TREE_CODE (where_found) == VAR_DECL
+         && FIELD_STATIC (where_found))
+       {
+         build_static_field_ref (where_found);
+         field_ref = build_class_init (DECL_CONTEXT (where_found), field_ref);
+       }
     }
   else
     field_ref = decl;