From 8ae6595c0b62f928fee2dbb3bb1a9b41299479a2 Mon Sep 17 00:00:00 2001 From: Ranjit Mathew Date: Thu, 6 May 2004 17:43:48 +0000 Subject: Fixes PR java/9685, PR java/15073 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(). From-SVN: r81573 --- gcc/java/ChangeLog | 17 +++++++++++++++++ gcc/java/parse.y | 49 ++++++++++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 21 deletions(-) (limited to 'gcc/java') diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index b566fff..13f3540 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,20 @@ +2004-05-06 Ranjit Mathew + + 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 Fixes PR java/15133 diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 7d4c2de..20b874e 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -76,6 +76,7 @@ definitions and other extensions. */ /* 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); @@ -3182,7 +3183,7 @@ not_accessible_field_error (tree wfl, tree decl) { 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)))); @@ -3228,6 +3229,22 @@ java_accstring_lookup (int flags) #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. */ @@ -9819,6 +9836,8 @@ resolve_qualified_expression_name (tree wfl, tree *found_decl, 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); @@ -9859,8 +9878,8 @@ resolve_qualified_expression_name (tree wfl, tree *found_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) { @@ -9869,15 +9888,8 @@ resolve_qualified_expression_name (tree wfl, tree *found_decl, 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); @@ -10140,14 +10152,9 @@ not_accessible_p (tree reference, tree member, tree where, int from_super) 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. */ @@ -10540,7 +10547,7 @@ patch_method_invocation (tree patch, tree primary, tree where, int from_super, { 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 = -- cgit v1.1