1 /* Name mangling for the 3.0 C++ ABI.
2 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Written by Alex Samuel <sameul@codesourcery.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file implements mangling of C++ names according to the IA64
23 C++ ABI specification. A mangled name encodes a function or
24 variable's name, scope, type, and/or template arguments into a text
25 identifier. This identifier is used as the function's or
26 variable's linkage name, to preserve compatibility between C++'s
27 language features (templates, scoping, and overloading) and C
30 Additionally, g++ uses mangled names internally. To support this,
31 mangling of types is allowed, even though the mangled name of a
32 type should not appear by itself as an exported name. Ditto for
33 uninstantiated templates.
35 The primary entry point for this module is mangle_decl, which
36 returns an identifier containing the mangled name for a decl.
37 Additional entry points are provided to build mangled names of
38 particular constructs when the appropriate decl for that construct
39 is not available. These are:
41 mangle_typeinfo_for_type: typeinfo data
42 mangle_typeinfo_string_for_type: typeinfo type name
43 mangle_vtbl_for_type: virtual table data
44 mangle_vtt_for_type: VTT data
45 mangle_ctor_vtbl_for_type: `C-in-B' constructor virtual table data
46 mangle_thunk: thunk function or entry
52 #include "coretypes.h"
62 /* Debugging support. */
64 /* Define DEBUG_MANGLE to enable very verbose trace messages. */
66 #define DEBUG_MANGLE 0
69 /* Macros for tracing the write_* functions. */
71 # define MANGLE_TRACE(FN, INPUT) \
72 fprintf (stderr, " %-24s: %-24s\n", (FN), (INPUT))
73 # define MANGLE_TRACE_TREE(FN, NODE) \
74 fprintf (stderr, " %-24s: %-24s (%p)\n", \
75 (FN), tree_code_name[TREE_CODE (NODE)], (void *) (NODE))
77 # define MANGLE_TRACE(FN, INPUT)
78 # define MANGLE_TRACE_TREE(FN, NODE)
81 /* Nonzero if NODE is a class template-id. We can't rely on
82 CLASSTYPE_USE_TEMPLATE here because of tricky bugs in the parser
83 that hard to distinguish A<T> from A, where A<T> is the type as
84 instantiated outside of the template, and A is the type used
85 without parameters inside the template. */
86 #define CLASSTYPE_TEMPLATE_ID_P(NODE) \
87 (TYPE_LANG_SPECIFIC (NODE) != NULL \
88 && (TREE_CODE (NODE) == BOUND_TEMPLATE_TEMPLATE_PARM \
89 || (CLASSTYPE_TEMPLATE_INFO (NODE) != NULL \
90 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (NODE))))))
92 /* Things we only need one of. This module is not reentrant. */
95 /* The name in which we're building the mangled name. */
96 struct obstack name_obstack;
98 /* An array of the current substitution candidates, in the order
100 varray_type substitutions;
102 /* The entity that is being mangled. */
105 /* True if the mangling will be different in a future version of the
107 bool need_abi_warning;
110 /* Indices into subst_identifiers. These are identifiers used in
111 special substitution rules. */
119 SUBID_BASIC_IOSTREAM,
122 substitution_identifier_index_t;
124 /* For quick substitution checks, look up these common identifiers
126 static GTY(()) tree subst_identifiers[SUBID_MAX];
128 /* Single-letter codes for builtin integer types, defined in
129 <builtin-type>. These are indexed by integer_type_kind values. */
131 integer_type_codes[itk_none] =
134 'a', /* itk_signed_char */
135 'h', /* itk_unsigned_char */
137 't', /* itk_unsigned_short */
139 'j', /* itk_unsigned_int */
141 'm', /* itk_unsigned_long */
142 'x', /* itk_long_long */
143 'y' /* itk_unsigned_long_long */
146 static int decl_is_template_id (const tree, tree* const);
148 /* Functions for handling substitutions. */
150 static inline tree canonicalize_for_substitution (tree);
151 static void add_substitution (tree);
152 static inline int is_std_substitution (const tree,
153 const substitution_identifier_index_t);
154 static inline int is_std_substitution_char (const tree,
155 const substitution_identifier_index_t);
156 static int find_substitution (tree);
157 static void mangle_call_offset (const tree, const tree);
159 /* Functions for emitting mangled representations of things. */
161 static void write_mangled_name (const tree, bool);
162 static void write_encoding (const tree);
163 static void write_name (tree, const int);
164 static void write_unscoped_name (const tree);
165 static void write_unscoped_template_name (const tree);
166 static void write_nested_name (const tree);
167 static void write_prefix (const tree);
168 static void write_template_prefix (const tree);
169 static void write_unqualified_name (const tree);
170 static void write_conversion_operator_name (const tree);
171 static void write_source_name (tree);
172 static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
174 static void write_number (unsigned HOST_WIDE_INT, const int,
176 static void write_integer_cst (const tree);
177 static void write_real_cst (const tree);
178 static void write_identifier (const char *);
179 static void write_special_name_constructor (const tree);
180 static void write_special_name_destructor (const tree);
181 static void write_type (tree);
182 static int write_CV_qualifiers_for_type (const tree);
183 static void write_builtin_type (tree);
184 static void write_function_type (const tree);
185 static void write_bare_function_type (const tree, const int, const tree);
186 static void write_method_parms (tree, const int, const tree);
187 static void write_class_enum_type (const tree);
188 static void write_template_args (tree);
189 static void write_expression (tree);
190 static void write_template_arg_literal (const tree);
191 static void write_template_arg (tree);
192 static void write_template_template_arg (const tree);
193 static void write_array_type (const tree);
194 static void write_pointer_to_member_type (const tree);
195 static void write_template_param (const tree);
196 static void write_template_template_param (const tree);
197 static void write_substitution (const int);
198 static int discriminator_for_local_entity (tree);
199 static int discriminator_for_string_literal (tree, tree);
200 static void write_discriminator (const int);
201 static void write_local_name (const tree, const tree, const tree);
202 static void dump_substitution_candidates (void);
203 static const char *mangle_decl_string (const tree);
205 /* Control functions. */
207 static inline void start_mangling (const tree);
208 static inline const char *finish_mangling (const bool);
209 static tree mangle_special_for_type (const tree, const char *);
211 /* Foreign language functions. */
213 static void write_java_integer_type_codes (const tree);
215 /* Append a single character to the end of the mangled
217 #define write_char(CHAR) \
218 obstack_1grow (&G.name_obstack, (CHAR))
220 /* Append a sized buffer to the end of the mangled representation. */
221 #define write_chars(CHAR, LEN) \
222 obstack_grow (&G.name_obstack, (CHAR), (LEN))
224 /* Append a NUL-terminated string to the end of the mangled
226 #define write_string(STRING) \
227 obstack_grow (&G.name_obstack, (STRING), strlen (STRING))
229 /* Nonzero if NODE1 and NODE2 are both TREE_LIST nodes and have the
230 same purpose (context, which may be a type) and value (template
231 decl). See write_template_prefix for more information on what this
233 #define NESTED_TEMPLATE_MATCH(NODE1, NODE2) \
234 (TREE_CODE (NODE1) == TREE_LIST \
235 && TREE_CODE (NODE2) == TREE_LIST \
236 && ((TYPE_P (TREE_PURPOSE (NODE1)) \
237 && same_type_p (TREE_PURPOSE (NODE1), TREE_PURPOSE (NODE2)))\
238 || TREE_PURPOSE (NODE1) == TREE_PURPOSE (NODE2)) \
239 && TREE_VALUE (NODE1) == TREE_VALUE (NODE2))
241 /* Write out an unsigned quantity in base 10. */
242 #define write_unsigned_number(NUMBER) \
243 write_number ((NUMBER), /*unsigned_p=*/1, 10)
245 /* If DECL is a template instance, return nonzero and, if
246 TEMPLATE_INFO is non-NULL, set *TEMPLATE_INFO to its template info.
247 Otherwise return zero. */
250 decl_is_template_id (const tree decl, tree* const template_info)
252 if (TREE_CODE (decl) == TYPE_DECL)
254 /* TYPE_DECLs are handled specially. Look at its type to decide
255 if this is a template instantiation. */
256 const tree type = TREE_TYPE (decl);
258 if (CLASS_TYPE_P (type) && CLASSTYPE_TEMPLATE_ID_P (type))
260 if (template_info != NULL)
261 /* For a templated TYPE_DECL, the template info is hanging
263 *template_info = TYPE_TEMPLATE_INFO (type);
269 /* Check if this is a primary template. */
270 if (DECL_LANG_SPECIFIC (decl) != NULL
271 && DECL_USE_TEMPLATE (decl)
272 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
273 && TREE_CODE (decl) != TEMPLATE_DECL)
275 if (template_info != NULL)
276 /* For most templated decls, the template info is hanging
278 *template_info = DECL_TEMPLATE_INFO (decl);
283 /* It's not a template id. */
287 /* Produce debugging output of current substitution candidates. */
290 dump_substitution_candidates (void)
294 fprintf (stderr, " ++ substitutions ");
295 for (i = 0; i < VARRAY_ACTIVE_SIZE (G.substitutions); ++i)
297 tree el = VARRAY_TREE (G.substitutions, i);
298 const char *name = "???";
301 fprintf (stderr, " ");
303 name = IDENTIFIER_POINTER (DECL_NAME (el));
304 else if (TREE_CODE (el) == TREE_LIST)
305 name = IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (el)));
306 else if (TYPE_NAME (el))
307 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (el)));
308 fprintf (stderr, " S%d_ = ", i - 1);
310 (CP_TYPE_RESTRICT_P (el)
311 || CP_TYPE_VOLATILE_P (el)
312 || CP_TYPE_CONST_P (el)))
313 fprintf (stderr, "CV-");
314 fprintf (stderr, "%s (%s at %p)\n",
315 name, tree_code_name[TREE_CODE (el)], (void *) el);
319 /* Both decls and types can be substitution candidates, but sometimes
320 they refer to the same thing. For instance, a TYPE_DECL and
321 RECORD_TYPE for the same class refer to the same thing, and should
322 be treated accordingly in substitutions. This function returns a
323 canonicalized tree node representing NODE that is used when adding
324 and substitution candidates and finding matches. */
327 canonicalize_for_substitution (tree node)
329 /* For a TYPE_DECL, use the type instead. */
330 if (TREE_CODE (node) == TYPE_DECL)
331 node = TREE_TYPE (node);
333 node = canonical_type_variant (node);
338 /* Add NODE as a substitution candidate. NODE must not already be on
339 the list of candidates. */
342 add_substitution (tree node)
347 fprintf (stderr, " ++ add_substitution (%s at %10p)\n",
348 tree_code_name[TREE_CODE (node)], (void *) node);
350 /* Get the canonicalized substitution candidate for NODE. */
351 c = canonicalize_for_substitution (node);
352 if (DEBUG_MANGLE && c != node)
353 fprintf (stderr, " ++ using candidate (%s at %10p)\n",
354 tree_code_name[TREE_CODE (node)], (void *) node);
358 /* Make sure NODE isn't already a candidate. */
361 for (i = VARRAY_ACTIVE_SIZE (G.substitutions); --i >= 0; )
363 const tree candidate = VARRAY_TREE (G.substitutions, i);
365 && node == candidate)
367 && TYPE_P (candidate)
368 && same_type_p (node, candidate)))
372 #endif /* ENABLE_CHECKING */
374 /* Put the decl onto the varray of substitution candidates. */
375 VARRAY_PUSH_TREE (G.substitutions, node);
378 dump_substitution_candidates ();
381 /* Helper function for find_substitution. Returns nonzero if NODE,
382 which may be a decl or a CLASS_TYPE, is a template-id with template
383 name of substitution_index[INDEX] in the ::std namespace. */
386 is_std_substitution (const tree node,
387 const substitution_identifier_index_t index)
394 type = TREE_TYPE (node);
397 else if (CLASS_TYPE_P (node))
400 decl = TYPE_NAME (node);
403 /* These are not the droids you're looking for. */
406 return (DECL_NAMESPACE_STD_P (CP_DECL_CONTEXT (decl))
407 && TYPE_LANG_SPECIFIC (type)
408 && TYPE_TEMPLATE_INFO (type)
409 && (DECL_NAME (TYPE_TI_TEMPLATE (type))
410 == subst_identifiers[index]));
413 /* Helper function for find_substitution. Returns nonzero if NODE,
414 which may be a decl or a CLASS_TYPE, is the template-id
415 ::std::identifier<char>, where identifier is
416 substitution_index[INDEX]. */
419 is_std_substitution_char (const tree node,
420 const substitution_identifier_index_t index)
423 /* Check NODE's name is ::std::identifier. */
424 if (!is_std_substitution (node, index))
426 /* Figure out its template args. */
428 args = DECL_TI_ARGS (node);
429 else if (CLASS_TYPE_P (node))
430 args = CLASSTYPE_TI_ARGS (node);
432 /* Oops, not a template. */
434 /* NODE's template arg list should be <char>. */
436 TREE_VEC_LENGTH (args) == 1
437 && TREE_VEC_ELT (args, 0) == char_type_node;
440 /* Check whether a substitution should be used to represent NODE in
443 First, check standard special-case substitutions.
445 <substitution> ::= St
452 # ::std::basic_string
455 # ::std::basic_string<char,
456 ::std::char_traits<char>,
457 ::std::allocator<char> >
460 # ::std::basic_istream<char, ::std::char_traits<char> >
463 # ::std::basic_ostream<char, ::std::char_traits<char> >
466 # ::std::basic_iostream<char, ::std::char_traits<char> >
468 Then examine the stack of currently available substitution
469 candidates for entities appearing earlier in the same mangling
471 If a substitution is found, write its mangled representation and
472 return nonzero. If none is found, just return zero. */
475 find_substitution (tree node)
478 const int size = VARRAY_ACTIVE_SIZE (G.substitutions);
483 fprintf (stderr, " ++ find_substitution (%s at %p)\n",
484 tree_code_name[TREE_CODE (node)], (void *) node);
486 /* Obtain the canonicalized substitution representation for NODE.
487 This is what we'll compare against. */
488 node = canonicalize_for_substitution (node);
490 /* Check for builtin substitutions. */
492 decl = TYPE_P (node) ? TYPE_NAME (node) : node;
493 type = TYPE_P (node) ? node : TREE_TYPE (node);
495 /* Check for std::allocator. */
497 && is_std_substitution (decl, SUBID_ALLOCATOR)
498 && !CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
504 /* Check for std::basic_string. */
505 if (decl && is_std_substitution (decl, SUBID_BASIC_STRING))
509 /* If this is a type (i.e. a fully-qualified template-id),
511 std::basic_string <char,
512 std::char_traits<char>,
513 std::allocator<char> > . */
514 if (cp_type_quals (type) == TYPE_UNQUALIFIED
515 && CLASSTYPE_USE_TEMPLATE (type))
517 tree args = CLASSTYPE_TI_ARGS (type);
518 if (TREE_VEC_LENGTH (args) == 3
519 && same_type_p (TREE_VEC_ELT (args, 0), char_type_node)
520 && is_std_substitution_char (TREE_VEC_ELT (args, 1),
522 && is_std_substitution_char (TREE_VEC_ELT (args, 2),
531 /* Substitute for the template name only if this isn't a type. */
538 /* Check for basic_{i,o,io}stream. */
540 && cp_type_quals (type) == TYPE_UNQUALIFIED
541 && CLASS_TYPE_P (type)
542 && CLASSTYPE_USE_TEMPLATE (type)
543 && CLASSTYPE_TEMPLATE_INFO (type) != NULL)
545 /* First, check for the template
546 args <char, std::char_traits<char> > . */
547 tree args = CLASSTYPE_TI_ARGS (type);
548 if (TREE_VEC_LENGTH (args) == 2
549 && TYPE_P (TREE_VEC_ELT (args, 0))
550 && same_type_p (TREE_VEC_ELT (args, 0), char_type_node)
551 && is_std_substitution_char (TREE_VEC_ELT (args, 1),
554 /* Got them. Is this basic_istream? */
555 tree name = DECL_NAME (CLASSTYPE_TI_TEMPLATE (type));
556 if (name == subst_identifiers[SUBID_BASIC_ISTREAM])
561 /* Or basic_ostream? */
562 else if (name == subst_identifiers[SUBID_BASIC_OSTREAM])
567 /* Or basic_iostream? */
568 else if (name == subst_identifiers[SUBID_BASIC_IOSTREAM])
576 /* Check for namespace std. */
577 if (decl && DECL_NAMESPACE_STD_P (decl))
583 /* Now check the list of available substitutions for this mangling
585 for (i = 0; i < size; ++i)
587 tree candidate = VARRAY_TREE (G.substitutions, i);
588 /* NODE is a matched to a candidate if it's the same decl node or
589 if it's the same type. */
590 if (decl == candidate
591 || (TYPE_P (candidate) && type && TYPE_P (type)
592 && same_type_p (type, candidate))
593 || NESTED_TEMPLATE_MATCH (node, candidate))
595 write_substitution (i);
600 /* No substitution found. */
605 /* TOP_LEVEL is true, if this is being called at outermost level of
606 mangling. It should be false when mangling a decl appearing in an
607 expression within some other mangling.
609 <mangled-name> ::= _Z <encoding> */
612 write_mangled_name (const tree decl, bool top_level)
614 MANGLE_TRACE_TREE ("mangled-name", decl);
616 if (/* The names of `extern "C"' functions are not mangled. */
617 DECL_EXTERN_C_FUNCTION_P (decl)
618 /* But overloaded operator names *are* mangled. */
619 && !DECL_OVERLOADED_OPERATOR_P (decl))
624 write_string (IDENTIFIER_POINTER (DECL_NAME (decl)));
627 /* The standard notes: "The <encoding> of an extern "C"
628 function is treated like global-scope data, i.e. as its
629 <source-name> without a type." We cannot write
630 overloaded operators that way though, because it contains
631 characters invalid in assembler. */
632 if (abi_version_at_least (2))
635 G.need_abi_warning = true;
636 write_source_name (DECL_NAME (decl));
639 else if (TREE_CODE (decl) == VAR_DECL
640 /* The names of global variables aren't mangled. */
641 && (CP_DECL_CONTEXT (decl) == global_namespace
642 /* And neither are `extern "C"' variables. */
643 || DECL_EXTERN_C_P (decl)))
645 if (top_level || abi_version_at_least (2))
649 G.need_abi_warning = true;
657 write_encoding (decl);
658 if (DECL_LANG_SPECIFIC (decl)
659 && (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)
660 || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)))
661 /* We need a distinct mangled name for these entities, but
662 we should never actually output it. So, we append some
663 characters the assembler won't like. */
664 write_string (" *INTERNAL* ");
668 /* <encoding> ::= <function name> <bare-function-type>
672 write_encoding (const tree decl)
674 MANGLE_TRACE_TREE ("encoding", decl);
676 if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl))
678 /* For overloaded operators write just the mangled name
679 without arguments. */
680 if (DECL_OVERLOADED_OPERATOR_P (decl))
681 write_name (decl, /*ignore_local_scope=*/0);
683 write_source_name (DECL_NAME (decl));
687 write_name (decl, /*ignore_local_scope=*/0);
688 if (TREE_CODE (decl) == FUNCTION_DECL)
692 if (decl_is_template_id (decl, NULL))
693 fn_type = get_mostly_instantiated_function_type (decl);
695 fn_type = TREE_TYPE (decl);
697 write_bare_function_type (fn_type,
698 (!DECL_CONSTRUCTOR_P (decl)
699 && !DECL_DESTRUCTOR_P (decl)
700 && !DECL_CONV_FN_P (decl)
701 && decl_is_template_id (decl, NULL)),
706 /* <name> ::= <unscoped-name>
707 ::= <unscoped-template-name> <template-args>
711 If IGNORE_LOCAL_SCOPE is nonzero, this production of <name> is
712 called from <local-name>, which mangles the enclosing scope
713 elsewhere and then uses this function to mangle just the part
714 underneath the function scope. So don't use the <local-name>
715 production, to avoid an infinite recursion. */
718 write_name (tree decl, const int ignore_local_scope)
722 MANGLE_TRACE_TREE ("name", decl);
724 if (TREE_CODE (decl) == TYPE_DECL)
726 /* In case this is a typedef, fish out the corresponding
727 TYPE_DECL for the main variant. */
728 decl = TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
729 context = TYPE_CONTEXT (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
732 context = (DECL_CONTEXT (decl) == NULL) ? NULL : CP_DECL_CONTEXT (decl);
734 /* A decl in :: or ::std scope is treated specially. The former is
735 mangled using <unscoped-name> or <unscoped-template-name>, the
736 latter with a special substitution. Also, a name that is
737 directly in a local function scope is also mangled with
738 <unscoped-name> rather than a full <nested-name>. */
740 || context == global_namespace
741 || DECL_NAMESPACE_STD_P (context)
742 || (ignore_local_scope && TREE_CODE (context) == FUNCTION_DECL))
745 /* Is this a template instance? */
746 if (decl_is_template_id (decl, &template_info))
748 /* Yes: use <unscoped-template-name>. */
749 write_unscoped_template_name (TI_TEMPLATE (template_info));
750 write_template_args (TI_ARGS (template_info));
753 /* Everything else gets an <unqualified-name>. */
754 write_unscoped_name (decl);
758 /* Handle local names, unless we asked not to (that is, invoked
759 under <local-name>, to handle only the part of the name under
761 if (!ignore_local_scope)
763 /* Scan up the list of scope context, looking for a
764 function. If we find one, this entity is in local
765 function scope. local_entity tracks context one scope
766 level down, so it will contain the element that's
767 directly in that function's scope, either decl or one of
768 its enclosing scopes. */
769 tree local_entity = decl;
770 while (context != NULL && context != global_namespace)
772 /* Make sure we're always dealing with decls. */
773 if (context != NULL && TYPE_P (context))
774 context = TYPE_NAME (context);
775 /* Is this a function? */
776 if (TREE_CODE (context) == FUNCTION_DECL)
778 /* Yes, we have local scope. Use the <local-name>
779 production for the innermost function scope. */
780 write_local_name (context, local_entity, decl);
783 /* Up one scope level. */
784 local_entity = context;
785 context = CP_DECL_CONTEXT (context);
788 /* No local scope found? Fall through to <nested-name>. */
791 /* Other decls get a <nested-name> to encode their scope. */
792 write_nested_name (decl);
796 /* <unscoped-name> ::= <unqualified-name>
797 ::= St <unqualified-name> # ::std:: */
800 write_unscoped_name (const tree decl)
802 tree context = CP_DECL_CONTEXT (decl);
804 MANGLE_TRACE_TREE ("unscoped-name", decl);
806 /* Is DECL in ::std? */
807 if (DECL_NAMESPACE_STD_P (context))
810 write_unqualified_name (decl);
812 /* If not, it should be either in the global namespace, or directly
813 in a local function scope. */
814 else if (context == global_namespace
816 || TREE_CODE (context) == FUNCTION_DECL)
817 write_unqualified_name (decl);
822 /* <unscoped-template-name> ::= <unscoped-name>
823 ::= <substitution> */
826 write_unscoped_template_name (const tree decl)
828 MANGLE_TRACE_TREE ("unscoped-template-name", decl);
830 if (find_substitution (decl))
832 write_unscoped_name (decl);
833 add_substitution (decl);
836 /* Write the nested name, including CV-qualifiers, of DECL.
838 <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
839 ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
841 <CV-qualifiers> ::= [r] [V] [K] */
844 write_nested_name (const tree decl)
848 MANGLE_TRACE_TREE ("nested-name", decl);
852 /* Write CV-qualifiers, if this is a member function. */
853 if (TREE_CODE (decl) == FUNCTION_DECL
854 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
856 if (DECL_VOLATILE_MEMFUNC_P (decl))
858 if (DECL_CONST_MEMFUNC_P (decl))
862 /* Is this a template instance? */
863 if (decl_is_template_id (decl, &template_info))
865 /* Yes, use <template-prefix>. */
866 write_template_prefix (decl);
867 write_template_args (TI_ARGS (template_info));
871 /* No, just use <prefix> */
872 write_prefix (DECL_CONTEXT (decl));
873 write_unqualified_name (decl);
878 /* <prefix> ::= <prefix> <unqualified-name>
880 ::= <template-prefix> <template-args>
882 ::= <substitution> */
885 write_prefix (const tree node)
888 /* Non-NULL if NODE represents a template-id. */
889 tree template_info = NULL;
891 MANGLE_TRACE_TREE ("prefix", node);
894 || node == global_namespace)
897 if (find_substitution (node))
902 /* If this is a function decl, that means we've hit function
903 scope, so this prefix must be for a local name. In this
904 case, we're under the <local-name> production, which encodes
905 the enclosing function scope elsewhere. So don't continue
907 if (TREE_CODE (node) == FUNCTION_DECL)
911 decl_is_template_id (decl, &template_info);
915 /* Node is a type. */
916 decl = TYPE_NAME (node);
917 if (CLASSTYPE_TEMPLATE_ID_P (node))
918 template_info = TYPE_TEMPLATE_INFO (node);
921 /* In G++ 3.2, the name of the template parameter was used. */
922 if (TREE_CODE (node) == TEMPLATE_TYPE_PARM
923 && !abi_version_at_least (2))
924 G.need_abi_warning = true;
926 if (TREE_CODE (node) == TEMPLATE_TYPE_PARM
927 && abi_version_at_least (2))
928 write_template_param (node);
929 else if (template_info != NULL)
932 write_template_prefix (decl);
933 write_template_args (TI_ARGS (template_info));
938 write_prefix (CP_DECL_CONTEXT (decl));
939 write_unqualified_name (decl);
942 add_substitution (node);
945 /* <template-prefix> ::= <prefix> <template component>
947 ::= <substitution> */
950 write_template_prefix (const tree node)
952 tree decl = DECL_P (node) ? node : TYPE_NAME (node);
953 tree type = DECL_P (node) ? TREE_TYPE (node) : node;
954 tree context = CP_DECL_CONTEXT (decl);
959 MANGLE_TRACE_TREE ("template-prefix", node);
961 /* Find the template decl. */
962 if (decl_is_template_id (decl, &template_info))
963 template = TI_TEMPLATE (template_info);
964 else if (CLASSTYPE_TEMPLATE_ID_P (type))
965 template = TYPE_TI_TEMPLATE (type);
967 /* Oops, not a template. */
970 /* For a member template, though, the template name for the
971 innermost name must have all the outer template levels
972 instantiated. For instance, consider
974 template<typename T> struct Outer {
975 template<typename U> struct Inner {};
978 The template name for `Inner' in `Outer<int>::Inner<float>' is
979 `Outer<int>::Inner<U>'. In g++, we don't instantiate the template
980 levels separately, so there's no TEMPLATE_DECL available for this
981 (there's only `Outer<T>::Inner<U>').
983 In order to get the substitutions right, we create a special
984 TREE_LIST to represent the substitution candidate for a nested
985 template. The TREE_PURPOSE is the template's context, fully
986 instantiated, and the TREE_VALUE is the TEMPLATE_DECL for the inner
989 So, for the example above, `Outer<int>::Inner' is represented as a
990 substitution candidate by a TREE_LIST whose purpose is `Outer<int>'
991 and whose value is `Outer<T>::Inner<U>'. */
992 if (TYPE_P (context))
993 substitution = build_tree_list (context, template);
995 substitution = template;
997 if (find_substitution (substitution))
1000 /* In G++ 3.2, the name of the template template parameter was used. */
1001 if (TREE_CODE (TREE_TYPE (template)) == TEMPLATE_TEMPLATE_PARM
1002 && !abi_version_at_least (2))
1003 G.need_abi_warning = true;
1005 if (TREE_CODE (TREE_TYPE (template)) == TEMPLATE_TEMPLATE_PARM
1006 && abi_version_at_least (2))
1007 write_template_param (TREE_TYPE (template));
1010 write_prefix (context);
1011 write_unqualified_name (decl);
1014 add_substitution (substitution);
1017 /* We don't need to handle thunks, vtables, or VTTs here. Those are
1018 mangled through special entry points.
1020 <unqualified-name> ::= <operator-name>
1022 ::= <source-name> */
1025 write_unqualified_name (const tree decl)
1027 MANGLE_TRACE_TREE ("unqualified-name", decl);
1029 if (DECL_LANG_SPECIFIC (decl) != NULL && DECL_CONSTRUCTOR_P (decl))
1030 write_special_name_constructor (decl);
1031 else if (DECL_LANG_SPECIFIC (decl) != NULL && DECL_DESTRUCTOR_P (decl))
1032 write_special_name_destructor (decl);
1033 else if (DECL_NAME (decl) == NULL_TREE)
1034 write_source_name (DECL_ASSEMBLER_NAME (decl));
1035 else if (DECL_CONV_FN_P (decl))
1037 /* Conversion operator. Handle it right here.
1038 <operator> ::= cv <type> */
1040 if (decl_is_template_id (decl, NULL))
1042 tree fn_type = get_mostly_instantiated_function_type (decl);
1043 type = TREE_TYPE (fn_type);
1046 type = DECL_CONV_FN_TYPE (decl);
1047 write_conversion_operator_name (type);
1049 else if (DECL_OVERLOADED_OPERATOR_P (decl))
1051 operator_name_info_t *oni;
1052 if (DECL_ASSIGNMENT_OPERATOR_P (decl))
1053 oni = assignment_operator_name_info;
1055 oni = operator_name_info;
1057 write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name);
1060 write_source_name (DECL_NAME (decl));
1063 /* Write the unqualified-name for a conversion operator to TYPE. */
1066 write_conversion_operator_name (const tree type)
1068 write_string ("cv");
1072 /* Non-terminal <source-name>. IDENTIFIER is an IDENTIFIER_NODE.
1074 <source-name> ::= </length/ number> <identifier> */
1077 write_source_name (tree identifier)
1079 MANGLE_TRACE_TREE ("source-name", identifier);
1081 /* Never write the whole template-id name including the template
1082 arguments; we only want the template name. */
1083 if (IDENTIFIER_TEMPLATE (identifier))
1084 identifier = IDENTIFIER_TEMPLATE (identifier);
1086 write_unsigned_number (IDENTIFIER_LENGTH (identifier));
1087 write_identifier (IDENTIFIER_POINTER (identifier));
1090 /* Convert NUMBER to ascii using base BASE and generating at least
1091 MIN_DIGITS characters. BUFFER points to the _end_ of the buffer
1092 into which to store the characters. Returns the number of
1093 characters generated (these will be layed out in advance of where
1097 hwint_to_ascii (unsigned HOST_WIDE_INT number, const unsigned int base,
1098 char *buffer, const unsigned int min_digits)
1100 static const char base_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1101 unsigned digits = 0;
1105 unsigned HOST_WIDE_INT d = number / base;
1107 *--buffer = base_digits[number - d * base];
1111 while (digits < min_digits)
1113 *--buffer = base_digits[0];
1119 /* Non-terminal <number>.
1121 <number> ::= [n] </decimal integer/> */
1124 write_number (unsigned HOST_WIDE_INT number, const int unsigned_p,
1125 const unsigned int base)
1127 char buffer[sizeof (HOST_WIDE_INT) * 8];
1130 if (!unsigned_p && (HOST_WIDE_INT) number < 0)
1133 number = -((HOST_WIDE_INT) number);
1135 count = hwint_to_ascii (number, base, buffer + sizeof (buffer), 1);
1136 write_chars (buffer + sizeof (buffer) - count, count);
1139 /* Write out an integral CST in decimal. Most numbers are small, and
1140 representable in a HOST_WIDE_INT. Occasionally we'll have numbers
1141 bigger than that, which we must deal with. */
1144 write_integer_cst (const tree cst)
1146 int sign = tree_int_cst_sgn (cst);
1148 if (TREE_INT_CST_HIGH (cst) + (sign < 0))
1150 /* A bignum. We do this in chunks, each of which fits in a
1152 char buffer[sizeof (HOST_WIDE_INT) * 8 * 2];
1153 unsigned HOST_WIDE_INT chunk;
1154 unsigned chunk_digits;
1155 char *ptr = buffer + sizeof (buffer);
1160 /* HOST_WIDE_INT must be at least 32 bits, so 10^9 is
1165 if (sizeof (HOST_WIDE_INT) >= 8)
1167 /* It is at least 64 bits, so 10^18 is representable. */
1172 type = c_common_signed_or_unsigned_type (1, TREE_TYPE (cst));
1173 base = build_int_2 (chunk, 0);
1174 n = build_int_2 (TREE_INT_CST_LOW (cst), TREE_INT_CST_HIGH (cst));
1175 TREE_TYPE (n) = TREE_TYPE (base) = type;
1180 n = fold (build1 (NEGATE_EXPR, type, n));
1184 tree d = fold (build (FLOOR_DIV_EXPR, type, n, base));
1185 tree tmp = fold (build (MULT_EXPR, type, d, base));
1188 done = integer_zerop (d);
1189 tmp = fold (build (MINUS_EXPR, type, n, tmp));
1190 c = hwint_to_ascii (TREE_INT_CST_LOW (tmp), 10, ptr,
1191 done ? 1 : chunk_digits);
1197 write_chars (ptr, count);
1202 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
1209 write_unsigned_number (low);
1213 /* Write out a floating-point literal.
1215 "Floating-point literals are encoded using the bit pattern of the
1216 target processor's internal representation of that number, as a
1217 fixed-length lowercase hexadecimal string, high-order bytes first
1218 (even if the target processor would store low-order bytes first).
1219 The "n" prefix is not used for floating-point literals; the sign
1220 bit is encoded with the rest of the number.
1222 Here are some examples, assuming the IEEE standard representation
1223 for floating point numbers. (Spaces are for readability, not
1224 part of the encoding.)
1227 -1.0f Lf bf80 0000 E
1228 1.17549435e-38f Lf 0080 0000 E
1229 1.40129846e-45f Lf 0000 0001 E
1230 0.0f Lf 0000 0000 E"
1232 Caller is responsible for the Lx and the E. */
1234 write_real_cst (const tree value)
1236 if (abi_version_at_least (2))
1238 long target_real[4]; /* largest supported float */
1239 char buffer[9]; /* eight hex digits in a 32-bit number */
1242 tree type = TREE_TYPE (value);
1243 int words = GET_MODE_BITSIZE (TYPE_MODE (type)) / 32;
1245 real_to_target (target_real, &TREE_REAL_CST (value),
1248 /* The value in target_real is in the target word order,
1249 so we must write it out backward if that happens to be
1250 little-endian. write_number cannot be used, it will
1251 produce uppercase. */
1252 if (FLOAT_WORDS_BIG_ENDIAN)
1253 i = 0, limit = words, dir = 1;
1255 i = words - 1, limit = -1, dir = -1;
1257 for (; i != limit; i += dir)
1259 sprintf (buffer, "%08lx", target_real[i]);
1260 write_chars (buffer, 8);
1265 /* In G++ 3.3 and before the REAL_VALUE_TYPE was written out
1266 literally. Note that compatibility with 3.2 is impossible,
1267 because the old floating-point emulator used a different
1268 format for REAL_VALUE_TYPE. */
1270 for (i = 0; i < sizeof (TREE_REAL_CST (value)); ++i)
1271 write_number (((unsigned char *) &TREE_REAL_CST (value))[i],
1274 G.need_abi_warning = 1;
1278 /* Non-terminal <identifier>.
1280 <identifier> ::= </unqualified source code identifier> */
1283 write_identifier (const char *identifier)
1285 MANGLE_TRACE ("identifier", identifier);
1286 write_string (identifier);
1289 /* Handle constructor productions of non-terminal <special-name>.
1290 CTOR is a constructor FUNCTION_DECL.
1292 <special-name> ::= C1 # complete object constructor
1293 ::= C2 # base object constructor
1294 ::= C3 # complete object allocating constructor
1296 Currently, allocating constructors are never used.
1298 We also need to provide mangled names for the maybe-in-charge
1299 constructor, so we treat it here too. mangle_decl_string will
1300 append *INTERNAL* to that, to make sure we never emit it. */
1303 write_special_name_constructor (const tree ctor)
1305 if (DECL_COMPLETE_CONSTRUCTOR_P (ctor)
1306 /* Even though we don't ever emit a definition of the
1307 old-style destructor, we still have to consider entities
1308 (like static variables) nested inside it. */
1309 || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor))
1310 write_string ("C1");
1311 else if (DECL_BASE_CONSTRUCTOR_P (ctor))
1312 write_string ("C2");
1317 /* Handle destructor productions of non-terminal <special-name>.
1318 DTOR is a destructor FUNCTION_DECL.
1320 <special-name> ::= D0 # deleting (in-charge) destructor
1321 ::= D1 # complete object (in-charge) destructor
1322 ::= D2 # base object (not-in-charge) destructor
1324 We also need to provide mangled names for the maybe-incharge
1325 destructor, so we treat it here too. mangle_decl_string will
1326 append *INTERNAL* to that, to make sure we never emit it. */
1329 write_special_name_destructor (const tree dtor)
1331 if (DECL_DELETING_DESTRUCTOR_P (dtor))
1332 write_string ("D0");
1333 else if (DECL_COMPLETE_DESTRUCTOR_P (dtor)
1334 /* Even though we don't ever emit a definition of the
1335 old-style destructor, we still have to consider entities
1336 (like static variables) nested inside it. */
1337 || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor))
1338 write_string ("D1");
1339 else if (DECL_BASE_DESTRUCTOR_P (dtor))
1340 write_string ("D2");
1345 /* Return the discriminator for ENTITY appearing inside
1346 FUNCTION. The discriminator is the lexical ordinal of VAR among
1347 entities with the same name in the same FUNCTION. */
1350 discriminator_for_local_entity (tree entity)
1354 /* Assume this is the only local entity with this name. */
1355 int discriminator = 0;
1357 if (DECL_DISCRIMINATOR_P (entity) && DECL_LANG_SPECIFIC (entity))
1358 discriminator = DECL_DISCRIMINATOR (entity);
1359 else if (TREE_CODE (entity) == TYPE_DECL)
1361 /* Scan the list of local classes. */
1362 entity = TREE_TYPE (entity);
1363 for (type = &VARRAY_TREE (local_classes, 0); *type != entity; ++type)
1364 if (TYPE_IDENTIFIER (*type) == TYPE_IDENTIFIER (entity)
1365 && TYPE_CONTEXT (*type) == TYPE_CONTEXT (entity))
1369 return discriminator;
1372 /* Return the discriminator for STRING, a string literal used inside
1373 FUNCTION. The discriminator is the lexical ordinal of STRING among
1374 string literals used in FUNCTION. */
1377 discriminator_for_string_literal (tree function ATTRIBUTE_UNUSED,
1378 tree string ATTRIBUTE_UNUSED)
1380 /* For now, we don't discriminate amongst string literals. */
1384 /* <discriminator> := _ <number>
1386 The discriminator is used only for the second and later occurrences
1387 of the same name within a single function. In this case <number> is
1388 n - 2, if this is the nth occurrence, in lexical order. */
1391 write_discriminator (const int discriminator)
1393 /* If discriminator is zero, don't write anything. Otherwise... */
1394 if (discriminator > 0)
1397 write_unsigned_number (discriminator - 1);
1401 /* Mangle the name of a function-scope entity. FUNCTION is the
1402 FUNCTION_DECL for the enclosing function. ENTITY is the decl for
1403 the entity itself. LOCAL_ENTITY is the entity that's directly
1404 scoped in FUNCTION_DECL, either ENTITY itself or an enclosing scope
1407 <local-name> := Z <function encoding> E <entity name> [<discriminator>]
1408 := Z <function encoding> E s [<discriminator>] */
1411 write_local_name (const tree function, const tree local_entity,
1414 MANGLE_TRACE_TREE ("local-name", entity);
1417 write_encoding (function);
1419 if (TREE_CODE (entity) == STRING_CST)
1422 write_discriminator (discriminator_for_string_literal (function,
1427 /* Now the <entity name>. Let write_name know its being called
1428 from <local-name>, so it doesn't try to process the enclosing
1429 function scope again. */
1430 write_name (entity, /*ignore_local_scope=*/1);
1431 write_discriminator (discriminator_for_local_entity (local_entity));
1435 /* Non-terminals <type> and <CV-qualifier>.
1437 <type> ::= <builtin-type>
1439 ::= <class-enum-type>
1441 ::= <pointer-to-member-type>
1442 ::= <template-param>
1445 ::= P <type> # pointer-to
1446 ::= R <type> # reference-to
1447 ::= C <type> # complex pair (C 2000)
1448 ::= G <type> # imaginary (C 2000) [not supported]
1449 ::= U <source-name> <type> # vendor extended type qualifier
1451 TYPE is a type node. */
1454 write_type (tree type)
1456 /* This gets set to nonzero if TYPE turns out to be a (possibly
1457 CV-qualified) builtin type. */
1458 int is_builtin_type = 0;
1460 MANGLE_TRACE_TREE ("type", type);
1462 if (type == error_mark_node)
1465 if (find_substitution (type))
1468 if (write_CV_qualifiers_for_type (type) > 0)
1469 /* If TYPE was CV-qualified, we just wrote the qualifiers; now
1470 mangle the unqualified type. The recursive call is needed here
1471 since both the qualified and unqualified types are substitution
1473 write_type (TYPE_MAIN_VARIANT (type));
1474 else if (TREE_CODE (type) == ARRAY_TYPE)
1475 /* It is important not to use the TYPE_MAIN_VARIANT of TYPE here
1476 so that the cv-qualification of the element type is available
1477 in write_array_type. */
1478 write_array_type (type);
1481 /* See through any typedefs. */
1482 type = TYPE_MAIN_VARIANT (type);
1484 if (TYPE_PTRMEM_P (type))
1485 write_pointer_to_member_type (type);
1486 else switch (TREE_CODE (type))
1490 case INTEGER_TYPE: /* Includes wchar_t. */
1492 /* If this is a typedef, TYPE may not be one of
1493 the standard builtin type nodes, but an alias of one. Use
1494 TYPE_MAIN_VARIANT to get to the underlying builtin type. */
1495 write_builtin_type (TYPE_MAIN_VARIANT (type));
1501 write_type (TREE_TYPE (type));
1506 write_function_type (type);
1512 /* A pointer-to-member function is represented as a special
1513 RECORD_TYPE, so check for this first. */
1514 if (TYPE_PTRMEMFUNC_P (type))
1515 write_pointer_to_member_type (type);
1517 write_class_enum_type (type);
1521 case UNBOUND_CLASS_TEMPLATE:
1522 /* We handle TYPENAME_TYPEs and UNBOUND_CLASS_TEMPLATEs like
1523 ordinary nested names. */
1524 write_nested_name (TYPE_STUB_DECL (type));
1529 write_type (TREE_TYPE (type));
1532 case REFERENCE_TYPE:
1534 write_type (TREE_TYPE (type));
1537 case TEMPLATE_TYPE_PARM:
1538 case TEMPLATE_PARM_INDEX:
1539 write_template_param (type);
1542 case TEMPLATE_TEMPLATE_PARM:
1543 write_template_template_param (type);
1546 case BOUND_TEMPLATE_TEMPLATE_PARM:
1547 write_template_template_param (type);
1549 (TI_ARGS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (type)));
1553 write_string ("U8__vector");
1554 write_type (TREE_TYPE (type));
1562 /* Types other than builtin types are substitution candidates. */
1563 if (!is_builtin_type)
1564 add_substitution (type);
1567 /* Non-terminal <CV-qualifiers> for type nodes. Returns the number of
1568 CV-qualifiers written for TYPE.
1570 <CV-qualifiers> ::= [r] [V] [K] */
1573 write_CV_qualifiers_for_type (const tree type)
1575 int num_qualifiers = 0;
1577 /* The order is specified by:
1579 "In cases where multiple order-insensitive qualifiers are
1580 present, they should be ordered 'K' (closest to the base type),
1581 'V', 'r', and 'U' (farthest from the base type) ..."
1583 Note that we do not use cp_type_quals below; given "const
1584 int[3]", the "const" is emitted with the "int", not with the
1587 if (TYPE_QUALS (type) & TYPE_QUAL_RESTRICT)
1592 if (TYPE_QUALS (type) & TYPE_QUAL_VOLATILE)
1597 if (TYPE_QUALS (type) & TYPE_QUAL_CONST)
1603 return num_qualifiers;
1606 /* Non-terminal <builtin-type>.
1608 <builtin-type> ::= v # void
1613 ::= h # unsigned char
1615 ::= t # unsigned short
1617 ::= j # unsigned int
1619 ::= m # unsigned long
1620 ::= x # long long, __int64
1621 ::= y # unsigned long long, __int64
1623 ::= o # unsigned __int128
1626 ::= e # long double, __float80
1627 ::= g # __float128 [not supported]
1628 ::= u <source-name> # vendor extended type */
1631 write_builtin_type (tree type)
1633 switch (TREE_CODE (type))
1644 /* If this is size_t, get the underlying int type. */
1645 if (TYPE_IS_SIZETYPE (type))
1646 type = TYPE_DOMAIN (type);
1648 /* TYPE may still be wchar_t, since that isn't in
1649 integer_type_nodes. */
1650 if (type == wchar_type_node)
1652 else if (TYPE_FOR_JAVA (type))
1653 write_java_integer_type_codes (type);
1657 /* Assume TYPE is one of the shared integer type nodes. Find
1658 it in the array of these nodes. */
1660 for (itk = 0; itk < itk_none; ++itk)
1661 if (type == integer_types[itk])
1663 /* Print the corresponding single-letter code. */
1664 write_char (integer_type_codes[itk]);
1668 if (itk == itk_none)
1670 tree t = c_common_type_for_mode (TYPE_MODE (type),
1671 TREE_UNSIGNED (type));
1674 if (TYPE_PRECISION (type) == 128)
1675 write_char (TREE_UNSIGNED (type) ? 'o' : 'n');
1677 /* Couldn't find this type. */
1690 if (type == float_type_node
1691 || type == java_float_type_node)
1693 else if (type == double_type_node
1694 || type == java_double_type_node)
1696 else if (type == long_double_type_node)
1707 /* Non-terminal <function-type>. NODE is a FUNCTION_TYPE or
1708 METHOD_TYPE. The return type is mangled before the parameter
1711 <function-type> ::= F [Y] <bare-function-type> E */
1714 write_function_type (const tree type)
1716 MANGLE_TRACE_TREE ("function-type", type);
1718 /* For a pointer to member function, the function type may have
1719 cv-qualifiers, indicating the quals for the artificial 'this'
1721 if (TREE_CODE (type) == METHOD_TYPE)
1723 /* The first parameter must be a POINTER_TYPE pointing to the
1724 `this' parameter. */
1725 tree this_type = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type)));
1726 write_CV_qualifiers_for_type (this_type);
1730 /* We don't track whether or not a type is `extern "C"'. Note that
1731 you can have an `extern "C"' function that does not have
1732 `extern "C"' type, and vice versa:
1734 extern "C" typedef void function_t();
1735 function_t f; // f has C++ linkage, but its type is
1738 typedef void function_t();
1739 extern "C" function_t f; // Vice versa.
1742 write_bare_function_type (type, /*include_return_type_p=*/1,
1747 /* Non-terminal <bare-function-type>. TYPE is a FUNCTION_TYPE or
1748 METHOD_TYPE. If INCLUDE_RETURN_TYPE is nonzero, the return value
1749 is mangled before the parameter types. If non-NULL, DECL is
1750 FUNCTION_DECL for the function whose type is being emitted.
1752 <bare-function-type> ::= </signature/ type>+ */
1755 write_bare_function_type (const tree type, const int include_return_type_p,
1758 MANGLE_TRACE_TREE ("bare-function-type", type);
1760 /* Mangle the return type, if requested. */
1761 if (include_return_type_p)
1762 write_type (TREE_TYPE (type));
1764 /* Now mangle the types of the arguments. */
1765 write_method_parms (TYPE_ARG_TYPES (type),
1766 TREE_CODE (type) == METHOD_TYPE,
1770 /* Write the mangled representation of a method parameter list of
1771 types given in PARM_TYPES. If METHOD_P is nonzero, the function is
1772 considered a non-static method, and the this parameter is omitted.
1773 If non-NULL, DECL is the FUNCTION_DECL for the function whose
1774 parameters are being emitted. */
1777 write_method_parms (tree parm_types, const int method_p, const tree decl)
1779 tree first_parm_type;
1780 tree parm_decl = decl ? DECL_ARGUMENTS (decl) : NULL_TREE;
1782 /* Assume this parameter type list is variable-length. If it ends
1783 with a void type, then it's not. */
1786 /* If this is a member function, skip the first arg, which is the
1788 "Member functions do not encode the type of their implicit this
1791 Similarly, there's no need to mangle artificial parameters, like
1792 the VTT parameters for constructors and destructors. */
1795 parm_types = TREE_CHAIN (parm_types);
1796 parm_decl = parm_decl ? TREE_CHAIN (parm_decl) : NULL_TREE;
1798 while (parm_decl && DECL_ARTIFICIAL (parm_decl))
1800 parm_types = TREE_CHAIN (parm_types);
1801 parm_decl = TREE_CHAIN (parm_decl);
1805 for (first_parm_type = parm_types;
1807 parm_types = TREE_CHAIN (parm_types))
1809 tree parm = TREE_VALUE (parm_types);
1810 if (parm == void_type_node)
1812 /* "Empty parameter lists, whether declared as () or
1813 conventionally as (void), are encoded with a void parameter
1815 if (parm_types == first_parm_type)
1817 /* If the parm list is terminated with a void type, it's
1820 /* A void type better be the last one. */
1821 my_friendly_assert (TREE_CHAIN (parm_types) == NULL, 20000523);
1828 /* <builtin-type> ::= z # ellipsis */
1832 /* <class-enum-type> ::= <name> */
1835 write_class_enum_type (const tree type)
1837 write_name (TYPE_NAME (type), /*ignore_local_scope=*/0);
1840 /* Non-terminal <template-args>. ARGS is a TREE_VEC of template
1843 <template-args> ::= I <template-arg>+ E */
1846 write_template_args (tree args)
1848 MANGLE_TRACE_TREE ("template-args", args);
1852 if (TREE_CODE (args) == TREE_VEC)
1855 int length = TREE_VEC_LENGTH (args);
1856 my_friendly_assert (length > 0, 20000422);
1858 if (TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1860 /* We have nested template args. We want the innermost template
1862 args = TREE_VEC_ELT (args, length - 1);
1863 length = TREE_VEC_LENGTH (args);
1865 for (i = 0; i < length; ++i)
1866 write_template_arg (TREE_VEC_ELT (args, i));
1870 my_friendly_assert (TREE_CODE (args) == TREE_LIST, 20021014);
1874 write_template_arg (TREE_VALUE (args));
1875 args = TREE_CHAIN (args);
1882 /* <expression> ::= <unary operator-name> <expression>
1883 ::= <binary operator-name> <expression> <expression>
1886 <expr-primary> ::= <template-param>
1887 ::= L <type> <value number> E # literal
1888 ::= L <mangled-name> E # external name
1889 ::= sr <type> <unqualified-name>
1890 ::= sr <type> <unqualified-name> <template-args> */
1893 write_expression (tree expr)
1895 enum tree_code code;
1897 code = TREE_CODE (expr);
1899 /* Handle pointers-to-members by making them look like expression
1901 if (code == PTRMEM_CST)
1903 expr = build_nt (ADDR_EXPR,
1904 build_nt (SCOPE_REF,
1905 PTRMEM_CST_CLASS (expr),
1906 PTRMEM_CST_MEMBER (expr)));
1907 code = TREE_CODE (expr);
1910 /* Skip NOP_EXPRs. They can occur when (say) a pointer argument
1911 is converted (via qualification conversions) to another
1913 while (TREE_CODE (expr) == NOP_EXPR
1914 || TREE_CODE (expr) == NON_LVALUE_EXPR)
1916 expr = TREE_OPERAND (expr, 0);
1917 code = TREE_CODE (expr);
1920 /* Handle template parameters. */
1921 if (code == TEMPLATE_TYPE_PARM
1922 || code == TEMPLATE_TEMPLATE_PARM
1923 || code == BOUND_TEMPLATE_TEMPLATE_PARM
1924 || code == TEMPLATE_PARM_INDEX)
1925 write_template_param (expr);
1926 /* Handle literals. */
1927 else if (TREE_CODE_CLASS (code) == 'c'
1928 || (abi_version_at_least (2) && code == CONST_DECL))
1929 write_template_arg_literal (expr);
1930 else if (DECL_P (expr))
1932 /* G++ 3.2 incorrectly mangled non-type template arguments of
1933 enumeration type using their names. */
1934 if (code == CONST_DECL)
1935 G.need_abi_warning = 1;
1937 write_mangled_name (expr, false);
1940 else if (TREE_CODE (expr) == SIZEOF_EXPR
1941 && TYPE_P (TREE_OPERAND (expr, 0)))
1943 write_string ("st");
1944 write_type (TREE_OPERAND (expr, 0));
1946 else if (abi_version_at_least (2) && TREE_CODE (expr) == SCOPE_REF)
1948 tree scope = TREE_OPERAND (expr, 0);
1949 tree member = TREE_OPERAND (expr, 1);
1951 /* If the MEMBER is a real declaration, then the qualifying
1952 scope was not dependent. Ideally, we would not have a
1953 SCOPE_REF in those cases, but sometimes we do. If the second
1954 argument is a DECL, then the name must not have been
1956 if (DECL_P (member))
1957 write_expression (member);
1962 write_string ("sr");
1964 /* If MEMBER is a template-id, separate the template
1965 from the arguments. */
1966 if (TREE_CODE (member) == TEMPLATE_ID_EXPR)
1968 template_args = TREE_OPERAND (member, 1);
1969 member = TREE_OPERAND (member, 0);
1972 template_args = NULL_TREE;
1973 /* Write out the name of the MEMBER. */
1974 if (IDENTIFIER_TYPENAME_P (member))
1975 write_conversion_operator_name (TREE_TYPE (member));
1976 else if (IDENTIFIER_OPNAME_P (member))
1979 const char *mangled_name = NULL;
1981 /* Unfortunately, there is no easy way to go from the
1982 name of the operator back to the corresponding tree
1984 for (i = 0; i < LAST_CPLUS_TREE_CODE; ++i)
1985 if (operator_name_info[i].identifier == member)
1987 /* The ABI says that we prefer binary operator
1988 names to unary operator names. */
1989 if (operator_name_info[i].arity == 2)
1991 mangled_name = operator_name_info[i].mangled_name;
1994 else if (!mangled_name)
1995 mangled_name = operator_name_info[i].mangled_name;
1997 else if (assignment_operator_name_info[i].identifier
2001 = assignment_operator_name_info[i].mangled_name;
2004 write_string (mangled_name);
2007 write_source_name (member);
2008 /* Write out the template arguments. */
2010 write_template_args (template_args);
2017 /* When we bind a variable or function to a non-type template
2018 argument with reference type, we create an ADDR_EXPR to show
2019 the fact that the entity's address has been taken. But, we
2020 don't actually want to output a mangling code for the `&'. */
2021 if (TREE_CODE (expr) == ADDR_EXPR
2023 && TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE)
2025 expr = TREE_OPERAND (expr, 0);
2028 write_expression (expr);
2032 code = TREE_CODE (expr);
2035 /* If it wasn't any of those, recursively expand the expression. */
2036 write_string (operator_name_info[(int) code].mangled_name);
2041 sorry ("call_expr cannot be mangled due to a defect in the C++ ABI");
2045 write_type (TREE_TYPE (expr));
2046 write_expression (TREE_VALUE (TREE_OPERAND (expr, 0)));
2049 case STATIC_CAST_EXPR:
2050 case CONST_CAST_EXPR:
2051 write_type (TREE_TYPE (expr));
2052 write_expression (TREE_OPERAND (expr, 0));
2056 /* Handle pointers-to-members specially. */
2058 write_type (TREE_OPERAND (expr, 0));
2059 if (TREE_CODE (TREE_OPERAND (expr, 1)) == IDENTIFIER_NODE)
2060 write_source_name (TREE_OPERAND (expr, 1));
2061 else if (TREE_CODE (TREE_OPERAND (expr, 1)) == TEMPLATE_ID_EXPR)
2066 template_id = TREE_OPERAND (expr, 1);
2067 name = TREE_OPERAND (template_id, 0);
2068 /* FIXME: What about operators? */
2069 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE,
2071 write_source_name (TREE_OPERAND (template_id, 0));
2072 write_template_args (TREE_OPERAND (template_id, 1));
2076 /* G++ 3.2 incorrectly put out both the "sr" code and
2077 the nested name of the qualified name. */
2078 G.need_abi_warning = 1;
2079 write_encoding (TREE_OPERAND (expr, 1));
2084 for (i = 0; i < TREE_CODE_LENGTH (code); ++i)
2086 tree operand = TREE_OPERAND (expr, i);
2087 /* As a GNU expression, the middle operand of a
2088 conditional may be omitted. Since expression
2089 manglings are supposed to represent the input token
2090 stream, there's no good way to mangle such an
2091 expression without extending the C++ ABI. */
2092 if (code == COND_EXPR && i == 1 && !operand)
2094 error ("omitted middle operand to `?:' operand "
2095 "cannot be mangled");
2098 write_expression (operand);
2104 /* Literal subcase of non-terminal <template-arg>.
2106 "Literal arguments, e.g. "A<42L>", are encoded with their type
2107 and value. Negative integer values are preceded with "n"; for
2108 example, "A<-42L>" becomes "1AILln42EE". The bool value false is
2109 encoded as 0, true as 1." */
2112 write_template_arg_literal (const tree value)
2114 tree type = TREE_TYPE (value);
2118 if (TREE_CODE (value) == CONST_DECL)
2119 write_integer_cst (DECL_INITIAL (value));
2120 else if (TREE_CODE (value) == INTEGER_CST)
2122 if (same_type_p (type, boolean_type_node))
2124 if (value == boolean_false_node || integer_zerop (value))
2125 write_unsigned_number (0);
2126 else if (value == boolean_true_node)
2127 write_unsigned_number (1);
2132 write_integer_cst (value);
2134 else if (TREE_CODE (value) == REAL_CST)
2135 write_real_cst (value);
2142 /* Non-terminal <tempalate-arg>.
2144 <template-arg> ::= <type> # type
2145 ::= L <type> </value/ number> E # literal
2146 ::= LZ <name> E # external name
2147 ::= X <expression> E # expression */
2150 write_template_arg (tree node)
2152 enum tree_code code = TREE_CODE (node);
2154 MANGLE_TRACE_TREE ("template-arg", node);
2156 /* A template template parameter's argument list contains TREE_LIST
2157 nodes of which the value field is the the actual argument. */
2158 if (code == TREE_LIST)
2160 node = TREE_VALUE (node);
2161 /* If it's a decl, deal with its type instead. */
2164 node = TREE_TYPE (node);
2165 code = TREE_CODE (node);
2171 else if (code == TEMPLATE_DECL)
2172 /* A template appearing as a template arg is a template template arg. */
2173 write_template_template_arg (node);
2174 else if ((TREE_CODE_CLASS (code) == 'c' && code != PTRMEM_CST)
2175 || (abi_version_at_least (2) && code == CONST_DECL))
2176 write_template_arg_literal (node);
2177 else if (DECL_P (node))
2179 /* G++ 3.2 incorrectly mangled non-type template arguments of
2180 enumeration type using their names. */
2181 if (code == CONST_DECL)
2182 G.need_abi_warning = 1;
2185 write_encoding (node);
2190 /* Template arguments may be expressions. */
2192 write_expression (node);
2197 /* <template-template-arg>
2199 ::= <substitution> */
2202 write_template_template_arg (const tree decl)
2204 MANGLE_TRACE_TREE ("template-template-arg", decl);
2206 if (find_substitution (decl))
2208 write_name (decl, /*ignore_local_scope=*/0);
2209 add_substitution (decl);
2213 /* Non-terminal <array-type>. TYPE is an ARRAY_TYPE.
2215 <array-type> ::= A [</dimension/ number>] _ </element/ type>
2216 ::= A <expression> _ </element/ type>
2218 "Array types encode the dimension (number of elements) and the
2219 element type. For variable length arrays, the dimension (but not
2220 the '_' separator) is omitted." */
2223 write_array_type (const tree type)
2226 if (TYPE_DOMAIN (type))
2231 index_type = TYPE_DOMAIN (type);
2232 /* The INDEX_TYPE gives the upper and lower bounds of the
2234 max = TYPE_MAX_VALUE (index_type);
2235 if (TREE_CODE (max) == INTEGER_CST)
2237 /* The ABI specifies that we should mangle the number of
2238 elements in the array, not the largest allowed index. */
2239 max = size_binop (PLUS_EXPR, max, size_one_node);
2240 write_unsigned_number (tree_low_cst (max, 1));
2243 write_expression (TREE_OPERAND (max, 0));
2246 write_type (TREE_TYPE (type));
2249 /* Non-terminal <pointer-to-member-type> for pointer-to-member
2250 variables. TYPE is a pointer-to-member POINTER_TYPE.
2252 <pointer-to-member-type> ::= M </class/ type> </member/ type> */
2255 write_pointer_to_member_type (const tree type)
2258 write_type (TYPE_PTRMEM_CLASS_TYPE (type));
2259 write_type (TYPE_PTRMEM_POINTED_TO_TYPE (type));
2262 /* Non-terminal <template-param>. PARM is a TEMPLATE_TYPE_PARM,
2263 TEMPLATE_TEMPLATE_PARM, BOUND_TEMPLATE_TEMPLATE_PARM or a
2264 TEMPLATE_PARM_INDEX.
2266 <template-param> ::= T </parameter/ number> _ */
2269 write_template_param (const tree parm)
2273 tree parm_type = NULL_TREE;
2275 MANGLE_TRACE_TREE ("template-parm", parm);
2277 switch (TREE_CODE (parm))
2279 case TEMPLATE_TYPE_PARM:
2280 case TEMPLATE_TEMPLATE_PARM:
2281 case BOUND_TEMPLATE_TEMPLATE_PARM:
2282 parm_index = TEMPLATE_TYPE_IDX (parm);
2283 parm_level = TEMPLATE_TYPE_LEVEL (parm);
2286 case TEMPLATE_PARM_INDEX:
2287 parm_index = TEMPLATE_PARM_IDX (parm);
2288 parm_level = TEMPLATE_PARM_LEVEL (parm);
2289 parm_type = TREE_TYPE (TEMPLATE_PARM_DECL (parm));
2297 /* NUMBER as it appears in the mangling is (-1)-indexed, with the
2298 earliest template param denoted by `_'. */
2300 write_unsigned_number (parm_index - 1);
2304 /* <template-template-param>
2305 ::= <template-param>
2306 ::= <substitution> */
2309 write_template_template_param (const tree parm)
2311 tree template = NULL_TREE;
2313 /* PARM, a TEMPLATE_TEMPLATE_PARM, is an instantiation of the
2314 template template parameter. The substitution candidate here is
2315 only the template. */
2316 if (TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM)
2319 = TI_TEMPLATE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parm));
2320 if (find_substitution (template))
2324 /* <template-param> encodes only the template parameter position,
2325 not its template arguments, which is fine here. */
2326 write_template_param (parm);
2328 add_substitution (template);
2331 /* Non-terminal <substitution>.
2333 <substitution> ::= S <seq-id> _
2337 write_substitution (const int seq_id)
2339 MANGLE_TRACE ("substitution", "");
2343 write_number (seq_id - 1, /*unsigned=*/1, 36);
2347 /* Start mangling ENTITY. */
2350 start_mangling (const tree entity)
2353 G.need_abi_warning = false;
2354 VARRAY_TREE_INIT (G.substitutions, 1, "mangling substitutions");
2355 obstack_free (&G.name_obstack, obstack_base (&G.name_obstack));
2358 /* Done with mangling. Return the generated mangled name. If WARN is
2359 true, and the name of G.entity will be mangled differently in a
2360 future version of the ABI, issue a warning. */
2362 static inline const char *
2363 finish_mangling (const bool warn)
2365 if (warn_abi && warn && G.need_abi_warning)
2366 warning ("the mangled name of `%D' will change in a future "
2370 /* Clear all the substitutions. */
2371 G.substitutions = 0;
2373 /* Null-terminate the string. */
2376 return (const char *) obstack_base (&G.name_obstack);
2379 /* Initialize data structures for mangling. */
2384 gcc_obstack_init (&G.name_obstack);
2386 /* Cache these identifiers for quick comparison when checking for
2387 standard substitutions. */
2388 subst_identifiers[SUBID_ALLOCATOR] = get_identifier ("allocator");
2389 subst_identifiers[SUBID_BASIC_STRING] = get_identifier ("basic_string");
2390 subst_identifiers[SUBID_CHAR_TRAITS] = get_identifier ("char_traits");
2391 subst_identifiers[SUBID_BASIC_ISTREAM] = get_identifier ("basic_istream");
2392 subst_identifiers[SUBID_BASIC_OSTREAM] = get_identifier ("basic_ostream");
2393 subst_identifiers[SUBID_BASIC_IOSTREAM] = get_identifier ("basic_iostream");
2396 /* Generate the mangled name of DECL. */
2399 mangle_decl_string (const tree decl)
2403 start_mangling (decl);
2405 if (TREE_CODE (decl) == TYPE_DECL)
2406 write_type (TREE_TYPE (decl));
2408 write_mangled_name (decl, true);
2410 result = finish_mangling (/*warn=*/true);
2412 fprintf (stderr, "mangle_decl_string = '%s'\n\n", result);
2416 /* Create an identifier for the external mangled name of DECL. */
2419 mangle_decl (const tree decl)
2421 tree id = get_identifier (mangle_decl_string (decl));
2423 SET_DECL_ASSEMBLER_NAME (decl, id);
2426 /* Generate the mangled representation of TYPE. */
2429 mangle_type_string (const tree type)
2433 start_mangling (type);
2435 result = finish_mangling (/*warn=*/false);
2437 fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
2441 /* Create an identifier for the mangled representation of TYPE. */
2444 mangle_type (const tree type)
2446 return get_identifier (mangle_type_string (type));
2449 /* Create an identifier for the mangled name of a special component
2450 for belonging to TYPE. CODE is the ABI-specified code for this
2454 mangle_special_for_type (const tree type, const char *code)
2458 /* We don't have an actual decl here for the special component, so
2459 we can't just process the <encoded-name>. Instead, fake it. */
2460 start_mangling (type);
2462 /* Start the mangling. */
2463 write_string ("_Z");
2464 write_string (code);
2468 result = finish_mangling (/*warn=*/false);
2471 fprintf (stderr, "mangle_special_for_type = %s\n\n", result);
2473 return get_identifier (result);
2476 /* Create an identifier for the mangled representation of the typeinfo
2477 structure for TYPE. */
2480 mangle_typeinfo_for_type (const tree type)
2482 return mangle_special_for_type (type, "TI");
2485 /* Create an identifier for the mangled name of the NTBS containing
2486 the mangled name of TYPE. */
2489 mangle_typeinfo_string_for_type (const tree type)
2491 return mangle_special_for_type (type, "TS");
2494 /* Create an identifier for the mangled name of the vtable for TYPE. */
2497 mangle_vtbl_for_type (const tree type)
2499 return mangle_special_for_type (type, "TV");
2502 /* Returns an identifier for the mangled name of the VTT for TYPE. */
2505 mangle_vtt_for_type (const tree type)
2507 return mangle_special_for_type (type, "TT");
2510 /* Return an identifier for a construction vtable group. TYPE is
2511 the most derived class in the hierarchy; BINFO is the base
2512 subobject for which this construction vtable group will be used.
2514 This mangling isn't part of the ABI specification; in the ABI
2515 specification, the vtable group is dumped in the same COMDAT as the
2516 main vtable, and is referenced only from that vtable, so it doesn't
2517 need an external name. For binary formats without COMDAT sections,
2518 though, we need external names for the vtable groups.
2520 We use the production
2522 <special-name> ::= CT <type> <offset number> _ <base type> */
2525 mangle_ctor_vtbl_for_type (const tree type, const tree binfo)
2529 start_mangling (type);
2531 write_string ("_Z");
2532 write_string ("TC");
2534 write_integer_cst (BINFO_OFFSET (binfo));
2536 write_type (BINFO_TYPE (binfo));
2538 result = finish_mangling (/*warn=*/false);
2540 fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n", result);
2541 return get_identifier (result);
2544 /* Mangle a this pointer or result pointer adjustment.
2546 <call-offset> ::= h <fixed offset number> _
2547 ::= v <fixed offset number> _ <virtual offset number> _ */
2550 mangle_call_offset (const tree fixed_offset, const tree virtual_offset)
2552 write_char (virtual_offset ? 'v' : 'h');
2554 /* For either flavor, write the fixed offset. */
2555 write_integer_cst (fixed_offset);
2558 /* For a virtual thunk, add the virtual offset. */
2561 write_integer_cst (virtual_offset);
2566 /* Return an identifier for the mangled name of a this-adjusting or
2567 covariant thunk to FN_DECL. FIXED_OFFSET is the initial adjustment
2568 to this used to find the vptr. If VIRTUAL_OFFSET is non-NULL, this
2569 is a virtual thunk, and it is the vtbl offset in
2570 bytes. THIS_ADJUSTING is nonzero for a this adjusting thunk and
2571 zero for a covariant thunk. Note, that FN_DECL might be a covariant
2572 thunk itself. A covariant thunk name always includes the adjustment
2573 for the this pointer, even if there is none.
2575 <special-name> ::= T <call-offset> <base encoding>
2576 ::= Tc <this_adjust call-offset> <result_adjust call-offset>
2581 mangle_thunk (tree fn_decl, const int this_adjusting, tree fixed_offset,
2582 tree virtual_offset)
2586 start_mangling (fn_decl);
2588 write_string ("_Z");
2591 if (!this_adjusting)
2593 /* Covariant thunk with no this adjustment */
2595 mangle_call_offset (integer_zero_node, NULL_TREE);
2596 mangle_call_offset (fixed_offset, virtual_offset);
2598 else if (!DECL_THUNK_P (fn_decl))
2599 /* Plain this adjusting thunk. */
2600 mangle_call_offset (fixed_offset, virtual_offset);
2603 /* This adjusting thunk to covariant thunk. */
2605 mangle_call_offset (fixed_offset, virtual_offset);
2606 fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn_decl));
2607 virtual_offset = THUNK_VIRTUAL_OFFSET (fn_decl);
2609 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
2610 mangle_call_offset (fixed_offset, virtual_offset);
2611 fn_decl = THUNK_TARGET (fn_decl);
2615 write_encoding (fn_decl);
2617 result = finish_mangling (/*warn=*/false);
2619 fprintf (stderr, "mangle_thunk = %s\n\n", result);
2620 return get_identifier (result);
2623 /* This hash table maps TYPEs to the IDENTIFIER for a conversion
2624 operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the
2627 static GTY ((param_is (union tree_node))) htab_t conv_type_names;
2629 /* Hash a node (VAL1) in the table. */
2632 hash_type (const void *val)
2634 return (hashval_t) TYPE_UID (TREE_TYPE ((tree) val));
2637 /* Compare VAL1 (a node in the table) with VAL2 (a TYPE). */
2640 compare_type (const void *val1, const void *val2)
2642 return TREE_TYPE ((tree) val1) == (tree) val2;
2645 /* Return an identifier for the mangled unqualified name for a
2646 conversion operator to TYPE. This mangling is not specified by the
2647 ABI spec; it is only used internally. */
2650 mangle_conv_op_name_for_type (const tree type)
2655 if (conv_type_names == NULL)
2656 conv_type_names = htab_create_ggc (31, &hash_type, &compare_type, NULL);
2658 slot = htab_find_slot_with_hash (conv_type_names, type,
2659 (hashval_t) TYPE_UID (type), INSERT);
2660 identifier = (tree)*slot;
2665 /* Create a unique name corresponding to TYPE. */
2666 sprintf (buffer, "operator %lu",
2667 (unsigned long) htab_elements (conv_type_names));
2668 identifier = get_identifier (buffer);
2671 /* Hang TYPE off the identifier so it can be found easily later
2672 when performing conversions. */
2673 TREE_TYPE (identifier) = type;
2675 /* Set bits on the identifier so we know later it's a conversion. */
2676 IDENTIFIER_OPNAME_P (identifier) = 1;
2677 IDENTIFIER_TYPENAME_P (identifier) = 1;
2683 /* Return an identifier for the name of an initialization guard
2684 variable for indicated VARIABLE. */
2687 mangle_guard_variable (const tree variable)
2689 start_mangling (variable);
2690 write_string ("_ZGV");
2691 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR", 4) == 0)
2692 /* The name of a guard variable for a reference temporary should refer
2693 to the reference, not the temporary. */
2694 write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
2696 write_name (variable, /*ignore_local_scope=*/0);
2697 return get_identifier (finish_mangling (/*warn=*/false));
2700 /* Return an identifier for the name of a temporary variable used to
2701 initialize a static reference. This isn't part of the ABI, but we might
2702 as well call them something readable. */
2705 mangle_ref_init_variable (const tree variable)
2707 start_mangling (variable);
2708 write_string ("_ZGR");
2709 write_name (variable, /*ignore_local_scope=*/0);
2710 return get_identifier (finish_mangling (/*warn=*/false));
2714 /* Foreign language type mangling section. */
2716 /* How to write the type codes for the integer Java type. */
2719 write_java_integer_type_codes (const tree type)
2721 if (type == java_int_type_node)
2723 else if (type == java_short_type_node)
2725 else if (type == java_byte_type_node)
2727 else if (type == java_char_type_node)
2729 else if (type == java_long_type_node)
2731 else if (type == java_boolean_type_node)
2737 #include "gt-cp-mangle.h"