1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 /* Handle method declarations. */
34 #include "hard-reg-set.h"
40 /* Various flags to control the mangling process. */
46 /* The thing we are presently mangling is part of a template type,
47 rather than a fully instantiated type. Therefore, we may see
48 complex expressions where we would normally expect to see a
49 simple integer constant. */
50 mf_maybe_uninstantiated = 1,
51 /* When mangling a numeric value, use the form `_XX_' (instead of
52 just `XX') if the value has more than one digit. */
53 mf_use_underscores_around_value = 2,
56 typedef enum mangling_flags mangling_flags;
58 /* TREE_LIST of the current inline functions that need to be
60 struct pending_inline *pending_inlines;
62 #define obstack_chunk_alloc xmalloc
63 #define obstack_chunk_free free
65 /* Obstack where we build text strings for overloading, etc. */
66 static struct obstack scratch_obstack;
67 static char *scratch_firstobj;
69 static void icat PARAMS ((HOST_WIDE_INT));
70 static void dicat PARAMS ((HOST_WIDE_INT, HOST_WIDE_INT));
71 static int old_backref_index PARAMS ((tree));
72 static int flush_repeats PARAMS ((int, tree));
73 static void build_overload_identifier PARAMS ((tree));
74 static void build_overload_nested_name PARAMS ((tree));
75 static void mangle_expression PARAMS ((tree));
76 static void build_overload_int PARAMS ((tree, mangling_flags));
77 static void build_overload_identifier PARAMS ((tree));
78 static void build_qualified_name PARAMS ((tree));
79 static void build_overload_value PARAMS ((tree, tree, mangling_flags));
80 static void issue_nrepeats PARAMS ((int, tree));
81 static char *build_mangled_name PARAMS ((tree,int,int));
82 static void process_modifiers PARAMS ((tree));
83 static void process_overload_item PARAMS ((tree,int));
84 static void do_build_assign_ref PARAMS ((tree));
85 static void do_build_copy_constructor PARAMS ((tree));
86 static void build_template_template_parm_names PARAMS ((tree));
87 static void build_template_parm_names PARAMS ((tree, tree));
88 static void build_underscore_int PARAMS ((int));
89 static void start_squangling PARAMS ((void));
90 static void end_squangling PARAMS ((void));
91 static int check_ktype PARAMS ((tree, int));
92 static int issue_ktype PARAMS ((tree));
93 static void build_overload_scope_ref PARAMS ((tree));
94 static void build_mangled_template_parm_index PARAMS ((const char *, tree));
95 #if HOST_BITS_PER_WIDE_INT >= 64
96 static void build_mangled_C9x_name PARAMS ((int));
98 static int is_back_referenceable_type PARAMS ((tree));
99 static int check_btype PARAMS ((tree));
100 static void build_mangled_name_for_type PARAMS ((tree));
101 static void build_mangled_name_for_type_with_Gcode PARAMS ((tree, int));
103 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
104 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
105 # define OB_PUTC2(C1,C2) \
106 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
107 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
108 # define OB_PUTID(ID) \
109 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
110 IDENTIFIER_LENGTH (ID)))
111 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
112 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
113 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
115 /* type tables for K and B type compression */
116 static varray_type btypelist;
117 static varray_type ktypelist;
119 /* number of each type seen */
120 static size_t maxbtype;
121 static size_t maxktype;
123 /* Array of types seen so far in top-level call to `build_mangled_name'.
124 Allocated and deallocated by caller. */
125 static varray_type typevec;
127 /* Number of types interned by `build_mangled_name' so far. */
128 static size_t maxtype;
130 /* Called once to initialize method.c. */
135 gcc_obstack_init (&scratch_obstack);
136 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
137 ggc_add_tree_varray_root (&btypelist, 1);
138 ggc_add_tree_varray_root (&ktypelist, 1);
139 ggc_add_tree_varray_root (&typevec, 1);
142 /* This must be large enough to hold any printed integer or floating-point
144 static char digit_buffer[128];
147 /* Here is where overload code starts. */
149 /* Nonzero if we should not try folding parameter types. */
152 /* Nonzero if an underscore is required before adding a digit to the
153 mangled name currently being built. */
154 static int numeric_output_need_bar;
159 if (flag_do_squangling)
164 VARRAY_TREE_INIT (btypelist, 50, "btypelist");
165 VARRAY_TREE_INIT (ktypelist, 50, "ktypelist");
172 if (flag_do_squangling)
174 VARRAY_FREE (ktypelist);
175 VARRAY_FREE (btypelist);
181 /* Code to concatenate an asciified integer to a string. */
187 unsigned HOST_WIDE_INT ui;
189 /* Handle this case first, to go really quickly. For many common values,
190 the result of ui/10 below is 1. */
208 OB_PUTC ('0' + (ui % 10));
213 HOST_WIDE_INT lo, hi;
215 unsigned HOST_WIDE_INT ulo, uhi, qlo, qhi;
224 uhi = (lo == 0 ? -hi : -hi-1);
228 && ulo < ((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)))
233 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
236 qlo = uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) / 5);
239 ulo += uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) % 5)
243 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
248 /* Returns the index of TYPE in the typevec, or -1 if it's not there. */
251 old_backref_index (type)
256 if (! is_back_referenceable_type (type))
259 /* The entry for this parm is at maxtype-1, so don't look there for
260 something to repeat. */
261 for (tindex = 0; tindex < maxtype - 1; ++tindex)
262 if (same_type_p (VARRAY_TREE (typevec, tindex), type))
265 if (tindex == maxtype - 1)
271 /* Old mangling style: If TYPE has already been used in the parameter list,
272 emit a backward reference and return non-zero; otherwise, return 0.
274 NREPEATS is the number of repeats we've recorded of this type, or 0 if
275 this is the first time we've seen it and we're just looking to see if
276 it had been used before. */
279 flush_repeats (nrepeats, type)
283 int tindex = old_backref_index (type);
287 my_friendly_assert (nrepeats == 0, 990316);
307 /* Returns nonzero iff this is a type to which we will want to make
308 back-references (using the `B' code). */
311 is_back_referenceable_type (type)
314 /* For some reason, the Java folks don't want back refs on these. */
315 if (TYPE_FOR_JAVA (type))
318 switch (TREE_CODE (type))
321 if (!flag_do_squangling)
322 /* Even though the mangling of this is just `b', we did
323 historically generate back-references for it. */
330 /* These types have single-character manglings, so there's no
331 point in generating back-references. */
334 case TEMPLATE_TYPE_PARM:
335 /* It would be a bit complex to demangle signatures correctly if
336 we generated back-references to these, and the manglings of
337 type parameters are short. */
345 /* Issue the squangling code indicating NREPEATS repetitions of TYPE,
346 which was the last parameter type output. */
349 issue_nrepeats (nrepeats, type)
353 if (nrepeats == 1 && !is_back_referenceable_type (type))
354 /* For types whose manglings are short, don't bother using the
355 repetition code if there's only one repetition, since the
356 repetition code will be about as long as the ordinary mangling. */
357 build_mangled_name_for_type (type);
367 /* Check to see if a tree node has been entered into the Kcode typelist.
368 If not, add it. Returns -1 if it isn't found, otherwise returns the
372 check_ktype (node, add)
377 tree localnode = node;
379 if (ktypelist == NULL)
382 if (TREE_CODE (node) == TYPE_DECL)
383 localnode = TREE_TYPE (node);
385 for (x = 0; x < maxktype; x++)
387 if (same_type_p (localnode, VARRAY_TREE (ktypelist, x)))
390 /* Didn't find it, so add it here. */
393 if (VARRAY_SIZE (ktypelist) <= maxktype)
394 VARRAY_GROW (ktypelist,
395 VARRAY_SIZE (ktypelist) * 3 / 2);
396 VARRAY_TREE (ktypelist, maxktype) = localnode;
408 kindex = check_ktype (decl, FALSE);
420 /* Build a representation for DECL, which may be an entity not at
421 global scope. If so, a marker indicating that the name is
422 qualified has already been output, but the qualifying context has
426 build_overload_nested_name (decl)
431 if (ktypelist && issue_ktype (decl))
434 if (decl == global_namespace)
437 context = CP_DECL_CONTEXT (decl);
439 /* try to issue a K type, and if we can't continue the normal path */
440 if (!(ktypelist && issue_ktype (context)))
442 /* For a template type parameter, we want to output an 'Xn'
443 rather than 'T' or some such. */
444 if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
445 || TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
446 build_mangled_name_for_type (context);
449 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
450 context = TYPE_NAME (context);
451 build_overload_nested_name (context);
455 if (TREE_CODE (decl) == FUNCTION_DECL)
457 static int static_labelno;
459 tree name = DECL_ASSEMBLER_NAME (decl);
462 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), static_labelno);
465 if (numeric_output_need_bar)
467 icat (strlen (label));
469 numeric_output_need_bar = 1;
471 else if (TREE_CODE (decl) == NAMESPACE_DECL)
472 build_overload_identifier (DECL_NAME (decl));
474 build_overload_identifier (decl);
477 /* Output the decimal representation of I. If I > 9, the decimal
478 representation is preceeded and followed by an underscore. */
481 build_underscore_int (i)
492 build_overload_scope_ref (value)
496 numeric_output_need_bar = 0;
497 build_mangled_name_for_type (TREE_OPERAND (value, 0));
498 build_overload_identifier (TREE_OPERAND (value, 1));
501 /* VALUE is a complex expression. Produce an appropriate mangling.
502 (We are forced to mangle complex expressions when dealing with
503 templates, and an expression involving template parameters appears
504 in the type of a function parameter.) */
507 mangle_expression (value)
510 if (TREE_CODE (value) == SCOPE_REF)
512 build_overload_scope_ref (value);
517 numeric_output_need_bar = 0;
519 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value))))
522 int operands = tree_code_length[(int) TREE_CODE (value)];
526 id = ansi_opname [(int) TREE_CODE (value)];
527 my_friendly_assert (id != NULL_TREE, 0);
528 name = IDENTIFIER_POINTER (id);
529 if (name[0] != '_' || name[1] != '_')
530 /* On some erroneous inputs, we can get here with VALUE a
531 LOOKUP_EXPR. In that case, the NAME will be the
532 identifier for "<invalid operator>". We must survive
533 this routine in order to issue a sensible error
534 message, so we fall through to the case below. */
537 for (i = 0; i < operands; ++i)
542 /* We just outputted either the `E' or the name of the
544 numeric_output_need_bar = 0;
547 /* Skip the leading underscores. */
550 operand = TREE_OPERAND (value, i);
551 tc = TREE_CODE (operand);
553 if (TREE_CODE_CLASS (tc) == 't')
554 /* We can get here with sizeof, e.g.:
556 template <class T> void f(A<sizeof(T)>); */
557 build_mangled_name_for_type (operand);
559 build_overload_value (TREE_TYPE (operand),
561 mf_maybe_uninstantiated);
566 /* We don't ever want this output, but it's
567 inconvenient not to be able to build the string.
568 This should cause assembler errors we'll notice. */
572 sprintf (digit_buffer, " *%d", n++);
573 OB_PUTCP (digit_buffer);
577 numeric_output_need_bar = 0;
580 /* Encoding for an INTEGER_CST value. */
583 build_overload_int (value, flags)
585 mangling_flags flags;
587 int multiple_words_p = 0;
588 int multiple_digits_p = 0;
590 if ((flags & mf_maybe_uninstantiated) && TREE_CODE (value) != INTEGER_CST)
592 mangle_expression (value);
596 /* Unless we were looking at an uninstantiated template, integers
597 should always be represented by constants. */
598 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
600 /* If the high-order word is not merely a sign-extension of the
601 low-order word, we must use a special output routine that can
603 if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (value)
604 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
606 multiple_words_p = 1;
607 /* And there is certainly going to be more than one digit. */
608 multiple_digits_p = 1;
611 multiple_digits_p = ((HOST_WIDE_INT) TREE_INT_CST_LOW (value) > 9
612 || (HOST_WIDE_INT) TREE_INT_CST_LOW (value) < -9);
614 /* If necessary, add a leading underscore. */
615 if (multiple_digits_p && (flags & mf_use_underscores_around_value))
618 /* Output the number itself. */
619 if (multiple_words_p)
620 dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value));
622 icat (TREE_INT_CST_LOW (value));
624 if (flags & mf_use_underscores_around_value)
626 if (multiple_digits_p)
628 /* Whether or not there were multiple digits, we don't need an
629 underscore. We've either terminated the number with an
630 underscore, or else it only had one digit. */
631 numeric_output_need_bar = 0;
634 /* We just output a numeric value. */
635 numeric_output_need_bar = 1;
639 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
640 supplied in INDEX. */
643 build_mangled_template_parm_index (s, index)
648 build_underscore_int (TEMPLATE_PARM_IDX (index));
649 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
650 representation of the function from the point of view of its
652 build_underscore_int (TEMPLATE_PARM_LEVEL (index));
656 /* Mangling for C9X integer types (and Cygnus extensions for 128-bit
657 and other types) is based on the letter "I" followed by the hex
658 representations of the bitsize for the type in question. For
659 encodings that result in larger than two digits, a leading and
660 trailing underscore is added.
671 int256_t = 100 = I_100_
672 int512_t = 200 = I_200_
674 Given an integer in decimal format, mangle according to this scheme. */
676 #if HOST_BITS_PER_WIDE_INT >= 64
678 build_mangled_C9x_name (bits)
681 char mangled[10] = "";
684 sprintf (mangled, "I_%x_", bits);
686 sprintf (mangled, "I%.2x", bits);
693 build_overload_value (type, value, flags)
695 mangling_flags flags;
697 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type)) == 't', 0);
699 while (TREE_CODE (value) == NON_LVALUE_EXPR
700 || TREE_CODE (value) == NOP_EXPR)
701 value = TREE_OPERAND (value, 0);
703 if (numeric_output_need_bar)
706 numeric_output_need_bar = 0;
709 if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
711 build_mangled_template_parm_index ("Y", value);
715 if (TYPE_PTRMEM_P (type))
717 if (TREE_CODE (value) != PTRMEM_CST)
718 /* We should have already rejected this pointer to member,
719 since it is not a constant. */
720 my_friendly_abort (0);
722 /* Get the actual FIELD_DECL. */
723 value = PTRMEM_CST_MEMBER (value);
724 my_friendly_assert (TREE_CODE (value) == FIELD_DECL, 0);
726 /* Output the name of the field. */
727 build_overload_identifier (DECL_NAME (value));
730 else if (INTEGRAL_TYPE_P (type))
732 build_overload_int (value, flags);
736 /* The only case where we use the extra underscores here is when
737 forming the mangling for an integral non-type template argument.
738 If that didn't happen, stop now. */
739 flags &= ~mf_use_underscores_around_value;
741 switch (TREE_CODE (type))
746 char *bufp = digit_buffer;
748 /* We must handle non-constants in templates. */
749 if (TREE_CODE (value) != REAL_CST)
751 mangle_expression (value);
755 val = TREE_REAL_CST (value);
756 if (REAL_VALUE_ISNAN (val))
758 sprintf (bufp, "NaN");
762 if (REAL_VALUE_NEGATIVE (val))
764 val = REAL_VALUE_NEGATE (val);
767 if (REAL_VALUE_ISINF (val))
769 sprintf (bufp, "Infinity");
773 REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
774 bufp = (char *) index (bufp, 'e');
776 strcat (digit_buffer, "e0");
802 #ifdef NO_DOT_IN_LABEL
803 bufp = (char *) index (bufp, '.');
809 OB_PUTCP (digit_buffer);
810 numeric_output_need_bar = 1;
814 if (TREE_CODE (value) == INTEGER_CST)
816 build_overload_int (value, flags);
819 else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
821 build_mangled_template_parm_index ("", value);
822 numeric_output_need_bar = 1;
826 value = TREE_OPERAND (value, 0);
831 if (TREE_CODE (value) == VAR_DECL)
833 my_friendly_assert (DECL_NAME (value) != 0, 245);
834 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
837 else if (TREE_CODE (value) == FUNCTION_DECL)
839 my_friendly_assert (DECL_NAME (value) != 0, 246);
840 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
843 else if (TREE_CODE (value) == SCOPE_REF)
844 build_overload_scope_ref (value);
846 my_friendly_abort (71);
847 break; /* not really needed */
857 my_friendly_assert (TYPE_PTRMEMFUNC_P (type), 0);
859 /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're
860 mangling, an instantiation of something like:
862 template <class T, void (T::*fp)()> class C {};
863 template <class T> C<T, &T::f> x();
865 We mangle the return type of the function, and that
866 contains template parameters. */
867 if (TREE_CODE (value) == ADDR_EXPR
868 && TREE_CODE (TREE_OPERAND (value, 0)) == SCOPE_REF)
870 build_overload_scope_ref (TREE_OPERAND (value, 0));
874 my_friendly_assert (TREE_CODE (value) == PTRMEM_CST, 0);
876 expand_ptrmemfunc_cst (value, &delta, &idx, &pfn, &delta2);
877 fn = PTRMEM_CST_MEMBER (value);
878 build_overload_int (delta, flags);
882 build_overload_int (idx, flags);
885 else if (DECL_VIRTUAL_P (fn))
887 build_overload_int (DECL_VINDEX (fn), flags);
891 if (!DECL_VIRTUAL_P (fn))
893 numeric_output_need_bar = 0;
894 build_overload_identifier (DECL_ASSEMBLER_NAME (fn));
896 else if (!flag_new_abi)
899 build_overload_int (delta2, flags);
905 sorry ("conversion of %s as template parameter",
906 tree_code_name [(int) TREE_CODE (type)]);
907 my_friendly_abort (72);
912 /* Add encodings for the declaration of template template parameters.
913 PARMLIST must be a TREE_VEC. */
916 build_template_template_parm_names (parmlist)
921 my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
922 nparms = TREE_VEC_LENGTH (parmlist);
924 for (i = 0; i < nparms; i++)
926 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
927 if (TREE_CODE (parm) == TYPE_DECL)
929 /* This parameter is a type. */
932 else if (TREE_CODE (parm) == TEMPLATE_DECL)
934 /* This parameter is a template. */
936 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
939 /* It's a PARM_DECL. */
940 build_mangled_name_for_type (TREE_TYPE (parm));
945 /* Add encodings for the vector of template parameters in PARMLIST,
946 given the vector of arguments to be substituted in ARGLIST. */
949 build_template_parm_names (parmlist, arglist)
954 tree inner_args = innermost_args (arglist);
956 nparms = TREE_VEC_LENGTH (parmlist);
958 for (i = 0; i < nparms; i++)
960 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
961 tree arg = TREE_VEC_ELT (inner_args, i);
962 if (TREE_CODE (parm) == TYPE_DECL)
964 /* This parameter is a type. */
966 build_mangled_name_for_type (arg);
968 else if (TREE_CODE (parm) == TEMPLATE_DECL)
970 /* This parameter is a template. */
971 if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
972 /* Output parameter declaration, argument index and level. */
973 build_mangled_name_for_type (arg);
976 /* A TEMPLATE_DECL node, output the parameter declaration
980 build_template_template_parm_names
981 (DECL_INNERMOST_TEMPLATE_PARMS (parm));
982 icat (IDENTIFIER_LENGTH (DECL_NAME (arg)));
983 OB_PUTID (DECL_NAME (arg));
988 parm = tsubst (parm, arglist, /*complain=*/1, NULL_TREE);
989 /* It's a PARM_DECL. */
990 build_mangled_name_for_type (TREE_TYPE (parm));
991 build_overload_value (TREE_TYPE (parm), arg,
992 ((mf_maybe_uninstantiated
993 * uses_template_parms (arglist))
994 | mf_use_underscores_around_value));
999 /* Output the representation for NAME, which is either a TYPE_DECL or
1003 build_overload_identifier (name)
1006 if (TREE_CODE (name) == TYPE_DECL
1007 && CLASS_TYPE_P (TREE_TYPE (name))
1008 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
1009 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))
1010 || (TREE_CODE (CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
1011 (TREE_TYPE (name))))
1014 /* NAME is the TYPE_DECL for a template specialization. */
1015 tree template, parmlist, arglist, tname;
1016 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name));
1017 arglist = CLASSTYPE_TI_ARGS (TREE_TYPE (name));
1018 tname = DECL_NAME (template);
1019 parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
1021 icat (IDENTIFIER_LENGTH (tname));
1023 build_template_parm_names (parmlist, arglist);
1027 if (TREE_CODE (name) == TYPE_DECL)
1028 name = DECL_NAME (name);
1029 if (numeric_output_need_bar)
1032 numeric_output_need_bar = 0;
1034 icat (IDENTIFIER_LENGTH (name));
1039 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
1040 the mangling for it. Used by build_mangled_name and build_static_name. */
1043 build_qualified_name (decl)
1049 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
1050 decl = TYPE_NAME (decl);
1052 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1053 if (TREE_CODE (decl) == TYPE_DECL
1054 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling)
1056 tree id = DECL_ASSEMBLER_NAME (decl);
1058 if (ISDIGIT (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1]))
1059 numeric_output_need_bar = 1;
1064 /* If we can't find a Ktype, do it the hard way. */
1065 if (check_ktype (context, FALSE) == -1)
1067 /* Count type and namespace scopes. */
1070 context = CP_DECL_CONTEXT (context);
1071 if (context == global_namespace)
1074 if (check_ktype (context, FALSE) != -1)
1077 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
1078 context = TYPE_NAME (context);
1085 build_underscore_int (i);
1086 numeric_output_need_bar = 0;
1088 build_overload_nested_name (decl);
1091 /* Output the mangled representation for TYPE. If EXTRA_GCODE is
1092 non-zero, mangled names for structure/union types are intentionally
1093 mangled differently from the method described in the ARM. */
1096 build_mangled_name_for_type_with_Gcode (type, extra_Gcode)
1100 if (TYPE_PTRMEMFUNC_P (type))
1101 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
1102 process_modifiers (type);
1103 process_overload_item (type, extra_Gcode);
1106 /* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1110 build_mangled_name_for_type (type)
1113 build_mangled_name_for_type_with_Gcode (type, 0);
1116 /* Given a list of parameters in PARMTYPES, create an unambiguous
1117 overload string. Should distinguish any type that C (or C++) can
1118 distinguish. I.e., pointers to functions are treated correctly.
1120 Caller must deal with whether a final `e' goes on the end or not.
1122 Any default conversions must take place before this function
1125 BEGIN and END control initialization and finalization of the
1126 obstack where we build the string. */
1129 build_overload_name (parmtypes, begin, end)
1134 start_squangling ();
1135 ret = build_mangled_name (parmtypes, begin, end);
1140 /* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1141 TREE_LIST, then it is a list of parameter types. Otherwise,
1142 PARMTYPES must be a single type. */
1145 build_mangled_name (parmtypes, begin, end)
1152 if (TREE_CODE (parmtypes) != TREE_LIST)
1153 /* There is only one type. */
1154 build_mangled_name_for_type (parmtypes);
1157 /* There are several types in a parameter list. */
1159 int old_style_repeats = !flag_do_squangling && !nofold && typevec;
1160 tree last_type = NULL_TREE;
1162 for (; parmtypes && parmtypes != void_list_node;
1163 parmtypes = TREE_CHAIN (parmtypes))
1165 /* We used to call canonical_type_variant here, but that isn't
1166 good enough; it doesn't handle pointers to typedef types. So
1167 we can't just set TREE_USED to say we've seen a type already;
1168 we have to check each of the earlier types with same_type_p. */
1169 tree parmtype = TREE_VALUE (parmtypes);
1171 if (old_style_repeats)
1173 /* Every argument gets counted. */
1174 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1175 VARRAY_TREE (typevec, maxtype) = parmtype;
1179 if (last_type && same_type_p (parmtype, last_type))
1181 if (flag_do_squangling
1182 || (old_style_repeats
1183 && is_back_referenceable_type (parmtype)))
1185 /* The next type is the same as this one. Keep
1186 track of the repetition, and output the repeat
1192 else if (nrepeats != 0)
1194 /* Indicate how many times the previous parameter was
1196 if (old_style_repeats)
1197 flush_repeats (nrepeats, last_type);
1199 issue_nrepeats (nrepeats, last_type);
1203 last_type = parmtype;
1205 /* Note that for bug-compatibility with 2.7.2, we can't build up
1206 repeats of types other than the most recent one. So we call
1207 flush_repeats every round, if we get this far. */
1208 if (old_style_repeats && flush_repeats (0, parmtype))
1211 /* Output the PARMTYPE. */
1212 build_mangled_name_for_type_with_Gcode (parmtype, 1);
1215 /* Output the repeat count for the last parameter, if
1219 if (old_style_repeats)
1220 flush_repeats (nrepeats, last_type);
1222 issue_nrepeats (nrepeats, last_type);
1227 /* The parameter list ends in an ellipsis. */
1233 return (char *)obstack_base (&scratch_obstack);
1236 /* Emit modifiers such as constant, read-only, and volatile. */
1239 process_modifiers (parmtype)
1242 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1243 we describe types recursively; we will get the `const' in
1244 `const int ()[10]' when processing the `const int' part. */
1245 if (TYPE_READONLY (parmtype))
1247 if (TREE_CODE (parmtype) == INTEGER_TYPE
1248 && parmtype != char_type_node
1249 && parmtype != wchar_type_node
1250 && (TYPE_MAIN_VARIANT (parmtype)
1251 == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
1252 && ! TYPE_FOR_JAVA (parmtype))
1254 if (TYPE_VOLATILE (parmtype))
1256 /* It would be better to use `R' for `restrict', but that's already
1257 used for reference types. And `r' is used for `long double'. */
1258 if (TYPE_RESTRICT (parmtype))
1262 /* Check to see if TYPE has been entered into the Bcode typelist. If
1263 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1264 to the list of back-referenceable types and return 0. */
1272 if (btypelist == NULL)
1275 if (!is_back_referenceable_type (type))
1278 for (x = 0; x < maxbtype; x++)
1279 if (same_type_p (type, VARRAY_TREE (btypelist, x)))
1288 if (VARRAY_SIZE (btypelist) <= maxbtype)
1289 /* Enlarge the table. */
1290 VARRAY_GROW (btypelist,
1291 VARRAY_SIZE (btypelist) * 3 / 2);
1293 /* Register the TYPE. */
1294 VARRAY_TREE (btypelist, maxbtype) = type;
1300 /* Emit the correct code for various node types. */
1303 process_overload_item (parmtype, extra_Gcode)
1307 numeric_output_need_bar = 0;
1309 /* Our caller should have already handed any qualifiers, so pull out the
1310 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1311 for arrays, because they are transparent to qualifiers. Sigh. */
1312 if (TREE_CODE (parmtype) == ARRAY_TYPE)
1313 parmtype = canonical_type_variant (parmtype);
1315 parmtype = TYPE_MAIN_VARIANT (parmtype);
1317 /* These tree types are considered modifiers for B code squangling,
1318 and therefore should not get entries in the Btypelist. They are,
1319 however, repeatable types. */
1321 switch (TREE_CODE (parmtype))
1323 case REFERENCE_TYPE:
1330 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
1334 tree length = array_type_nelts (parmtype);
1335 if (TREE_CODE (length) != INTEGER_CST || flag_do_squangling)
1337 length = fold (build (PLUS_EXPR, TREE_TYPE (length),
1338 length, integer_one_node));
1339 STRIP_NOPS (length);
1341 build_overload_value (sizetype, length, 1);
1343 if (numeric_output_need_bar && ! flag_do_squangling)
1351 build_mangled_name_for_type (TREE_TYPE (parmtype));
1359 if (flag_do_squangling && check_btype (parmtype))
1360 /* If PARMTYPE is already in the list of back-referenceable types,
1361 then check_btype will output the appropriate reference, and
1362 there's nothing more to do. */
1365 switch (TREE_CODE (parmtype))
1369 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype));
1371 build_mangled_name_for_type (TREE_TYPE (parmtype));
1377 tree parms = TYPE_ARG_TYPES (parmtype);
1379 /* Rather than implementing a reentrant TYPEVEC, we turn off
1380 repeat codes here, unless we're squangling. Squangling
1381 doesn't make use of the TYPEVEC, so there's no reentrancy
1383 int old_nofold = nofold;
1384 if (!flag_do_squangling)
1387 if (TREE_CODE (parmtype) == METHOD_TYPE)
1389 /* Mark this as a method. */
1391 /* Output the class of which this method is a member. */
1392 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype));
1393 /* Output any qualifiers for the `this' parameter. */
1394 process_modifiers (TREE_TYPE (TREE_VALUE (parms)));
1397 /* Output the parameter types. */
1399 if (parms == NULL_TREE)
1401 else if (parms == void_list_node)
1404 build_mangled_name (parms, 0, 0);
1406 /* Output the return type. */
1408 build_mangled_name_for_type (TREE_TYPE (parmtype));
1410 nofold = old_nofold;
1415 if (parmtype == integer_type_node
1416 || parmtype == unsigned_type_node
1417 || parmtype == java_int_type_node)
1419 else if (parmtype == long_integer_type_node
1420 || parmtype == long_unsigned_type_node)
1422 else if (parmtype == short_integer_type_node
1423 || parmtype == short_unsigned_type_node
1424 || parmtype == java_short_type_node)
1426 else if (parmtype == signed_char_type_node)
1431 else if (parmtype == char_type_node
1432 || parmtype == unsigned_char_type_node
1433 || parmtype == java_byte_type_node)
1435 else if (parmtype == wchar_type_node
1436 || parmtype == java_char_type_node)
1438 else if (parmtype == long_long_integer_type_node
1439 || parmtype == long_long_unsigned_type_node
1440 || parmtype == java_long_type_node)
1442 else if (parmtype == java_boolean_type_node)
1444 #if HOST_BITS_PER_WIDE_INT >= 64
1447 int bits = TREE_INT_CST_LOW (TYPE_SIZE (parmtype));
1448 build_mangled_C9x_name (bits);
1452 my_friendly_abort (73);
1461 if (parmtype == long_double_type_node)
1463 else if (parmtype == double_type_node
1464 || parmtype == java_double_type_node)
1466 else if (parmtype == float_type_node
1467 || parmtype == java_float_type_node)
1469 else my_friendly_abort (74);
1474 build_mangled_name_for_type (TREE_TYPE (parmtype));
1481 case ERROR_MARK: /* not right, but nothing is anyway */
1484 /* have to do these */
1489 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1490 /* drop through into next case */
1494 tree name = TYPE_NAME (parmtype);
1496 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
1498 build_qualified_name (name);
1503 /* This will take some work. */
1507 case TEMPLATE_TEMPLATE_PARM:
1508 /* Find and output the original template parameter
1510 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype))
1512 build_mangled_template_parm_index ("tzX",
1513 TEMPLATE_TYPE_PARM_INDEX
1515 build_template_parm_names
1516 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype)),
1517 TYPE_TI_ARGS (parmtype));
1521 build_mangled_template_parm_index ("ZzX",
1522 TEMPLATE_TYPE_PARM_INDEX
1524 build_template_template_parm_names
1525 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
1529 case TEMPLATE_TYPE_PARM:
1530 build_mangled_template_parm_index ("X",
1531 TEMPLATE_TYPE_PARM_INDEX
1536 /* When mangling the type of a function template whose
1537 declaration looks like:
1539 template <class T> void foo(typename T::U)
1541 we have to mangle these. */
1542 build_qualified_name (parmtype);
1546 my_friendly_abort (75);
1551 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1552 be either a class TYPE or a FUNCTION_DECL. */
1555 build_static_name (context, name)
1559 numeric_output_need_bar = 0;
1560 start_squangling ();
1563 build_qualified_name (context);
1566 OB_PUTS ("__static_");
1567 build_qualified_name (context);
1574 return get_identifier ((char *)obstack_base (&scratch_obstack));
1577 /* FOR_METHOD should be 1 if the declaration in question is for a member
1578 of a class (including a static member) and 2 if the declaration is
1579 for a constructor. */
1581 build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1590 const char *name = IDENTIFIER_POINTER (dname);
1592 /* member operators new and delete look like methods at this point. */
1593 if (! for_method && current_namespace == global_namespace
1594 && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
1595 && TREE_CHAIN (parms) == void_list_node)
1597 if (dname == ansi_opname[(int) DELETE_EXPR])
1598 return get_identifier ("__builtin_delete");
1599 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1600 return get_identifier ("__builtin_vec_delete");
1601 if (dname == ansi_opname[(int) NEW_EXPR])
1602 return get_identifier ("__builtin_new");
1603 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1604 return get_identifier ("__builtin_vec_new");
1607 start_squangling ();
1609 if (for_method != 2)
1611 /* Otherwise, we can divine that this is a constructor,
1612 and figure out its name without any extra encoding. */
1614 OB_PUTC2 ('_', '_');
1615 numeric_output_need_bar = 0;
1620 build_template_parm_names (tparms, targs);
1623 else if (!for_method && current_namespace == global_namespace)
1624 /* XXX this works only if we call this in the same namespace
1625 as the declaration. Unfortunately, we don't have the _DECL,
1629 if (!for_method && current_namespace != global_namespace)
1630 /* qualify with namespace */
1631 build_qualified_name (current_namespace);
1633 if (parms == NULL_TREE)
1635 else if (parms == void_list_node)
1639 if (!flag_do_squangling)
1641 /* Allocate typevec array. */
1642 size_t typevec_size = list_length (parms);
1644 if (!for_method && current_namespace != global_namespace)
1645 /* The namespace of a global function needs one slot. */
1647 VARRAY_TREE_INIT (typevec, typevec_size, "typevec");
1653 tree this_type = TREE_TYPE (TREE_VALUE (parms));
1655 build_mangled_name_for_type (this_type);
1657 if (!flag_do_squangling)
1659 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1660 VARRAY_TREE (typevec, maxtype) = this_type;
1664 if (TREE_CHAIN (parms))
1665 build_mangled_name (TREE_CHAIN (parms), 0, 0);
1671 /* the namespace qualifier for a global function
1672 will count as type */
1673 if (current_namespace != global_namespace
1674 && !flag_do_squangling)
1676 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1677 VARRAY_TREE (typevec, maxtype) = current_namespace;
1680 build_mangled_name (parms, 0, 0);
1683 if (!flag_do_squangling)
1684 /* Deallocate typevec array. */
1685 VARRAY_FREE (typevec);
1688 if (ret_type != NULL_TREE && for_method != 2)
1690 /* Add the return type. */
1692 build_mangled_name_for_type (ret_type);
1698 tree n = get_identifier (obstack_base (&scratch_obstack));
1699 if (IDENTIFIER_OPNAME_P (dname))
1700 IDENTIFIER_OPNAME_P (n) = 1;
1705 /* Change the name of a function definition so that it may be
1706 overloaded. NAME is the name of the function to overload,
1707 PARMS is the parameter list (which determines what name the
1708 final function obtains).
1710 FOR_METHOD is 1 if this overload is being performed
1711 for a method, rather than a function type. It is 2 if
1712 this overload is being performed for a constructor. */
1715 build_decl_overload (dname, parms, for_method)
1720 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1721 NULL_TREE, for_method);
1724 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
1727 set_mangled_name_for_decl (decl)
1732 if (processing_template_decl)
1733 /* There's no need to mangle the name of a template function. */
1736 parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
1738 if (DECL_STATIC_FUNCTION_P (decl))
1740 hash_tree_chain (build_pointer_type (DECL_CONTEXT (decl)),
1743 /* The only member functions whose type is a FUNCTION_TYPE, rather
1744 than a METHOD_TYPE, should be static members. */
1745 my_friendly_assert (!DECL_CONTEXT (decl)
1746 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl)))
1747 || TREE_CODE (TREE_TYPE (decl)) != FUNCTION_TYPE,
1750 DECL_ASSEMBLER_NAME (decl)
1751 = build_decl_overload (DECL_NAME (decl), parm_types,
1752 DECL_FUNCTION_MEMBER_P (decl)
1753 + DECL_CONSTRUCTOR_P (decl));
1756 /* Build an overload name for the type expression TYPE. */
1759 build_typename_overload (type)
1765 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1767 start_squangling ();
1768 build_mangled_name (type, 0, 1);
1769 id = get_identifier (obstack_base (&scratch_obstack));
1770 IDENTIFIER_OPNAME_P (id) = 1;
1772 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1774 TREE_TYPE (id) = type;
1780 build_overload_with_type (name, type)
1787 start_squangling ();
1788 build_mangled_name (type, 0, 1);
1790 return get_identifier (obstack_base (&scratch_obstack));
1794 get_id_2 (name, name2)
1802 return get_identifier (obstack_base (&scratch_obstack));
1805 /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1808 build_destructor_name (type)
1811 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX),
1815 /* Given a tree_code CODE, and some arguments (at least one),
1816 attempt to use an overloaded operator on the arguments.
1818 For unary operators, only the first argument need be checked.
1819 For binary operators, both arguments may need to be checked.
1821 Member functions can convert class references to class pointers,
1822 for one-level deep indirection. More than that is not supported.
1823 Operators [](), ()(), and ->() must be member functions.
1825 We call function call building calls with LOOKUP_COMPLAIN if they
1826 are our only hope. This is true when we see a vanilla operator
1827 applied to something of aggregate type. If this fails, we are free
1828 to return `error_mark_node', because we will have reported the
1831 Operators NEW and DELETE overload in funny ways: operator new takes
1832 a single `size' parameter, and operator delete takes a pointer to the
1833 storage being deleted. When overloading these operators, success is
1834 assumed. If there is a failure, report an error message and return
1835 `error_mark_node'. */
1839 build_opfncall (code, flags, xarg1, xarg2, arg3)
1840 enum tree_code code;
1842 tree xarg1, xarg2, arg3;
1844 return build_new_op (code, flags, xarg1, xarg2, arg3);
1847 /* This function takes an identifier, ID, and attempts to figure out what
1848 it means. There are a number of possible scenarios, presented in increasing
1851 1) not in a class's scope
1852 2) in class's scope, member name of the class's method
1853 3) in class's scope, but not a member name of the class
1854 4) in class's scope, member name of a class's variable
1856 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1857 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1859 As a last ditch, try to look up the name as a label and return that
1862 Values which are declared as being of REFERENCE_TYPE are
1863 automatically dereferenced here (as a hack to make the
1864 compiler faster). */
1867 hack_identifier (value, name)
1872 if (value == error_mark_node)
1874 if (current_class_name)
1876 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1877 if (fields == error_mark_node)
1878 return error_mark_node;
1883 fndecl = TREE_VALUE (fields);
1884 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1885 /* I could not trigger this code. MvL */
1886 my_friendly_abort (980325);
1888 if (DECL_CHAIN (fndecl) == NULL_TREE)
1890 warning ("methods cannot be converted to function pointers");
1895 error ("ambiguous request for method pointer `%s'",
1896 IDENTIFIER_POINTER (name));
1897 return error_mark_node;
1902 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1904 return IDENTIFIER_LABEL_VALUE (name);
1906 return error_mark_node;
1909 type = TREE_TYPE (value);
1910 if (TREE_CODE (value) == FIELD_DECL)
1912 if (current_class_ptr == NULL_TREE)
1914 if (current_function_decl
1915 && DECL_STATIC_FUNCTION_P (current_function_decl))
1916 cp_error ("invalid use of member `%D' in static member function",
1919 /* We can get here when processing a bad default
1921 struct S { int a; void f(int i = a); } */
1922 cp_error ("invalid use of member `%D'", value);
1924 return error_mark_node;
1926 TREE_USED (current_class_ptr) = 1;
1928 /* Mark so that if we are in a constructor, and then find that
1929 this field was initialized by a base initializer,
1930 we can emit an error message. */
1931 TREE_USED (value) = 1;
1932 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
1934 else if ((TREE_CODE (value) == FUNCTION_DECL
1935 && DECL_FUNCTION_MEMBER_P (value))
1936 || (TREE_CODE (value) == OVERLOAD
1937 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
1941 if (TREE_CODE (value) == OVERLOAD)
1942 value = OVL_CURRENT (value);
1944 decl = maybe_dummy_object (DECL_CONTEXT (value), 0);
1945 value = build_component_ref (decl, name, NULL_TREE, 1);
1947 else if (really_overloaded_fn (value))
1949 else if (TREE_CODE (value) == OVERLOAD)
1950 /* not really overloaded function */
1951 mark_used (OVL_FUNCTION (value));
1952 else if (TREE_CODE (value) == TREE_LIST)
1954 /* Ambiguous reference to base members, possibly other cases?. */
1956 while (t && TREE_CODE (t) == TREE_LIST)
1958 mark_used (TREE_VALUE (t));
1962 else if (TREE_CODE (value) == NAMESPACE_DECL)
1964 cp_error ("use of namespace `%D' as expression", value);
1965 return error_mark_node;
1967 else if (DECL_CLASS_TEMPLATE_P (value))
1969 cp_error ("use of class template `%T' as expression", value);
1970 return error_mark_node;
1975 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
1976 || TREE_CODE (value) == RESULT_DECL)
1978 tree context = decl_function_context (value);
1979 if (context != NULL_TREE && context != current_function_decl
1980 && ! TREE_STATIC (value))
1982 cp_error ("use of %s from containing function",
1983 (TREE_CODE (value) == VAR_DECL
1984 ? "`auto' variable" : "parameter"));
1985 cp_error_at (" `%#D' declared here", value);
1986 value = error_mark_node;
1990 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1992 if (DECL_CLASS_SCOPE_P (value)
1993 && DECL_CONTEXT (value) != current_class_type)
1996 path = currently_open_derived_class (DECL_CONTEXT (value));
1997 enforce_access (path, value);
2000 else if (TREE_CODE (value) == TREE_LIST
2001 && TREE_TYPE (value) == error_mark_node)
2003 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2004 IDENTIFIER_POINTER (name));
2005 print_candidates (value);
2006 return error_mark_node;
2009 if (! processing_template_decl)
2010 value = convert_from_reference (value);
2016 make_thunk (function, delta, vcall_index)
2025 if (TREE_CODE (function) != ADDR_EXPR)
2027 func_decl = TREE_OPERAND (function, 0);
2028 if (TREE_CODE (func_decl) != FUNCTION_DECL)
2032 OB_PUTS ("__thunk_");
2041 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl));
2048 thunk_id = get_identifier (obstack_base (&scratch_obstack));
2050 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
2051 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
2053 cp_error ("implementation-reserved name `%D' used", thunk_id);
2055 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
2057 if (thunk == NULL_TREE)
2059 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
2060 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
2061 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
2062 comdat_linkage (thunk);
2063 TREE_SET_CODE (thunk, THUNK_DECL);
2064 DECL_INITIAL (thunk) = function;
2065 THUNK_DELTA (thunk) = delta;
2066 THUNK_VCALL_OFFSET (thunk)
2067 = vcall_index * TREE_INT_CST_LOW (TYPE_SIZE (vtable_entry_type));
2068 DECL_EXTERNAL (thunk) = 1;
2069 DECL_ARTIFICIAL (thunk) = 1;
2070 /* So that finish_file can write out any thunks that need to be: */
2071 pushdecl_top_level (thunk);
2076 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2079 emit_thunk (thunk_fndecl)
2082 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
2083 int delta = THUNK_DELTA (thunk_fndecl);
2085 if (TREE_ASM_WRITTEN (thunk_fndecl))
2088 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
2090 TREE_ADDRESSABLE (function) = 1;
2091 mark_used (function);
2093 if (current_function_decl)
2096 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
2098 #ifdef ASM_OUTPUT_MI_THUNK
2099 if (!flag_syntax_only)
2102 current_function_decl = thunk_fndecl;
2103 /* Make sure we build up its RTL before we go onto the
2104 temporary obstack. */
2105 make_function_rtl (thunk_fndecl);
2106 DECL_RESULT (thunk_fndecl)
2107 = build_decl (RESULT_DECL, 0, integer_type_node);
2108 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2109 init_function_start (thunk_fndecl, input_filename, lineno);
2110 current_function_is_thunk = 1;
2111 assemble_start_function (thunk_fndecl, fnname);
2112 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
2113 assemble_end_function (thunk_fndecl, fnname);
2114 current_function_decl = 0;
2117 #else /* ASM_OUTPUT_MI_THUNK */
2119 /* If we don't have the necessary macro for efficient thunks, generate a
2120 thunk function that just makes a call to the real function.
2121 Unfortunately, this doesn't work for varargs. */
2125 if (varargs_function_p (function))
2126 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2129 /* Set up clone argument trees for the thunk. */
2131 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
2133 tree x = copy_node (a);
2135 DECL_CONTEXT (x) = thunk_fndecl;
2139 DECL_ARGUMENTS (thunk_fndecl) = a;
2140 DECL_RESULT (thunk_fndecl) = NULL_TREE;
2141 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
2142 copy_lang_decl (thunk_fndecl);
2143 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
2144 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
2146 start_function (NULL_TREE, thunk_fndecl, NULL_TREE,
2147 SF_DEFAULT | SF_PRE_PARSED);
2148 store_parm_decls ();
2149 current_function_is_thunk = 1;
2151 /* Build up the call to the real function. */
2152 t = build_int_2 (delta, -1 * (delta < 0));
2153 TREE_TYPE (t) = signed_type (sizetype);
2154 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
2155 t = tree_cons (NULL_TREE, t, NULL_TREE);
2156 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
2157 t = tree_cons (NULL_TREE, a, t);
2159 t = build_call (function, t);
2160 finish_return_stmt (t);
2162 expand_body (finish_function (lineno, 0));
2164 /* Don't let the backend defer this function. */
2165 if (DECL_DEFER_OUTPUT (thunk_fndecl))
2166 output_inline_function (thunk_fndecl);
2168 #endif /* ASM_OUTPUT_MI_THUNK */
2170 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
2173 /* Code for synthesizing methods which have default semantics defined. */
2175 /* Generate code for default X(X&) constructor. */
2178 do_build_copy_constructor (fndecl)
2181 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2184 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2185 parm = TREE_CHAIN (parm);
2186 parm = convert_from_reference (parm);
2188 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
2189 && is_empty_class (current_class_type))
2190 /* Don't copy the padding byte; it might not have been allocated
2191 if *this is a base subobject. */;
2192 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2194 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
2195 finish_expr_stmt (t);
2199 tree fields = TYPE_FIELDS (current_class_type);
2200 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2201 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2204 /* Initialize all the base-classes. */
2205 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2207 current_base_init_list
2208 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
2209 for (i = 0; i < n_bases; ++i)
2211 t = TREE_VEC_ELT (binfos, i);
2212 if (TREE_VIA_VIRTUAL (t))
2215 current_base_init_list
2216 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
2219 for (; fields; fields = TREE_CHAIN (fields))
2222 tree field = fields;
2224 if (TREE_CODE (field) != FIELD_DECL)
2228 if (DECL_NAME (field))
2230 if (VFIELD_NAME_P (DECL_NAME (field)))
2232 if (VBASE_NAME_P (DECL_NAME (field)))
2235 /* True for duplicate members. */
2236 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2239 else if ((t = TREE_TYPE (field)) != NULL_TREE
2240 && ANON_AGGR_TYPE_P (t)
2241 && TYPE_FIELDS (t) != NULL_TREE)
2242 /* Just use the field; anonymous types can't have
2243 nontrivial copy ctors or assignment ops. */;
2247 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2248 init = build_tree_list (NULL_TREE, init);
2250 current_member_init_list
2251 = tree_cons (field, init, current_member_init_list);
2253 current_member_init_list = nreverse (current_member_init_list);
2254 current_base_init_list = nreverse (current_base_init_list);
2260 do_build_assign_ref (fndecl)
2263 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2266 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
2267 parm = convert_from_reference (parm);
2269 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
2270 && is_empty_class (current_class_type))
2271 /* Don't copy the padding byte; it might not have been allocated
2272 if *this is a base subobject. */;
2273 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2275 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
2276 finish_expr_stmt (t);
2280 tree fields = TYPE_FIELDS (current_class_type);
2281 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2282 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2285 for (i = 0; i < n_bases; ++i)
2287 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2288 tree p = convert_to_reference
2289 (build_reference_type (basetype), parm,
2290 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2291 p = convert_from_reference (p);
2292 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2293 build_tree_list (NULL_TREE, p));
2294 finish_expr_stmt (p);
2296 for (; fields; fields = TREE_CHAIN (fields))
2299 tree field = fields;
2301 if (TREE_CODE (field) != FIELD_DECL)
2304 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
2306 if (DECL_NAME (field))
2307 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
2309 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
2312 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2314 if (DECL_NAME (field))
2315 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
2317 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
2321 comp = current_class_ref;
2324 if (DECL_NAME (field))
2326 if (VFIELD_NAME_P (DECL_NAME (field)))
2328 if (VBASE_NAME_P (DECL_NAME (field)))
2331 /* True for duplicate members. */
2332 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2335 else if ((t = TREE_TYPE (field)) != NULL_TREE
2336 && ANON_AGGR_TYPE_P (t)
2337 && TYPE_FIELDS (t) != NULL_TREE)
2338 /* Just use the field; anonymous types can't have
2339 nontrivial copy ctors or assignment ops. */;
2343 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2344 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2346 finish_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2349 finish_return_stmt (current_class_ref);
2350 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
2354 synthesize_method (fndecl)
2357 int nested = (current_function_decl != NULL_TREE);
2358 tree context = decl_function_context (fndecl);
2362 import_export_decl (fndecl);
2365 push_to_top_level ();
2367 push_function_context_to (context);
2369 /* Put the function definition at the position where it is needed,
2370 rather than within the body of the class. That way, an error
2371 during the generation of the implicit body points at the place
2372 where the attempt to generate the function occurs, giving the
2373 user a hint as to why we are attempting to generate the
2375 DECL_SOURCE_LINE (fndecl) = lineno;
2376 DECL_SOURCE_FILE (fndecl) = input_filename;
2378 interface_unknown = 1;
2379 start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
2380 store_parm_decls ();
2383 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2385 do_build_assign_ref (fndecl);
2388 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2392 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2393 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2394 arg_chain = TREE_CHAIN (arg_chain);
2395 if (arg_chain != void_list_node)
2396 do_build_copy_constructor (fndecl);
2397 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2401 /* If we haven't yet generated the body of the function, just
2402 generate an empty compound statement. */
2406 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
2407 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
2410 expand_body (finish_function (lineno, 0));
2412 extract_interface_info ();
2414 pop_from_top_level ();
2416 pop_function_context_from (context);