From b6250dbca7accdcd4850fc4b42a551f5ffee95f5 Mon Sep 17 00:00:00 2001 From: apbianco Date: Wed, 10 Jan 2001 17:05:43 +0000 Subject: [PATCH] 2001-01-08 Alexandre Petit-Bianco * java-tree.h (lang_printable_name_wls): New prototype. * lang.c (put_decl_name): Removed dead code. Use DECL_CONTEXT rather than `current_class' to print type name. Don't prepend type names when printing constructor names. (lang_printable_name_wls): New function. * jcf-parse.c (jcf_parse_source): Pass NULL `file' argument to `build_expr_wfl', alway set EXPR_WFL_FILENAME_NODE. * parse.y (patch_method_invocation): Message tuned for constructors. (not_accessible_p): Grant `private' access from within enclosing contexts. 2001-01-05 Alexandre Petit-Bianco * parse.y (patch_binop): Compute missing type in error situations. (http://gcc.gnu.org/ml/gcc-patches/2001-01/msg00752.html) git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38870 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/java/ChangeLog | 17 +++++++++++++++++ gcc/java/java-tree.h | 1 + gcc/java/jcf-parse.c | 5 ++--- gcc/java/lang.c | 32 +++++++++++++++++++++----------- gcc/java/parse.y | 40 ++++++++++++++++++++++++++++++++++------ 5 files changed, 75 insertions(+), 20 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index ebf96fa..f7bae10 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,20 @@ +2001-01-08 Alexandre Petit-Bianco + + * java-tree.h (lang_printable_name_wls): New prototype. + * lang.c (put_decl_name): Removed dead code. Use DECL_CONTEXT + rather than `current_class' to print type name. Don't prepend type + names when printing constructor names. + (lang_printable_name_wls): New function. + * jcf-parse.c (jcf_parse_source): Pass NULL `file' argument to + `build_expr_wfl', alway set EXPR_WFL_FILENAME_NODE. + * parse.y (patch_method_invocation): Message tuned for constructors. + (not_accessible_p): Grant `private' access from within + enclosing contexts. + +2001-01-05 Alexandre Petit-Bianco + + * parse.y (patch_binop): Compute missing type in error situations. + 2001-01-05 Bryce McKinlay * class.c (make_class_data): Push initial value for "arrayclass". diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h index f9b47dd..510511e 100644 --- a/gcc/java/java-tree.h +++ b/gcc/java/java-tree.h @@ -1111,6 +1111,7 @@ extern boolean java_hash_compare_tree_node PARAMS ((hash_table_key, hash_table_key)); extern void java_check_methods PARAMS ((tree)); extern void init_jcf_parse PARAMS((void)); +extern const char *lang_printable_name_wls PARAMS ((tree, int)); /* We use ARGS_SIZE_RTX to indicate that gcc/expr.h has been included to declare `enum expand_modifier'. */ diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index dcfb612..3fa64b2 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -569,9 +569,8 @@ jcf_parse_source () java_push_parser_context (); BUILD_FILENAME_IDENTIFIER_NODE (file, current_jcf->filename); if (wfl_operator == NULL_TREE) - wfl_operator = build_expr_wfl (NULL_TREE, file, 0, 0); - else - EXPR_WFL_FILENAME_NODE (wfl_operator) = file; + wfl_operator = build_expr_wfl (NULL_TREE, NULL, 0, 0); + EXPR_WFL_FILENAME_NODE (wfl_operator) = file; input_filename = ggc_strdup (current_jcf->filename); current_class = NULL_TREE; current_function_decl = NULL_TREE; diff --git a/gcc/java/lang.c b/gcc/java/lang.c index a88203c..e312f50 100644 --- a/gcc/java/lang.c +++ b/gcc/java/lang.c @@ -502,18 +502,13 @@ put_decl_node (node) if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd' && DECL_NAME (node) != NULL_TREE) { -#if 0 - if (DECL_CONTEXT (node) != NULL_TREE) - { - put_decl_node (DECL_CONTEXT (node)); - put_decl_string (".", 1); - } -#endif + /* We want to print the type the DECL belongs to. We don't do + that when we handle constructors. */ if (TREE_CODE (node) == FUNCTION_DECL - && DECL_INIT_P (node) - && !DECL_ARTIFICIAL (node) && current_class) - put_decl_node (TYPE_NAME (current_class)); - else + && ! DECL_CONSTRUCTOR_P (node) + && ! DECL_ARTIFICIAL (node) && DECL_CONTEXT (node)) + put_decl_node (TYPE_NAME (DECL_CONTEXT (node))); + else if (! DECL_CONSTRUCTOR_P (node)) put_decl_node (DECL_NAME (node)); if (TREE_CODE (node) == FUNCTION_DECL && TREE_TYPE (node) != NULL_TREE) { @@ -574,6 +569,21 @@ lang_printable_name (decl, v) return decl_buf; } +/* Does the same thing that lang_printable_name, but add a leading + space to the DECL name string -- With Leading Space. */ + +const char * +lang_printable_name_wls (decl, v) + tree decl; + int v __attribute__ ((__unused__)); +{ + decl_bufpos = 1; + put_decl_node (decl); + put_decl_string ("", 1); + decl_buf [0] = ' '; + return decl_buf; +} + /* Print on stderr the current class and method context. This function is the value of the hook print_error_function, called from toplev.c. */ diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 9dc5804..a59e198 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -9701,11 +9701,16 @@ not_accessible_p (reference, member, from_super) } /* Check access on private members. Access is granted only if it - occurs from within the class in which it is declared. Exceptions - are accesses from inner-classes. */ + occurs from within the class in which it is declared -- that does + it for innerclasses too. */ if (access_flag & ACC_PRIVATE) - return (current_class == DECL_CONTEXT (member) ? 0 : - (INNER_CLASS_TYPE_P (current_class) ? 0 : 1)); + { + if (reference == DECL_CONTEXT (member)) + return 0; + if (enclosing_context_p (reference, DECL_CONTEXT (member))) + return 0; + return 1; + } /* Default access are permitted only when occuring within the package in which the type (REFERENCE) is declared. In other words, @@ -10054,10 +10059,13 @@ patch_method_invocation (patch, primary, where, is_static, ret_decl) if (not_accessible_p (DECL_CONTEXT (current_function_decl), list, 0)) { char *fct_name = xstrdup (lang_printable_name (list, 0)); + int ctor_p = DECL_CONSTRUCTOR_P (list); parse_error_context - (wfl, "Can't access %s method `%s %s.%s' from `%s'", + (wfl, "Can't access %s %s `%s%s.%s' from `%s'", java_accstring_lookup (get_access_flags_from_decl (list)), - lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0), + (ctor_p ? "constructor" : "method"), + (ctor_p ? + "" : lang_printable_name_wls (TREE_TYPE (TREE_TYPE (list)), 0)), IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list)))), fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class)))); free (fct_name); @@ -13117,6 +13125,26 @@ patch_binop (node, wfl_op1, wfl_op2) EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node); + /* If either op_type are NULL, this might be early signs of an + error situation, unless it's too early to tell (in case we're + handling a `+', `==', `!=' or `instanceof'.) We want to set op_type + correctly so the error can be later on reported accurately. */ + if (! (code == PLUS_EXPR || code == NE_EXPR + || code == EQ_EXPR || code == INSTANCEOF_EXPR)) + { + tree n; + if (! op1_type) + { + n = java_complete_tree (op1); + op1_type = TREE_TYPE (n); + } + if (! op2_type) + { + n = java_complete_tree (op2); + op2_type = TREE_TYPE (n); + } + } + switch (code) { /* 15.16 Multiplicative operators */ -- 2.7.4