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


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

C++ PATCH to add BINFO_FOR_VBASE



This patch just adds a new macro to make code dealing with virtual
base classes easier to read.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-12-31  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (CLASSTYPE_VBASECLASSES): Update documentation.
	(CLASSTYPE_N_BASECLASSES): Likewise.
	(BINFO_FOR_VBASE): New macro.
	(get_vbase_types): Change prototype.
	* class.c (build_vbase_path): Use BINFO_FOR_VBASE.
	(prepare_fresh_vtable): Likewise.
	(finish_vtbls): Likewise.
	(get_class_offset_1): Likewise.
	(modify_all_indirect_vtables): Likewise.
	(build_vbase_pointer_fields): Likewise.
	* decl.c (xref_basetypes): Don't set CLASSTYPE_VBASECLASSES here.
	* init.c (sort_base_init): Use BINFO_FOR_VBASE.
	(expand_member_init): Likewise.
	* search.c (get_base_distance): Likewise.
	(lookup_field_queue_p): Likewise.
	(virtual_context): Likewise.
	(get_vbase_types): Don't return a value.  Set
	CLASSTYPE_VBASECLASSES here.
	* typeck.c (get_delta_difference): Use BINFO_FOR_VBASE.

Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.214
diff -c -p -r1.214 class.c
*** class.c	1999/12/30 17:23:24	1.214
--- class.c	1999/12/31 20:13:30
*************** build_vbase_path (code, type, expr, path
*** 331,338 ****
      {
        if (last_virtual)
  	{
! 	  offset = BINFO_OFFSET (binfo_member (last_virtual,
! 					       CLASSTYPE_VBASECLASSES (basetype)));
  	  offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
  	}
        else
--- 331,338 ----
      {
        if (last_virtual)
  	{
! 	  offset = BINFO_OFFSET (BINFO_FOR_VBASE (last_virtual, 
! 						  basetype));
  	  offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
  	}
        else
*************** prepare_fresh_vtable (binfo, for_type)
*** 884,891 ****
  
    if (TREE_VIA_VIRTUAL (binfo))
      {
!       tree binfo1 = binfo_member (BINFO_TYPE (binfo), 
! 				  CLASSTYPE_VBASECLASSES (for_type));
  
        /* XXX - This should never happen, if it does, the caller should
  	 ensure that the binfo is from for_type's binfos, not from any
--- 884,890 ----
  
    if (TREE_VIA_VIRTUAL (binfo))
      {
!       tree binfo1 = BINFO_FOR_VBASE (BINFO_TYPE (binfo), for_type);
  
        /* XXX - This should never happen, if it does, the caller should
  	 ensure that the binfo is from for_type's binfos, not from any
*************** prepare_fresh_vtable (binfo, for_type)
*** 911,918 ****
    import_export_vtable (new_decl, for_type, 0);
  
    if (TREE_VIA_VIRTUAL (binfo))
!     my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
! 				   CLASSTYPE_VBASECLASSES (current_class_type)),
  			170);
    SET_BINFO_NEW_VTABLE_MARKED (binfo);
  }
--- 910,917 ----
    import_export_vtable (new_decl, for_type, 0);
  
    if (TREE_VIA_VIRTUAL (binfo))
!     my_friendly_assert (binfo == BINFO_FOR_VBASE (BINFO_TYPE (binfo),
! 						  current_class_type),
  			170);
    SET_BINFO_NEW_VTABLE_MARKED (binfo);
  }
*************** finish_vtbls (binfo, do_self, t)
*** 2321,2328 ****
        int is_not_base_vtable
  	= i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
        if (TREE_VIA_VIRTUAL (base_binfo))
! 	base_binfo = binfo_member (BINFO_TYPE (base_binfo), 
! 				   CLASSTYPE_VBASECLASSES (t));
        finish_vtbls (base_binfo, is_not_base_vtable, t);
      }
  }
--- 2320,2326 ----
        int is_not_base_vtable
  	= i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
        if (TREE_VIA_VIRTUAL (base_binfo))
! 	base_binfo = BINFO_FOR_VBASE (BINFO_TYPE (base_binfo), t);
        finish_vtbls (base_binfo, is_not_base_vtable, t);
      }
  }
*************** get_class_offset_1 (parent, binfo, conte
*** 2375,2382 ****
        tree nrval;
  
        if (TREE_VIA_VIRTUAL (base_binfo))
! 	base_binfo = binfo_member (BINFO_TYPE (base_binfo),
! 				   CLASSTYPE_VBASECLASSES (t));
        nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
        /* See if we have a new value */
        if (nrval && (nrval != error_mark_node || rval==0))
--- 2373,2379 ----
        tree nrval;
  
        if (TREE_VIA_VIRTUAL (base_binfo))
! 	base_binfo = BINFO_FOR_VBASE (BINFO_TYPE (base_binfo), t);
        nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
        /* See if we have a new value */
        if (nrval && (nrval != error_mark_node || rval==0))
*************** modify_all_indirect_vtables (binfo, do_s
*** 2699,2705 ****
        if (TREE_VIA_VIRTUAL (base_binfo))
  	{
  	  via_virtual = 1;
! 	  base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
  	}
        modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl);
      }
--- 2696,2702 ----
        if (TREE_VIA_VIRTUAL (base_binfo))
  	{
  	  via_virtual = 1;
! 	  base_binfo = BINFO_FOR_VBASE (BINFO_TYPE (base_binfo), t);
  	}
        modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl);
      }
*************** build_vbase_pointer_fields (rec, empty_p
*** 3769,3778 ****
  	    {
  	      tree other_base_binfo = TREE_VEC_ELT (binfos, j);
  	      if (! TREE_VIA_VIRTUAL (other_base_binfo)
! 		  && binfo_member (basetype,
! 				   CLASSTYPE_VBASECLASSES (BINFO_TYPE
! 							   (other_base_binfo))
! 				   ))
  		goto got_it;
  	    }
  	  FORMAT_VBASE_NAME (name, basetype);
--- 3766,3772 ----
  	    {
  	      tree other_base_binfo = TREE_VEC_ELT (binfos, j);
  	      if (! TREE_VIA_VIRTUAL (other_base_binfo)
! 		  && BINFO_FOR_VBASE (basetype, BINFO_TYPE (other_base_binfo)))
  		goto got_it;
  	    }
  	  FORMAT_VBASE_NAME (name, basetype);
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.371
diff -c -p -r1.371 cp-tree.h
*** cp-tree.h	1999/12/29 08:28:50	1.371
--- cp-tree.h	1999/12/31 20:13:33
*************** struct lang_type
*** 1406,1421 ****
  /* The number of virtual functions defined for this
     _CLASSTYPE node.  */
  #define CLASSTYPE_VSIZE(NODE) (TYPE_LANG_SPECIFIC(NODE)->vsize)
! /* The direct and indirect virtual base classes that this type uses in
!    depth-first left-to-right order.  */
  #define CLASSTYPE_VBASECLASSES(NODE) (TYPE_LANG_SPECIFIC(NODE)->vbases)
  /* The virtual function pointer fields that this type contains.  */
  #define CLASSTYPE_VFIELDS(NODE) (TYPE_LANG_SPECIFIC(NODE)->vfields)
  
! /* Number of baseclasses defined for this type.
!    0 means no base classes.  */
  #define CLASSTYPE_N_BASECLASSES(NODE) \
!   (TYPE_BINFO_BASETYPES (NODE) ? TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES(NODE)) : 0)
  
  /* Used for keeping search-specific information.  Any search routine
     which uses this must define what exactly this slot is used for.  */
--- 1406,1427 ----
  /* The number of virtual functions defined for this
     _CLASSTYPE node.  */
  #define CLASSTYPE_VSIZE(NODE) (TYPE_LANG_SPECIFIC(NODE)->vsize)
! 
! /* A chain of BINFOs for the direct and indirect virtual base classes
!    that this type uses in depth-first left-to-right order.  */
  #define CLASSTYPE_VBASECLASSES(NODE) (TYPE_LANG_SPECIFIC(NODE)->vbases)
+ 
+ /* The BINFO (if any) for the virtual baseclass T of the class C.  */
+ #define BINFO_FOR_VBASE(T, C) \
+   (binfo_member (T, CLASSTYPE_VBASECLASSES (C)))
+ 
  /* The virtual function pointer fields that this type contains.  */
  #define CLASSTYPE_VFIELDS(NODE) (TYPE_LANG_SPECIFIC(NODE)->vfields)
  
! /* Number of direct baseclasses of NODE.  */
  #define CLASSTYPE_N_BASECLASSES(NODE) \
!   (TYPE_BINFO_BASETYPES (NODE) ? \
!    TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES(NODE)) : 0)
  
  /* Used for keeping search-specific information.  Any search routine
     which uses this must define what exactly this slot is used for.  */
*************** extern void get_pure_virtuals		        P
*** 3877,3883 ****
  extern tree init_vbase_pointers			PROTO((tree, tree));
  extern void expand_indirect_vtbls_init		PROTO((tree, tree, tree));
  extern void clear_search_slots			PROTO((tree));
! extern tree get_vbase_types			PROTO((tree));
  extern void maybe_suppress_debug_info		PROTO((tree));
  extern void note_debug_info_needed		PROTO((tree));
  extern void push_class_decls			PROTO((tree));
--- 3883,3889 ----
  extern tree init_vbase_pointers			PROTO((tree, tree));
  extern void expand_indirect_vtbls_init		PROTO((tree, tree, tree));
  extern void clear_search_slots			PROTO((tree));
! extern void get_vbase_types			PROTO((tree));
  extern void maybe_suppress_debug_info		PROTO((tree));
  extern void note_debug_info_needed		PROTO((tree));
  extern void push_class_decls			PROTO((tree));
Index: decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.527
diff -c -p -r1.527 decl.c
*** decl.c	1999/12/29 07:31:51	1.527
--- decl.c	1999/12/31 20:13:42
*************** xref_basetypes (code_type_node, name, re
*** 12522,12528 ****
  
    /* Now that we know all the base-classes, set up the list of virtual
       bases.  */
!   CLASSTYPE_VBASECLASSES (ref) = get_vbase_types (ref);
  }
    
  
--- 12522,12528 ----
  
    /* Now that we know all the base-classes, set up the list of virtual
       bases.  */
!   get_vbase_types (ref);
  }
    
  
Index: init.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/init.c,v
retrieving revision 1.157
diff -c -p -r1.157 init.c
*** init.c	1999/12/15 09:51:23	1.157
--- init.c	1999/12/31 20:13:44
*************** sort_base_init (t, rbase_ptr, vbase_ptr)
*** 388,397 ****
  	     this constructor is the top-level constructor called.  */
  	  if (TREE_VIA_VIRTUAL (binfo))
  	    {
! 	      tree v = CLASSTYPE_VBASECLASSES (t);
! 	      while (BINFO_TYPE (v) != BINFO_TYPE (binfo))
! 		v = TREE_CHAIN (v);
! 
  	      vbases = tree_cons (v, TREE_VALUE (x), vbases);
  	      continue;
  	    }
--- 388,394 ----
  	     this constructor is the top-level constructor called.  */
  	  if (TREE_VIA_VIRTUAL (binfo))
  	    {
! 	      tree v = BINFO_FOR_VBASE (BINFO_TYPE (binfo), t);
  	      vbases = tree_cons (v, TREE_VALUE (x), vbases);
  	      continue;
  	    }
*************** expand_member_init (exp, name, init)
*** 916,922 ****
  	       && ! current_template_parms
  	       && ! vec_binfo_member (basetype,
  				      TYPE_BINFO_BASETYPES (type))
! 	       && ! binfo_member (basetype, CLASSTYPE_VBASECLASSES (type)))
  	{
  	  if (IDENTIFIER_CLASS_VALUE (name))
  	    goto try_member;
--- 913,919 ----
  	       && ! current_template_parms
  	       && ! vec_binfo_member (basetype,
  				      TYPE_BINFO_BASETYPES (type))
! 	       && ! BINFO_FOR_VBASE (basetype, type))
  	{
  	  if (IDENTIFIER_CLASS_VALUE (name))
  	    goto try_member;
Index: search.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/search.c,v
retrieving revision 1.135
diff -c -p -r1.135 search.c
*** search.c	1999/12/29 06:39:42	1.135
--- search.c	1999/12/31 20:13:48
*************** get_base_distance (parent, binfo, protec
*** 485,492 ****
       tree, deal with it.  This happens when we are called from
       expand_upcast_fixups.  */
    if (rval == -1 && TREE_CODE (parent) == TREE_VEC
!       && parent == binfo_member (BINFO_TYPE (parent),
! 				 CLASSTYPE_VBASECLASSES (type)))
      {
        my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent) == binfo, 980827);
        new_binfo = parent;
--- 485,491 ----
       tree, deal with it.  This happens when we are called from
       expand_upcast_fixups.  */
    if (rval == -1 && TREE_CODE (parent) == TREE_VEC
!       && parent == BINFO_FOR_VBASE (BINFO_TYPE (parent), type))
      {
        my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent) == binfo, 980827);
        new_binfo = parent;
*************** lookup_field_queue_p (binfo, data)
*** 1287,1294 ****
      return NULL_TREE;
  
    if (TREE_VIA_VIRTUAL (binfo))
!     return binfo_member (BINFO_TYPE (binfo),
! 			 CLASSTYPE_VBASECLASSES (lfi->type));
    else
      return binfo;
  }
--- 1286,1292 ----
      return NULL_TREE;
  
    if (TREE_VIA_VIRTUAL (binfo))
!     return BINFO_FOR_VBASE (BINFO_TYPE (binfo), lfi->type);
    else
      return binfo;
  }
*************** virtual_context (fndecl, t, vbase)
*** 2557,2563 ****
  	      /* Not sure if checking path == vbase is necessary here, but just in
  		 case it is.  */
  	      if (TREE_VIA_VIRTUAL (path) || path == vbase)
! 		return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t));
  	      path = BINFO_INHERITANCE_CHAIN (path);
  	    }
  	}
--- 2555,2561 ----
  	      /* Not sure if checking path == vbase is necessary here, but just in
  		 case it is.  */
  	      if (TREE_VIA_VIRTUAL (path) || path == vbase)
! 		return BINFO_FOR_VBASE (BINFO_TYPE (path), t);
  	      path = BINFO_INHERITANCE_CHAIN (path);
  	    }
  	}
*************** dfs_get_vbase_types (binfo, data)
*** 2886,2892 ****
     depth-first search order.  The list is freshly allocated, so
     no modification is made to  the current binfo hierarchy.  */
  
! tree
  get_vbase_types (type)
       tree type;
  {
--- 2884,2890 ----
     depth-first search order.  The list is freshly allocated, so
     no modification is made to  the current binfo hierarchy.  */
  
! void
  get_vbase_types (type)
       tree type;
  {
*************** get_vbase_types (type)
*** 2906,2912 ****
    for (vbases = vbase_types; vbases; vbases = TREE_CHAIN (vbases))
      CLEAR_BINFO_VBASE_MARKED (vbases);
  
!   return vbase_types;
  }
  
  /* Debug info for C++ classes can get very large; try to avoid
--- 2904,2910 ----
    for (vbases = vbase_types; vbases; vbases = TREE_CHAIN (vbases))
      CLEAR_BINFO_VBASE_MARKED (vbases);
  
!   CLASSTYPE_VBASECLASSES (type) = vbase_types;
  }
  
  /* Debug info for C++ classes can get very large; try to avoid
Index: typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.232
diff -c -p -r1.232 typeck.c
*** typeck.c	1999/12/21 00:19:01	1.232
--- typeck.c	1999/12/31 20:14:06
*************** get_delta_difference (from, to, force)
*** 6045,6052 ****
  	return delta;
        if (binfo_from_vbase (binfo))
  	{
! 	  binfo = binfo_member (BINFO_TYPE (binfo),
! 				CLASSTYPE_VBASECLASSES (from));
  	  cp_warning ("pointer to member cast to virtual base `%T'",
  		      BINFO_TYPE (binfo));
  	  warning ("  will only work if you are very careful");
--- 6045,6051 ----
  	return delta;
        if (binfo_from_vbase (binfo))
  	{
! 	  binfo = BINFO_FOR_VBASE (BINFO_TYPE (binfo), from);
  	  cp_warning ("pointer to member cast to virtual base `%T'",
  		      BINFO_TYPE (binfo));
  	  warning ("  will only work if you are very careful");


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