gcj/172

Alexandre Petit-Bianco apbianco@cygnus.com
Mon Apr 24 20:50:00 GMT 2000


The following reply was made to PR gcj/172; it has been noted by GNATS.

From: Alexandre Petit-Bianco <apbianco@cygnus.com>
To: Bryce McKinlay <bryce@albatross.co.nz>
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: gcj/172
Date: Mon, 24 Apr 2000 20:42:48 -0700 (PDT)

 Bryce McKinlay writes:
 
 > And here's another, although I'm guessing this might be a seperate
 > issue:
 
 Yes. I just posted a patch. It's related to the PR #177.
 
 ./A
 
 2000-04-24  Alexandre Petit-Bianco  <apbianco@cygnus.com>
 
 	* class.c (common_enclosing_context_p): New function.
 	* parse.h (INNER_ENCLOSING_SCOPE_CHECK): Relaxed test to allow
 	classes sharing an outer context with the current instance.
 	* parse.y (verify_constructor_super): Skip enclosing context
 	argument in the case of a pure inner class constructor.
 	(patch_method_invocation): Insert enclosing context as second
 	parameter to pure inner class constructor super invocations.
 
 Index: class.c
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/java/class.c,v
 retrieving revision 1.65
 diff -u -p -r1.65 class.c
 --- class.c	2000/04/06 01:01:11	1.65
 +++ class.c	2000/04/25 03:20:49
 @@ -486,6 +486,30 @@ enclosing_context_p (type1, type2)
    return 0;
  }
  
 +/* Return 1 iff there exists a common enclosing context between TYPE1
 +   and TYPE2.  */
 +
 +int common_enclosing_context_p (type1, type2)
 +     tree type1, type2;
 +{
 +  if (!PURE_INNER_CLASS_TYPE_P (type2) && !PURE_INNER_CLASS_TYPE_P (type2))
 +    return 0;
 +  
 +  for (type1 = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type1))); type1; 
 +       type1 = (PURE_INNER_CLASS_TYPE_P (type1) ?
 +		TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type1))) : NULL_TREE))
 +    {
 +      tree current;
 +      for (current = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type2))); current;
 +	   current = (PURE_INNER_CLASS_TYPE_P (current) ?
 +		      TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current))) : 
 +		      NULL_TREE))
 +	if (type1 == current)
 +	  return 1;
 +    }
 +  return 0;
 +}
 +
  static void
  add_interface_do (basetype_vec, interface_class, i)
       tree basetype_vec, interface_class;
 Index: parse.h
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/java/parse.h,v
 retrieving revision 1.51
 diff -u -p -r1.51 parse.h
 --- parse.h	2000/04/24 16:17:03	1.51
 +++ parse.h	2000/04/25 03:20:51
 @@ -822,15 +822,17 @@ struct parser_ctxt {
  
  /* Make sure that innerclass T sits in an appropriate enclosing
     context.  */
 -#define INNER_ENCLOSING_SCOPE_CHECK(T)					\
 -  (INNER_CLASS_TYPE_P ((T)) && !ANONYMOUS_CLASS_P ((T))			\
 -   && ((current_this							\
 -	/* We have a this and it's not the right one */			\
 -	&& (DECL_CONTEXT (TYPE_NAME ((T)))				\
 -	    != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this))))	\
 -	&& !inherits_from_p (TREE_TYPE (TREE_TYPE (current_this)),	\
 -			     TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T)))))	\
 -       /* We don't have a this. */					\
 +#define INNER_ENCLOSING_SCOPE_CHECK(T)					      \
 +  (INNER_CLASS_TYPE_P ((T)) && !ANONYMOUS_CLASS_P ((T))			      \
 +   && ((current_this							      \
 +	/* We have a this and it's not the right one */			      \
 +	&& (DECL_CONTEXT (TYPE_NAME ((T)))				      \
 +	    != TYPE_NAME (TREE_TYPE (TREE_TYPE (current_this))))	      \
 +	&& !inherits_from_p (TREE_TYPE (TREE_TYPE (current_this)),	      \
 +			     TREE_TYPE (DECL_CONTEXT (TYPE_NAME (T))))	      \
 +        && !common_enclosing_context_p (TREE_TYPE (TREE_TYPE (current_this)), \
 +					(T)))				      \
 +       /* We don't have a this. */					      \
         || !current_this))
  
  /* Push macro. First argument to PUSH_CPC is a DECL_TYPE, second
 Index: parse.y
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
 retrieving revision 1.155
 diff -u -p -r1.155 parse.y
 --- parse.y	2000/04/24 23:27:39	1.155
 +++ parse.y	2000/04/25 03:21:25
 @@ -8220,11 +8220,14 @@ verify_constructor_super (mdecl)
      }
    else
      {
 +      int inner = PURE_INNER_CLASS_TYPE_P (class);
        for (sdecl = TYPE_METHODS (class); sdecl; sdecl = TREE_CHAIN (sdecl))
  	{
 -	  if (DECL_CONSTRUCTOR_P (sdecl)
 -	      && TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl))) 
 -	         == end_params_node)
 +	  tree arg = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (sdecl)));
 +	  if (inner)
 +	    arg = TREE_CHAIN (arg);
 +		      
 +	  if (DECL_CONSTRUCTOR_P (sdecl) && arg == end_params_node)
  	    return 0;
  	}
      }
 @@ -9501,6 +9504,13 @@ patch_method_invocation (patch, primary,
        else
  	args = tree_cons (NULL_TREE, integer_zero_node, args);
      }
 +
 +  /* This handles the situation where a constructor invokation needs
 +     to have an enclosing context passed as a second parameter (the
 +     constructor is one of an inner class.) */
 +  if (is_super_init
 +      && PURE_INNER_CLASS_TYPE_P (DECL_CONTEXT (list)))
 +    args = tree_cons (NULL_TREE, (primary ? primary : current_this), args);
  
    is_static_flag = METHOD_STATIC (list);
    if (! METHOD_STATIC (list) && this_arg != NULL_TREE)
 


More information about the Java-prs mailing list