1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #ifndef PARM_CAN_BE_ARRAY_TYPE
29 #define PARM_CAN_BE_ARRAY_TYPE 1
32 /* Handle method declarations. */
41 #include "hard-reg-set.h"
46 /* TREE_LIST of the current inline functions that need to be
48 struct pending_inline *pending_inlines;
52 #define obstack_chunk_alloc xmalloc
53 #define obstack_chunk_free free
55 /* Obstack where we build text strings for overloading, etc. */
56 static struct obstack scratch_obstack;
57 static char *scratch_firstobj;
59 static void icat PROTO((HOST_WIDE_INT));
60 static void dicat PROTO((HOST_WIDE_INT, HOST_WIDE_INT));
61 static int old_backref_index PROTO((tree));
62 static int flush_repeats PROTO((int, tree));
63 static void build_overload_identifier PROTO((tree));
64 static void build_overload_nested_name PROTO((tree));
65 static void build_overload_int PROTO((tree, int));
66 static void build_overload_identifier PROTO((tree));
67 static void build_qualified_name PROTO((tree));
68 static void build_overload_value PROTO((tree, tree, int));
69 static void issue_nrepeats PROTO((int, tree));
70 static char *build_mangled_name PROTO((tree,int,int));
71 static void process_modifiers PROTO((tree));
72 static void process_overload_item PROTO((tree,int));
73 static void do_build_assign_ref PROTO((tree));
74 static void do_build_copy_constructor PROTO((tree));
75 static tree largest_union_member PROTO((tree));
76 static void build_template_template_parm_names PROTO((tree));
77 static void build_template_parm_names PROTO((tree, tree));
78 static void build_underscore_int PROTO((int));
79 static void start_squangling PROTO((void));
80 static void end_squangling PROTO((void));
81 static int check_ktype PROTO((tree, int));
82 static int issue_ktype PROTO((tree));
83 static void build_overload_scope_ref PROTO((tree));
84 static void build_mangled_template_parm_index PROTO((char *, tree));
85 #if HOST_BITS_PER_WIDE_INT >= 64
86 static void build_mangled_C9x_name PROTO((int));
88 static int is_back_referenceable_type PROTO((tree));
89 static int check_btype PROTO((tree));
90 static void build_mangled_name_for_type PROTO((tree));
91 static void build_mangled_name_for_type_with_Gcode PROTO((tree, int));
92 static tree build_base_path PROTO((tree, int));
95 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
96 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
97 # define OB_PUTC2(C1,C2) \
98 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
99 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
100 # define OB_PUTID(ID) \
101 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
102 IDENTIFIER_LENGTH (ID)))
103 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
104 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
105 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
110 gcc_obstack_init (&scratch_obstack);
111 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
114 /* This must be large enough to hold any printed integer or floating-point
116 static char digit_buffer[128];
118 /* Move inline function definitions out of structure so that they
119 can be processed normally. CNAME is the name of the class
120 we are working from, METHOD_LIST is the list of method lists
121 of the structure. We delete friend methods here, after
122 saving away their inline function definitions (if any). */
125 do_inline_function_hair (type, friend_list)
126 tree type, friend_list;
128 tree method = TYPE_METHODS (type);
130 if (method && TREE_CODE (method) == TREE_VEC)
132 if (TREE_VEC_ELT (method, 1))
133 method = TREE_VEC_ELT (method, 1);
134 else if (TREE_VEC_ELT (method, 0))
135 method = TREE_VEC_ELT (method, 0);
137 method = TREE_VEC_ELT (method, 2);
142 /* Do inline member functions. */
143 struct pending_inline *info = DECL_PENDING_INLINE_INFO (method);
148 my_friendly_assert (info->fndecl == method, 238);
149 args = DECL_ARGUMENTS (method);
152 DECL_CONTEXT (args) = method;
153 args = TREE_CHAIN (args);
156 method = TREE_CHAIN (method);
160 tree fndecl = TREE_VALUE (friend_list);
161 struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl);
166 my_friendly_assert (info->fndecl == fndecl, 239);
167 args = DECL_ARGUMENTS (fndecl);
170 DECL_CONTEXT (args) = fndecl;
171 args = TREE_CHAIN (args);
175 friend_list = TREE_CHAIN (friend_list);
179 /* Here is where overload code starts. */
181 /* type tables for K and B type compression */
182 static tree *btypelist = NULL;
183 static tree *ktypelist = NULL;
184 static int maxbsize = 0;
185 static int maxksize = 0;
187 /* number of each type seen */
188 static int maxbtype = 0;
189 static int maxktype = 0;
191 /* Array of types seen so far in top-level call to `build_mangled_name'.
192 Allocated and deallocated by caller. */
193 static tree *typevec = NULL;
194 static int typevec_size;
196 /* Number of types interned by `build_mangled_name' so far. */
197 static int maxtype = 0;
199 /* Nonzero if we should not try folding parameter types. */
202 /* This appears to be set to true if an underscore is required to be
203 comcatenated before another number can be outputed. */
204 static int numeric_output_need_bar;
209 if (flag_do_squangling)
216 btypelist = (tree *)xmalloc (sizeof (tree) * maxbsize);
217 ktypelist = (tree *)xmalloc (sizeof (tree) * maxksize);
224 if (flag_do_squangling)
239 /* Code to concatenate an asciified integer to a string. */
245 unsigned HOST_WIDE_INT ui;
247 /* Handle this case first, to go really quickly. For many common values,
248 the result of ui/10 below is 1. */
266 OB_PUTC ('0' + (ui % 10));
271 HOST_WIDE_INT lo, hi;
273 unsigned HOST_WIDE_INT ulo, uhi, qlo, qhi;
282 uhi = (lo == 0 ? -hi : -hi-1);
286 && ulo < ((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)))
291 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
294 qlo = uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) / 5);
297 ulo += uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) % 5)
301 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
306 /* Returns the index of TYPE in the typevec, or -1 if it's not there. */
309 old_backref_index (type)
314 if (! is_back_referenceable_type (type))
317 /* The entry for this parm is at maxtype-1, so don't look there for
318 something to repeat. */
319 for (tindex = 0; tindex < maxtype - 1; ++tindex)
320 if (same_type_p (typevec[tindex], type))
323 if (tindex == maxtype - 1)
329 /* Old mangling style: If TYPE has already been used in the parameter list,
330 emit a backward reference and return non-zero; otherwise, return 0.
332 NREPEATS is the number of repeats we've recorded of this type, or 0 if
333 this is the first time we've seen it and we're just looking to see if
334 it had been used before. */
337 flush_repeats (nrepeats, type)
341 int tindex = old_backref_index (type);
345 my_friendly_assert (nrepeats == 0, 990316);
365 /* Returns nonzero iff this is a type to which we will want to make
366 back-references (using the `B' code). */
369 is_back_referenceable_type (type)
372 /* For some reason, the Java folks don't want back refs on these. */
373 if (TYPE_FOR_JAVA (type))
376 switch (TREE_CODE (type))
379 if (!flag_do_squangling)
380 /* Even though the mangling of this is just `b', we did
381 historically generate back-references for it. */
388 /* These types have single-character manglings, so there's no
389 point in generating back-references. */
392 case TEMPLATE_TYPE_PARM:
393 /* It would be a bit complex to demangle signatures correctly if
394 we generated back-references to these, and the manglings of
395 type parameters are short. */
403 /* Issue the squangling code indicating NREPEATS repetitions of TYPE,
404 which was the last parameter type output. */
407 issue_nrepeats (nrepeats, type)
411 if (nrepeats == 1 && !is_back_referenceable_type (type))
412 /* For types whose manglings are short, don't bother using the
413 repetition code if there's only one repetition, since the
414 repetition code will be about as long as the ordinary mangling. */
415 build_mangled_name_for_type (type);
425 /* Check to see if a tree node has been entered into the Kcode typelist.
426 If not, add it. Returns -1 if it isn't found, otherwise returns the
430 check_ktype (node, add)
435 tree localnode = node;
437 if (ktypelist == NULL)
440 if (TREE_CODE (node) == TYPE_DECL)
441 localnode = TREE_TYPE (node);
443 for (x=0; x < maxktype; x++)
445 if (same_type_p (localnode, ktypelist[x]))
448 /* Didn't find it, so add it here. */
451 if (maxksize <= maxktype)
453 maxksize = maxksize* 3 / 2;
454 ktypelist = (tree *)xrealloc (ktypelist, sizeof (tree) * maxksize);
456 ktypelist[maxktype++] = localnode;
467 kindex = check_ktype (decl, FALSE);
479 /* Build a representation for DECL, which may be an entity not at
480 global scope. If so, a marker indicating that the name is
481 qualified has already been output, but the qualifying context has
485 build_overload_nested_name (decl)
490 if (ktypelist && issue_ktype (decl))
493 if (decl == global_namespace)
496 context = CP_DECL_CONTEXT (decl);
498 /* try to issue a K type, and if we can't continue the normal path */
499 if (!(ktypelist && issue_ktype (context)))
501 /* For a template type parameter, we want to output an 'Xn'
502 rather than 'T' or some such. */
503 if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
504 || TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
505 build_mangled_name_for_type (context);
508 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
509 context = TYPE_NAME (context);
510 build_overload_nested_name (context);
514 if (TREE_CODE (decl) == FUNCTION_DECL)
516 tree name = DECL_ASSEMBLER_NAME (decl);
519 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), static_labelno);
522 if (numeric_output_need_bar)
524 icat (strlen (label));
526 numeric_output_need_bar = 1;
528 else if (TREE_CODE (decl) == NAMESPACE_DECL)
529 build_overload_identifier (DECL_NAME (decl));
531 build_overload_identifier (decl);
534 /* Output the decimal representation of I. If I > 9, the decimal
535 representation is preceeded and followed by an underscore. */
538 build_underscore_int (i)
549 build_overload_scope_ref (value)
553 numeric_output_need_bar = 0;
554 build_mangled_name_for_type (TREE_OPERAND (value, 0));
555 build_overload_identifier (TREE_OPERAND (value, 1));
558 /* Encoding for an INTEGER_CST value. */
561 build_overload_int (value, in_template)
565 if (in_template && TREE_CODE (value) != INTEGER_CST)
567 if (TREE_CODE (value) == SCOPE_REF)
569 build_overload_scope_ref (value);
574 numeric_output_need_bar = 0;
576 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value))))
579 int operands = tree_code_length[(int) TREE_CODE (value)];
583 id = ansi_opname [(int) TREE_CODE (value)];
584 my_friendly_assert (id != NULL_TREE, 0);
585 name = IDENTIFIER_POINTER (id);
586 if (name[0] != '_' || name[1] != '_')
587 /* On some erroneous inputs, we can get here with VALUE a
588 LOOKUP_EXPR. In that case, the NAME will be the
589 identifier for "<invalid operator>". We must survive
590 this routine in order to issue a sensible error
591 message, so we fall through to the case below. */
594 for (i = 0; i < operands; ++i)
599 /* We just outputted either the `E' or the name of the
601 numeric_output_need_bar = 0;
604 /* Skip the leading underscores. */
607 operand = TREE_OPERAND (value, i);
608 tc = TREE_CODE (operand);
610 if (TREE_CODE_CLASS (tc) == 't')
611 /* We can get here with sizeof, e.g.:
613 template <class T> void f(A<sizeof(T)>); */
614 build_mangled_name_for_type (operand);
615 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc)))
616 build_overload_int (operand, in_template);
618 build_overload_value (TREE_TYPE (operand),
625 /* We don't ever want this output, but it's
626 inconvenient not to be able to build the string.
627 This should cause assembler errors we'll notice. */
631 sprintf (digit_buffer, " *%d", n++);
632 OB_PUTCP (digit_buffer);
636 numeric_output_need_bar = 0;
640 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
641 if (TYPE_PRECISION (TREE_TYPE (value)) == 2 * HOST_BITS_PER_WIDE_INT)
643 if (TREE_INT_CST_HIGH (value)
644 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
646 /* need to print a DImode value in decimal */
647 dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value));
648 numeric_output_need_bar = 1;
651 /* else fall through to print in smaller mode */
653 /* Wordsize or smaller */
654 icat (TREE_INT_CST_LOW (value));
655 numeric_output_need_bar = 1;
659 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
660 supplied in INDEX. */
663 build_mangled_template_parm_index (s, index)
668 build_underscore_int (TEMPLATE_PARM_IDX (index));
669 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
670 representation of the function from the point of view of its
672 build_underscore_int (TEMPLATE_PARM_LEVEL (index));
676 /* Mangling for C9X integer types (and Cygnus extensions for 128-bit
677 and other types) is based on the letter "I" followed by the hex
678 representations of the bitsize for the type in question. For
679 encodings that result in larger than two digits, a leading and
680 trailing underscore is added.
691 int256_t = 100 = I_100_
692 int512_t = 200 = I_200_
694 Given an integer in decimal format, mangle according to this scheme. */
696 #if HOST_BITS_PER_WIDE_INT >= 64
698 build_mangled_C9x_name (bits)
701 char mangled[10] = "";
704 sprintf (mangled, "I_%x_", bits);
706 sprintf (mangled, "I%.2x", bits);
713 build_overload_value (type, value, in_template)
717 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type)) == 't', 0);
719 while (TREE_CODE (value) == NON_LVALUE_EXPR
720 || TREE_CODE (value) == NOP_EXPR)
721 value = TREE_OPERAND (value, 0);
723 if (numeric_output_need_bar)
726 numeric_output_need_bar = 0;
729 if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
731 build_mangled_template_parm_index ("Y", value);
735 if (TYPE_PTRMEM_P (type))
737 if (TREE_CODE (value) != PTRMEM_CST)
738 /* We should have already rejected this pointer to member,
739 since it is not a constant. */
740 my_friendly_abort (0);
742 /* Get the actual FIELD_DECL. */
743 value = PTRMEM_CST_MEMBER (value);
744 my_friendly_assert (TREE_CODE (value) == FIELD_DECL, 0);
746 /* Output the name of the field. */
747 build_overload_identifier (DECL_NAME (value));
751 switch (TREE_CODE (type))
757 build_overload_int (value, in_template);
763 char *bufp = digit_buffer;
765 pedwarn ("ANSI C++ forbids floating-point template arguments");
767 my_friendly_assert (TREE_CODE (value) == REAL_CST, 244);
768 val = TREE_REAL_CST (value);
769 if (REAL_VALUE_ISNAN (val))
771 sprintf (bufp, "NaN");
775 if (REAL_VALUE_NEGATIVE (val))
777 val = REAL_VALUE_NEGATE (val);
780 if (REAL_VALUE_ISINF (val))
782 sprintf (bufp, "Infinity");
786 REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
787 bufp = (char *) index (bufp, 'e');
789 strcat (digit_buffer, "e0");
815 #ifdef NO_DOT_IN_LABEL
816 bufp = (char *) index (bufp, '.');
822 OB_PUTCP (digit_buffer);
823 numeric_output_need_bar = 1;
827 if (TREE_CODE (value) == INTEGER_CST)
829 build_overload_int (value, in_template);
832 else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
834 build_mangled_template_parm_index ("", value);
835 numeric_output_need_bar = 1;
839 value = TREE_OPERAND (value, 0);
844 if (TREE_CODE (value) == VAR_DECL)
846 my_friendly_assert (DECL_NAME (value) != 0, 245);
847 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
850 else if (TREE_CODE (value) == FUNCTION_DECL)
852 my_friendly_assert (DECL_NAME (value) != 0, 246);
853 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
856 else if (TREE_CODE (value) == SCOPE_REF)
857 build_overload_scope_ref (value);
859 my_friendly_abort (71);
860 break; /* not really needed */
869 my_friendly_assert (TYPE_PTRMEMFUNC_P (type), 0);
871 /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're
872 mangling, an instantiation of something like:
874 template <class T, void (T::*fp)()> class C {};
875 template <class T> C<T, &T::f> x();
877 We mangle the return type of the function, and that
878 contains template parameters. */
879 if (TREE_CODE (value) == ADDR_EXPR
880 && TREE_CODE (TREE_OPERAND (value, 0)) == SCOPE_REF)
882 build_overload_scope_ref (TREE_OPERAND (value, 0));
886 my_friendly_assert (TREE_CODE (value) == PTRMEM_CST, 0);
888 expand_ptrmemfunc_cst (value, &delta, &idx, &pfn, &delta2);
889 build_overload_int (delta, in_template);
891 build_overload_int (idx, in_template);
895 numeric_output_need_bar = 0;
896 build_overload_identifier (DECL_ASSEMBLER_NAME
897 (PTRMEM_CST_MEMBER (value)));
902 build_overload_int (delta2, in_template);
908 sorry ("conversion of %s as template parameter",
909 tree_code_name [(int) TREE_CODE (type)]);
910 my_friendly_abort (72);
915 /* Add encodings for the declaration of template template parameters.
916 PARMLIST must be a TREE_VEC. */
919 build_template_template_parm_names (parmlist)
924 my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
925 nparms = TREE_VEC_LENGTH (parmlist);
927 for (i = 0; i < nparms; i++)
929 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
930 if (TREE_CODE (parm) == TYPE_DECL)
932 /* This parameter is a type. */
935 else if (TREE_CODE (parm) == TEMPLATE_DECL)
937 /* This parameter is a template. */
939 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
942 /* It's a PARM_DECL. */
943 build_mangled_name_for_type (TREE_TYPE (parm));
948 /* Add encodings for the vector of template parameters in PARMLIST,
949 given the vector of arguments to be substituted in ARGLIST. */
952 build_template_parm_names (parmlist, arglist)
957 tree inner_args = innermost_args (arglist);
959 nparms = TREE_VEC_LENGTH (parmlist);
961 for (i = 0; i < nparms; i++)
963 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
964 tree arg = TREE_VEC_ELT (inner_args, i);
965 if (TREE_CODE (parm) == TYPE_DECL)
967 /* This parameter is a type. */
969 build_mangled_name_for_type (arg);
971 else if (TREE_CODE (parm) == TEMPLATE_DECL)
973 /* This parameter is a template. */
974 if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
975 /* Output parameter declaration, argument index and level. */
976 build_mangled_name_for_type (arg);
979 /* A TEMPLATE_DECL node, output the parameter declaration
983 build_template_template_parm_names
984 (DECL_INNERMOST_TEMPLATE_PARMS (parm));
985 icat (IDENTIFIER_LENGTH (DECL_NAME (arg)));
986 OB_PUTID (DECL_NAME (arg));
991 parm = tsubst (parm, arglist, /*complain=*/1, NULL_TREE);
992 /* It's a PARM_DECL. */
993 build_mangled_name_for_type (TREE_TYPE (parm));
994 build_overload_value (TREE_TYPE (parm), arg,
995 uses_template_parms (arglist));
1000 /* Output the representation for NAME, which is either a TYPE_DECL or
1004 build_overload_identifier (name)
1007 if (TREE_CODE (name) == TYPE_DECL
1008 && CLASS_TYPE_P (TREE_TYPE (name))
1009 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
1010 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))
1011 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
1012 (TREE_TYPE (name))))
1015 /* NAME is the TYPE_DECL for a template specialization. */
1016 tree template, parmlist, arglist, tname;
1017 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name));
1018 arglist = CLASSTYPE_TI_ARGS (TREE_TYPE (name));
1019 tname = DECL_NAME (template);
1020 parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
1022 icat (IDENTIFIER_LENGTH (tname));
1024 build_template_parm_names (parmlist, arglist);
1028 if (TREE_CODE (name) == TYPE_DECL)
1029 name = DECL_NAME (name);
1030 if (numeric_output_need_bar)
1033 numeric_output_need_bar = 0;
1035 icat (IDENTIFIER_LENGTH (name));
1040 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
1041 the mangling for it. Used by build_mangled_name and build_static_name. */
1044 build_qualified_name (decl)
1050 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
1051 decl = TYPE_NAME (decl);
1053 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1054 if (TREE_CODE (decl) == TYPE_DECL
1055 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling)
1057 tree id = DECL_ASSEMBLER_NAME (decl);
1059 if (ISDIGIT (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1]))
1060 numeric_output_need_bar = 1;
1065 /* If we can't find a Ktype, do it the hard way. */
1066 if (check_ktype (context, FALSE) == -1)
1068 /* Count type and namespace scopes. */
1071 context = CP_DECL_CONTEXT (context);
1072 if (context == global_namespace)
1075 if (check_ktype (context, FALSE) != -1)
1078 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
1079 context = TYPE_NAME (context);
1086 build_underscore_int (i);
1087 numeric_output_need_bar = 0;
1089 build_overload_nested_name (decl);
1092 /* Output the mangled representation for TYPE. If EXTRA_GCODE is
1093 non-zero, mangled names for structure/union types are intentionally
1094 mangled differently from the method described in the ARM. */
1097 build_mangled_name_for_type_with_Gcode (type, extra_Gcode)
1101 if (TYPE_PTRMEMFUNC_P (type))
1102 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
1103 process_modifiers (type);
1104 process_overload_item (type, extra_Gcode);
1107 /* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1111 build_mangled_name_for_type (type)
1114 build_mangled_name_for_type_with_Gcode (type, 0);
1117 /* Given a list of parameters in PARMTYPES, create an unambiguous
1118 overload string. Should distinguish any type that C (or C++) can
1119 distinguish. I.e., pointers to functions are treated correctly.
1121 Caller must deal with whether a final `e' goes on the end or not.
1123 Any default conversions must take place before this function
1126 BEGIN and END control initialization and finalization of the
1127 obstack where we build the string. */
1130 build_overload_name (parmtypes, begin, end)
1135 start_squangling ();
1136 ret = build_mangled_name (parmtypes, begin, end);
1141 /* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1142 TREE_LIST, then it is a list of parameter types. Otherwise,
1143 PARMTYPES must be a single type. */
1146 build_mangled_name (parmtypes, begin, end)
1153 if (TREE_CODE (parmtypes) != TREE_LIST)
1154 /* There is only one type. */
1155 build_mangled_name_for_type (parmtypes);
1158 /* There are several types in a parameter list. */
1160 int old_style_repeats = !flag_do_squangling && !nofold && typevec;
1161 tree last_type = NULL_TREE;
1163 for (; parmtypes && parmtypes != void_list_node;
1164 parmtypes = TREE_CHAIN (parmtypes))
1166 /* We used to call canonical_type_variant here, but that isn't
1167 good enough; it doesn't handle pointers to typedef types. So
1168 we can't just set TREE_USED to say we've seen a type already;
1169 we have to check each of the earlier types with same_type_p. */
1170 tree parmtype = TREE_VALUE (parmtypes);
1172 if (old_style_repeats)
1174 /* Every argument gets counted. */
1175 my_friendly_assert (maxtype < typevec_size, 387);
1176 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, btypelist[x]))
1288 if (maxbsize <= maxbtype)
1290 /* Enlarge the table. */
1291 maxbsize = maxbsize * 3 / 2;
1292 btypelist = (tree *)xrealloc (btypelist, sizeof (tree) * maxbsize);
1295 /* Register the TYPE. */
1296 btypelist[maxbtype++] = type;
1301 /* Emit the correct code for various node types. */
1304 process_overload_item (parmtype, extra_Gcode)
1308 numeric_output_need_bar = 0;
1310 /* Our caller should have already handed any qualifiers, so pull out the
1311 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1312 for arrays, because they are transparent to qualifiers. Sigh. */
1313 if (TREE_CODE (parmtype) == ARRAY_TYPE)
1314 parmtype = canonical_type_variant (parmtype);
1316 parmtype = TYPE_MAIN_VARIANT (parmtype);
1318 /* These tree types are considered modifiers for B code squangling,
1319 and therefore should not get entries in the Btypelist. They are,
1320 however, repeatable types. */
1322 switch (TREE_CODE (parmtype))
1324 case REFERENCE_TYPE:
1329 #if PARM_CAN_BE_ARRAY_TYPE
1332 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
1336 tree length = array_type_nelts (parmtype);
1337 if (TREE_CODE (length) != INTEGER_CST || flag_do_squangling)
1339 length = fold (build (PLUS_EXPR, TREE_TYPE (length),
1340 length, integer_one_node));
1341 STRIP_NOPS (length);
1343 build_overload_value (sizetype, length, 1);
1345 if (numeric_output_need_bar && ! flag_do_squangling)
1355 /* Even though the vlist_type_node is PPPFe (i.e. `int
1356 (***)(...)'), it is different from the any other occurence of
1357 the pointer type, because the underlying function type is
1359 if (parmtype == vlist_type_node)
1361 OB_PUTS (VLIST_TYPE_NAME);
1366 build_mangled_name_for_type (TREE_TYPE (parmtype));
1374 if (flag_do_squangling && check_btype (parmtype))
1375 /* If PARMTYPE is already in the list of back-referenceable types,
1376 then check_btype will output the appropriate reference, and
1377 there's nothing more to do. */
1380 switch (TREE_CODE (parmtype))
1384 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype));
1386 build_mangled_name_for_type (TREE_TYPE (parmtype));
1392 tree parms = TYPE_ARG_TYPES (parmtype);
1394 /* Rather than implementing a reentrant TYPEVEC, we turn off
1395 repeat codes here, unless we're squangling. Squangling
1396 doesn't make use of the TYPEVEC, so there's no reentrancy
1398 int old_nofold = nofold;
1399 if (!flag_do_squangling)
1402 if (TREE_CODE (parmtype) == METHOD_TYPE)
1404 /* Mark this as a method. */
1406 /* Output the class of which this method is a member. */
1407 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype));
1408 /* Output any qualifiers for the `this' parameter. */
1409 process_modifiers (TREE_TYPE (TREE_VALUE (parms)));
1412 /* Output the parameter types. */
1414 if (parms == NULL_TREE)
1416 else if (parms == void_list_node)
1419 build_mangled_name (parms, 0, 0);
1421 /* Output the return type. */
1423 build_mangled_name_for_type (TREE_TYPE (parmtype));
1425 nofold = old_nofold;
1430 if (parmtype == integer_type_node
1431 || parmtype == unsigned_type_node
1432 || parmtype == java_int_type_node)
1434 else if (parmtype == long_integer_type_node
1435 || parmtype == long_unsigned_type_node)
1437 else if (parmtype == short_integer_type_node
1438 || parmtype == short_unsigned_type_node
1439 || parmtype == java_short_type_node)
1441 else if (parmtype == signed_char_type_node)
1446 else if (parmtype == char_type_node
1447 || parmtype == unsigned_char_type_node
1448 || parmtype == java_byte_type_node)
1450 else if (parmtype == wchar_type_node
1451 || parmtype == java_char_type_node)
1453 else if (parmtype == long_long_integer_type_node
1454 || parmtype == long_long_unsigned_type_node
1455 || parmtype == java_long_type_node)
1457 else if (parmtype == java_boolean_type_node)
1459 #if HOST_BITS_PER_WIDE_INT >= 64
1460 else if (parmtype == intTI_type_node
1461 || parmtype == unsigned_intTI_type_node)
1463 /* Should just check a flag here instead of specific
1464 *_type_nodes, because all C9x types could use this. */
1465 int bits = TREE_INT_CST_LOW (TYPE_SIZE (parmtype));
1466 build_mangled_C9x_name (bits);
1470 my_friendly_abort (73);
1478 if (parmtype == long_double_type_node)
1480 else if (parmtype == double_type_node
1481 || parmtype == java_double_type_node)
1483 else if (parmtype == float_type_node
1484 || parmtype == java_float_type_node)
1486 else my_friendly_abort (74);
1491 build_mangled_name_for_type (TREE_TYPE (parmtype));
1498 case ERROR_MARK: /* not right, but nothing is anyway */
1501 /* have to do these */
1506 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1507 /* drop through into next case */
1511 tree name = TYPE_NAME (parmtype);
1513 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
1515 build_qualified_name (name);
1520 /* This will take some work. */
1524 case TEMPLATE_TEMPLATE_PARM:
1525 /* Find and output the original template parameter
1527 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype))
1529 build_mangled_template_parm_index ("tzX",
1530 TEMPLATE_TYPE_PARM_INDEX
1532 build_template_parm_names
1533 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype)),
1534 TYPE_TI_ARGS (parmtype));
1538 build_mangled_template_parm_index ("ZzX",
1539 TEMPLATE_TYPE_PARM_INDEX
1541 build_template_template_parm_names
1542 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
1546 case TEMPLATE_TYPE_PARM:
1547 build_mangled_template_parm_index ("X",
1548 TEMPLATE_TYPE_PARM_INDEX
1553 /* When mangling the type of a function template whose
1554 declaration looks like:
1556 template <class T> void foo(typename T::U)
1558 we have to mangle these. */
1559 build_qualified_name (parmtype);
1563 my_friendly_abort (75);
1568 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1569 be either a class TYPE or a FUNCTION_DECL. */
1572 build_static_name (context, name)
1576 numeric_output_need_bar = 0;
1577 start_squangling ();
1580 build_qualified_name (context);
1583 OB_PUTS ("__static_");
1584 build_qualified_name (context);
1591 return get_identifier ((char *)obstack_base (&scratch_obstack));
1594 /* FOR_METHOD should be 1 if the declaration in question is for a member
1595 of a class (including a static member) and 2 if the declaration is
1596 for a constructor. */
1598 build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1607 char *name = IDENTIFIER_POINTER (dname);
1609 /* member operators new and delete look like methods at this point. */
1610 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
1611 && TREE_CHAIN (parms) == void_list_node)
1613 if (dname == ansi_opname[(int) DELETE_EXPR])
1614 return get_identifier ("__builtin_delete");
1615 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1616 return get_identifier ("__builtin_vec_delete");
1617 if (dname == ansi_opname[(int) NEW_EXPR])
1618 return get_identifier ("__builtin_new");
1619 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1620 return get_identifier ("__builtin_vec_new");
1623 start_squangling ();
1625 if (for_method != 2)
1627 /* Otherwise, we can divine that this is a constructor,
1628 and figure out its name without any extra encoding. */
1630 OB_PUTC2 ('_', '_');
1631 numeric_output_need_bar = 0;
1636 build_template_parm_names (tparms, targs);
1639 else if (!for_method && current_namespace == global_namespace)
1640 /* XXX this works only if we call this in the same namespace
1641 as the declaration. Unfortunately, we don't have the _DECL,
1645 if (!for_method && current_namespace != global_namespace)
1646 /* qualify with namespace */
1647 build_qualified_name (current_namespace);
1649 if (parms == NULL_TREE)
1651 else if (parms == void_list_node)
1655 if (!flag_do_squangling)
1657 /* Allocate typevec array. */
1659 typevec_size = list_length (parms);
1660 if (!for_method && current_namespace != global_namespace)
1661 /* The namespace of a global function needs one slot. */
1663 typevec = (tree *)alloca (typevec_size * sizeof (tree));
1669 tree this_type = TREE_VALUE (parms);
1671 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
1672 this_type = SIGNATURE_TYPE (this_type);
1674 this_type = TREE_TYPE (this_type);
1676 build_mangled_name_for_type (this_type);
1678 if (!flag_do_squangling)
1680 my_friendly_assert (maxtype < typevec_size, 387);
1681 typevec[maxtype++] = this_type;
1684 if (TREE_CHAIN (parms))
1685 build_mangled_name (TREE_CHAIN (parms), 0, 0);
1691 /* the namespace qualifier for a global function
1692 will count as type */
1693 if (current_namespace != global_namespace
1694 && !flag_do_squangling)
1696 my_friendly_assert (maxtype < typevec_size, 387);
1697 typevec[maxtype++] = current_namespace;
1699 build_mangled_name (parms, 0, 0);
1702 if (!flag_do_squangling)
1703 /* Deallocate typevec array. */
1707 if (ret_type != NULL_TREE && for_method != 2)
1709 /* Add the return type. */
1711 build_mangled_name_for_type (ret_type);
1717 tree n = get_identifier (obstack_base (&scratch_obstack));
1718 if (IDENTIFIER_OPNAME_P (dname))
1719 IDENTIFIER_OPNAME_P (n) = 1;
1724 /* Change the name of a function definition so that it may be
1725 overloaded. NAME is the name of the function to overload,
1726 PARMS is the parameter list (which determines what name the
1727 final function obtains).
1729 FOR_METHOD is 1 if this overload is being performed
1730 for a method, rather than a function type. It is 2 if
1731 this overload is being performed for a constructor. */
1734 build_decl_overload (dname, parms, for_method)
1739 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1740 NULL_TREE, for_method);
1743 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
1746 set_mangled_name_for_decl (decl)
1751 if (processing_template_decl)
1752 /* There's no need to mangle the name of a template function. */
1755 parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
1757 if (DECL_STATIC_FUNCTION_P (decl))
1759 hash_tree_chain (build_pointer_type (DECL_CLASS_CONTEXT (decl)),
1762 /* The only member functions whose type is a FUNCTION_TYPE, rather
1763 than a METHOD_TYPE, should be static members. */
1764 my_friendly_assert (!DECL_CONTEXT (decl)
1765 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl)))
1766 || TREE_CODE (TREE_TYPE (decl)) != FUNCTION_TYPE,
1769 DECL_ASSEMBLER_NAME (decl)
1770 = build_decl_overload (DECL_NAME (decl), parm_types,
1771 DECL_FUNCTION_MEMBER_P (decl)
1772 + DECL_CONSTRUCTOR_P (decl));
1775 /* Build an overload name for the type expression TYPE. */
1778 build_typename_overload (type)
1784 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1786 start_squangling ();
1787 build_mangled_name (type, 0, 1);
1788 id = get_identifier (obstack_base (&scratch_obstack));
1789 IDENTIFIER_OPNAME_P (id) = 1;
1791 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1793 TREE_TYPE (id) = type;
1799 build_overload_with_type (name, type)
1806 start_squangling ();
1807 build_mangled_name (type, 0, 1);
1809 return get_identifier (obstack_base (&scratch_obstack));
1813 get_id_2 (name, name2)
1821 return get_identifier (obstack_base (&scratch_obstack));
1824 /* Print a binfo path T, starting with the most derived class. If
1825 OMIT_LAST is set, drop and return the most derived class. */
1828 build_base_path (t, omit_last)
1832 tree ret = NULL_TREE;
1833 if (BINFO_INHERITANCE_CHAIN (t))
1834 ret = build_base_path (BINFO_INHERITANCE_CHAIN (t), omit_last);
1837 process_overload_item (BINFO_TYPE (t), 0);
1841 /* Return a mangled name for a vlist vtable, using the path of both
1845 get_vlist_vtable_id (base, vbase)
1850 OB_PUTS (VCTABLE_NAME);
1851 build_base_path (base, 0);
1853 /* Since the base path should end where the vbase path starts, we
1854 can omit the most-derived class in the vbase path. Check below
1855 that this really happens. */
1856 last = build_base_path (vbase, 1);
1857 my_friendly_assert (BINFO_TYPE (last) == BINFO_TYPE (base), 990402);
1859 return get_identifier (obstack_base (&scratch_obstack));
1862 /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. If
1863 HAS_VLIST is set, also add the vlist argument. */
1866 build_destructor_name (type, has_vlist)
1871 OB_PUTS (DESTRUCTOR_DECL_PREFIX);
1872 start_squangling ();
1873 build_mangled_name_for_type (type);
1874 /* If we need backwards compatibility, we can get aways by
1875 not linking type-safely, as the dtor will check whether
1876 the argument was provided. */
1877 if (has_vlist && !flag_vtable_thunks_compat)
1878 OB_PUTS (VLIST_TYPE_NAME);
1881 return get_identifier (obstack_base (&scratch_obstack));
1884 /* Given a tree_code CODE, and some arguments (at least one),
1885 attempt to use an overloaded operator on the arguments.
1887 For unary operators, only the first argument need be checked.
1888 For binary operators, both arguments may need to be checked.
1890 Member functions can convert class references to class pointers,
1891 for one-level deep indirection. More than that is not supported.
1892 Operators [](), ()(), and ->() must be member functions.
1894 We call function call building calls with LOOKUP_COMPLAIN if they
1895 are our only hope. This is true when we see a vanilla operator
1896 applied to something of aggregate type. If this fails, we are free
1897 to return `error_mark_node', because we will have reported the
1900 Operators NEW and DELETE overload in funny ways: operator new takes
1901 a single `size' parameter, and operator delete takes a pointer to the
1902 storage being deleted. When overloading these operators, success is
1903 assumed. If there is a failure, report an error message and return
1904 `error_mark_node'. */
1908 build_opfncall (code, flags, xarg1, xarg2, arg3)
1909 enum tree_code code;
1911 tree xarg1, xarg2, arg3;
1913 return build_new_op (code, flags, xarg1, xarg2, arg3);
1916 /* This function takes an identifier, ID, and attempts to figure out what
1917 it means. There are a number of possible scenarios, presented in increasing
1920 1) not in a class's scope
1921 2) in class's scope, member name of the class's method
1922 3) in class's scope, but not a member name of the class
1923 4) in class's scope, member name of a class's variable
1925 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1926 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1928 As a last ditch, try to look up the name as a label and return that
1931 Values which are declared as being of REFERENCE_TYPE are
1932 automatically dereferenced here (as a hack to make the
1933 compiler faster). */
1936 hack_identifier (value, name)
1941 if (value == error_mark_node)
1943 if (current_class_name)
1945 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1946 if (fields == error_mark_node)
1947 return error_mark_node;
1952 fndecl = TREE_VALUE (fields);
1953 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1954 /* I could not trigger this code. MvL */
1955 my_friendly_abort (980325);
1957 if (DECL_CHAIN (fndecl) == NULL_TREE)
1959 warning ("methods cannot be converted to function pointers");
1964 error ("ambiguous request for method pointer `%s'",
1965 IDENTIFIER_POINTER (name));
1966 return error_mark_node;
1971 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1973 return IDENTIFIER_LABEL_VALUE (name);
1975 return error_mark_node;
1978 type = TREE_TYPE (value);
1979 if (TREE_CODE (value) == FIELD_DECL)
1981 if (current_class_ptr == NULL_TREE)
1983 if (current_function_decl
1984 && DECL_STATIC_FUNCTION_P (current_function_decl))
1985 cp_error ("invalid use of member `%D' in static member function",
1988 /* We can get here when processing a bad default
1990 struct S { int a; void f(int i = a); } */
1991 cp_error ("invalid use of member `%D'", value);
1993 return error_mark_node;
1995 TREE_USED (current_class_ptr) = 1;
1997 /* Mark so that if we are in a constructor, and then find that
1998 this field was initialized by a base initializer,
1999 we can emit an error message. */
2000 TREE_USED (value) = 1;
2001 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
2003 else if ((TREE_CODE (value) == FUNCTION_DECL
2004 && DECL_FUNCTION_MEMBER_P (value))
2005 || (TREE_CODE (value) == OVERLOAD
2006 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
2010 if (TREE_CODE (value) == OVERLOAD)
2011 value = OVL_CURRENT (value);
2013 if (IS_SIGNATURE (DECL_CLASS_CONTEXT (value)))
2016 decl = maybe_dummy_object (DECL_CLASS_CONTEXT (value), 0);
2017 value = build_component_ref (decl, name, NULL_TREE, 1);
2019 else if (really_overloaded_fn (value))
2021 else if (TREE_CODE (value) == OVERLOAD)
2022 /* not really overloaded function */
2023 mark_used (OVL_FUNCTION (value));
2024 else if (TREE_CODE (value) == TREE_LIST)
2026 /* Ambiguous reference to base members, possibly other cases?. */
2028 while (t && TREE_CODE (t) == TREE_LIST)
2030 mark_used (TREE_VALUE (t));
2034 else if (TREE_CODE (value) == NAMESPACE_DECL)
2036 cp_error ("use of namespace `%D' as expression", value);
2037 return error_mark_node;
2039 else if (DECL_CLASS_TEMPLATE_P (value))
2041 cp_error ("use of class template `%T' as expression", value);
2042 return error_mark_node;
2047 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
2048 || TREE_CODE (value) == RESULT_DECL)
2050 tree context = decl_function_context (value);
2051 if (context != NULL_TREE && context != current_function_decl
2052 && ! TREE_STATIC (value))
2054 cp_error ("use of %s from containing function",
2055 (TREE_CODE (value) == VAR_DECL
2056 ? "`auto' variable" : "parameter"));
2057 cp_error_at (" `%#D' declared here", value);
2058 value = error_mark_node;
2062 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
2064 if (DECL_LANG_SPECIFIC (value)
2065 && DECL_CLASS_CONTEXT (value) != current_class_type)
2068 register tree context
2069 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
2070 ? DECL_CLASS_CONTEXT (value)
2071 : DECL_CONTEXT (value);
2073 get_base_distance (context, current_class_type, 0, &path);
2074 if (path && !enforce_access (current_class_type, value))
2075 return error_mark_node;
2078 else if (TREE_CODE (value) == TREE_LIST
2079 && TREE_TYPE (value) == error_mark_node)
2081 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2082 IDENTIFIER_POINTER (name));
2083 print_candidates (value);
2084 return error_mark_node;
2087 if (! processing_template_decl)
2088 value = convert_from_reference (value);
2094 make_thunk (function, delta)
2102 if (TREE_CODE (function) != ADDR_EXPR)
2104 func_decl = TREE_OPERAND (function, 0);
2105 if (TREE_CODE (func_decl) != FUNCTION_DECL)
2109 OB_PUTS ("__thunk_");
2118 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl));
2120 thunk_id = get_identifier (obstack_base (&scratch_obstack));
2122 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
2123 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
2125 cp_error ("implementation-reserved name `%D' used", thunk_id);
2127 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
2129 if (thunk == NULL_TREE)
2131 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
2132 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
2133 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
2134 comdat_linkage (thunk);
2135 TREE_SET_CODE (thunk, THUNK_DECL);
2136 DECL_INITIAL (thunk) = function;
2137 THUNK_DELTA (thunk) = delta;
2138 DECL_EXTERNAL (thunk) = 1;
2139 DECL_ARTIFICIAL (thunk) = 1;
2140 /* So that finish_file can write out any thunks that need to be: */
2141 pushdecl_top_level (thunk);
2146 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2149 emit_thunk (thunk_fndecl)
2152 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
2153 int delta = THUNK_DELTA (thunk_fndecl);
2155 if (TREE_ASM_WRITTEN (thunk_fndecl))
2158 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
2160 TREE_ADDRESSABLE (function) = 1;
2161 mark_used (function);
2163 if (current_function_decl)
2166 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
2169 #ifdef ASM_OUTPUT_MI_THUNK
2171 current_function_decl = thunk_fndecl;
2172 /* Make sure we build up its RTL before we go onto the
2173 temporary obstack. */
2174 make_function_rtl (thunk_fndecl);
2175 temporary_allocation ();
2176 DECL_RESULT (thunk_fndecl)
2177 = build_decl (RESULT_DECL, 0, integer_type_node);
2178 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2179 init_function_start (thunk_fndecl, input_filename, lineno);
2180 current_function_is_thunk = 1;
2181 assemble_start_function (thunk_fndecl, fnname);
2182 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
2183 assemble_end_function (thunk_fndecl, fnname);
2184 permanent_allocation (1);
2185 current_function_decl = 0;
2186 #else /* ASM_OUTPUT_MI_THUNK */
2187 /* If we don't have the necessary macro for efficient thunks, generate a
2188 thunk function that just makes a call to the real function.
2189 Unfortunately, this doesn't work for varargs. */
2193 if (varargs_function_p (function))
2194 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2197 /* Set up clone argument trees for the thunk. */
2199 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
2201 tree x = copy_node (a);
2203 DECL_CONTEXT (x) = thunk_fndecl;
2207 DECL_ARGUMENTS (thunk_fndecl) = a;
2208 DECL_RESULT (thunk_fndecl) = NULL_TREE;
2209 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
2210 copy_lang_decl (thunk_fndecl);
2211 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
2212 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
2214 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, 1);
2215 store_parm_decls ();
2216 current_function_is_thunk = 1;
2218 /* Build up the call to the real function. */
2219 t = build_int_2 (delta, -1 * (delta < 0));
2220 TREE_TYPE (t) = signed_type (sizetype);
2221 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
2222 t = expr_tree_cons (NULL_TREE, t, NULL_TREE);
2223 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
2224 t = expr_tree_cons (NULL_TREE, a, t);
2226 t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t);
2227 c_expand_return (t);
2229 finish_function (lineno, 0, 0);
2231 /* Don't let the backend defer this function. */
2232 if (DECL_DEFER_OUTPUT (thunk_fndecl))
2234 output_inline_function (thunk_fndecl);
2235 permanent_allocation (1);
2237 #endif /* ASM_OUTPUT_MI_THUNK */
2240 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
2244 maybe_vlist_ctor_wrapper (fn, definep)
2249 tree arg_types, parms, parm, basetype, pbasetype;
2252 if (!flag_vtable_thunks_compat
2253 || !DECL_CONSTRUCTOR_FOR_PVBASE_P (fn))
2256 arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn));
2257 pbasetype = TREE_VALUE (arg_types);
2258 basetype = TREE_TYPE (pbasetype);
2259 parms = DECL_ARGUMENTS (fn);
2261 /* Skip this, __in_chrg, and _vlist */
2262 arg_types = TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arg_types)));
2265 /* Add __in_charge. */
2266 arg_types = hash_tree_chain (integer_type_node, arg_types);
2268 /* Don't add this to arg_types, as build_cplus_method_type does so. */
2270 fntype = build_cplus_method_type (basetype, TREE_TYPE (TREE_TYPE (fn)),
2273 decl = build_lang_decl (FUNCTION_DECL, DECL_NAME (fn), fntype);
2274 DECL_LANG_SPECIFIC (decl)->decl_flags = DECL_LANG_SPECIFIC (fn)->decl_flags;
2275 DECL_EXTERNAL (decl) = 0;
2276 TREE_PUBLIC (decl) = 1;
2277 DECL_ARTIFICIAL (decl) = 1;
2278 DECL_CONSTRUCTOR_P (decl) = 1;
2279 DECL_CONSTRUCTOR_FOR_VBASE (decl) = CONSTRUCTOR_FOR_VBASE;
2280 /* Claim that this is never a template instantiation. */
2281 DECL_USE_TEMPLATE (decl) = 0;
2282 DECL_TEMPLATE_INFO (decl) = NULL_TREE;
2284 /* Set up clone argument trees for the thunk. */
2285 parms = TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (parms)));
2287 t = build_decl (PARM_DECL, this_identifier, pbasetype);
2288 SET_DECL_ARTIFICIAL (t);
2289 DECL_ARG_TYPE (t) = pbasetype;
2290 DECL_REGISTER (t) = 1;
2291 /* Add __in_charge. */
2292 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
2293 SET_DECL_ARTIFICIAL (parm);
2294 DECL_ARG_TYPE (parm) = integer_type_node;
2295 TREE_CHAIN (parm) = t;
2300 tree x = copy_node (parms);
2302 DECL_CONTEXT (x) = decl;
2304 parms = TREE_CHAIN (parms);
2306 parms = nreverse (t);
2307 DECL_ARGUMENTS (decl) = parms;
2309 DECL_ASSEMBLER_NAME (decl)
2310 = build_decl_overload (DECL_NAME (decl),
2311 TYPE_ARG_TYPES (TREE_TYPE (decl)), 2);
2313 ctors = CLASSTYPE_METHOD_VEC (basetype);
2315 ctors = TREE_VEC_ELT (ctors, 0);
2316 for ( ; ctors; ctors = OVL_NEXT (ctors))
2317 if (DECL_ASSEMBLER_NAME (OVL_CURRENT (ctors))
2318 == DECL_ASSEMBLER_NAME (decl))
2323 add_method (basetype, 0, decl);
2324 cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0, 0);
2327 decl = OVL_CURRENT (ctors);
2329 /* Remember the original function. */
2330 DECL_VLIST_CTOR_WRAPPED (decl) = fn;
2332 /* If this is called from start_method, definep is -1. Then we
2333 are inside the class, and fn is inline by default. */
2336 /* Record that the ctor is being defined, so we also emit the
2338 if (DECL_THIS_INLINE (fn) || (definep == -1))
2340 DECL_THIS_INLINE (decl) = 1;
2341 DECL_INLINE (decl) = 1;
2342 pushdecl_top_level (decl);
2346 TREE_USED (decl) = 1;
2347 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) = 1;
2349 mark_inline_for_output (decl);
2354 emit_vlist_ctor_wrapper (decl)
2359 current_function_is_thunk = 1;
2361 parms = DECL_ARGUMENTS (decl);
2362 fn = DECL_VLIST_CTOR_WRAPPED (decl);
2365 /* Build up the call to the real function. */
2367 /* Push this, __in_charge. */
2368 t = expr_tree_cons (NULL_TREE, parms, t);
2369 parms = TREE_CHAIN (parms);
2370 t = expr_tree_cons (NULL_TREE, parms, t);
2371 parms = TREE_CHAIN (parms);
2372 /* Push 0 as __vlist. */
2373 t = expr_tree_cons (NULL_TREE, vlist_zero_node, t);
2374 /* Push rest of arguments. */
2377 t = expr_tree_cons (NULL_TREE, parms, t);
2378 parms = TREE_CHAIN (parms);
2381 t = build_call (fn, TREE_TYPE (TREE_TYPE (fn)), t);
2382 expand_expr_stmt (t);
2386 /* Code for synthesizing methods which have default semantics defined. */
2388 /* For the anonymous union in TYPE, return the member that is at least as
2389 large as the rest of the members, so we can copy it. */
2392 largest_union_member (type)
2395 tree f, type_size = TYPE_SIZE (type);
2397 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
2398 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
2401 /* We should always find one. */
2402 my_friendly_abort (323);
2406 /* Generate code for default X(X&) constructor. */
2409 do_build_copy_constructor (fndecl)
2412 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2418 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2419 parm = TREE_CHAIN (parm);
2420 if (TYPE_USES_PVBASES (current_class_type))
2421 parm = TREE_CHAIN (parm);
2422 parm = convert_from_reference (parm);
2424 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
2425 && is_empty_class (current_class_type))
2426 /* Don't copy the padding byte; it might not have been allocated
2427 if *this is a base subobject. */;
2428 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2430 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
2431 TREE_SIDE_EFFECTS (t) = 1;
2432 cplus_expand_expr_stmt (t);
2436 tree fields = TYPE_FIELDS (current_class_type);
2437 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2438 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2441 /* Initialize all the base-classes. */
2442 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2444 current_base_init_list
2445 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
2446 for (i = 0; i < n_bases; ++i)
2448 t = TREE_VEC_ELT (binfos, i);
2449 if (TREE_VIA_VIRTUAL (t))
2452 current_base_init_list
2453 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
2456 for (; fields; fields = TREE_CHAIN (fields))
2459 tree field = fields;
2461 if (TREE_CODE (field) != FIELD_DECL)
2465 if (DECL_NAME (field))
2467 if (VFIELD_NAME_P (DECL_NAME (field)))
2469 if (VBASE_NAME_P (DECL_NAME (field)))
2472 /* True for duplicate members. */
2473 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2476 else if ((t = TREE_TYPE (field)) != NULL_TREE
2477 && ANON_UNION_TYPE_P (t)
2478 && TYPE_FIELDS (t) != NULL_TREE)
2482 init = build (COMPONENT_REF, t, init, field);
2483 field = largest_union_member (t);
2485 while ((t = TREE_TYPE (field)) != NULL_TREE
2486 && ANON_UNION_TYPE_P (t)
2487 && TYPE_FIELDS (t) != NULL_TREE);
2492 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2493 init = build_tree_list (NULL_TREE, init);
2495 current_member_init_list
2496 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2498 current_member_init_list = nreverse (current_member_init_list);
2499 current_base_init_list = nreverse (current_base_init_list);
2507 do_build_assign_ref (fndecl)
2510 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2515 parm = convert_from_reference (parm);
2517 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
2518 && is_empty_class (current_class_type))
2519 /* Don't copy the padding byte; it might not have been allocated
2520 if *this is a base subobject. */;
2521 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2523 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
2524 TREE_SIDE_EFFECTS (t) = 1;
2525 cplus_expand_expr_stmt (t);
2529 tree fields = TYPE_FIELDS (current_class_type);
2530 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2531 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2534 for (i = 0; i < n_bases; ++i)
2536 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2537 tree p = convert_to_reference
2538 (build_reference_type (basetype), parm,
2539 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2540 p = convert_from_reference (p);
2541 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2542 build_expr_list (NULL_TREE, p));
2543 expand_expr_stmt (p);
2545 for (; fields; fields = TREE_CHAIN (fields))
2548 tree field = fields;
2550 if (TREE_CODE (field) != FIELD_DECL)
2553 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
2555 if (DECL_NAME (field))
2556 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
2558 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
2561 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2563 if (DECL_NAME (field))
2564 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
2566 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
2570 comp = current_class_ref;
2573 if (DECL_NAME (field))
2575 if (VFIELD_NAME_P (DECL_NAME (field)))
2577 if (VBASE_NAME_P (DECL_NAME (field)))
2580 /* True for duplicate members. */
2581 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2584 else if ((t = TREE_TYPE (field)) != NULL_TREE
2585 && ANON_UNION_TYPE_P (t)
2586 && TYPE_FIELDS (t) != NULL_TREE)
2590 comp = build (COMPONENT_REF, t, comp, field);
2591 init = build (COMPONENT_REF, t, init, field);
2592 field = largest_union_member (t);
2594 while ((t = TREE_TYPE (field)) != NULL_TREE
2595 && ANON_UNION_TYPE_P (t)
2596 && TYPE_FIELDS (t) != NULL_TREE);
2601 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2602 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2604 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2607 c_expand_return (current_class_ref);
2612 synthesize_method (fndecl)
2615 int nested = (current_function_decl != NULL_TREE);
2616 tree context = hack_decl_function_context (fndecl);
2618 /* If this is a wrapper around a undefined vlist ctor, don't emit it
2619 even if it is used. */
2620 if (DECL_VLIST_CTOR_WRAPPER_P (fndecl))
2622 tree orig_fn = DECL_VLIST_CTOR_WRAPPED (fndecl);
2623 mark_used (orig_fn);
2624 if (DECL_INITIAL (orig_fn) == NULL_TREE)
2629 import_export_decl (fndecl);
2632 push_to_top_level ();
2634 push_cp_function_context (context);
2636 interface_unknown = 1;
2637 start_function (NULL_TREE, fndecl, NULL_TREE, 1);
2638 store_parm_decls ();
2640 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2641 do_build_assign_ref (fndecl);
2642 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2646 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2647 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2648 arg_chain = TREE_CHAIN (arg_chain);
2649 else if (DECL_CONSTRUCTOR_FOR_PVBASE_P (fndecl))
2650 arg_chain = TREE_CHAIN (TREE_CHAIN (arg_chain));
2651 if (DECL_VLIST_CTOR_WRAPPER_P (fndecl))
2652 emit_vlist_ctor_wrapper (fndecl);
2653 else if (arg_chain != void_list_node)
2654 do_build_copy_constructor (fndecl);
2655 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2659 finish_function (lineno, 0, nested);
2661 extract_interface_info ();
2663 pop_from_top_level ();
2665 pop_cp_function_context (context);