cp-tree.h (lang_decl_flags): Add global_ctor_p and global_dtor_p.
authorMark Mitchell <mark@codesourcery.com>
Thu, 30 Sep 1999 17:43:44 +0000 (17:43 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Thu, 30 Sep 1999 17:43:44 +0000 (17:43 +0000)
* cp-tree.h (lang_decl_flags): Add global_ctor_p and
global_dtor_p.  Add init_priority.
(DECL_ACCESS): Adjust accordingly.
(DECL_GLOBAL_CTOR_P, DECL_GLOBAL_DTOR_P): New macros.
(GLOBAL_INIT_PRIORITY): Likewise.
* decl.c (lang_mark_tree): Adjust accordingly.
(start_objects): Set DECL_GLOBAL_CTOR_P, DECL_GLOBAL_DTOR_P,
and GLOBAL_INIT_PRIORITY.
* dump.c (dequeue_and_dump): Print them.
* ir.texi: Document them.

From-SVN: r29733

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/dump.c
gcc/cp/ir.texi

index 0272a87..85a03fe 100644 (file)
@@ -1,5 +1,16 @@
 1999-09-30  Mark Mitchell  <mark@codesourcery.com>
 
+       * cp-tree.h (lang_decl_flags): Add global_ctor_p and
+       global_dtor_p.  Add init_priority.
+       (DECL_ACCESS): Adjust accordingly.
+       (DECL_GLOBAL_CTOR_P, DECL_GLOBAL_DTOR_P): New macros.
+       (GLOBAL_INIT_PRIORITY): Likewise.
+       * decl.c (lang_mark_tree): Adjust accordingly.
+       (start_objects): Set DECL_GLOBAL_CTOR_P, DECL_GLOBAL_DTOR_P, 
+       and GLOBAL_INIT_PRIORITY.
+       * dump.c (dequeue_and_dump): Print them.
+       * ir.texi: Document them.
+
        * decl2.c (struct priority_info_s): Remove initialization_sequence
        and destruction_sequence.
        (start_static_storage_duration_function): Return the body of the
index a3146dd..c5886fc 100644 (file)
@@ -1585,9 +1585,10 @@ struct lang_decl_flags
   unsigned bitfield : 1;
   unsigned defined_in_class : 1;
   unsigned pending_inline_p : 1;
-  unsigned dummy : 5;
+  unsigned global_ctor_p : 1;
+  unsigned global_dtor_p : 1;
+  unsigned dummy : 3;
 
-  tree access;
   tree context;
 
   union {
@@ -1597,6 +1598,15 @@ struct lang_decl_flags
     /* In a NAMESPACE_DECL, this is NAMESPACE_LEVEL.  */
     struct binding_level *level;
   } u;
+
+  union {
+    /* This is DECL_ACCESS.  */
+    tree access;
+
+    /* In a namespace-scope FUNCTION_DECL, this is
+       GLOBAL_INIT_PRIORITY.  */
+    int init_priority;
+  } u2;
 };
 
 struct lang_decl
@@ -2347,7 +2357,22 @@ extern int flag_new_for_scope;
    For example, if a member that would normally be public in a
    derived class is made protected, then the derived class and the
    protected_access_node will appear in the DECL_ACCESS for the node.  */
-#define DECL_ACCESS(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.access)
+#define DECL_ACCESS(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.u2.access)
+
+/* Nonzero if the FUNCTION_DECL is a global constructor.  */
+#define DECL_GLOBAL_CTOR_P(NODE) \
+  (DECL_LANG_SPECIFIC ((NODE))->decl_flags.global_ctor_p)
+
+/* Nonzero if the FUNCTION_DECL is a global destructor.  */
+#define DECL_GLOBAL_DTOR_P(NODE) \
+  (DECL_LANG_SPECIFIC ((NODE))->decl_flags.global_dtor_p)
+
+/* If DECL_GLOBAL_CTOR_P or DECL_GLOBAL_DTOR_P holds, this macro
+   returns the initialization priority for the function.  Constructors
+   with lower numbers should be run first.  Destructors should be run
+   in the reverse order of constructors.  */
+#define GLOBAL_INIT_PRIORITY(NODE) \
+  (DECL_LANG_SPECIFIC ((NODE))->decl_flags.u2.init_priority)
 
 /* Accessor macros for C++ template decl nodes.  */
 
index bdbd1e8..49d80dc 100644 (file)
@@ -14293,7 +14293,8 @@ lang_mark_tree (t)
       if (ld)
        {
          ggc_mark (ld);
-         ggc_mark_tree (ld->decl_flags.access);
+         if (!DECL_GLOBAL_CTOR_P (t) && !DECL_GLOBAL_DTOR_P (t))
+           ggc_mark_tree (ld->decl_flags.u2.access);
          ggc_mark_tree (ld->decl_flags.context);
          if (TREE_CODE (t) != NAMESPACE_DECL)
            ggc_mark_tree (ld->decl_flags.u.template_info);
index 747e28d..7420c97 100644 (file)
@@ -625,6 +625,15 @@ dequeue_and_dump (di)
            dump_string (di, "operator");
          if (DECL_CONV_FN_P (t))
            dump_string (di, "conversion");
+         if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
+           {
+             if (DECL_GLOBAL_CTOR_P (t))
+               dump_string (di, "global init");
+             if (DECL_GLOBAL_DTOR_P (t))
+               dump_string (di, "global fini");
+             dump_int (di, "prio", GLOBAL_INIT_PRIORITY (t));
+           }
+
          if (dump_children_p)
            dump_child ("body", DECL_SAVED_TREE (t));
        }
index f85c657..2831e3b 100644 (file)
@@ -948,6 +948,9 @@ the @code{DECL_REAL_CONTEXT} for @code{f} will be the
 @findex DECL_OVERLOADED_OPERATOR_P
 @findex DECL_CONV_FN_P
 @findex DECL_ARTIFIICIAL
+@findex DECL_GLOBAL_CTOR_P
+@findex DECL_GLOBAL_DTOR_P
+@findex GLOBAL_INIT_PRIORITY
 
 The following macros and functions can be used on a @code{FUNCTION_DECL}:
 @ftable @code
@@ -1006,6 +1009,22 @@ This macro holds if the function is an overloaded operator.
 @item DECL_CONV_FN_P
 This macro holds if the function is a type-conversion operator.
 
+@item DECL_GLOBAL_CTOR_P
+This predicate holds if the function is a file-scope initialization
+function.
+
+@item DECL_GLOBAL_DTOR_P
+This predicate holds if the function is a file-scope finalization
+function.
+
+@item GLOBAL_INIT_PRIORITY
+If either @code{DECL_GLOBAL_CTOR_P} or @code{DECL_GLOBAL_DTOR_P} holds,
+then this gives the initialization priority for the function.  The
+linker will arrange that all functions for which
+@code{DECL_GLOBAL_CTOR_P} holds are run in increasing order of priority
+before @code{main} is called.  When the program exits, all functions for
+which @code{DECL_GLOBAL_DTOR_P} holds are run in the reverse order.
+
 @item DECL_ARTIFICIAL
 This macro holds if the function was implicitly generated by the
 compiler, rather than explicitly declared.  In addition to implicitly