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
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 {
/* 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
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. */
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);
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));
}
@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
@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