+2004-05-06 Ranjit Mathew <rmathew@hotmail.com>
+
+ Fixes PR java/9685, PR java/15073
+ * parse.y (accessibility_string): New method.
+ (not_accessible_field_error): Use accessibility_string()
+ instead of java_accstring_lookup().
+ (resolve_qualified_expression_name): Check with
+ check_pkg_class_access() before allowing access using
+ qualified names.
+ Fix comment typo.
+ Use check_pkg_class_access() instead of not_accessible_p()
+ for unqualified types.
+ (not_accessible_p): Use DECL_CONTEXT (member) instead of
+ REFERENCE for package-private access checking.
+ (patch_method_invocation): Use accessibility_string() instead
+ of java_accstring_lookup().
+
2004-04-30 Ranjit Mathew <rmathew@hotmail.com>
Fixes PR java/15133
/* Local function prototypes */
static char *java_accstring_lookup (int);
+static const char *accessibility_string (int);
static void classitf_redefinition_error (const char *,tree, tree, tree);
static void variable_redefinition_error (tree, tree, tree, int);
static tree create_class (int, tree, tree, tree);
{
parse_error_context
(wfl, "Can't access %s field `%s.%s' from `%s'",
- java_accstring_lookup (get_access_flags_from_decl (decl)),
+ accessibility_string (get_access_flags_from_decl (decl)),
GET_TYPE_NAME (DECL_CONTEXT (decl)),
IDENTIFIER_POINTER (DECL_NAME (decl)),
IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
#undef COPY_RETURN
}
+/* Returns a string denoting the accessibility of a class or a member as
+ indicated by FLAGS. We need a separate function from
+ java_accstring_lookup, as the latter can return spurious "static", etc.
+ if package-private access is defined (in which case none of the
+ relevant access control bits in FLAGS is set). */
+
+static const char *
+accessibility_string (int flags)
+{
+ if (flags & ACC_PRIVATE) return "private";
+ if (flags & ACC_PROTECTED) return "protected";
+ if (flags & ACC_PUBLIC) return "public";
+
+ return "package-private";
+}
+
/* Issuing error messages upon redefinition of classes, interfaces or
variables. */
tree list;
*where_found = decl;
+ check_pkg_class_access (DECL_NAME (decl), qual_wfl, true);
+
/* We want to be absolutely sure that the class is laid
out. We're going to search something inside it. */
*type_found = type = TREE_TYPE (decl);
decl = QUAL_RESOLUTION (q);
/* Sneak preview. If next we see a `new', we're facing a
- qualification with resulted in a type being selected
- instead of a field. Report the error */
+ qualification which resulted in a type being selected
+ instead of a field. Report the error. */
if(TREE_CHAIN (q)
&& TREE_CODE (TREE_PURPOSE (TREE_CHAIN (q))) == NEW_CLASS_EXPR)
{
return 1;
}
- if (not_accessible_p (TREE_TYPE (decl), decl, type, 0))
- {
- parse_error_context
- (qual_wfl, "Can't access %s class '%s' from '%s'",
- java_accstring_lookup (get_access_flags_from_decl (decl)),
- IDENTIFIER_POINTER (DECL_NAME (decl)),
- IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
- return 1;
- }
+ check_pkg_class_access (DECL_NAME (decl), qual_wfl, true);
+
check_deprecation (qual_wfl, decl);
type = TREE_TYPE (decl);
return 1;
}
- /* Default access are permitted only when occurring within the
- package in which the type (REFERENCE) is declared. In other words,
- REFERENCE is defined in the current package */
- if (ctxp->package)
- return !class_in_current_package (reference);
-
- /* Otherwise, access is granted */
- return 0;
+ /* Default access is permitted only when occurring from within the
+ package in which the context (MEMBER) is declared. */
+ return !class_in_current_package (DECL_CONTEXT (member));
}
/* Test deprecated decl access. */
{
const char *const fct_name = IDENTIFIER_POINTER (DECL_NAME (list));
const char *const access =
- java_accstring_lookup (get_access_flags_from_decl (list));
+ accessibility_string (get_access_flags_from_decl (list));
const char *const klass =
IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list))));
const char *const refklass =