This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Java: Fix PR 15715 - Interface access flags


This patch fixes PR java/15715, setting the correct access modifiers for both inner and top-level interfaces. It also adds code to differentiate between the modifiers field in a classfile header and the access flags set as part of the "InnerClasses" attribute. Only a restricted set of flags are valid in the access_flags field in the top level header - see the JVM Spec section 4.1:

http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#74353

No testsuite regressions. OK to commit?

Bryce


2004-06-26  Bryce McKinlay  <mckinlay@redhat.com>

	PR java/15715.
	* parse.y (create_interface): Set correct access modifiers for
	interfaces.
	* jcf-write.c (get_classfile_modifiers): New function.
	(generate_classfile): Use get_classfile_modifiers, not 
	get_access_flags.

Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.486
diff -u -r1.486 parse.y
--- parse.y	27 Jun 2004 00:34:57 -0000	1.486
+++ parse.y	27 Jun 2004 02:25:03 -0000
@@ -3852,6 +3852,13 @@
   /* Create a new decl if DECL is NULL, otherwise fix it */
   decl = maybe_create_class_interface_decl (decl, raw_name, q_name, id);
 
+  /* Interfaces are always abstract. */
+  flags |= ACC_ABSTRACT;
+
+  /* Inner interfaces are always static.  */
+  if (INNER_CLASS_DECL_P (decl))
+    flags |= ACC_STATIC;
+
   /* Set super info and mark the class a complete */
   set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl),
 		  object_type_node, ctxp->interface_number);

Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.146
diff -u -r1.146 jcf-write.c
--- jcf-write.c	31 May 2004 14:54:37 -0000	1.146
+++ jcf-write.c	27 Jun 2004 02:25:04 -0000
@@ -304,6 +304,7 @@
 static void init_jcf_state (struct jcf_partial *, struct obstack *);
 static void init_jcf_method (struct jcf_partial *, tree);
 static void release_jcf_state (struct jcf_partial *);
+static int get_classfile_modifiers (tree class);
 static struct chunk * generate_classfile (tree, struct jcf_partial *);
 static struct jcf_handler *alloc_handler (struct jcf_block *,
 					  struct jcf_block *,
@@ -2886,6 +2887,32 @@
   obstack_free (state->chunk_obstack, state->first);
 }
 
+/* Get the access flags (modifiers) of a class (TYPE_DECL) to be used in the
+   access_flags field of the class file header.  */
+
+static int get_classfile_modifiers (tree class)
+{
+  /* These are the flags which are valid class file modifiers. 
+     See JVMS2 S4.1.  */
+  int valid_toplevel_class_flags = ACC_PUBLIC | ACC_FINAL | ACC_SUPER | 
+				   ACC_INTERFACE | ACC_ABSTRACT;
+  int flags = get_access_flags (class);
+
+  /* ACC_SUPER should always be set, except for interfaces.  */
+  if (! (flags & ACC_INTERFACE))
+    flags |= ACC_SUPER;
+   
+  /* A protected member class becomes public at the top level. */
+  if (flags & ACC_PROTECTED)
+    flags |= ACC_PUBLIC;
+ 
+  /* Filter out flags that are not valid for a class or interface in the 
+     top-level access_flags field.  */
+  flags &= valid_toplevel_class_flags;
+
+  return flags;
+}
+
 /* Generate and return a list of chunks containing the class CLAS
    in the .class file representation.  The list can be written to a
    .class file using write_chunks.  Allocate chunks from obstack WORK. */
@@ -2921,9 +2948,7 @@
   else
     i = 8 + 2 * total_supers;
   ptr = append_chunk (NULL, i, state);
-  i = get_access_flags (TYPE_NAME (clas));
-  if (! (i & ACC_INTERFACE))
-    i |= ACC_SUPER;
+  i = get_classfile_modifiers (TYPE_NAME (clas));  
   PUT2 (i); /* access_flags */
   i = find_class_constant (&state->cpool, clas);  PUT2 (i);  /* this_class */
   if (clas == object_type_node)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]