This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Java: fix for PR #224
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Java: fix for PR #224
- From: Alexandre Petit-Bianco <apbianco at cygnus dot com>
- Date: Mon, 26 Jun 2000 21:01:45 -0700
- Reply-to: apbianco at redhat dot com
I'm checking in the following patch in order to fix the Java PR #224:
http://sourceware.cygnus.com/ml/java-prs/2000-q2/msg00158.html
./A
2000-06-23 Alexandre Petit-Bianco <apbianco@cygnus.com>
* class.c (set_super_info): Handle ACC_PRIVATE for (inner)
classes.
* java-tree.h (TYPE_PRIVATE_INNER_CLASS): New macro.
(struct lang_type): New field `pic.'
(CLASS_PRIVATE): New macro.
* parse.y (check_inner_class_access): New function.
(jdep_resolve_class): Call it.
Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/class.c,v
retrieving revision 1.69
diff -u -p -r1.69 class.c
--- class.c 2000/06/03 00:46:44 1.69
+++ class.c 2000/06/27 03:52:12
@@ -400,6 +400,7 @@ set_super_info (access_flags, this_class
if (access_flags & ACC_INTERFACE) CLASS_INTERFACE (class_decl) = 1;
if (access_flags & ACC_ABSTRACT) CLASS_ABSTRACT (class_decl) = 1;
if (access_flags & ACC_STATIC) CLASS_STATIC (class_decl) = 1;
+ if (access_flags & ACC_PRIVATE) CLASS_PRIVATE (class_decl) = 1;
}
/* Return length of inheritance chain of CLAS, where java.lang.Object is 0,
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/java-tree.h,v
retrieving revision 1.73
diff -u -p -r1.73 java-tree.h
--- java-tree.h 2000/06/22 05:17:33 1.73
+++ java-tree.h 2000/06/27 03:52:16
@@ -575,6 +575,7 @@ struct lang_decl_var
/* The decl of the synthetic method `class$' used to handle `.class'
for non primitive types when compiling to bytecode. */
#define TYPE_DOT_CLASS(T) (TYPE_LANG_SPECIFIC(T)->dot_class)
+#define TYPE_PRIVATE_INNER_CLASS(T) (TYPE_LANG_SPECIFIC(T)->pic)
struct lang_type
{
@@ -589,6 +590,7 @@ struct lang_type
needs to be invoked and generated when
compiling to bytecode to implement
<non_primitive_type>.class */
+ unsigned pic:1; /* Private Inner Class. */
};
#ifdef JAVA_USE_HANDLES
@@ -837,6 +839,7 @@ struct rtx_def * java_lang_expand_expr P
#define CLASS_ABSTRACT(DECL) DECL_LANG_FLAG_5 (DECL)
#define CLASS_SUPER(DECL) DECL_LANG_FLAG_6 (DECL)
#define CLASS_STATIC(DECL) DECL_LANG_FLAG_7 (DECL)
+#define CLASS_PRIVATE(DECL) (TYPE_PRIVATE_INNER_CLASS (TREE_TYPE (DECL)))
/* @deprecated marker flag on methods, fields and classes */
Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.182
diff -u -p -r1.182 parse.y
--- parse.y 2000/06/26 07:26:08 1.182
+++ parse.y 2000/06/27 03:53:35
@@ -100,6 +100,7 @@ static int process_imports PARAMS ((void
static void read_import_dir PARAMS ((tree));
static int find_in_imports_on_demand PARAMS ((tree));
static void find_in_imports PARAMS ((tree));
+static void check_inner_class_access PARAMS ((tree, tree, tree));
static int check_pkg_class_access PARAMS ((tree, tree));
static void register_package PARAMS ((tree));
static tree resolve_package PARAMS ((tree, tree *));
@@ -5203,6 +5204,7 @@ jdep_resolve_class (dep)
if (!decl)
complete_class_report_errors (dep);
+ check_inner_class_access (decl, JDEP_ENCLOSING (dep), JDEP_WFL (dep));
return decl;
}
@@ -6774,6 +6776,27 @@ lookup_package_type (name, from)
strncpy (subname, name, sub-name);
subname [sub-name] = '\0';
return get_identifier (subname);
+}
+
+static void
+check_inner_class_access (decl, enclosing_type, cl)
+ tree decl, enclosing_type, cl;
+{
+ /* We don't issue an error message when CL is null. CL can be null
+ as a result of processing a JDEP crafted by
+ source_start_java_method for the purpose of patching its parm
+ decl. But the error would have been already trapped when fixing
+ the method's signature. */
+ if (!(cl && PURE_INNER_CLASS_DECL_P (decl) && CLASS_PRIVATE (decl))
+ || (PURE_INNER_CLASS_DECL_P (enclosing_type)
+ && common_enclosing_context_p (TREE_TYPE (enclosing_type),
+ TREE_TYPE (decl)))
+ || enclosing_context_p (TREE_TYPE (enclosing_type), TREE_TYPE (decl)))
+ return;
+
+ parse_error_context (cl, "Can't access nested %s %s. Only plublic classes and interfaces in other packages can be accessed",
+ (CLASS_INTERFACE (decl) ? "interface" : "class"),
+ lang_printable_name (decl, 0));
}
/* Check that CLASS_NAME refers to a PUBLIC class. Return 0 if no