cp-tree.h (unemitted_tinfo_decls): Declaration of a new varray.
authorMatt Austern <austern@apple.com>
Thu, 20 Mar 2003 21:14:30 +0000 (21:14 +0000)
committerMatt Austern <austern@gcc.gnu.org>
Thu, 20 Mar 2003 21:14:30 +0000 (21:14 +0000)
* cp-tree.h (unemitted_tinfo_decls): Declaration of a new varray.
(unemitted_tinfo_decl_p): Remove.
(emit_tinfo_decl): Change declaration to remove unused parameter.
* decl2.c (finish_file): Change tinfo emission to loop through
unemitted_tinfo_decls array instead of looping through all decls.
* rtti.c (unemitted_tinfo_decl_p): Declare as static, remove
unused second parameter.
(init_rtti_processing): initialize unemitted_tinfo_decls varray.
(get_tinfo_decls): push new tinfo decl on unemitted_tinfo_decls.
(emit_tinfo_decl): remove unused second parameter, add assertion
that decl hasn't already been emitted.

From-SVN: r64621

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/cp/rtti.c

index d5864cd7dea06aef5d6815380b2c98844547b57f..7c263488cbbf1b0f5fbb5773ddde9b9ef7165cda 100644 (file)
@@ -1,3 +1,17 @@
+2003-03-14  Matt Austern  <austern@apple.com>
+
+       * cp-tree.h (unemitted_tinfo_decls): Declaration of a new varray.
+       (unemitted_tinfo_decl_p): Remove.
+       (emit_tinfo_decl): Change declaration to remove unused parameter.
+       * decl2.c (finish_file): Change tinfo emission to loop through
+       unemitted_tinfo_decls array instead of looping through all decls.
+       * rtti.c (unemitted_tinfo_decl_p): Declare as static, remove
+       unused second parameter.
+       (init_rtti_processing): initialize unemitted_tinfo_decls varray.
+       (get_tinfo_decls): push new tinfo decl on unemitted_tinfo_decls.
+       (emit_tinfo_decl): remove unused second parameter, add assertion
+       that decl hasn't already been emitted.  
+       
 2003-03-19  Nathanael Nerode  <neroden@gcc.gnu.org>
 
        * dump.c (cp_dump_tree), cp-tree.h (cp_dump_tree): Change return
index f8ded19f7c7299878905ba95e15c57f74984e485..2a207a1a7f91765cff918bd246d48e1484d5aeac 100644 (file)
@@ -4062,14 +4062,16 @@ extern void init_repo (const char *);
 extern void finish_repo (void);
 
 /* in rtti.c */
+/* A varray of all tinfo decls that haven't been emitted yet. */
+extern GTY(()) varray_type unemitted_tinfo_decls;
+
 extern void init_rtti_processing (void);
 extern tree build_typeid (tree);
 extern tree get_tinfo_decl (tree);
 extern tree get_typeid (tree);
 extern tree build_dynamic_cast (tree, tree);
 extern void emit_support_tinfos (void);
-extern bool unemitted_tinfo_decl_p (tree, void *);
-extern bool emit_tinfo_decl (tree *, void *);
+extern bool emit_tinfo_decl (tree);
 
 /* in search.c */
 extern tree lookup_base (tree, tree, base_access, base_kind *);
index 9937e754ab7a93f6f70e762cd263e41ab9e326eb..1ba80d7a7d8130cbaee4cf026cc71b38d522cdd0 100644 (file)
@@ -2595,6 +2595,7 @@ finish_file ()
   do 
     {
       tree t;
+      size_t n_old, n_new;
 
       reconsider = false;
 
@@ -2611,7 +2612,7 @@ finish_file ()
       while (keyed_classes != NULL_TREE
             && maybe_emit_vtables (TREE_VALUE (keyed_classes)))
        {
-         reconsider = 1;
+         reconsider = true;
          keyed_classes = TREE_CHAIN (keyed_classes);
        }
  
@@ -2624,7 +2625,7 @@ finish_file ()
            {
              if (maybe_emit_vtables (TREE_VALUE (next)))
                {
-                 reconsider = 1;
+                 reconsider = true;
                  TREE_CHAIN (t) = TREE_CHAIN (next);
                }
              else
@@ -2634,10 +2635,34 @@ finish_file ()
            }
        }
        
-      /* Write out needed type info variables. Writing out one variable
-         might cause others to be needed.  */
-      if (walk_globals (unemitted_tinfo_decl_p, emit_tinfo_decl, /*data=*/0))
-       reconsider = true;
+      /* Write out needed type info variables.  We have to be careful
+        looping through unemitted decls, because emit_tinfo_decl may
+        cause other variables to be needed.  We stick new elements
+        (and old elements that we may need to reconsider) at the end
+        of the array, then shift them back to the beginning once we're
+        done. */
+  
+      n_old = VARRAY_ACTIVE_SIZE (unemitted_tinfo_decls);
+      for (i = 0; i < n_old; ++i)
+       {
+         tree tinfo_decl = VARRAY_TREE (unemitted_tinfo_decls, i);
+         if (emit_tinfo_decl (tinfo_decl))
+           reconsider = true;
+         else
+           VARRAY_PUSH_TREE (unemitted_tinfo_decls, tinfo_decl);
+       }
+  
+      /* The only elements we want to keep are the new ones.  Copy
+        them to the beginning of the array, then get rid of the
+        leftovers. */
+      n_new = VARRAY_ACTIVE_SIZE (unemitted_tinfo_decls) - n_old;
+      memmove (&VARRAY_TREE (unemitted_tinfo_decls, 0),
+              &VARRAY_TREE (unemitted_tinfo_decls, n_old),
+              n_new * sizeof (tree));
+      memset (&VARRAY_TREE (unemitted_tinfo_decls, n_new),
+             0,
+             n_old * sizeof (tree));
+      VARRAY_ACTIVE_SIZE (unemitted_tinfo_decls) = n_new;
 
       /* The list of objects with static storage duration is built up
         in reverse order.  We clear STATIC_AGGREGATES so that any new
index eab85f700504396abefad8e154592a5bd166f746..a9a7cdbcea084feb2f0bd840c143c3677e4f4efd 100644 (file)
@@ -73,6 +73,9 @@ Boston, MA 02111-1307, USA.  */
 /* The IDENTIFIER_NODE naming the real class.  */
 #define TINFO_REAL_NAME(NODE) TREE_PURPOSE (NODE)
 
+/* A varray of all tinfo decls that haven't yet been emitted. */
+varray_type unemitted_tinfo_decls;
+
 static tree build_headof PARAMS((tree));
 static tree ifnonnull PARAMS((tree, tree));
 static tree tinfo_name PARAMS((tree));
@@ -97,6 +100,7 @@ static tree get_pseudo_ti_init PARAMS ((tree, tree, bool *));
 static tree get_pseudo_ti_desc PARAMS((tree));
 static void create_tinfo_types PARAMS((void));
 static bool typeinfo_in_lib_p (tree);
+static bool unemitted_tinfo_decl_p PARAMS((tree));
 
 static int doing_runtime = 0;
 \f
@@ -122,6 +126,8 @@ init_rtti_processing (void)
   type_info_ptr_type = build_pointer_type (const_type_info_type);
   type_info_ref_type = build_reference_type (const_type_info_type);
 
+  VARRAY_TREE_INIT (unemitted_tinfo_decls, 10, "RTTI decls");
+
   create_tinfo_types ();
 }
 
@@ -367,6 +373,10 @@ get_tinfo_decl (tree type)
 
       /* Remember the type it is for.  */
       TREE_TYPE (name) = type;
+
+      /* Add decl to the global array of tinfo decls. */
+      my_friendly_assert (unemitted_tinfo_decls != 0, 20030312);
+      VARRAY_PUSH_TREE (unemitted_tinfo_decls, d);
     }
 
   return d;
@@ -1403,8 +1413,8 @@ emit_support_tinfos (void)
 /* Return true, iff T is a type_info variable which has not had a
    definition emitted for it.  */
 
-bool
-unemitted_tinfo_decl_p (tree t, void *data ATTRIBUTE_UNUSED)
+static bool
+unemitted_tinfo_decl_p (tree t)
 {
   if (/* It's a var decl */
       TREE_CODE (t) == VAR_DECL
@@ -1429,13 +1439,14 @@ unemitted_tinfo_decl_p (tree t, void *data ATTRIBUTE_UNUSED)
    generate the initializer.  */
 
 bool
-emit_tinfo_decl (tree *decl_ptr, void *data ATTRIBUTE_UNUSED)
+emit_tinfo_decl (tree decl)
 {
-  tree decl = *decl_ptr;
   tree type = TREE_TYPE (DECL_NAME (decl));
   bool non_public;
   int in_library = typeinfo_in_lib_p (type);
   tree var_desc, var_init;
+
+  my_friendly_assert (unemitted_tinfo_decl_p (decl), 20030307); 
   
   import_export_tinfo (decl, type, in_library);
   if (DECL_REALLY_EXTERN (decl) || !DECL_NEEDED_P (decl))