C++ PATCH: new-abi rtti prepatch 2

Nathan Sidwell sidwell@codesourcery.com
Mon Jan 24 03:01:00 GMT 2000


Hi,
I've installed this second rtti setup patch.
It breaks out the generation of a vtable VAR_DECL into a separate
function, so that rtti will be able to get hold of the name, even
if the class is not defined. The new function can force the completion
of the vtable definition, effectively creating an object of type void.
All that is useful for is taking its address, and will only be done when
it is known that the vtable will never be created. finish_vtable_vardecl
needs adjusting to recognize such dummy vtables, and not attempt to
emit them.

This functionality will be used to emit the new-abi type_info
objects.

nathan
-- 
Dr Nathan Sidwell :: sidwell@codesourcery.com
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
2000-01-24  Nathan Sidwell  <sidwell@codesourcery.com>

	* cp-tree.h (get_vtable_decl): Prototype new function.
	* class.c (get_vtable_decl): New function. Broken out from ...
	(build_vtable): ... here. Use it.
	* decl2.c (finish_vtable_vardecl): Ignore dummy vtables created
	by get_vtable_decl.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.388
diff -c -3 -p -r1.388 cp-tree.h
*** cp-tree.h	2000/01/18 10:23:31	1.388
--- cp-tree.h	2000/01/22 22:57:45
*************** extern tree perform_implicit_conversion 
*** 3483,3488 ****
--- 3483,3489 ----
  extern tree build_vbase_path			PROTO((enum tree_code, tree, tree, tree, int));
  extern tree build_vtbl_ref			PROTO((tree, tree));
  extern tree build_vfn_ref			PROTO((tree *, tree, tree));
+ extern tree get_vtable_decl                     PROTO((tree, int));
  extern void add_method				PROTO((tree, tree *, tree));
  extern int currently_open_class			PROTO((tree));
  extern tree get_vfield_offset			PROTO((tree));
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.241
diff -c -3 -p -r1.241 class.c
*** class.c	2000/01/20 08:12:26	1.241
--- class.c	2000/01/22 22:57:44
*************** set_rtti_entry (virtuals, offset, type)
*** 853,858 ****
--- 853,906 ----
    TREE_VALUE (virtuals) = fn;
  }
  
+ /* 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
+    impossible to actually build the vtable, but is useful to get at those
+    which are known to exist in the runtime.  */
+ 
+ tree get_vtable_decl (type, complete)
+      tree type;
+      int complete;
+ {
+   tree name = get_vtable_name (type);
+   tree decl = IDENTIFIER_GLOBAL_VALUE (name);
+   
+   if (decl)
+     {
+       my_friendly_assert (TREE_CODE (decl) == VAR_DECL
+                           && 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;
+ }
+ 
  /* Build a virtual function for type TYPE.
     If BINFO is non-NULL, build the vtable starting with the initial
     approximation that it is the same as the one which is the head of
*************** static void
*** 862,870 ****
  build_vtable (binfo, type)
       tree binfo, type;
  {
-   tree name = get_vtable_name (type);
    tree virtuals, decl;
  
    if (binfo)
      {
        tree offset;
--- 910,919 ----
  build_vtable (binfo, type)
       tree binfo, type;
  {
    tree virtuals, decl;
  
+   decl = get_vtable_decl (type, /*complete=*/0);
+   
    if (binfo)
      {
        tree offset;
*************** build_vtable (binfo, type)
*** 875,882 ****
  	return;
  
        virtuals = copy_list (BINFO_VIRTUALS (binfo));
!       decl = build_lang_decl (VAR_DECL, name, 
! 			      TREE_TYPE (BINFO_VTABLE (binfo)));
  
        /* Now do rtti stuff.  */
        offset = get_derived_offset (TYPE_BINFO (type), NULL_TREE);
--- 924,931 ----
  	return;
  
        virtuals = copy_list (BINFO_VIRTUALS (binfo));
!       TREE_TYPE (decl) = TREE_TYPE (BINFO_VTABLE (binfo));
!       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (BINFO_VTABLE (binfo)));
  
        /* Now do rtti stuff.  */
        offset = get_derived_offset (TYPE_BINFO (type), NULL_TREE);
*************** build_vtable (binfo, type)
*** 885,892 ****
      }
    else
      {
        virtuals = NULL_TREE;
-       decl = build_lang_decl (VAR_DECL, name, void_type_node);
      }
  
  #ifdef GATHER_STATISTICS
--- 934,942 ----
      }
    else
      {
+       my_friendly_assert (TREE_CODE (TREE_TYPE (decl)) == VOID_TYPE,
+                           20000118);
        virtuals = NULL_TREE;
      }
  
  #ifdef GATHER_STATISTICS
*************** build_vtable (binfo, type)
*** 894,922 ****
    n_vtable_elems += list_length (virtuals);
  #endif
  
-   /* 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);
    /* Initialize the association list for this type, based
       on our first approximation.  */
    TYPE_BINFO_VTABLE (type) = decl;
    TYPE_BINFO_VIRTUALS (type) = virtuals;
- 
-   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;
-   DECL_CONTEXT (decl) = type;
  
    binfo = TYPE_BINFO (type);
    SET_BINFO_NEW_VTABLE_MARKED (binfo);
--- 944,953 ----
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.300
diff -c -3 -p -r1.300 decl2.c
*** decl2.c	2000/01/19 11:34:03	1.300
--- decl2.c	2000/01/22 22:57:49
*************** finish_vtable_vardecl (t, data)
*** 2551,2556 ****
--- 2551,2560 ----
  	  || (hack_decl_function_context (vars) && TREE_USED (vars)))
        && ! TREE_ASM_WRITTEN (vars))
      {
+       if (TREE_TYPE (vars) == void_type_node)
+         /* It is a dummy vtable made by get_vtable_decl. Ignore it.  */
+         return 0;
+       
        /* Write it out.  */
        mark_vtable_entries (vars);
        if (TREE_TYPE (DECL_INITIAL (vars)) == 0)


More information about the Gcc-patches mailing list