Commit 1f6e1acc by Alex Samuel Committed by Mark Mitchell

Make-lang.in (CXX_SRCS): Add mangle.c.

	* Make-lang.in (CXX_SRCS): Add mangle.c.
	* Makefile.in (CXX_OBJS): Add mangle.o.
	(mangle.o): New rule.

Co-Authored-By: Mark Mitchell <mark@codesourcery.com>

From-SVN: r34394
parent 031926e2
2000-06-03 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (TMPL_ARGS_LEVEL): Clarify comment.
(INNERMOST_TEMPLATE_ARGS): New macro.
(innermost_args): Remove.
(get_innermost_template_args): New function.
* decl2.c (arg_assoc_class): Use INNERMOST_TEMPLATE_ARGS.
* error.c (dump_function_decl): Be caution when using
most_general_template.
* method.c (build_template_parm_names): Use
INNERMOST_TEMPLATE_ARGS.
* pt.c (add_to_template_args): Tidy comment
(get_innermost_template_args): New function.
(check_explicit_specialization): Clear DECL_INITIAL for a new
specialization.
(process_partial_specialization): Use INNERMOST_TEMPLATE_ARGS.
Tidy.
(push_template_decl): Always register specializations of the most
general template.
(convert_template_argument): Use INNERMOST_TEMPLATE_ARGS.
(coerce_template_parms): Likewise.
(lookup_template_class): Likewise.
(innermost_args): Remove.
(tsubst_decl): Use INNERMOST_TEMPLATE_ARGS.
(tsubst_decl): Handle tricky specializations. Use
get_innermost_template_args.
(instantiate_template): Simplify handling of partial
instantiations.
(get_class_bindings): Use INNERMOST_TEMPLATE_ARGS.
(most_general_template): Reimplement, in a more straightforward
manner.
(regenerate_decl_from_template): Tweak formatting. Use
TMPL_ARGS_DEPTH for clarity.
(set_mangled_name_for_template_decl): Use INNERMOST_ARGS.
* dump.c (dequeue_and_dump): Dump information about thunks.
2000-06-02 Jason Merrill <jason@casey.soma.redhat.com>
* exception.cc (__cp_pop_exception): If we aren't popping or
rethrowing, push down past any uncaught exceptions.
(__uncatch_exception): Rethrow the currently handled exception.
Move it to the top of the exception stack.
Fri Jun 2 19:38:57 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* cp-tree.h: Use struct tree_common instead of a char array.
* decl.c (grokdeclarator): Set DECL_NONADDRESSABLE_P instead
of TREE_ADDRESSABLE.
2000-06-02 Richard Henderson <rth@cygnus.com>
* decl.c (init_decl_processing): Don't set lang_get_alias_set.
2000-06-02 Jason Merrill <jason@casey.soma.redhat.com>
* decl.c (store_return_init): Call put_var_into_stack.
2000-06-01 Mark Mitchell <mark@codesourcery.com>
2000-06-03 Alex Samuel <samuel@codesourcery.com>
Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (lang_decl_flags): Add anticipated_p.
(DECL_ANTICIPATED): Use it.
* Make-lang.in (CXX_SRCS): Add mangle.c.
* Makefile.in (CXX_OBJS): Add mangle.o.
(mangle.o): New rule.
* class.c (local_classes): New variable.
* class.c (get_vtable_name): Use mangle_vtable_for_type for new ABI.
(get_vtt_name): Use mangle_vtt_name for new ABI.
(init_class_processing): Initialize local_classes.
(build_ctor_vtbl_group): Use mangle_ctor_vtbl_for_type for new ABI.
* cp-tree.h (cp_tree_index): Add CPTI_STD_IDENTIFIER.
(std_identifier): New macro.
(DECL_VOLATILE_MEMFUNC_P): New macro.
(DECL_NAMESPACE_STD_P): Likewise.
(local_classes): Declare.
(get_mostly_instantiated_function_type): Declare.
(init_mangle): Declare.
(mangle_decl): Likewise.
(mangle_type_string): Likewise.
(mangle_type): Likewise.
(mangle_typeinfo_for_type): Likewise.
(mangle_typeinfo_string_for_type): Likewise.
(mangle_vtbl_for_type): Likewise.
(mangle_vtt_for_type): Likewise.
(mangle_ctor_vtbl_for_type): Likewise.
(mangle_thunk): Likewise.
(mangle_conv_op_name_for_type): Likewise.
(mangle_guard_variable): Likewise.
* decl.c (pushtag): Keep track of local classes.
(initialize_predefined_identifiers): Initialize std_identifier.
(init_decl_processing): Use std_identifier.
(start_decl): Don't treat instantiations as specializations.
(grokdeclarator): Likewise.
(grokvardecl): Call mangle_decl for new ABI. Only set mangled
name for fully-instantiated templates.
* decl2.c (grokclassfn): Use set_mangled_name_for_decl for
destructors with the new ABI.
(finish_static_data_member_decl): Use mangle_decl under the new ABI.
(grokfield): Use mangle_type for new ABI.
(grokoptypename): Use mangle_conv_op_for_type for new ABI.
(get_sentry): Use mangle_guard_variable for new ABI.
(start_static_initialization_or_destruction): Likewise.
* expr.c (extract_aggr_init): Remove.
(extract_scalar_init): Likewise.
(extract_init): Remove #if 0'd code.
* mangle.c: New function.
* method.c (build_mangled_name): Assert not flag_new_abi.
(build_static_name): Likewise.
(build_decl_overload_real): Likewise.
(build_typename_overload): Likewise.
(build_overload_with_type): Likewise.
(build_overload_name): Likewise.
(get_ctor_vtbl_name): Likewise.
(start_squangling): Likewise.
(get_id_2): Likewise.
(set_mangled_name_for_decl): Call mangle_decl for new ABI.
(init_method): Call init_mangle for new ABI.
(make_thunk): Call mangle_thunk for new ABI.
* operators.def: Correct new ABI manglings for the `%' operator.
Add `::' operator.
* pt.c (build_template_decl): Copy DECL_OVERLOADED_OPERATOR_P and
DECL_ASSIGNMENT_OPERATOR_P to the TEMPLATE_DECL.
(lookup_template_class): Call mangle_decl for new ABI.
(get_mostly_instantiated_function_type): New function.
(set_mangled_name_for_template_decl): Use it.
(tsubst_decl): Use set_mangled_name_for_decl for destructors with
the new ABI. Use mangle_conv_op_name_for_type for instantiated
conversion op names.
* rtti.c (tinfo_name): Call mangle_type_string for new ABI.
(get_tinfo_decl): Call mangle_typeinfo_for_type for new ABI.
(tinfo_base_init): Likewise. Mangle typeinfo string name with
mangle_typeinfo_string_for_type.
2000-06-01 Richard Henderson <rth@cygnus.com>
......
......@@ -115,11 +115,11 @@ CXX_SRCS = $(srcdir)/cp/call.c $(srcdir)/cp/class.c $(srcdir)/cp/cp-tree.def \
$(srcdir)/cp/errfn.c $(srcdir)/cp/error.c $(srcdir)/cp/except.c \
$(srcdir)/cp/expr.c $(srcdir)/cp/friend.c $(srcdir)/cp/init.c \
$(srcdir)/cp/input.c $(srcdir)/cp/lex.c $(srcdir)/cp/lex.h \
$(srcdir)/cp/method.c $(srcdir)/cp/optimize.c $(srcdir)/cp/parse.y \
$(srcdir)/cp/pt.c $(srcdir)/cp/ptree.c $(srcdir)/cp/repo.c \
$(srcdir)/cp/rtti.c $(srcdir)/cp/search.c $(srcdir)/cp/semantics.c \
$(srcdir)/cp/spew.c $(srcdir)/cp/tree.c $(srcdir)/cp/typeck.c \
$(srcdir)/cp/typeck2.c $(srcdir)/cp/xref.c
$(srcdir)/cp/mangle.c $(srcdir)/cp/method.c $(srcdir)/cp/optimize.c \
$(srcdir)/cp/parse.y $(srcdir)/cp/pt.c $(srcdir)/cp/ptree.c \
$(srcdir)/cp/repo.c $(srcdir)/cp/rtti.c $(srcdir)/cp/search.c \
$(srcdir)/cp/semantics.c $(srcdir)/cp/spew.c $(srcdir)/cp/tree.c \
$(srcdir)/cp/typeck.c $(srcdir)/cp/typeck2.c $(srcdir)/cp/xref.c
cc1plus$(exeext): $(P) $(CXX_SRCS) $(LIBDEPS) stamp-objlist c-common.o \
c-pragma.o $(srcdir)/cp/cp-tree.h $(srcdir)/cp/cp-tree.def \
......
......@@ -176,7 +176,7 @@ INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config -I$(srcdir)
CXX_OBJS = call.o decl.o errfn.o expr.o pt.o typeck2.o \
class.o decl2.o error.o lex.o parse.o ptree.o rtti.o spew.o typeck.o cvt.o \
except.o friend.o init.o method.o search.o semantics.o tree.o xref.o \
repo.o dump.o optimize.o @extra_cxx_objs@
repo.o dump.o optimize.o mangle.o @extra_cxx_objs@
# Language-independent object files.
OBJS = `cat ../stamp-objlist` ../c-common.o ../c-pragma.o
......@@ -311,6 +311,7 @@ dump.o: dump.c $(CXX_TREE_H)
optimize.o: optimize.c $(CXX_TREE_H) \
$(srcdir)/../rtl.h $(srcdir)/../integrate.h ../insn-config.h \
$(srcdir)/../input.h
mangle.o: mangle.c $(CXX_TREE_H) $(srcdir)/../toplev.h
#
# These exist for maintenance purposes.
......
......@@ -83,6 +83,10 @@ typedef struct vcall_offset_data_s
static int current_class_stack_size;
static class_stack_node_t current_class_stack;
/* An array of all local classes present in this translation unit, in
declaration order. */
varray_type local_classes;
static tree get_vfield_name PARAMS ((tree));
static void finish_struct_anon PARAMS ((tree));
static tree build_vbase_pointer PARAMS ((tree, tree));
......@@ -630,6 +634,9 @@ static tree
get_vtable_name (type)
tree type;
{
if (flag_new_abi)
return mangle_vtbl_for_type (type);
else
return build_overload_with_type (get_identifier (VTABLE_NAME_PREFIX),
type);
}
......@@ -641,6 +648,9 @@ tree
get_vtt_name (type)
tree type;
{
if (flag_new_abi)
return mangle_vtt_for_type (type);
else
return build_overload_with_type (get_identifier (VTT_NAME_PREFIX),
type);
}
......@@ -5296,6 +5306,8 @@ init_class_processing ()
current_class_stack
= (class_stack_node_t) xmalloc (current_class_stack_size
* sizeof (struct class_stack_node));
VARRAY_TREE_INIT (local_classes, 8, "local_classes");
ggc_add_tree_varray_root (&local_classes, 1);
access_default_node = build_int_2 (0, 0);
access_public_node = build_int_2 (ak_public, 0);
......@@ -6698,6 +6710,9 @@ build_ctor_vtbl_group (binfo, t)
tree id;
/* See if we've already create this construction vtable group. */
if (flag_new_abi)
id = mangle_ctor_vtbl_for_type (t, binfo);
else
id = get_ctor_vtbl_name (t, binfo);
if (IDENTIFIER_GLOBAL_VALUE (id))
return;
......
......@@ -588,6 +588,7 @@ enum cp_tree_index
CPTI_PFN_OR_DELTA2_IDENTIFIER,
CPTI_VPTR_IDENTIFIER,
CPTI_PUSH_EXCEPTION_IDENTIFIER,
CPTI_STD_IDENTIFIER,
CPTI_LANG_NAME_C,
CPTI_LANG_NAME_CPLUSPLUS,
......@@ -707,6 +708,8 @@ extern tree cp_global_trees[CPTI_MAX];
/* The name of the function to call to push an exception onto the
exception stack. */
#define cp_push_exception_identifier cp_global_trees[CPTI_PUSH_EXCEPTION_IDENTIFIER]
/* The name of the std namespace. */
#define std_identifier cp_global_trees[CPTI_STD_IDENTIFIER]
#define lang_name_c cp_global_trees[CPTI_LANG_NAME_C]
#define lang_name_cplusplus cp_global_trees[CPTI_LANG_NAME_CPLUSPLUS]
......@@ -1968,8 +1971,7 @@ struct lang_decl
#define DECL_COPY_CONSTRUCTOR_P(NODE) \
(DECL_CONSTRUCTOR_P (NODE) && copy_args_p (NODE))
/* There ought to be a better way to find out whether or not something is
a destructor. */
/* Nonzero if NODE is a destructor. */
#define DECL_DESTRUCTOR_P(NODE) \
(DECL_LANG_SPECIFIC (NODE)->decl_flags.destructor_attr)
......@@ -2118,6 +2120,13 @@ struct lang_decl
&& CP_TYPE_CONST_P (TREE_TYPE (TREE_VALUE \
(TYPE_ARG_TYPES (TREE_TYPE (NODE))))))
/* Nonzero for FUNCTION_DECL means that this member function
has `this' as volatile X *const. */
#define DECL_VOLATILE_MEMFUNC_P(NODE) \
(DECL_NONSTATIC_MEMBER_FUNCTION_P (NODE) \
&& CP_TYPE_VOLATILE_P (TREE_TYPE (TREE_VALUE \
(TYPE_ARG_TYPES (TREE_TYPE (NODE))))))
/* Nonzero for a DECL means that this member is a non-static member. */
#define DECL_NONSTATIC_MEMBER_P(NODE) \
((TREE_CODE (NODE) == FUNCTION_DECL \
......@@ -2226,6 +2235,12 @@ struct lang_decl
#define ORIGINAL_NAMESPACE(NODE) \
(DECL_NAMESPACE_ALIAS (NODE) ? DECL_NAMESPACE_ALIAS (NODE) : (NODE))
/* Non-zero if NODE is the std namespace. */
#define DECL_NAMESPACE_STD_P(NODE) \
(TREE_CODE (NODE) == NAMESPACE_DECL \
&& CP_DECL_CONTEXT (NODE) == global_namespace \
&& DECL_NAME (NODE) == std_identifier)
/* In a non-local VAR_DECL with static storage duration, this is the
initialization priority. If this value is zero, the NODE will be
initialized at the DEFAULT_INIT_PRIORITY. */
......@@ -3397,6 +3412,10 @@ extern int current_class_depth;
of CURRENT_FUNCTION_DECL due to overloading */
extern tree original_function_name;
/* An array of all local classes present in this translation unit, in
declaration order. */
extern varray_type local_classes;
/* Here's where we control how name mangling takes place. */
#define OPERATOR_ASSIGN_FORMAT "__a%s"
......@@ -4355,7 +4374,7 @@ extern void print_candidates PARAMS ((tree));
extern int instantiate_pending_templates PARAMS ((void));
extern tree tsubst_default_argument PARAMS ((tree, tree, tree));
extern tree most_general_template PARAMS ((tree));
extern tree get_mostly_instantiated_function_type PARAMS ((tree, tree *, tree *));
extern int processing_template_parmlist;
/* in repo.c */
......@@ -4718,6 +4737,20 @@ extern void GNU_xref_member PARAMS ((tree, tree));
/* in dump.c */
extern void dump_node_to_file PARAMS ((tree, const char *));
/* in mangle.c */
extern void init_mangle PARAMS ((void));
extern tree mangle_decl PARAMS ((tree));
extern const char *mangle_type_string PARAMS ((tree));
extern tree mangle_type PARAMS ((tree));
extern tree mangle_typeinfo_for_type PARAMS ((tree));
extern tree mangle_typeinfo_string_for_type PARAMS ((tree));
extern tree mangle_vtbl_for_type PARAMS ((tree));
extern tree mangle_vtt_for_type PARAMS ((tree));
extern tree mangle_ctor_vtbl_for_type PARAMS ((tree, tree));
extern tree mangle_thunk PARAMS ((tree, int, int));
extern tree mangle_conv_op_name_for_type PARAMS ((tree));
extern tree mangle_guard_variable PARAMS ((tree));
/* -- end of C++ */
#endif /* not _CP_TREE_H */
......@@ -2881,10 +2881,25 @@ pushtag (name, type, globalize)
TYPE_CONTEXT (type) = DECL_CONTEXT (d);
DECL_ASSEMBLER_NAME (d) = DECL_NAME (d);
/* If this is a local class, keep track of it. We need this
information for name-mangling, and so that it is possible to find
all function definitions in a translation unit in a convenient
way. (It's otherwise tricky to find a member function definition
it's only pointed to from within a local class.) */
if (TYPE_CONTEXT (type)
&& TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL)
VARRAY_PUSH_TREE (local_classes, type);
if (!uses_template_parms (type))
{
if (flag_new_abi)
DECL_ASSEMBLER_NAME (d) = mangle_type (type);
else
DECL_ASSEMBLER_NAME (d)
= get_identifier (build_overload_name (type, 1, 1));
}
}
if (b->parm_flag == 2)
{
if (!COMPLETE_TYPE_P (current_class_type))
......@@ -6229,6 +6244,7 @@ initialize_predefined_identifiers ()
{ "_vptr", &vptr_identifier, 0 },
{ "__cp_push_exception", &cp_push_exception_identifier, 0 },
{ "__vtt_parm", &vtt_parm_identifier, 0 },
{ "std", &std_identifier, 0 },
{ NULL, NULL, 0 }
};
......@@ -6577,7 +6593,8 @@ init_decl_processing ()
record_builtin_type (RID_MAX, NULL_PTR, vtbl_ptr_type_node);
std_node = build_decl (NAMESPACE_DECL,
get_identifier (flag_honor_std ? "fake std":"std"),
flag_honor_std
? get_identifier ("fake std") : std_identifier,
void_type_node);
pushdecl (std_node);
......@@ -7246,7 +7263,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
/* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
DECL_IN_AGGR_P (decl) = 0;
if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
|| CLASSTYPE_USE_TEMPLATE (context))
|| CLASSTYPE_TEMPLATE_INSTANTIATION (context))
{
SET_DECL_TEMPLATE_SPECIALIZATION (decl);
/* [temp.expl.spec] An explicit specialization of a static data
......@@ -9086,7 +9103,16 @@ grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace)
type = TREE_TYPE (type);
decl = build_lang_decl (VAR_DECL, declarator, type);
DECL_CONTEXT (decl) = basetype;
DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
/* DECL_ASSEMBLER_NAME is needed only for full-instantiated
templates. */
if (!uses_template_parms (decl))
{
if (flag_new_abi)
DECL_ASSEMBLER_NAME (decl) = mangle_decl (decl);
else
DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype,
declarator);
}
}
else
{
......@@ -9111,7 +9137,13 @@ grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace)
context = DECL_CONTEXT (decl);
if (declarator && context && current_lang_name != lang_name_c)
DECL_ASSEMBLER_NAME (decl) = build_static_name (context, declarator);
{
if (flag_new_abi)
DECL_ASSEMBLER_NAME (decl) = mangle_decl (decl);
else
DECL_ASSEMBLER_NAME (decl)
= build_static_name (context, declarator);
}
}
if (in_namespace)
......@@ -11146,6 +11178,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
DECL_NAME (CLASSTYPE_TI_TEMPLATE (type))
= TYPE_IDENTIFIER (type);
if (flag_new_abi)
DECL_ASSEMBLER_NAME (decl) = mangle_type (type);
else
{
/* XXX Temporarily set the scope.
When returning, start_decl expects it as NULL_TREE,
and will then then set it using pushdecl. */
......@@ -11159,6 +11195,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
DECL_ASSEMBLER_NAME (decl)
= get_identifier (build_overload_name (type, 1, 1));
DECL_CONTEXT (decl) = NULL_TREE;
}
/* FIXME remangle member functions; member functions of a
type with external linkage have external linkage. */
......
......@@ -1116,7 +1116,12 @@ grokclassfn (ctype, function, flags, quals)
if (flags == DTOR_FLAG)
{
DECL_DESTRUCTOR_P (function) = 1;
if (flag_new_abi)
set_mangled_name_for_decl (function);
else
DECL_ASSEMBLER_NAME (function) = build_destructor_name (ctype);
TYPE_HAS_DESTRUCTOR (ctype) = 1;
}
else
......@@ -1578,6 +1583,8 @@ finish_static_data_member_decl (decl, init, asmspec_tree, flags)
my_friendly_assert (TREE_PUBLIC (decl), 0);
DECL_CONTEXT (decl) = current_class_type;
/* We cannot call pushdecl here, because that would fill in the
decl of our TREE_CHAIN. Instead, we modify cp_finish_decl to do
the right thing, namely, to put this decl out straight away. */
......@@ -1585,6 +1592,9 @@ finish_static_data_member_decl (decl, init, asmspec_tree, flags)
if (!asmspec && current_class_type)
{
DECL_INITIAL (decl) = error_mark_node;
if (flag_new_abi)
DECL_ASSEMBLER_NAME (decl) = mangle_decl (decl);
else
DECL_ASSEMBLER_NAME (decl)
= build_static_name (current_class_type, DECL_NAME (decl));
}
......@@ -1611,7 +1621,6 @@ finish_static_data_member_decl (decl, init, asmspec_tree, flags)
TREE_USED (decl) = 1;
DECL_INITIAL (decl) = init;
DECL_IN_AGGR_P (decl) = 1;
DECL_CONTEXT (decl) = current_class_type;
cp_finish_decl (decl, init, asmspec_tree, flags);
}
......@@ -1718,8 +1727,13 @@ grokfield (declarator, declspecs, init, asmspec_tree, attrlist)
name for this TYPE_DECL. */
DECL_ASSEMBLER_NAME (value) = DECL_NAME (value);
if (!uses_template_parms (value))
{
if (flag_new_abi)
DECL_ASSEMBLER_NAME (value) = mangle_type (TREE_TYPE (value));
else
DECL_ASSEMBLER_NAME (value) =
get_identifier (build_overload_name (TREE_TYPE (value), 1, 1));
}
if (processing_template_decl)
value = push_template_decl (value);
......@@ -1905,6 +1919,9 @@ grokoptypename (declspecs, declarator)
tree declspecs, declarator;
{
tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
if (flag_new_abi)
return mangle_conv_op_name_for_type (t);
else
return build_typename_overload (t);
}
......@@ -2856,16 +2873,25 @@ build_cleanup (decl)
return temp;
}
/* Returns the initialization guard variable for the non-local
variable DECL. */
static tree
get_sentry (base)
tree base;
get_sentry (decl)
tree decl;
{
tree sname = get_id_2 ("__sn", base);
tree sname;
tree sentry;
if (!flag_new_abi)
sname = get_id_2 ("__sn", DECL_ASSEMBLER_NAME (decl));
else
sname = mangle_guard_variable (decl);
/* For struct X foo __attribute__((weak)), there is a counter
__snfoo. Since base is already an assembler name, sname should
be globally unique */
tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
sentry = IDENTIFIER_GLOBAL_VALUE (sname);
if (! sentry)
{
sentry = build_decl (VAR_DECL, sname, integer_type_node);
......@@ -3239,7 +3265,9 @@ start_static_initialization_or_destruction (decl, initp)
cond = build_binary_op (TRUTH_ANDIF_EXPR, cond, init_cond);
/* We need a sentry if this is an object with external linkage that
might be initialized in more than one place. */
might be initialized in more than one place. (For example, a
static data member of a template, when the data member requires
construction.) */
if (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
|| DECL_ONE_ONLY (decl)
|| DECL_WEAK (decl)))
......@@ -3247,7 +3275,7 @@ start_static_initialization_or_destruction (decl, initp)
tree sentry;
tree sentry_cond;
sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
sentry = get_sentry (decl);
/* We do initializations only if the SENTRY is zero, i.e., if we
are the first to initialize the variable. We do destructions
......
......@@ -32,10 +32,6 @@ Boston, MA 02111-1307, USA. */
#include "except.h"
#include "tm_p.h"
#if 0
static tree extract_aggr_init PARAMS ((tree, tree));
static tree extract_scalar_init PARAMS ((tree, tree));
#endif
static rtx cplus_expand_expr PARAMS ((tree, rtx, enum machine_mode,
enum expand_modifier));
......@@ -202,86 +198,11 @@ fixup_result_decl (decl, result)
}
}
#if 0
/* Expand this initialization inline and see if it's simple enough that
it can be done at compile-time. */
static tree
extract_aggr_init (decl, init)
tree decl, init;
{
return 0;
}
static tree
extract_scalar_init (decl, init)
tree decl, init;
{
rtx value, insns, insn;
extern struct obstack temporary_obstack;
tree t = NULL_TREE;
start_sequence ();
value = expand_expr (init, NULL_RTX, VOIDmode, 0);
insns = get_insns ();
end_sequence ();
reg_scan (insns, max_reg_num (), 0);
jump_optimize (insns, 0, 0, 1);
for (insn = insns; insn; insn = NEXT_INSN (insn))
{
rtx r, to;
if (GET_CODE (insn) == NOTE)
continue;
else if (GET_CODE (insn) != INSN)
return 0;
r = PATTERN (insn);
if (GET_CODE (r) != SET)
return 0;
to = XEXP (r, 0);
if (! (to == value
|| (GET_CODE (to) == SUBREG && XEXP (to, 0) == value)))
return 0;
r = XEXP (r, 1);
switch (GET_CODE (r))
{
case CONST_INT:
t = build_int_2 (XEXP (r, 0), 0);
break;
default:
return 0;
}
}
return t;
}
#endif
int
extract_init (decl, init)
tree decl ATTRIBUTE_UNUSED, init ATTRIBUTE_UNUSED;
{
return 0;
#if 0
if (IS_AGGR_TYPE (TREE_TYPE (decl))
|| TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
init = extract_aggr_init (decl, init);
else
init = extract_scalar_init (decl, init);
if (init == NULL_TREE)
return 0;
DECL_INITIAL (decl) = init;
return 1;
#endif
}
void
......
/* Name mangling for the new standard C++ ABI.
Copyright (C) 2000 Free Software Foundation, Inc.
Written by Alex Samuel <sameul@codesourcery.com>
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* This file implements mangling of C++ names according to the IA64
C++ ABI specification. A mangled name encodes a function or
variable's name, scope, type, and/or template arguments into a text
identifier. This identifier is used as the function's or
variable's linkage name, to preserve compatibility between C++'s
language features (templates, scoping, and overloading) and C
linkers.
Additionally, g++ uses mangled names internally. To support this,
mangling of types is allowed, even though the mangled name of a
type should not appear by itself as an exported name. Ditto for
uninstantiated templates.
The primary entry point for this module is mangle_decl, which
returns an identifier containing the mangled name for a decl.
Additional entry points are provided to build mangled names of
particular constructs when the appropriate decl for that construct
is not available. These are:
mangle_typeinfo_for_type: typeinfo data
mangle_typeinfo_string_for_type: typeinfo type name
mangle_vtbl_for_type: virtual table data
mangle_vtt_for_type: VTT data
mangle_ctor_vtbl_for_type: `C-in-B' constructor virtual table data
mangle_thunk: thunk function or entry
*/
#include "config.h"
#include "system.h"
#include "tree.h"
#include "cp-tree.h"
#include "obstack.h"
#include "toplev.h"
#include "varray.h"
/* Debugging support. */
/* Define DEBUG_MANGLE to enable very verbose trace messages. */
#ifndef DEBUG_MANGLE
#define DEBUG_MANGLE 0
#endif
/* Macros for tracing the write_* functions. */
#if DEBUG_MANGLE
# define MANGLE_TRACE(FN, INPUT) \
fprintf (stderr, " %-24s: %-24s\n", FN, INPUT)
# define MANGLE_TRACE_TREE(FN, NODE) \
fprintf (stderr, " %-24s: %-24s (%p)\n", \
FN, tree_code_name[TREE_CODE (NODE)], (void *) NODE)
#else
# define MANGLE_TRACE(FN, INPUT)
# define MANGLE_TRACE_TREE(FN, NODE)
#endif
/* Non-zero if NODE is a template-id. */
#define DECL_TEMPLATE_ID_P(NODE) \
(DECL_LANG_SPECIFIC (NODE) != NULL \
&& DECL_USE_TEMPLATE (NODE) \
&& PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (NODE)))
/* Non-zero if NODE is a class template-id. */
#define CLASSTYPE_TEMPLATE_ID_P(NODE) \
(TYPE_LANG_SPECIFIC (NODE) != NULL \
&& CLASSTYPE_USE_TEMPLATE (NODE) \
&& PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (NODE)))
/* Things we only need one of. This module is not reentrant. */
static struct globals
{
/* The name in which we're building the mangled name. */
struct obstack name_obstack;
/* The current innermost template args. */
tree template_args;
/* An array of the current substitution candidates, in the order
we've seen them. */
varray_type substitutions;
} G;
/* Indices into subst_identifiers. These are identifiers used in
special substitution rules. */
typedef enum
{
SUBID_ALLOCATOR,
SUBID_BASIC_STRING,
SUBID_CHAR_TRAITS,
SUBID_BASIC_ISTREAM,
SUBID_BASIC_OSTREAM,
SUBID_BASIC_IOSTREAM,
SUBID_MAX
}
substitution_identifier_index_t;
/* For quick substitution checks, look up these common identifiers
once only. */
static tree subst_identifiers[SUBID_MAX];
/* Single-letter codes for builtin integer types, defined in
<builtin-type>. These are indexed by integer_type_kind values. */
static char
integer_type_codes[itk_none] =
{
'c', /* itk_char */
'a', /* itk_signed_char */
'h', /* itk_unsigned_char */
's', /* itk_short */
't', /* itk_unsigned_short */
'i', /* itk_int */
'j', /* itk_unsigned_int */
'l', /* itk_long */
'm', /* itk_unsigned_long */
'x', /* itk_long_long */
'y' /* itk_unsigned_long_long */
};
/* Functions for handling substitutions. */
static inline tree canonicalize_for_substitution PARAMS ((tree));
static void add_substitution PARAMS ((tree));
static inline int is_std_substitution PARAMS ((tree, substitution_identifier_index_t));
static inline int is_std_substitution_char PARAMS ((tree, substitution_identifier_index_t));
static int find_substitution PARAMS ((tree));
/* Functions for emitting mangled representations of things. */
static void write_mangled_name PARAMS ((tree));
static void write_encoding PARAMS ((tree));
static void write_name PARAMS ((tree));
static void write_unscoped_name PARAMS ((tree));
static void write_unscoped_template_name PARAMS ((tree));
static void write_nested_name PARAMS ((tree));
static void write_prefix PARAMS ((tree));
static void write_template_prefix PARAMS ((tree));
static void write_component PARAMS ((tree));
static void write_unqualified_name PARAMS ((tree));
static void write_source_name PARAMS ((tree));
static void write_number PARAMS ((int, int));
static void write_integer_cst PARAMS ((tree));
static void write_identifier PARAMS ((char *));
static void write_special_name_constructor PARAMS ((tree));
static void write_special_name_destructor PARAMS ((tree));
static void write_type PARAMS ((tree));
static int write_CV_qualifiers_for_type PARAMS ((tree));
static void write_builtin_type PARAMS ((tree));
static void write_function_type PARAMS ((tree, int));
static void write_bare_function_type PARAMS ((tree, int));
static void write_method_parms PARAMS ((tree, int));
static void write_class_enum_type PARAMS ((tree));
static void write_template_args PARAMS ((tree));
static void write_expression PARAMS ((tree));
static void write_template_arg_literal PARAMS ((tree));
static void write_template_arg PARAMS ((tree));
static void write_template_template_arg PARAMS ((tree));
static void write_array_type PARAMS ((tree));
static void write_pointer_to_member_type PARAMS ((tree));
static void write_template_param PARAMS ((tree));
static void write_template_template_param PARAMS ((tree));
static void write_substitution PARAMS ((int));
static int discriminator_for_local_entity PARAMS ((tree));
static int discriminator_for_string_literal PARAMS ((tree, tree));
static void write_discriminator PARAMS ((int));
static void write_local_name PARAMS ((tree, tree));
static void dump_substitution_candidates PARAMS ((void));
static const char *mangle_decl_string PARAMS ((tree));
/* Control functions. */
static inline void start_mangling PARAMS ((void));
static inline const char *finish_mangling PARAMS ((void));
static tree mangle_special_for_type PARAMS ((tree, const char *));
/* Append a single character to the end of the mangled
representation. */
#define write_char(CHAR) \
obstack_1grow (&G.name_obstack, (CHAR))
/* Append a NUL-terminated string to the end of the mangled
representation. */
#define write_string(STRING) \
obstack_grow (&G.name_obstack, (STRING), strlen (STRING))
/* Return the position at which the next character will be appended to
the mangled representation. */
#define mangled_position() \
obstack_object_size (&G.name_obstack)
/* Non-zero if NODE1__ and NODE2__ are both TREE_LIST nodes and have
the same purpose (context, which may be a type) and value (template
decl). See write_template_prefix for more information on what this
is used for. */
#define NESTED_TEMPLATE_MATCH(NODE1, NODE2) \
(TREE_CODE (NODE1) == TREE_LIST \
&& TREE_CODE (NODE2) == TREE_LIST \
&& ((TYPE_P (TREE_PURPOSE (NODE1)) \
&& same_type_p (TREE_PURPOSE (NODE1), TREE_PURPOSE (NODE2)))\
|| TREE_PURPOSE (NODE1) == TREE_PURPOSE (NODE2)) \
&& TREE_VALUE (NODE1) == TREE_VALUE (NODE2))
/* Produce debugging output of current substitution candidates. */
static void
dump_substitution_candidates ()
{
unsigned i;
fprintf (stderr, " ++ substitutions ");
for (i = 0; i < VARRAY_ACTIVE_SIZE (G.substitutions); ++i)
{
tree el = VARRAY_TREE (G.substitutions, i);
const char *name = "???";
if (i > 0)
fprintf (stderr, " ");
if (DECL_P (el))
name = IDENTIFIER_POINTER (DECL_NAME (el));
else if (TREE_CODE (el) == TREE_LIST)
name = IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (el)));
else if (TYPE_NAME (el))
name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (el)));
fprintf (stderr, " S%d_ = ", i - 1);
if (TYPE_P (el) &&
(CP_TYPE_RESTRICT_P (el)
|| CP_TYPE_VOLATILE_P (el)
|| CP_TYPE_CONST_P (el)))
fprintf (stderr, "CV-");
fprintf (stderr, "%s (%s at %p)\n",
name, tree_code_name[TREE_CODE (el)], (void *) el);
}
}
/* Both decls and types can be substitution candidates, but sometimes
they refer to the same thing. For instance, a TYPE_DECL and
RECORD_TYPE for the same class refer to the same thing, and should
be treated accordinginly in substitutions. This function returns a
canonicalized tree node representing NODE that is used when adding
and substitution candidates and finding matches. */
static inline tree
canonicalize_for_substitution (node)
tree node;
{
/* For a TYPE_DECL, use the type instead. */
if (TREE_CODE (node) == TYPE_DECL)
node = TREE_TYPE (node);
return node;
}
/* Add NODE as a substitution candidate. NODE must not already be on
the list of candidates. */
static void
add_substitution (node)
tree node;
{
tree c;
if (DEBUG_MANGLE)
fprintf (stderr, " ++ add_substitution (%s at %10p)\n",
tree_code_name[TREE_CODE (node)], (void *) node);
/* Get the canonicalized substitution candidate for NODE. */
c = canonicalize_for_substitution (node);
if (DEBUG_MANGLE && c != node)
fprintf (stderr, " ++ using candidate (%s at %10p)\n",
tree_code_name[TREE_CODE (node)], (void *) node);
node = c;
#if ENABLE_CHECKING
/* Make sure NODE isn't already a candidate. */
{
int i;
for (i = VARRAY_ACTIVE_SIZE (G.substitutions); --i >= 0; )
{
tree candidate = VARRAY_TREE (G.substitutions, i);
if ((DECL_P (node)
&& node == candidate)
|| (TYPE_P (node)
&& TYPE_P (candidate)
&& same_type_p (node, candidate)))
my_friendly_abort (20000524);
}
}
#endif /* ENABLE_CHECKING */
/* Put the decl onto the varray of substitution candidates. */
VARRAY_PUSH_TREE (G.substitutions, node);
if (DEBUG_MANGLE)
dump_substitution_candidates ();
}
/* Helper function for find_substitution. Returns non-zero if NODE,
which may be a decl or a CLASS_TYPE, is a template-id with template
name of substitution_index[INDEX] in the ::std namespace. */
static inline int
is_std_substitution (node, index)
tree node;
substitution_identifier_index_t index;
{
tree type = NULL;
tree decl = NULL;
if (DECL_P (node))
{
type = TREE_TYPE (node);
decl = node;
}
else if (CLASS_TYPE_P (node))
{
type = node;
decl = TYPE_NAME (node);
}
else
/* These are not the droids you're looking for. */
return 0;
return
DECL_NAMESPACE_STD_P (CP_DECL_CONTEXT (decl))
&& TYPE_LANG_SPECIFIC (type)
&& CLASSTYPE_USE_TEMPLATE (type)
&& (DECL_NAME (CLASSTYPE_TI_TEMPLATE (type))
== subst_identifiers[index]);
}
/* Helper function for find_substitution. Returns non-zero if NODE,
which may be a decl or a CLASS_TYPE, is the template-id
::std::identifier<char>, where identifier is
substitution_index[INDEX]. */
static inline int
is_std_substitution_char (node, index)
tree node;
substitution_identifier_index_t index;
{
tree args;
/* Check NODE's name is ::std::identifier. */
if (!is_std_substitution (node, index))
return 0;
/* Figure out its template args. */
if (DECL_P (node))
args = DECL_TI_ARGS (node);
else if (CLASS_TYPE_P (node))
args = CLASSTYPE_TI_ARGS (node);
else
/* Oops, not a template. */
return 0;
/* NODE's template arg list should be <char>. */
return
TREE_VEC_LENGTH (args) == 1
&& TREE_VEC_ELT (args, 0) == char_type_node;
}
/* Check whether a substitution should be used to represent NODE in
the mangling.
First, check standard special-case substitutions.
<substitution> ::= St
# ::std
::= Sa
# ::std::allocator
::= Sb
# ::std::basic_string
::= Ss
# ::std::basic_string<char,
::std::char_traits<char>,
::std::allocator<char> >
::= Si
# ::std::basic_istream<char, ::std::char_traits<char> >
::= So
# ::std::basic_ostream<char, ::std::char_traits<char> >
::= Sd
# ::std::basic_iostream<char, ::std::char_traits<char> >
Then examine the stack of currently available substitution
candidates for entities appearing earlier in the same mangling
If a substitution is found, write its mangled representation and
return non-zero. If none is found, just return zero. */
static int
find_substitution (node)
tree node;
{
int i;
int size = VARRAY_ACTIVE_SIZE (G.substitutions);
tree decl;
tree type;
if (DEBUG_MANGLE)
fprintf (stderr, " ++ find_substitution (%s at %p)\n",
tree_code_name[TREE_CODE (node)], (void *) node);
/* Obtain the canonicalized substitution representation for NODE.
This is what we'll compare against. */
node = canonicalize_for_substitution (node);
/* Check for builtin substitutions. */
decl = TYPE_P (node) ? TYPE_NAME (node) : node;
type = TYPE_P (node) ? node : TREE_TYPE (node);
/* Check for std::allocator. */
if (decl && is_std_substitution (decl, SUBID_ALLOCATOR))
{
write_string ("Sa");
return 1;
}
/* Check for std::basic_string. */
if (decl && is_std_substitution (decl, SUBID_BASIC_STRING))
{
if (type)
{
/* If this is a type (i.e. a fully-qualified template-id),
check for
std::basic_string <char,
std::char_traits<char>,
std::allocator<char> > . */
if (CP_TYPE_QUALS (type) == TYPE_UNQUALIFIED
&& CLASSTYPE_USE_TEMPLATE (type))
{
tree args = CLASSTYPE_TI_ARGS (type);
if (TREE_VEC_LENGTH (args) == 3
&& TREE_VEC_ELT (args, 0) == char_type_node
&& is_std_substitution_char (TREE_VEC_ELT (args, 1),
SUBID_CHAR_TRAITS)
&& is_std_substitution_char (TREE_VEC_ELT (args, 2),
SUBID_ALLOCATOR))
{
write_string ("Ss");
return 1;
}
}
}
else
/* Substitute for the template name only if this isn't a type. */
{
write_string ("Sb");
return 1;
}
}
/* Check for basic_{i,o,io}stream. */
if (type
&& CP_TYPE_QUALS (type) == TYPE_UNQUALIFIED
&& CLASS_TYPE_P (type)
&& CLASSTYPE_USE_TEMPLATE (type)
&& CLASSTYPE_TEMPLATE_INFO (type) != NULL)
{
/* First, check for the template
args <char, std::char_traits<char> > . */
tree args = CLASSTYPE_TI_ARGS (type);
if (TREE_VEC_LENGTH (args) == 2
&& TREE_VEC_ELT (args, 0) == char_type_node
&& is_std_substitution_char (TREE_VEC_ELT (args, 1),
SUBID_CHAR_TRAITS))
{
/* Got them. Is this basic_istream? */
tree name = DECL_NAME (CLASSTYPE_TI_TEMPLATE (type));
if (name == subst_identifiers[SUBID_BASIC_ISTREAM])
{
write_string ("Si");
return 1;
}
/* Or basic_ostream? */
else if (name == subst_identifiers[SUBID_BASIC_OSTREAM])
{
write_string ("So");
return 1;
}
/* Or basic_iostream? */
else if (name == subst_identifiers[SUBID_BASIC_IOSTREAM])
{
write_string ("Sd");
return 1;
}
}
}
/* Check for namespace std. */
if (decl&& DECL_NAMESPACE_STD_P (decl))
{
write_string ("St");
return 1;
}
/* Now check the list of available substitutions for this mangling
operation. */
for (i = 0; i < size; ++i)
{
tree candidate = VARRAY_TREE (G.substitutions, i);
/* NODE is a matched to a candidate if it's the same decl node or
if it's the same type. */
if (decl == candidate
|| (TYPE_P (candidate) && type && TYPE_P (type)
&& same_type_p (type, candidate))
|| NESTED_TEMPLATE_MATCH (node, candidate))
{
write_substitution (i);
return 1;
}
}
/* No substitution found. */
return 0;
}
/* <mangled-name> ::= _Z <encoding> */
static inline void
write_mangled_name (decl)
tree decl;
{
MANGLE_TRACE_TREE ("mangled-name", decl);
if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl))
/* The standard notes:
"The <encoding> of an extern "C" function is treated like
global-scope data, i.e. as its <source-name> without a type." */
write_source_name (DECL_NAME (decl));
else
/* C++ name; needs to be mangled. */
{
write_string ("_Z");
write_encoding (decl);
}
}
/* <encoding> ::= <function name> <bare-function-type>
::= <data name>
::= <substitution> */
static void
write_encoding (decl)
tree decl;
{
MANGLE_TRACE_TREE ("encoding", decl);
if (find_substitution (decl))
return;
if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl))
{
write_source_name (DECL_NAME (decl));
return;
}
write_name (decl);
if (TREE_CODE (decl) == FUNCTION_DECL)
{
tree fn_type;
if (DECL_TEMPLATE_ID_P (decl))
fn_type = get_mostly_instantiated_function_type (decl, NULL, NULL);
else
fn_type = TREE_TYPE (decl);
write_bare_function_type (fn_type, DECL_TEMPLATE_ID_P (decl));
}
add_substitution (decl);
}
/* <name> ::= <unscoped-name>
::= <unscoped-template-name> <template-args>
::= <nested-name>
::= <local-name> */
static void
write_name (decl)
tree decl;
{
tree context = CP_DECL_CONTEXT (decl);
MANGLE_TRACE_TREE ("name", decl);
/* Decls in :: or ::std scope are treated specially. */
if (context == global_namespace || DECL_NAMESPACE_STD_P (context))
{
if (decl && DECL_TEMPLATE_ID_P (decl))
{
/* Templated decls get an <unqualified-template-name>. */
write_unscoped_template_name (DECL_TI_TEMPLATE (decl));
write_template_args (DECL_TI_ARGS (decl));
}
else if (TREE_CODE (decl) == TYPE_DECL
&& CLASSTYPE_TEMPLATE_ID_P (TREE_TYPE (decl)))
{
tree type;
/* Templated decls get an <unqualified-template-name>. */
type = TREE_TYPE (decl);
write_unscoped_template_name (TYPE_TI_TEMPLATE (type));
write_template_args (TYPE_TI_ARGS (type));
}
else
/* Everything else gets an <unqualified-name>. */
write_unscoped_name (decl);
}
/* Handle local names. */
else if (TREE_CODE (context) == FUNCTION_DECL)
write_local_name (context, decl);
/* Other decls get a <nested-name> to encode their scope. */
else
write_nested_name (decl);
}
/* <unscoped-name> ::= <unqualified-name>
::= St <unqualified-name> # ::std:: */
static void
write_unscoped_name (decl)
tree decl;
{
tree context = CP_DECL_CONTEXT (decl);
MANGLE_TRACE_TREE ("unscoped-name", decl);
/* Is DECL in ::std? */
if (DECL_NAMESPACE_STD_P (context))
{
write_string ("St");
write_unqualified_name (decl);
}
/* If not, it should be in the global namespace. */
else if (context == global_namespace || context == NULL)
write_unqualified_name (decl);
else
my_friendly_abort (20000521);
}
/* <unscoped-template-name> ::= <unscoped-name>
::= <substitution> */
static void
write_unscoped_template_name (decl)
tree decl;
{
MANGLE_TRACE_TREE ("unscoped-template-name", decl);
if (find_substitution (decl))
return;
write_unscoped_name (decl);
add_substitution (decl);
}
/* Write the nested name, including CV-qualifiers, of DECL.
<nested-name> ::= N [<CV-qualifiers>] <prefix> <component> E
::= N [<CV-qualifiers>] <template-prefix> <template-args> E
<CV-qualifiers> ::= [r] [V] [K] */
static void
write_nested_name (decl)
tree decl;
{
MANGLE_TRACE_TREE ("nested-name", decl);
write_char ('N');
/* Write CV-qualifiers, if this is a member function. */
if (TREE_CODE (decl) == FUNCTION_DECL
&& DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
{
if (DECL_VOLATILE_MEMFUNC_P (decl))
write_char ('V');
if (DECL_CONST_MEMFUNC_P (decl))
write_char ('K');
}
if (DECL_TEMPLATE_ID_P (decl))
{
write_template_prefix (decl);
write_template_args (DECL_TI_ARGS (decl));
}
else if (CLASSTYPE_TEMPLATE_ID_P (TREE_TYPE (decl)))
{
write_template_prefix (decl);
write_template_args (CLASSTYPE_TI_ARGS (TREE_TYPE (decl)));
}
else
{
write_prefix (DECL_CONTEXT (decl));
write_component (decl);
}
write_char ('E');
}
/* <prefix> ::= <prefix> <component>
::= <template-prefix> <template-args>
::= # empty
::= <substitution> */
static void
write_prefix (node)
tree node;
{
tree decl;
tree type;
tree context;
if (node == NULL
|| node == global_namespace)
return;
MANGLE_TRACE_TREE ("prefix", node);
decl = DECL_P (node) ? node : TYPE_NAME (node);
type = DECL_P (node) ? TREE_TYPE (node) : node;
context = CP_DECL_CONTEXT (decl);
if (find_substitution (node))
return;
/* Check if this is a template-id. For a template member, the
template info will be hanging off the decl. */
if (DECL_TEMPLATE_ID_P (decl))
{
write_template_prefix (decl);
write_template_args (DECL_TI_ARGS (decl));
}
/* For a template class, the template info will be hanging off the
type. */
else if (type && CLASSTYPE_TEMPLATE_ID_P (type))
{
write_template_prefix (type);
write_template_args (CLASSTYPE_TI_ARGS (type));
}
else
/* Not templated. */
{
write_prefix (context);
write_component (decl);
}
add_substitution (node);
}
/* <template-prefix> ::= <prefix> <template component>
::= <substitution>
Names of templates are substitution candidates. For a nested
template, though, the template name for the innermost name must
have all the outer template levels instantiated. For instance,
consider
template<typename T> struct Outer
{
template<typename U> struct Inner {};
};
The template name for `Inner' in `Outer<int>::Inner<float>' is
`Outer<int>::Inner<U>'. In g++, we don't instantiate the template
levels separately, so there's no TEMPLATE_DECL available for this
(there's only `Outer<T>::Inner<U>').
In order to get the substitutions right, we create a special
TREE_LIST to represent the substitution candidate for a nested
template. The TREE_PURPOSE is the tempate's context, fully
instantiated, and the TREE_VALUE is the TEMPLATE_DECL for the inner
template.
So, for the example above, `Inner' is represented as a substitution
candidate by a TREE_LIST whose purpose is `Outer<int>' and whose
value is `Outer<T>::Inner<U>'. */
static void
write_template_prefix (node)
tree node;
{
tree decl = DECL_P (node) ? node : TYPE_NAME (node);
tree type = DECL_P (node) ? TREE_TYPE (node) : node;
tree context = CP_DECL_CONTEXT (decl);
tree template;
tree substitution;
MANGLE_TRACE_TREE ("template-prefix", node);
/* Find the template decl. */
if (DECL_TEMPLATE_ID_P (decl))
template = DECL_TI_TEMPLATE (decl);
else if (CLASSTYPE_TEMPLATE_ID_P (type))
template = CLASSTYPE_TI_TEMPLATE (type);
else
/* Oops, not a template. */
my_friendly_abort (20000524);
/* Build the substitution candidate TREE_LIST. */
substitution = build_tree_list (context, template);
if (find_substitution (substitution))
return;
write_prefix (context);
write_component (decl);
add_substitution (substitution);
}
/* <component> ::= <unqualified-name>
::= <local-name> */
static void
write_component (decl)
tree decl;
{
MANGLE_TRACE_TREE ("component", decl);
switch (TREE_CODE (decl))
{
case TEMPLATE_DECL:
case NAMESPACE_DECL:
case VAR_DECL:
case TYPE_DECL:
case FUNCTION_DECL:
case FIELD_DECL:
if (TREE_CODE (CP_DECL_CONTEXT (decl)) == FUNCTION_DECL)
write_local_name (CP_DECL_CONTEXT (decl), decl);
else
write_unqualified_name (decl);
break;
default:
my_friendly_abort (2000509);
}
}
/* We don't need to handle thunks, vtables, or VTTs here. Those are
mangled through special entry points.
<unqualified-name> ::= <operator-name>
::= <special-name>
::= <source-name> */
static void
write_unqualified_name (decl)
tree decl;
{
MANGLE_TRACE_TREE ("unqualified-name", decl);
if (DECL_LANG_SPECIFIC (decl) != NULL && DECL_CONSTRUCTOR_P (decl))
write_special_name_constructor (decl);
else if (DECL_LANG_SPECIFIC (decl) != NULL && DECL_DESTRUCTOR_P (decl))
write_special_name_destructor (decl);
else if (DECL_CONV_FN_P (decl))
{
/* Conversion operator. Handle it right here.
<operator> ::= cv <type> */
write_string ("cv");
write_type (TREE_TYPE (DECL_NAME (decl)));
}
else if (DECL_OVERLOADED_OPERATOR_P (decl))
{
operator_name_info_t *oni;
if (DECL_ASSIGNMENT_OPERATOR_P (decl))
oni = assignment_operator_name_info;
else
oni = operator_name_info;
write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
}
else
write_source_name (DECL_NAME (decl));
}
/* Non-termial <source-name>. IDENTIFIER is an IDENTIFIER_NODE.
<source-name> ::= </length/ number> <identifier> */
static void
write_source_name (identifier)
tree identifier;
{
MANGLE_TRACE_TREE ("source-name", identifier);
/* Never write the whole template-id name including the template
arguments; we only want the template name. */
if (IDENTIFIER_TEMPLATE (identifier))
identifier = IDENTIFIER_TEMPLATE (identifier);
write_number (IDENTIFIER_LENGTH (identifier), 10);
write_identifier (IDENTIFIER_POINTER (identifier));
}
/* Non-terminal <number>.
<number> ::= [n] </decimal integer/> */
static void
write_number (number, base)
int number;
int base;
{
static const char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int n;
int m = 1;
if (number < 0)
{
write_char ('n');
number = -number;
}
n = number;
while (n >= base)
{
n /= base;
m *= base;
}
while (m > 0)
{
int digit = number / m;
write_char (digits[digit]);
number -= digit * m;
m /= base;
}
my_friendly_assert (number == 0, 20000407);
}
/* Write out an integeral CST in decimal. */
static inline void
write_integer_cst (cst)
tree cst;
{
write_number (tree_low_cst (cst, TREE_UNSIGNED (TREE_TYPE (cst))), 10);
}
/* Non-terminal <identifier>.
<identifier> ::= </unqualified source code identifier> */
static void
write_identifier (identifier)
char *identifier;
{
MANGLE_TRACE ("identifier", identifier);
write_string (identifier);
}
/* Handle constructor productions of non-terminal <special-name>.
CTOR is a constructor FUNCTION_DECL.
<special-name> ::= C1 # complete object constructor
::= C2 # base object constructor
::= C3 # complete object allocating constructor
::= C4 # base object allocating constructor
Currently, allocating constructors are never used.
We also need to provide unique mangled names (which should never be
exported) for the constructor that takes an in-charge parameter,
and for a constructor whose name is the same as its class's name.
We use "C*INTERNAL*" for these. */
static void
write_special_name_constructor (ctor)
tree ctor;
{
if (DECL_COMPLETE_CONSTRUCTOR_P (ctor))
write_string ("C1");
else if (DECL_BASE_CONSTRUCTOR_P (ctor))
write_string ("C2");
else
write_string ("C*INTERNAL*");
}
/* Handle destructor productions of non-terminal <special-name>.
DTOR is a denstructor FUNCTION_DECL.
<special-name> ::= D0 # deleting (in-charge) destructor
::= D1 # complete object (in-charge) destructor
::= D2 # base object (not-in-charge) destructor
We also need to provide unique mngled names for old-ABI
destructors, sometimes. These should only be used internally. We
use "D*INTERNAL*" for these. */
static void
write_special_name_destructor (dtor)
tree dtor;
{
if (DECL_DELETING_DESTRUCTOR_P (dtor))
write_string ("D0");
else if (DECL_COMPLETE_DESTRUCTOR_P (dtor))
write_string ("D1");
else if (DECL_BASE_DESTRUCTOR_P (dtor))
write_string ("D2");
else
/* Old-ABI destructor. */
write_string ("D*INTERNAL*");
}
/* Return the discriminator for ENTITY appearing inside
FUNCTION. The discriminator is the lexical ordinal of VAR among
entities with the same name in the same FUNCTION. */
static int
discriminator_for_local_entity (entity)
tree entity;
{
tree *type;
int discriminator;
/* Assume this is the only local entity with this name. */
discriminator = 0;
/* For now, we don't discriminate amongst local variables. */
if (TREE_CODE (entity) != TYPE_DECL)
return 0;
/* Scan the list of local classes. */
entity = TREE_TYPE (entity);
for (type = &VARRAY_TREE (local_classes, 0); *type != entity; ++type)
if (TYPE_IDENTIFIER (*type) == TYPE_IDENTIFIER (entity)
&& TYPE_CONTEXT (*type) == TYPE_CONTEXT (entity))
++discriminator;
return discriminator;
}
/* Return the discriminator for STRING, a string literal used inside
FUNCTION. The disciminator is the lexical ordinal of STRING among
string literals used in FUNCTION. */
static int
discriminator_for_string_literal (function, string)
tree function ATTRIBUTE_UNUSED;
tree string ATTRIBUTE_UNUSED;
{
/* For now, we don't discriminate amongst string literals. */
return 0;
}
/* <discriminator> := _ <number>
The discriminator is used only for the second and later occurrences
of the same name within a single function. In this case <number> is
n - 2, if this is the nth occurrence, in lexical order. */
static void
write_discriminator (discriminator)
int discriminator;
{
/* If discriminator is zero, don't write anything. Otherwise... */
if (discriminator > 0)
{
write_char ('_');
/* The number is omitted for discriminator == 1. Beyond 1, the
numbering starts at 0. */
if (discriminator > 1)
write_number (discriminator - 2, 10);
}
}
/* Mangle the name of a function-scope entity. FUNCTION is the
FUNCTION_DECL for the enclosing function. ENTITY is the decl for
the entity itself.
<local-name> := Z <function encoding> E <entity name> [<discriminator>]
:= Z <function encoding> E s [<discriminator>] */
static void
write_local_name (function, entity)
tree function;
tree entity;
{
MANGLE_TRACE_TREE ("local-name", entity);
write_char ('Z');
write_encoding (function);
write_char ('E');
if (TREE_CODE (entity) == STRING_CST)
{
write_char ('s');
write_discriminator (discriminator_for_string_literal (function,
entity));
}
else
{
write_unqualified_name (entity);
write_discriminator (discriminator_for_local_entity (entity));
}
}
/* Non-terminals <type> and <CV-qualifier>.
<type> ::= <builtin-type>
::= <function-type>
::= <class-enum-type>
::= <array-type>
::= <pointer-to-member-type>
::= <template-param>
::= <substitution>
::= <CV-qualifier>
::= P <type> # pointer-to
::= R <type> # reference-to
::= C <type> # complex pair (C 2000) [not supported]
::= G <type> # imaginary (C 2000) [not supported]
::= U <source-name> <type> # vendor extended type qualifier
[not supported]
TYPE is a type node. */
static void
write_type (type)
tree type;
{
/* This gets set to non-zero if TYPE turns out to be a (possibly
CV-qualified) builtin type. */
int is_builtin_type = 0;
MANGLE_TRACE_TREE ("type", type);
if (find_substitution (type))
return;
if (write_CV_qualifiers_for_type (type) > 0)
/* If TYPE was CV-qualified, we just wrote the qualifiers; now
mangle the unqualified type. The recursive call is needed here
since both the qualified and uqualified types are substitution
candidates. */
write_type (TYPE_MAIN_VARIANT (type));
else
switch (TREE_CODE (type))
{
case VOID_TYPE:
case BOOLEAN_TYPE:
case INTEGER_TYPE: /* Includes wchar_t. */
case REAL_TYPE:
/* If this is a typedef, TYPE may not be one of
the standard builtin type nodes, but an alias of one. Use
TYPE_MAIN_VARIANT to get to the underlying builtin type. */
write_builtin_type (TYPE_MAIN_VARIANT (type));
++is_builtin_type;
break;
case COMPLEX_TYPE:
write_char ('C');
write_type (TREE_TYPE (type));
break;
case FUNCTION_TYPE:
case METHOD_TYPE:
write_function_type (type, 1);
break;
case UNION_TYPE:
case RECORD_TYPE:
case ENUMERAL_TYPE:
/* A pointer-to-member function is represented as a special
RECORD_TYPE, so check for this first. */
if (TYPE_PTRMEMFUNC_P (type))
write_pointer_to_member_type (type);
else
write_class_enum_type (type);
break;
case TYPENAME_TYPE:
/* We handle TYPENAME_TYPEs like ordinary nested names. */
write_nested_name (TYPE_STUB_DECL (type));
break;
case ARRAY_TYPE:
write_array_type (type);
break;
case POINTER_TYPE:
/* A pointer-to-member variable is represented by a POINTER_TYPE
to an OFFSET_TYPE, so check for this first. */
if (TYPE_PTRMEM_P (type))
write_pointer_to_member_type (type);
else
{
write_char ('P');
write_type (TREE_TYPE (type));
}
break;
case REFERENCE_TYPE:
write_char ('R');
write_type (TREE_TYPE (type));
break;
case TEMPLATE_TYPE_PARM:
case TEMPLATE_PARM_INDEX:
write_template_param (type);
break;
case TEMPLATE_TEMPLATE_PARM:
write_template_template_param (type);
if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (type))
write_template_args
(TI_ARGS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (type)));
break;
case OFFSET_TYPE:
write_pointer_to_member_type (build_pointer_type (type));
break;
default:
my_friendly_abort (20000409);
}
/* Types other than builtin types are substitution candidates. */
if (!is_builtin_type)
add_substitution (type);
}
/* Non-terminal <CV-qualifiers> for type nodes. Returns the number of
CV-qualifiers written for TYPE.
<CV-qualifiers> ::= [r] [V] [K] */
static int
write_CV_qualifiers_for_type (type)
tree type;
{
int num_qualifiers = 0;
/* The order is specified by:
"In cases where multiple order-insensitive qualifiers are
present, they should be ordered 'K' (closest to the base type),
'V', 'r', and 'U' (farthest from the base type) ..." */
if (CP_TYPE_RESTRICT_P (type))
{
write_char ('r');
++num_qualifiers;
}
if (CP_TYPE_VOLATILE_P (type))
{
write_char ('V');
++num_qualifiers;
}
if (CP_TYPE_CONST_P (type))
{
write_char ('K');
++num_qualifiers;
}
return num_qualifiers;
}
/* Non-terminal <builtin-type>.
<builtin-type> ::= v # void
::= b # bool
::= w # wchar_t
::= c # char
::= a # signed char
::= h # unsigned char
::= s # short
::= t # unsigned short
::= i # int
::= j # unsigned int
::= l # long
::= m # unsigned long
::= x # long long, __int64
::= y # unsigned long long, __int64
::= n # __int128 [not supported]
::= o # unsigned __int128 [not supported]
::= f # float
::= d # double
::= e # long double, __float80
::= g # __float128 [not supported] */
static void
write_builtin_type (type)
tree type;
{
switch (TREE_CODE (type))
{
case VOID_TYPE:
write_char ('v');
break;
case BOOLEAN_TYPE:
write_char ('b');
break;
case INTEGER_TYPE:
/* If this is size_t, get the underlying int type. */
if (TYPE_IS_SIZETYPE (type))
type = TYPE_DOMAIN (type);
/* TYPE may still be wchar_t, since that isn't in
integer_type_nodes. */
if (type == wchar_type_node)
write_char ('w');
else
{
size_t itk;
/* Assume TYPE is one of the shared integer type nodes. Find
it in the array of these nodes. */
for (itk = 0; itk < itk_none; ++itk)
if (type == integer_types[itk])
{
/* Print the corresponding single-letter code. */
write_char (integer_type_codes[itk]);
break;
}
if (itk == itk_none)
/* Couldn't find this type. */
my_friendly_abort (20000408);
}
break;
case REAL_TYPE:
if (type == float_type_node)
write_char ('f');
else if (type == double_type_node)
write_char ('d');
else if (type == long_double_type_node)
write_char ('e');
else
my_friendly_abort (20000409);
break;
default:
my_friendly_abort (20000509);
}
}
/* Non-terminal <function-type>. NODE is a FUNCTION_TYPE or
METHOD_TYPE. If INCLUDE_RETURN_TYPE is non-zero, the return type
is mangled before the parameter types.
<function-type> ::= F [Y] <bare-function-type> E */
static void
write_function_type (type, include_return_type)
tree type;
int include_return_type;
{
MANGLE_TRACE_TREE ("function-type", type);
write_char ('F');
/* We don't track whether or not a type is `extern "C"'. Note that
you can have an `extern "C"' function that does not have
`extern "C"' type, and vice versa:
extern "C" typedef void function_t();
function_t f; // f has C++ linkage, but its type is
// `extern "C"'
typedef void function_t();
extern "C" function_t f; // Vice versa.
See [dcl.link]. */
write_bare_function_type (type, include_return_type);
write_char ('E');
}
/* Non-terminal <bare-function-type>. NODE is a FUNCTION_DECL or a
METHOD_TYPE. If INCLUDE_RETURN_TYPE is non-zero, the return value
is mangled before the parameter types.
<bare-function-type> ::= </signature/ type>+ */
static void
write_bare_function_type (type, include_return_type_p)
tree type;
int include_return_type_p;
{
MANGLE_TRACE_TREE ("bare-function-type", type);
/* Mangle the return type, if requested. */
if (include_return_type_p)
write_type (TREE_TYPE (type));
/* Now mangle the types of the arguments. */
write_method_parms (TYPE_ARG_TYPES (type),
TREE_CODE (type) == METHOD_TYPE);
}
/* Write the mangled representation of a method parameter list of
types given in PARM_LIST. If METHOD_P is non-zero, the function is
considered a non-static method, and the this parameter is omitted.
If VARARGS_P is non-zero, an additional token designating varargs
is appended. */
static void
write_method_parms (parm_list, method_p)
tree parm_list;
int method_p;
{
tree first_parm;
/* Assume this parameter type list is variable-length. If it ends
with a void type, then it's not. */
int varargs_p = 1;
/* If this is a member function, skip the first arg, which is the
this pointer.
"Member functions do not encode the type of their implicit this
parameter." */
if (method_p)
parm_list = TREE_CHAIN (parm_list);
for (first_parm = parm_list;
parm_list;
parm_list = TREE_CHAIN (parm_list))
{
tree parm = TREE_VALUE (parm_list);
if (same_type_p (parm, void_type_node))
{
/* "Empty parameter lists, whether declared as () or
conventionally as (void), are encoded with a void parameter
(v)." */
if (parm_list == first_parm)
write_type (parm);
/* If the parm list is terminated with a void type, it's
fixed-length. */
varargs_p = 0;
/* A void type better be the last one. */
my_friendly_assert (TREE_CHAIN (parm_list) == NULL, 20000523);
}
else
write_type (parm);
}
if (varargs_p)
/* <builtin-type> ::= z # ellipsis */
write_char ('z');
}
/* <class-enum-type> ::= <name> */
static void
write_class_enum_type (type)
tree type;
{
write_name (TYPE_NAME (type));
}
/* Non-terminal <template-args>. ARGS is a TREE_VEC of template
arguments.
<template-args> ::= I <template-arg>+ E */
static void
write_template_args (args)
tree args;
{
int i;
int length = TREE_VEC_LENGTH (args);
MANGLE_TRACE_TREE ("template-args", args);
my_friendly_assert (length > 0, 20000422);
if (TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
{
/* We have nested template args. We want the innermost template
argument list. */
args = TREE_VEC_ELT (args, length - 1);
length = TREE_VEC_LENGTH (args);
}
write_char ('I');
for (i = 0; i < length; ++i)
write_template_arg (TREE_VEC_ELT (args, i));
write_char ('E');
}
/* <expression> ::= <unary operator-name> <expression>
::= <binary operator-name> <expression> <expression>
::= <expr-primary>
<expr-primary> ::= <template-param>
::= L <type> <value number> E # literal
::= L <mangled-name> E # external name */
static void
write_expression (expr)
tree expr;
{
enum tree_code code;
code = TREE_CODE (expr);
/* Handle pointers-to-members by making them look like expression
nodes. */
if (code == PTRMEM_CST)
{
expr = build_nt (ADDR_EXPR,
build_nt (SCOPE_REF,
PTRMEM_CST_CLASS (expr),
PTRMEM_CST_MEMBER (expr)));
code = TREE_CODE (expr);
}
/* Handle template parameters. */
if (code == TEMPLATE_TYPE_PARM
|| code == TEMPLATE_TEMPLATE_PARM
|| code == TEMPLATE_PARM_INDEX)
write_template_param (expr);
/* Handle literals. */
else if (TREE_CODE_CLASS (code) == 'c')
write_template_arg_literal (expr);
else if (DECL_P (expr))
{
write_char ('L');
write_mangled_name (expr);
write_char ('E');
}
else
{
int i;
/* Skip NOP_EXPRs. They can occur when (say) a pointer argument
is converted (via qualification conversions) to another
type. */
while (TREE_CODE (expr) == NOP_EXPR)
{
expr = TREE_OPERAND (expr, 0);
code = TREE_CODE (expr);
}
/* If it wasn't any of those, recursively expand the expression. */
write_string (operator_name_info[(int) code].mangled_name);
/* Handle pointers-to-members specially. */
if (code == SCOPE_REF)
{
write_type (TREE_OPERAND (expr, 0));
if (TREE_CODE (TREE_OPERAND (expr, 1)) == IDENTIFIER_NODE)
write_source_name (TREE_OPERAND (expr, 1));
else
write_encoding (TREE_OPERAND (expr, 1));
}
else
for (i = 0; i < TREE_CODE_LENGTH (code); ++i)
write_expression (TREE_OPERAND (expr, i));
}
}
/* Literal subcase of non-terminal <template-arg>.
"Literal arguments, e.g. "A<42L>", are encoded with their type
and value. Negative integer values are preceded with "n"; for
example, "A<-42L>" becomes "1AILln42EE". The bool value false is
encoded as 0, true as 1. If floating-point arguments are accepted
as an extension, their values should be encoded using a
fixed-length lowercase hexadecimal string corresponding to the
internal representation (IEEE on IA-64), high-order bytes first,
without leading zeroes. For example: "Lfbff000000E" is -1.0f." */
static void
write_template_arg_literal (value)
tree value;
{
tree type = TREE_TYPE (value);
write_char ('L');
write_type (type);
if (TREE_CODE (value) == CONST_DECL)
write_integer_cst (DECL_INITIAL (value));
else if (TREE_CODE (value) == INTEGER_CST)
{
if (same_type_p (type, boolean_type_node))
{
if (value == boolean_false_node || integer_zerop (value))
write_number (0, 10);
else if (value == boolean_true_node)
write_number (1, 10);
else
my_friendly_abort (20000412);
}
else
write_integer_cst (value);
}
else if (TREE_CODE (value) == REAL_CST)
{
#ifdef CROSS_COMPILE
static int explained;
if (!explained)
{
sorry ("real-valued template parameters when cross-compiling");
explained = 1;
}
#else
size_t i;
for (i = 0; i < sizeof (TREE_REAL_CST (value)); ++i)
write_number (((unsigned char *)
&TREE_REAL_CST (value))[i], 16);
#endif
}
else
my_friendly_abort (20000412);
write_char ('E');
}
/* Non-terminal <tempalate-arg>.
<template-arg> ::= <type> # type
::= L <type> </value/ number> E # literal
::= LZ <name> E # external name
::= X <expression> E # expression */
static void
write_template_arg (node)
tree node;
{
enum tree_code code = TREE_CODE (node);
MANGLE_TRACE_TREE ("template-arg", node);
/* A template template paramter's argument list contains TREE_LIST
nodes of which the value field is the the actual argument. */
if (code == TREE_LIST)
{
node = TREE_VALUE (node);
/* If it's a decl, deal with its type instead. */
if (DECL_P (node))
{
node = TREE_TYPE (node);
code = TREE_CODE (node);
}
}
if (TYPE_P (node))
write_type (node);
else if (code == TEMPLATE_DECL)
/* A template appearing as a template arg is a template template arg. */
write_template_template_arg (node);
else if (DECL_P (node))
{
write_char ('L');
write_char ('Z');
write_encoding (node);
write_char ('E');
}
else if (TREE_CODE_CLASS (code) == 'c' && code != PTRMEM_CST)
write_template_arg_literal (node);
else
{
/* Template arguments may be expressions. */
write_char ('X');
write_expression (node);
write_char ('E');
}
}
/* <template-template-arg>
::= <name>
::= <substitution> */
void
write_template_template_arg (tree decl)
{
MANGLE_TRACE_TREE ("template-template-arg", decl);
if (find_substitution (decl))
return;
write_name (decl);
add_substitution (decl);
}
/* Non-terminal <array-type>. TYPE is an ARRAY_TYPE.
<array-type> ::= A [</dimension/ number>] _ </element/ type>
"Array types encode the dimension (number of elements) and the
element type. For variable length arrays, the dimension (but not
the '_' separator) is omitted." */
static void
write_array_type (type)
tree type;
{
write_char ('A');
if (TYPE_DOMAIN (type))
{
tree index_type;
tree max;
index_type = TYPE_DOMAIN (type);
/* The INDEX_TYPE gives the upper and lower bounds of the
array. */
max = TYPE_MAX_VALUE (index_type);
if (TREE_CODE (max) == INTEGER_CST)
write_number (TREE_INT_CST_LOW (max) + 1, 10);
else
write_expression (TREE_OPERAND (max, 0));
}
write_char ('_');
write_type (TREE_TYPE (type));
}
/* Non-terminal <pointer-to-member-type> for pointer-to-member
variables. TYPE is a pointer-to-member POINTER_TYPE.
<pointer-to-member-type> ::= M </class/ type> </member/ type> */
static void
write_pointer_to_member_type (type)
tree type;
{
write_char ('M');
write_type (TYPE_PTRMEM_CLASS_TYPE (type));
write_type (TYPE_PTRMEM_POINTED_TO_TYPE (type));
}
/* Non-terminal <template-param>. PARM is a TEMPLATE_TYPE_PARM,
TEMPLATE_TEMPLATE_PARM, or a TEMPLATE_PARM_INDEX.
<template-param> ::= T </parameter/ number> _ */
static void
write_template_param (parm)
tree parm;
{
int parm_index;
MANGLE_TRACE_TREE ("template-parm", parm);
switch (TREE_CODE (parm))
{
case TEMPLATE_TYPE_PARM:
case TEMPLATE_TEMPLATE_PARM:
parm_index = TEMPLATE_TYPE_IDX (parm);
break;
case TEMPLATE_PARM_INDEX:
parm_index = TEMPLATE_PARM_IDX (parm);
break;
default:
my_friendly_abort (20000523);
}
write_char ('T');
/* NUMBER as it appears in the mangling is (-1)-indexed, with the
earliest template param denoted by `_'. */
if (parm_index > 0)
write_number (parm_index - 1, 10);
write_char ('_');
}
/* <template-template-param>
::= <template-param>
::= <substitution> */
static void
write_template_template_param (parm)
tree parm;
{
tree template = NULL_TREE;
/* PARM, a TEMPLATE_TEMPLATE_PARM, is an instantiation of the
template template parameter. The substitution candidate here is
only the template. */
if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parm))
{
template
= TI_TEMPLATE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parm));
if (find_substitution (template))
return;
}
/* <template-param> encodes only the template parameter position,
not its template arguments, which is fine here. */
write_template_param (parm);
if (template)
add_substitution (template);
}
/* Non-terminal <substitution>.
<substitution> ::= S <seq-id> _
::= S_ */
static void
write_substitution (seq_id)
int seq_id;
{
MANGLE_TRACE ("substitution", "");
write_char ('S');
if (seq_id > 0)
write_number (seq_id - 1, 36);
write_char ('_');
}
/* Start mangling a new name or type. */
static inline void
start_mangling ()
{
obstack_free (&G.name_obstack, obstack_base (&G.name_obstack));
}
/* Done with mangling. Return the generated mangled name. */
static inline const char *
finish_mangling ()
{
/* Clear all the substitutions. */
VARRAY_POP_ALL (G.substitutions);
/* Null-terminate the string. */
write_char ('\0');
return (const char *) obstack_base (&G.name_obstack);
}
/* Initialize data structures for mangling. */
void
init_mangle ()
{
gcc_obstack_init (&G.name_obstack);
VARRAY_TREE_INIT (G.substitutions, 1, "mangling substitutions");
/* Cache these identifiers for quick comparison when checking for
standard substitutions. */
subst_identifiers[SUBID_ALLOCATOR] = get_identifier ("allocator");
subst_identifiers[SUBID_BASIC_STRING] = get_identifier ("basic_string");
subst_identifiers[SUBID_CHAR_TRAITS] = get_identifier ("char_traits");
subst_identifiers[SUBID_BASIC_ISTREAM] = get_identifier ("basic_istream");
subst_identifiers[SUBID_BASIC_OSTREAM] = get_identifier ("basic_ostream");
subst_identifiers[SUBID_BASIC_IOSTREAM] = get_identifier ("basic_iostream");
}
/* Generate the mangled name of DECL. */
static const char *
mangle_decl_string (decl)
tree decl;
{
const char *result;
start_mangling ();
if (TREE_CODE (decl) == TYPE_DECL)
write_type (TREE_TYPE (decl));
else
write_mangled_name (decl);
result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_decl_string = '%s'\n\n", result);
return result;
}
/* Create an identifier for the external mangled name of DECL. */
tree
mangle_decl (decl)
tree decl;
{
return get_identifier (mangle_decl_string (decl));
}
/* Generate the mangled representation of TYPE. */
const char *
mangle_type_string (type)
tree type;
{
const char *result;
start_mangling ();
write_type (type);
result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
return result;
}
/* Create an identifier for the mangled representation of TYPE. */
tree
mangle_type (type)
tree type;
{
return get_identifier (mangle_type_string (type));
}
/* Create an identifier for the mangled name of a special component
for belonging to TYPE. CODE is the ABI-specified code for this
component. */
static tree
mangle_special_for_type (type, code)
tree type;
const char *code;
{
const char *result;
/* We don't have an actual decl here for the special component, so
we can't just process the <encoded-name>. Instead, fake it. */
start_mangling ();
/* Start the mangling. */
write_string ("_Z");
write_string (code);
/* Add the type. */
write_type (type);
result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_special_for_type = %s\n\n", result);
return get_identifier (result);
}
/* Create an identifier for the mangled representation of the typeinfo
structure for TYPE. */
tree
mangle_typeinfo_for_type (type)
tree type;
{
return mangle_special_for_type (type, "TI");
}
/* Create an identifier for the mangled name of the NTBS containing
the mangled name of TYPE. */
tree
mangle_typeinfo_string_for_type (type)
tree type;
{
return mangle_special_for_type (type, "TS");
}
/* Create an identifier for the mangled name of the vtable for TYPE. */
tree
mangle_vtbl_for_type (type)
tree type;
{
return mangle_special_for_type (type, "TV");
}
/* Returns an identifier for the mangled name of the VTT for TYPE. */
tree
mangle_vtt_for_type (type)
tree type;
{
return mangle_special_for_type (type, "TT");
}
/* Return an identifier for a construction vtable group. TYPE is
the most derived class in the hierarchy; BINFO is the base
subobject for which this construction vtable group will be used.
This mangling isn't part of the ABI specification; in the ABI
specification, the vtable group is dumped in the same COMDAT as the
main vtable, and is referenced only from that vtable, so it doesn't
need an external name. For binary formats without COMDAT sections,
though, we need external names for the vtable groups.
We use the production
<special-name> ::= CT <type> <offset number> _ <base type> */
tree
mangle_ctor_vtbl_for_type (type, binfo)
tree type;
tree binfo;
{
const char *result;
start_mangling ();
write_string ("_Z");
write_string ("TC");
write_type (type);
write_integer_cst (BINFO_OFFSET (binfo));
write_char ('_');
write_type (BINFO_TYPE (binfo));
result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n", result);
return get_identifier (result);
}
/* Return an identifier for the mangled name of a thunk to FN_DECL.
OFFSET is the initial adjustment to this used to find the vptr. If
VCALL_OFFSET is non-zero, this is a virtual thunk, and it is the
vtbl offset in bytes.
<special-name> ::= Th <offset number> _ <base encoding>
::= Tv <offset number> _ <vcall offset number> _
<base encoding>
*/
tree
mangle_thunk (fn_decl, offset, vcall_offset)
tree fn_decl;
int offset;
int vcall_offset;
{
const char *result;
start_mangling ();
write_string ("_Z");
/* The <special-name> for virtual thunks is Tv, for non-virtual
thunks Th. */
write_char ('T');
if (vcall_offset != 0)
write_char ('v');
else
write_char ('h');
/* For either flavor, write the offset to this. */
write_number (offset, 10);
write_char ('_');
/* For a virtual thunk, add the vcall offset. */
if (vcall_offset != 0)
{
/* Virtual thunk. Write the vcall offset and base type name. */
write_number (vcall_offset, 10);
write_char ('_');
}
/* Scoped name. */
write_encoding (fn_decl);
result = finish_mangling ();
if (DEBUG_MANGLE)
fprintf (stderr, "mangle_thunk = %s\n\n", result);
return get_identifier (result);
}
/* Return an identifier for the mangled unqualified name for a
conversion operator to TYPE. This mangling is not specified by the
ABI spec; it is only used internally.
For compatibility with existing conversion operator mechanisms,
the mangled form is `__op<type>' where <type> is the mangled
representation of TYPE.
FIXME: Though identifiers with starting with __op are reserved for
the implementation, it would eventually be nice to use inaccessible
names for these operators. */
tree
mangle_conv_op_name_for_type (type)
tree type;
{
tree identifier;
/* Build the mangling for TYPE. */
const char *mangled_type = mangle_type_string (type);
/* Allocate a temporary buffer for the complete name. */
char *op_name = (char *) xmalloc (strlen (OPERATOR_TYPENAME_FORMAT)
+ strlen (mangled_type) + 1);
/* Assemble the mangling. */
strcpy (op_name, OPERATOR_TYPENAME_FORMAT);
strcat (op_name, mangled_type);
/* Find or create an identifier. */
identifier = get_identifier (op_name);
/* Done with the temporary buffer. */
free (op_name);
/* Set bits on the identifier so we know later it's a conversion. */
IDENTIFIER_OPNAME_P (identifier) = 1;
IDENTIFIER_TYPENAME_P (identifier) = 1;
/* Hang TYPE off the identifier so it can be found easily later when
performing conversions. */
TREE_TYPE (identifier) = type;
return identifier;
}
/* Return an identifier for the name of an initialization guard
variable for indicated VARIABLE. */
tree
mangle_guard_variable (variable)
tree variable;
{
start_mangling ();
write_string ("_ZGV");
write_name (variable);
return get_identifier (finish_mangling ());
}
......@@ -137,6 +137,8 @@ init_method ()
ggc_add_tree_varray_root (&btypelist, 1);
ggc_add_tree_varray_root (&ktypelist, 1);
ggc_add_tree_varray_root (&typevec, 1);
if (flag_new_abi)
init_mangle ();
}
/* This must be large enough to hold any printed integer or floating-point
......@@ -156,6 +158,9 @@ static int numeric_output_need_bar;
static inline void
start_squangling ()
{
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 200005222);
if (flag_do_squangling)
{
nofold = 0;
......@@ -1125,6 +1130,10 @@ build_overload_name (parmtypes, begin, end)
int begin, end;
{
char *ret;
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 200005221);
start_squangling ();
ret = build_mangled_name (parmtypes, begin, end);
end_squangling ();
......@@ -1140,6 +1149,9 @@ build_mangled_name (parmtypes, begin, end)
tree parmtypes;
int begin, end;
{
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 200004105);
if (begin)
OB_INIT ();
......@@ -1549,6 +1561,9 @@ tree
build_static_name (context, name)
tree context, name;
{
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 200004106);
OB_INIT ();
numeric_output_need_bar = 0;
start_squangling ();
......@@ -1584,6 +1599,9 @@ build_decl_overload_real (decl, parms, ret_type, tparms, targs,
const char *name;
enum tree_code operator_code;
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 20000410);
operator_code = DECL_OVERLOADED_OPERATOR_P (decl);
if (!DECL_CONV_FN_P (decl) && operator_code)
{
......@@ -1719,6 +1737,12 @@ set_mangled_name_for_decl (decl)
/* There's no need to mangle the name of a template function. */
return;
if (flag_new_abi)
{
DECL_ASSEMBLER_NAME (decl) = mangle_decl (decl);
return;
}
parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
if (DECL_STATIC_FUNCTION_P (decl))
......@@ -1748,6 +1772,9 @@ build_typename_overload (type)
{
tree id;
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 200004108);
OB_INIT ();
OB_PUTS (OPERATOR_TYPENAME_FORMAT);
nofold = 1;
......@@ -1765,6 +1792,9 @@ tree
build_overload_with_type (name, type)
tree name, type;
{
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 200004109);
OB_INIT ();
OB_PUTID (name);
nofold = 1;
......@@ -1780,6 +1810,9 @@ get_id_2 (name, name2)
const char *name;
tree name2;
{
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 20000411);
OB_INIT ();
OB_PUTCP (name);
OB_PUTID (name2);
......@@ -1796,6 +1829,9 @@ get_ctor_vtbl_name (type, binfo)
tree type;
tree binfo;
{
/* This function is obsoleted by the new ABI. */
my_friendly_assert (!flag_new_abi, 200005220);
start_squangling ();
OB_INIT ();
OB_PUTCP (CTOR_VTBL_NAME_PREFIX);
......@@ -2019,6 +2055,11 @@ hack_identifier (value, name)
}
/* Return a thunk to FUNCTION. For a virtual thunk, DELTA is the
offset to this used to locate the vptr, and VCALL_INDEX is used to
look up the eventual subobject location. For a non-virtual thunk,
DELTA is the offset to this and VCALL_INDEX is zero. */
tree
make_thunk (function, delta, vcall_index)
tree function;
......@@ -2028,6 +2069,7 @@ make_thunk (function, delta, vcall_index)
tree thunk_id;
tree thunk;
tree func_decl;
int vcall_offset = vcall_index * int_size_in_bytes (vtable_entry_type);
if (TREE_CODE (function) != ADDR_EXPR)
abort ();
......@@ -2035,6 +2077,10 @@ make_thunk (function, delta, vcall_index)
if (TREE_CODE (func_decl) != FUNCTION_DECL)
abort ();
if (flag_new_abi)
thunk_id = mangle_thunk (TREE_OPERAND (function, 0), delta, vcall_offset);
else
{
OB_INIT ();
OB_PUTS ("__thunk_");
if (delta > 0)
......@@ -2053,6 +2099,7 @@ make_thunk (function, delta, vcall_index)
OB_PUTID (DECL_ASSEMBLER_NAME (func_decl));
OB_FINISH ();
thunk_id = get_identifier (obstack_base (&scratch_obstack));
}
thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
if (thunk && !DECL_THUNK_P (thunk))
......@@ -2073,8 +2120,7 @@ make_thunk (function, delta, vcall_index)
SET_DECL_THUNK_P (thunk);
DECL_INITIAL (thunk) = function;
THUNK_DELTA (thunk) = delta;
THUNK_VCALL_OFFSET (thunk)
= vcall_index * int_size_in_bytes (vtable_entry_type);
THUNK_VCALL_OFFSET (thunk) = vcall_offset;
/* The thunk itself is not a constructor or destructor, even if
the thing it is thunking to is. */
DECL_INTERFACE_KNOWN (thunk) = 1;
......
......@@ -108,7 +108,7 @@ DEF_SIMPLE_OPERATOR ("+", PLUS_EXPR, "pl", "__pl", 2)
DEF_SIMPLE_OPERATOR ("-", MINUS_EXPR, "mi", "__mi", 2)
DEF_SIMPLE_OPERATOR ("*", MULT_EXPR, "ml", "__ml", 2)
DEF_SIMPLE_OPERATOR ("/", TRUNC_DIV_EXPR, "dv", "__dv", 2)
DEF_SIMPLE_OPERATOR ("%", TRUNC_MOD_EXPR, "md", "__md", 2)
DEF_SIMPLE_OPERATOR ("%", TRUNC_MOD_EXPR, "rm", "__md", 2)
DEF_SIMPLE_OPERATOR ("&", BIT_AND_EXPR, "an", "__ad", 2)
DEF_SIMPLE_OPERATOR ("|", BIT_IOR_EXPR, "or", "__or", 2)
DEF_SIMPLE_OPERATOR ("^", BIT_XOR_EXPR, "eo", "__er", 2)
......@@ -131,6 +131,8 @@ DEF_SIMPLE_OPERATOR ("--", POSTDECREMENT_EXPR, "mm", "__mm", 2)
/* These are extensions. */
DEF_SIMPLE_OPERATOR ("<?", MIN_EXPR, "vx3min", "__mn", 2)
DEF_SIMPLE_OPERATOR (">?", MAX_EXPR, "vx3max", "__mx", 2)
/* This one is needed for mangling. */
DEF_SIMPLE_OPERATOR ("::", SCOPE_REF, "sr", NULL, 2);
/* Assignment operators. */
DEF_ASSN_OPERATOR ("=", NOP_EXPR, "aS", "__as", 2)
......@@ -138,7 +140,7 @@ DEF_ASSN_OPERATOR ("+=", PLUS_EXPR, "pL", "__apl", 2)
DEF_ASSN_OPERATOR ("-=", MINUS_EXPR, "mI", "__ami", 2)
DEF_ASSN_OPERATOR ("*=", MULT_EXPR, "mL", "__aml", 2)
DEF_ASSN_OPERATOR ("/=", TRUNC_DIV_EXPR, "dV", "__adv", 2)
DEF_ASSN_OPERATOR ("%=", TRUNC_MOD_EXPR, "mD", "__amd", 2)
DEF_ASSN_OPERATOR ("%=", TRUNC_MOD_EXPR, "rM", "__amd", 2)
DEF_ASSN_OPERATOR ("&=", BIT_AND_EXPR, "aN", "__aad", 2)
DEF_ASSN_OPERATOR ("|=", BIT_IOR_EXPR, "oR", "__aor", 2)
DEF_ASSN_OPERATOR ("^=", BIT_XOR_EXPR, "eO", "__aer", 2)
......@@ -150,4 +152,3 @@ DEF_SIMPLE_OPERATOR ("?:", COND_EXPR, "qu", "__cn", 3)
/* Miscellaneous. */
DEF_SIMPLE_OPERATOR ("()", CALL_EXPR, "cl", "__cl", -1)
......@@ -1984,6 +1984,10 @@ build_template_decl (decl, parms)
DECL_STATIC_FUNCTION_P (tmpl) = DECL_STATIC_FUNCTION_P (decl);
DECL_CONSTRUCTOR_P (tmpl) = DECL_CONSTRUCTOR_P (decl);
DECL_NONCONVERTING_P (tmpl) = DECL_NONCONVERTING_P (decl);
DECL_ASSIGNMENT_OPERATOR_P (tmpl) = DECL_ASSIGNMENT_OPERATOR_P (decl);
if (DECL_OVERLOADED_OPERATOR_P (decl))
SET_OVERLOADED_OPERATOR_CODE (tmpl,
DECL_OVERLOADED_OPERATOR_P (decl));
}
return tmpl;
......@@ -4047,6 +4051,9 @@ lookup_template_class (d1, arglist, in_decl, context, entering_scope)
DECL_ASSEMBLER_NAME (type_decl) = DECL_NAME (type_decl);
if (!is_partial_instantiation)
{
if (flag_new_abi)
DECL_ASSEMBLER_NAME (type_decl) = mangle_decl (type_decl);
else
DECL_ASSEMBLER_NAME (type_decl)
= get_identifier (build_overload_name (t, 1, 1));
......@@ -5709,9 +5716,14 @@ tsubst_decl (t, args, type, in_decl)
/*entering_scope=*/1);
if (member && DECL_CONV_FN_P (r))
{
/* Type-conversion operator. Reconstruct the name, in
case it's the name of one of the template's parameters. */
if (flag_new_abi)
DECL_NAME (r) = mangle_conv_op_name_for_type (TREE_TYPE (type));
else
DECL_NAME (r) = build_typename_overload (TREE_TYPE (type));
}
DECL_ARGUMENTS (r) = tsubst (DECL_ARGUMENTS (t), args,
/*complain=*/1, t);
......@@ -5746,7 +5758,12 @@ tsubst_decl (t, args, type, in_decl)
/* Set the mangled name for R. */
if (DECL_DESTRUCTOR_P (t))
{
if (flag_new_abi)
set_mangled_name_for_decl (r);
else
DECL_ASSEMBLER_NAME (r) = build_destructor_name (ctx);
}
else
{
/* Instantiations of template functions must be mangled
......@@ -7078,8 +7095,13 @@ tsubst_copy (t, args, complain, in_decl)
case IDENTIFIER_NODE:
if (IDENTIFIER_TYPENAME_P (t))
return (build_typename_overload
(tsubst (TREE_TYPE (t), args, complain, in_decl)));
{
tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
if (flag_new_abi)
return mangle_conv_op_name_for_type (new_type);
else
return (build_typename_overload (new_type));
}
else
return t;
......@@ -9911,6 +9933,80 @@ tsubst_enum (tag, newtag, args)
finish_enum (newtag);
}
/* DECL is a FUNCTION_DECL that is a template specialization. Return
its type -- but without substituting the innermost set of template
arguments. So, innermost set of template parameters will appear in
the type. If CONTEXTP is non-NULL, then the partially substituted
DECL_CONTEXT (if any) will also be filled in. Similarly, TPARMSP
will be filled in with the substituted template parameters, if it
is non-NULL. */
tree
get_mostly_instantiated_function_type (decl, contextp, tparmsp)
tree decl;
tree *contextp;
tree *tparmsp;
{
tree context = NULL_TREE;
tree fn_type;
tree tmpl;
tree targs;
tree tparms;
int parm_depth;
tmpl = most_general_template (DECL_TI_TEMPLATE (decl));
targs = DECL_TI_ARGS (decl);
tparms = DECL_TEMPLATE_PARMS (tmpl);
parm_depth = TMPL_PARMS_DEPTH (tparms);
/* There should be as many levels of arguments as there are levels
of parameters. */
my_friendly_assert (parm_depth == TMPL_ARGS_DEPTH (targs), 0);
fn_type = TREE_TYPE (tmpl);
if (DECL_STATIC_FUNCTION_P (decl))
context = DECL_CONTEXT (decl);
if (parm_depth == 1)
/* No substitution is necessary. */
;
else
{
int i;
tree partial_args;
/* Replace the innermost level of the TARGS with NULL_TREEs to
let tsubst know not to subsitute for those parameters. */
partial_args = make_tree_vec (TREE_VEC_LENGTH (targs));
for (i = 1; i < TMPL_ARGS_DEPTH (targs); ++i)
SET_TMPL_ARGS_LEVEL (partial_args, i,
TMPL_ARGS_LEVEL (targs, i));
SET_TMPL_ARGS_LEVEL (partial_args,
TMPL_ARGS_DEPTH (targs),
make_tree_vec (DECL_NTPARMS (tmpl)));
/* Now, do the (partial) substitution to figure out the
appropriate function type. */
fn_type = tsubst (fn_type, partial_args, /*complain=*/1, NULL_TREE);
if (DECL_STATIC_FUNCTION_P (decl))
context = tsubst (context, partial_args, /*complain=*/1, NULL_TREE);
/* Substitute into the template parameters to obtain the real
innermost set of parameters. This step is important if the
innermost set of template parameters contains value
parameters whose types depend on outer template parameters. */
TREE_VEC_LENGTH (partial_args)--;
tparms = tsubst_template_parms (tparms, partial_args, /*complain=*/1);
}
if (contextp)
*contextp = context;
if (tparmsp)
*tparmsp = tparms;
return fn_type;
}
/* Set the DECL_ASSEMBLER_NAME for DECL, which is a FUNCTION_DECL that
is either an instantiation or specialization of a template
function. */
......@@ -9925,12 +10021,17 @@ set_mangled_name_for_template_decl (decl)
tree parm_types;
tree tparms;
tree targs;
tree tmpl;
int parm_depth;
my_friendly_assert (TREE_CODE (decl) == FUNCTION_DECL, 0);
my_friendly_assert (DECL_TEMPLATE_INFO (decl) != NULL_TREE, 0);
/* Under the new ABI, we don't need special machinery. */
if (flag_new_abi)
{
set_mangled_name_for_decl (decl);
return;
}
/* The names of template functions must be mangled so as to indicate
what template is being specialized with what template arguments.
For example, each of the following three functions must get
......@@ -9946,14 +10047,6 @@ set_mangled_name_for_template_decl (decl)
mangle the name of such an entity. */
return;
tmpl = most_general_template (DECL_TI_TEMPLATE (decl));
tparms = DECL_TEMPLATE_PARMS (tmpl);
parm_depth = TMPL_PARMS_DEPTH (tparms);
/* There should be as many levels of arguments as there are levels
of parameters. */
my_friendly_assert (parm_depth == TMPL_ARGS_DEPTH (targs), 0);
/* We now compute the PARMS and RET_TYPE to give to
build_decl_overload_real. The PARMS and RET_TYPE are the
parameter and return types of the template, after all but the
......@@ -9972,41 +10065,7 @@ set_mangled_name_for_template_decl (decl)
{int, U}. Thus, the args that we want to subsitute into the
return and parameter type for the function are those in TARGS,
with the innermost level omitted. */
fn_type = TREE_TYPE (tmpl);
if (DECL_STATIC_FUNCTION_P (decl))
context = DECL_CONTEXT (decl);
if (parm_depth == 1)
/* No substitution is necessary. */
;
else
{
int i;
tree partial_args;
/* Replace the innermost level of the TARGS with NULL_TREEs to
let tsubst know not to subsitute for those parameters. */
partial_args = make_tree_vec (TMPL_ARGS_DEPTH (targs));
for (i = 1; i < TMPL_ARGS_DEPTH (targs); ++i)
SET_TMPL_ARGS_LEVEL (partial_args, i,
TMPL_ARGS_LEVEL (targs, i));
SET_TMPL_ARGS_LEVEL (partial_args,
TMPL_ARGS_DEPTH (targs),
make_tree_vec (DECL_NTPARMS (tmpl)));
/* Now, do the (partial) substitution to figure out the
appropriate function type. */
fn_type = tsubst (fn_type, partial_args, /*complain=*/1, NULL_TREE);
if (DECL_STATIC_FUNCTION_P (decl))
context = tsubst (context, partial_args, /*complain=*/1, NULL_TREE);
/* Substitute into the template parameters to obtain the real
innermost set of parameters. This step is important if the
innermost set of template parameters contains value
parameters whose types depend on outer template parameters. */
TREE_VEC_LENGTH (partial_args)--;
tparms = tsubst_template_parms (tparms, partial_args, /*complain=*/1);
}
fn_type = get_mostly_instantiated_function_type (decl, &context, &tparms);
/* Now, get the innermost parameters and arguments, and figure out
the parameter and return types. */
......@@ -10034,7 +10093,7 @@ set_mangled_name_for_template_decl (decl)
my_friendly_assert (TREE_VEC_LENGTH (tparms) == TREE_VEC_LENGTH (targs),
0);
/* Actually set the DCL_ASSEMBLER_NAME. */
/* Actually set the DECL_ASSEMBLER_NAME. */
DECL_ASSEMBLER_NAME (decl)
= build_decl_overload_real (decl, parm_types, ret_type,
tparms, targs,
......
......@@ -377,8 +377,14 @@ static tree
tinfo_name (type)
tree type;
{
const char *name = build_overload_name (type, 1, 1);
tree name_string = combine_strings (build_string (strlen (name) + 1, name));
const char *name;
tree name_string;
if (flag_new_abi)
name = mangle_type_string (type);
else
name = build_overload_name (type, 1, 1);
name_string = combine_strings (build_string (strlen (name) + 1, name));
return name_string;
}
......@@ -403,6 +409,9 @@ get_tinfo_decl (type)
type = build_function_type (TREE_TYPE (type),
TREE_CHAIN (TYPE_ARG_TYPES (type)));
if (flag_new_abi)
name = mangle_typeinfo_for_type (type);
else
name = build_overload_with_type (tinfo_decl_id, type);
d = IDENTIFIER_GLOBAL_VALUE (name);
......@@ -410,8 +419,8 @@ get_tinfo_decl (type)
/* OK */;
else if (!new_abi_rtti_p ())
{
/* The tinfo decl is a function returning a reference to the type_info
object. */
/* The tinfo decl is a function returning a reference to the
type_info object. */
d = push_library_fn (name, tinfo_decl_type);
DECL_NOT_REALLY_EXTERN (d) = 1;
SET_DECL_TINFO_FN_P (d);
......@@ -1298,12 +1307,18 @@ tinfo_base_init (desc, target)
tree name_decl;
{
tree name_name;
/* Generate the NTBS array variable. */
tree name_name = build_overload_with_type (tinfo_var_id, target);
tree name_type = build_cplus_array_type
(build_qualified_type (char_type_node, TYPE_QUAL_CONST),
NULL_TREE);
tree name_string = tinfo_name (target);
if (flag_new_abi)
name_name = mangle_typeinfo_for_type (target);
else
name_name = build_overload_with_type (tinfo_var_id, target);
name_decl = build_lang_decl (VAR_DECL, name_name, name_type);
DECL_ARTIFICIAL (name_decl) = 1;
......@@ -1312,6 +1327,12 @@ tinfo_base_init (desc, target)
DECL_EXTERNAL (name_decl) = 0;
TREE_PUBLIC (name_decl) = 1;
comdat_linkage (name_decl);
if (flag_new_abi)
/* The new ABI specifies the external name of the string
containing the type's name. */
DECL_ASSEMBLER_NAME (name_decl)
= mangle_typeinfo_string_for_type (target);
else
DECL_ASSEMBLER_NAME (name_decl) = DECL_NAME (name_decl);
DECL_INITIAL (name_decl) = name_string;
cp_finish_decl (name_decl, name_string, NULL_TREE, 0);
......
......@@ -26,9 +26,9 @@ struct T : public S
// Provide access to the raw function pointers. This is
// mangling-dependent.
extern "C" void f__1T ();
extern "C" void g__1T ();
extern "C" void h__1T ();
extern "C" void _ZN1T1fEv ();
extern "C" void _ZN1T1gEv ();
extern "C" void _ZN1T1hEv ();
// This structure is a C representation of a pointer-to-member.
......@@ -72,12 +72,12 @@ main ()
// There should be no adjustment for the `T' version, and an
// appropriate adjustment for the `S' version.
y = &T::f;
if (yp->ptr != &f__1T)
if (yp->ptr != &_ZN1T1fEv)
return 5;
if (yp->adj != 0)
return 6;
x = (sp) y;
if (xp->ptr != &f__1T)
if (xp->ptr != &_ZN1T1fEv)
return 7;
if (xp->adj != delta)
return 8;
......
......@@ -122,8 +122,8 @@ void S4::s1 ()
// These are tricks to allow us to get raw function pointers for
// member functions.
extern "C" {
void s3__2S3 ();
void s1__2S4 ();
void _ZN2S32s3Ev ();
void _ZN2S42s1Ev ();
}
int main ()
......@@ -147,9 +147,9 @@ int main ()
return 4;
// Skip the RTTI entry.
vtbl++;
if (*vtbl++ != (ptrdiff_t) &s3__2S3)
if (*vtbl++ != (ptrdiff_t) &_ZN2S32s3Ev)
return 5;
if (*vtbl++ != (ptrdiff_t) &s1__2S4)
if (*vtbl++ != (ptrdiff_t) &_ZN2S42s1Ev)
return 6;
// The S1 vbase offset.
if (*vtbl++ != 0)
......
// Test for proper mangling by setting up name clashes.
// Special g++ Options: -fno-squangle
#if (!defined (__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100)
#define NAME(OLD, NEW) OLD
#else
#define NAME(OLD, NEW) NEW
#endif /* (!defined (__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100) */
class A { };
typedef A A2;
typedef int I;
......@@ -8,38 +14,45 @@ typedef void V;
typedef I I2;
void f (const A2&, int, const A2&, const A&) { } // ERROR - name clash
int f__FRC1AiT0T0 = 0; // ERROR - name clash
int NAME (f__FRC1AiT0T0, _Z1fRK1AiS1_S1_) = 0; // ERROR - name clash
void f (int, long, int, I) { } // ERROR - name clash
int f__Filii = 0; // ERROR - name clash
int NAME (f__Filii, _Z1filii) = 0; // ERROR - name clash
void f (I, float, I, I2) { } // ERROR - name clash
int f__Fifii = 0; // ERROR - name clash
int NAME (f__Fifii, _Z1fifii) = 0; // ERROR - name clash
void f (void*, float, void*, V*) { } // ERROR - name clash
int f__FPvfT0T0 = 0; // ERROR - name clash
int NAME (f__FPvfT0T0, _Z1fPvfS_S_) = 0; // ERROR - name clash
void f (wchar_t) { } // ERROR - name clash
int f__Fw = 0; // ERROR - name clash
int NAME (f__Fw, _Z1fw) = 0; // ERROR - name clash
void f(int, A, A2, A) { } // ERROR - name clash
int f__FiG1AN21 = 0; // ERROR - name clash
int NAME (f__FiG1AN21, _Z1fi1AS_S_) = 0; // ERROR - name clash
void f(const A2&, const A2&, const A2&, const A2&,
int&) { } // ERROR - name clash
int f__FRC1AN30Ri = 0; // ERROR - name clash
int NAME (f__FRC1AN30Ri, _Z1fRK1AS1_S1_S1_Ri) = 0; // ERROR - name clash
void f(const A2&, int, const A2&, const A2&, const A2&,
int&) { } // ERROR - name clash
int f__FRC1AiT0N20Ri = 0; // ERROR - name clash
int NAME (f__FRC1AiT0N20Ri, _Z1fRK1AiS1_S1_S1_Ri) = 0; // ERROR - name clash
void f(const A2&, int, const A2&, const A2&, const A2&, int&, int&,
int&) { } // ERROR - name clash
int f__FRC1AiT0N20RiN25 = 0; // ERROR - name clash
int NAME (f__FRC1AiT0N20RiN25, _Z1fRK1AiS1_S1_S1_RiS2_S2_) = 0; // ERROR - name clash
void f(const A2&, int, const A2&, const A2&, const A2&, int, int,
int) { } // ERROR - name clash
int f__FRC1AiT0N20iii = 0; // ERROR - name clash
int NAME (f__FRC1AiT0N20iii, _Z1fRK1AiS1_S1_S1_iii) = 0; // ERROR - name clash
void f(bool, bool) {} // ERROR - name clash
int f__FbT0 = 0; // ERROR - name clash
int NAME (f__FbT0, _Z1fbb) = 0; // ERROR - name clash
int
main ()
{
return 0;
}
// Test for proper mangling by setting up name clashes.
// Special g++ Options: -fsquangle
class A;
typedef A A2;
typedef int I;
typedef void V;
typedef I I2;
void f (const A2&, int, const A2&, const A&) { } // ERROR - name clash
int f__FRC1AiRCB0n1 = 0; // ERROR - name clash
void f (int, long, int, I) { } // ERROR - name clash
int f__Filii = 0; // ERROR - name clash
void f (I, float, I, I2) { } // ERROR - name clash
int f__Fifii = 0; // ERROR - name clash
void f (void*, float, void*, V*) { } // ERROR - name clash
int f__FPvfPvn1 = 0; // ERROR - name clash
void f (wchar_t) { } // ERROR - name clash
int f__Fw = 0; // ERROR - name clash
void f(int, A, A2, A) { } // ERROR - name clash
int f__FiG1An2 = 0; // ERROR - name clash
void f(const A2&, const A2&, const A2&, const A2&,
int&) { } // ERROR - name clash
int f__FRC1An3Ri = 0; // ERROR - name clash
void f(const A2&, int, const A2&, const A2&, const A2&,
int&) { } // ERROR - name clash
int f__FRC1AiRCB0n2Ri = 0; // ERROR - name clash
void f(const A2&, int, const A2&, const A2&, const A2&, int&, int&,
int&) { } // ERROR - name clash
int f__FRC1AiRCB0n2Rin2 = 0; // ERROR - name clash
void f(const A2&, int, const A2&, const A2&, const A2&, int, int,
int) { } // ERROR - name clash
int f__FRC1AiRCB0n2in2 = 0; // ERROR - name clash
......@@ -2,6 +2,12 @@
// Special g++ Options: -fno-squangle
// Origin: Mark Mitchell <mark@codesourcery.com>
#if (!defined (__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100)
#define NAME(OLD, NEW) OLD
#else
#define NAME(OLD, NEW) NEW
#endif /* (!defined (__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100) */
static unsigned int strlen (const char*) {} // ERROR - previous declaration
int strlen__FPCc = 0; // ERROR - duplicate declaration
int NAME (strlen__FPCc, _Z6strlenPKc) = 0; // ERROR - duplicate declaration
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment