This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Fwd: Stop java making non-canonical trees]



-- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk

--- Begin Message --- Hi,
I discovered java was creating a COMPONENT_REF (a tcc_reference class node) with a _TYPE as operand0 (rather than an _EXPR or equivalent). This is getting in the way of some cleanups I'm doing.


I've fixed this by placing the necessary _TYPE as the type of a NOP_EXPR, which is then used as operand 0 of the COMPONENT_REF. Java is using this COMPONENT_REF as a sort of place holder. An alternative would have been a java specific node, but that looked like more work -- AFAICT java has no bespoke nodes, so the entire infrastructure for that would need implementing.

booted & tested on i686-pc-linux-gnu, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-08-08  Nathan Sidwell  <nathan@codesourcery.com>

	* class.c (build_class_ref): Wrap the primary class type in a
	NOP_EXPR.
	* parse.y (java_complete_lhs) <COMPONENT_REF case>: Extract the
	primary class type from the NOP_EXPR in which it was placed.

Index: java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.236
diff -c -3 -p -r1.236 class.c
*** java/class.c	20 Jul 2005 01:19:40 -0000	1.236
--- java/class.c	8 Aug 2005 14:24:26 -0000
*************** build_class_ref (tree type)
*** 1011,1016 ****
--- 1011,1021 ----
  		abort ();
  
  	      prim_class = lookup_class (get_identifier (prim_class_name));
+ 	      /* We wrap the class in a NOP_EXPR, because it is a
+ 	         type.  We can't hold it in the COMPONENT_REF itself,
+ 	         as that type must remain NULL.  */
+ 	      prim_class = build1 (NOP_EXPR, prim_class, NULL_TREE);
+ 	      
  	      return build3 (COMPONENT_REF, NULL_TREE,
  			     prim_class, TYPE_identifier_node, NULL_TREE);
  	    }
Index: java/parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.549
diff -c -3 -p -r1.549 parse.y
*** java/parse.y	20 Jul 2005 01:19:44 -0000	1.549
--- java/parse.y	8 Aug 2005 14:24:35 -0000
*************** java_complete_lhs (tree node)
*** 12382,12407 ****
  
      case COMPONENT_REF:
        /* The first step in the re-write of qualified name handling.  FIXME.
! 	 So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
!       TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
!       if (TREE_CODE (TREE_OPERAND (node, 0)) == RECORD_TYPE)
! 	{
! 	  tree name = TREE_OPERAND (node, 1);
! 	  tree field = lookup_field_wrapper (TREE_OPERAND (node, 0), name);
! 	  if (field == NULL_TREE)
! 	    {
! 	      error ("missing static field %qs", IDENTIFIER_POINTER (name));
! 	      return error_mark_node;
! 	    }
! 	  if (! FIELD_STATIC (field))
! 	    {
! 	      error ("not a static field %qs", IDENTIFIER_POINTER (name));
! 	      return error_mark_node;
! 	    }
! 	  return field;
! 	}
!       else
! 	abort ();
        break;
  
      case THIS_EXPR:
--- 12382,12411 ----
  
      case COMPONENT_REF:
        /* The first step in the re-write of qualified name handling.  FIXME.
! 	 So far, this is only to support PRIMTYPE.class ->
! 	 PRIMCLASS.TYPE. */
!       {
! 	tree prim_class = TREE_OPERAND (node, 0);
! 	tree name = TREE_OPERAND (node, 1);
! 	tree field;
! 	
! 	gcc_assert (TREE_CODE (prim_class) == NOP_EXPR);
! 	prim_class = java_complete_tree (TREE_TYPE (prim_class));
! 	gcc_assert (TREE_CODE (prim_class) == RECORD_TYPE);
! 	field = lookup_field_wrapper (prim_class, name);
! 	
! 	if (field == NULL_TREE)
! 	  {
! 	    error ("missing static field %qs", IDENTIFIER_POINTER (name));
! 	    return error_mark_node;
! 	  }
! 	if (! FIELD_STATIC (field))
! 	  {
! 	    error ("not a static field %qs", IDENTIFIER_POINTER (name));
! 	    return error_mark_node;
! 	  }
! 	return field;
!       }
        break;
  
      case THIS_EXPR:

--- End Message ---

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]