C++ PATCH: minor cleanup for class.c

Mark Mitchell mark@codesourcery.com
Sun Feb 20 15:25:00 GMT 2000


This patch fixes a formatting error in pt.c, and introdues a new
function to contain common vtable-creation code in class.c.

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

2000-02-20  Mark Mitchell  <mark@codesourcery.com>

	* class.c (build_vtable): New function, split out from ...
	(get_vtable_decl): ... here, and ...
	(build_secondary_vtable): ... here.

	* pt.c (tsubst_decl): Fix formatting.
	
Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.259
diff -c -p -r1.259 class.c
*** class.c	2000/02/20 02:46:55	1.259
--- class.c	2000/02/20 23:20:11
*************** set_rtti_entry (virtuals, offset, type)
*** 989,994 ****
--- 989,1020 ----
    BV_FN (virtuals) = decl;
  }
  
+ /* Create a VAR_DECL for a primary or secondary vtable for
+    CLASS_TYPE.  Use NAME for the name of the vtable, and VTABLE_TYPE
+    for its type.  */
+ 
+ static tree
+ build_vtable (class_type, name, vtable_type)
+      tree class_type;
+      tree name;
+      tree vtable_type;
+ {
+   tree decl;
+ 
+   decl = build_lang_decl (VAR_DECL, name, vtable_type);
+   DECL_CONTEXT (decl) = class_type;
+   DECL_ARTIFICIAL (decl) = 1;
+   TREE_STATIC (decl) = 1;
+ #ifndef WRITABLE_VTABLES
+   /* Make them READONLY by default. (mrs) */
+   TREE_READONLY (decl) = 1;
+ #endif
+   DECL_VIRTUAL_P (decl) = 1;
+   import_export_vtable (decl, class_type, 0);
+ 
+   return decl;
+ }
+ 
  /* Get the VAR_DECL of the vtable for TYPE. TYPE need not be polymorphic,
     or even complete.  If this does not exist, create it.  If COMPLETE is
     non-zero, then complete the definition of it -- that will render it
*************** get_vtable_decl (type, complete)
*** 1009,1040 ****
                            && DECL_VIRTUAL_P (decl), 20000118);
        return decl;
      }
-   
-   decl = build_lang_decl (VAR_DECL, name, void_type_node);
    
!   /* Set TREE_PUBLIC and TREE_EXTERN as appropriate.  */
!   import_export_vtable (decl, type, 0);
! 
    decl = pushdecl_top_level (decl);
    SET_IDENTIFIER_GLOBAL_VALUE (name, decl);
    
-   DECL_ARTIFICIAL (decl) = 1;
-   TREE_STATIC (decl) = 1;
- #ifndef WRITABLE_VTABLES
-   /* Make them READONLY by default. (mrs) */
-   TREE_READONLY (decl) = 1;
- #endif
    /* At one time the vtable info was grabbed 2 words at a time.  This
       fails on sparc unless you have 8-byte alignment.  (tiemann) */
    DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
  			   DECL_ALIGN (decl));
  
-   DECL_VIRTUAL_P (decl) = 1;
-   
    if (complete)
      cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
  
-   DECL_CONTEXT (decl) = type;
    return decl;
  }
  
--- 1035,1053 ----
                            && DECL_VIRTUAL_P (decl), 20000118);
        return decl;
      }
    
!   decl = build_vtable (type, name, void_type_node);
    decl = pushdecl_top_level (decl);
    SET_IDENTIFIER_GLOBAL_VALUE (name, decl);
    
    /* At one time the vtable info was grabbed 2 words at a time.  This
       fails on sparc unless you have 8-byte alignment.  (tiemann) */
    DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
  			   DECL_ALIGN (decl));
  
    if (complete)
      cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0);
  
    return decl;
  }
  
*************** build_secondary_vtable (binfo, for_type)
*** 1210,1228 ****
        buf2 = new_buf2;
      }
  
!   new_decl = build_lang_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
!   /* Remember which class this vtable is really for.  */
!   DECL_CONTEXT (new_decl) = for_type;
! 
!   DECL_ARTIFICIAL (new_decl) = 1;
!   TREE_STATIC (new_decl) = 1;
!   BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
!   DECL_VIRTUAL_P (new_decl) = 1;
! #ifndef WRITABLE_VTABLES
!   /* Make them READONLY by default. (mrs) */
!   TREE_READONLY (new_decl) = 1;
! #endif
    DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
  
    /* Make fresh virtual list, so we can smash it later.  */
    BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
--- 1223,1231 ----
        buf2 = new_buf2;
      }
  
!   new_decl = build_vtable (for_type, name, TREE_TYPE (orig_decl));
    DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
+   BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
  
    /* Make fresh virtual list, so we can smash it later.  */
    BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
*************** build_secondary_vtable (binfo, for_type)
*** 1250,1258 ****
    n_vtables += 1;
    n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
  #endif
- 
-   /* Set TREE_PUBLIC and TREE_EXTERN as appropriate.  */
-   import_export_vtable (new_decl, for_type, 0);
  
    if (TREE_VIA_VIRTUAL (binfo))
      my_friendly_assert (binfo == BINFO_FOR_VBASE (BINFO_TYPE (binfo),
--- 1253,1258 ----
Index: pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.397
diff -c -p -r1.397 pt.c
*** pt.c	2000/02/20 01:10:49	1.397
--- pt.c	2000/02/20 23:20:16
*************** tsubst_decl (t, args, type, in_decl)
*** 5856,5862 ****
  	{
  	  /* For a template type parameter, we don't have to do
  	     anything special.  */
! 	  r= TYPE_NAME (type);
  	  break;
  	}
  
--- 5856,5862 ----
  	{
  	  /* For a template type parameter, we don't have to do
  	     anything special.  */
! 	  r = TYPE_NAME (type);
  	  break;
  	}
  


More information about the Gcc-patches mailing list