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"
45 /* TREE_LIST of the current inline functions that need to be
47 struct pending_inline
*pending_inlines
;
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
54 /* Obstack where we build text strings for overloading, etc. */
55 static struct obstack scratch_obstack
;
56 static char *scratch_firstobj
;
58 static void icat
PROTO((HOST_WIDE_INT
));
59 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
60 static int old_backref_index
PROTO((tree
));
61 static int flush_repeats
PROTO((int, tree
));
62 static void build_overload_identifier
PROTO((tree
));
63 static void build_overload_nested_name
PROTO((tree
));
64 static void build_overload_int
PROTO((tree
, int));
65 static void build_overload_identifier
PROTO((tree
));
66 static void build_qualified_name
PROTO((tree
));
67 static void build_overload_value
PROTO((tree
, tree
, int));
68 static void issue_nrepeats
PROTO((int, tree
));
69 static char *build_mangled_name
PROTO((tree
,int,int));
70 static void process_modifiers
PROTO((tree
));
71 static void process_overload_item
PROTO((tree
,int));
72 static void do_build_assign_ref
PROTO((tree
));
73 static void do_build_copy_constructor
PROTO((tree
));
74 static tree largest_union_member
PROTO((tree
));
75 static void build_template_template_parm_names
PROTO((tree
));
76 static void build_template_parm_names
PROTO((tree
, tree
));
77 static void build_underscore_int
PROTO((int));
78 static void start_squangling
PROTO((void));
79 static void end_squangling
PROTO((void));
80 static int check_ktype
PROTO((tree
, int));
81 static int issue_ktype
PROTO((tree
));
82 static void build_overload_scope_ref
PROTO((tree
));
83 static void build_mangled_template_parm_index
PROTO((char *, tree
));
84 #if HOST_BITS_PER_WIDE_INT >= 64
85 static void build_mangled_C9x_name
PROTO((int));
87 static int is_back_referenceable_type
PROTO((tree
));
88 static int check_btype
PROTO((tree
));
89 static void build_mangled_name_for_type
PROTO((tree
));
90 static void build_mangled_name_for_type_with_Gcode
PROTO((tree
, int));
92 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
93 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
94 # define OB_PUTC2(C1,C2) \
95 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
96 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
97 # define OB_PUTID(ID) \
98 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
99 IDENTIFIER_LENGTH (ID)))
100 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
101 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
102 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
107 gcc_obstack_init (&scratch_obstack
);
108 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
111 /* This must be large enough to hold any printed integer or floating-point
113 static char digit_buffer
[128];
115 /* Move inline function definitions out of structure so that they
116 can be processed normally. CNAME is the name of the class
117 we are working from, METHOD_LIST is the list of method lists
118 of the structure. We delete friend methods here, after
119 saving away their inline function definitions (if any). */
122 do_inline_function_hair (type
, friend_list
)
123 tree type
, friend_list
;
125 tree method
= TYPE_METHODS (type
);
127 if (method
&& TREE_CODE (method
) == TREE_VEC
)
129 if (TREE_VEC_ELT (method
, 1))
130 method
= TREE_VEC_ELT (method
, 1);
131 else if (TREE_VEC_ELT (method
, 0))
132 method
= TREE_VEC_ELT (method
, 0);
134 method
= TREE_VEC_ELT (method
, 2);
139 /* Do inline member functions. */
140 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
145 my_friendly_assert (info
->fndecl
== method
, 238);
146 args
= DECL_ARGUMENTS (method
);
149 DECL_CONTEXT (args
) = method
;
150 args
= TREE_CHAIN (args
);
153 method
= TREE_CHAIN (method
);
157 tree fndecl
= TREE_VALUE (friend_list
);
158 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
163 my_friendly_assert (info
->fndecl
== fndecl
, 239);
164 args
= DECL_ARGUMENTS (fndecl
);
167 DECL_CONTEXT (args
) = fndecl
;
168 args
= TREE_CHAIN (args
);
172 friend_list
= TREE_CHAIN (friend_list
);
176 /* Here is where overload code starts. */
178 /* type tables for K and B type compression */
179 static tree
*btypelist
= NULL
;
180 static tree
*ktypelist
= NULL
;
181 static int maxbsize
= 0;
182 static int maxksize
= 0;
184 /* number of each type seen */
185 static int maxbtype
= 0;
186 static int maxktype
= 0;
188 /* Array of types seen so far in top-level call to `build_mangled_name'.
189 Allocated and deallocated by caller. */
190 static tree
*typevec
= NULL
;
191 static int typevec_size
;
193 /* Number of types interned by `build_mangled_name' so far. */
194 static int maxtype
= 0;
196 /* Nonzero if we should not try folding parameter types. */
199 /* This appears to be set to true if an underscore is required to be
200 comcatenated before another number can be outputed. */
201 static int numeric_output_need_bar
;
206 if (flag_do_squangling
)
213 btypelist
= (tree
*)xmalloc (sizeof (tree
) * maxbsize
);
214 ktypelist
= (tree
*)xmalloc (sizeof (tree
) * maxksize
);
221 if (flag_do_squangling
)
236 /* Code to concatenate an asciified integer to a string. */
242 unsigned HOST_WIDE_INT ui
;
244 /* Handle this case first, to go really quickly. For many common values,
245 the result of ui/10 below is 1. */
263 OB_PUTC ('0' + (ui
% 10));
268 HOST_WIDE_INT lo
, hi
;
270 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
279 uhi
= (lo
== 0 ? -hi
: -hi
-1);
283 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
288 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
291 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
294 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
298 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
303 /* Returns the index of TYPE in the typevec, or -1 if it's not there. */
306 old_backref_index (type
)
311 if (! is_back_referenceable_type (type
))
314 /* The entry for this parm is at maxtype-1, so don't look there for
315 something to repeat. */
316 for (tindex
= 0; tindex
< maxtype
- 1; ++tindex
)
317 if (same_type_p (typevec
[tindex
], type
))
320 if (tindex
== maxtype
- 1)
326 /* Old mangling style: If TYPE has already been used in the parameter list,
327 emit a backward reference and return non-zero; otherwise, return 0.
329 NREPEATS is the number of repeats we've recorded of this type, or 0 if
330 this is the first time we've seen it and we're just looking to see if
331 it had been used before. */
334 flush_repeats (nrepeats
, type
)
338 int tindex
= old_backref_index (type
);
342 my_friendly_assert (nrepeats
== 0, 990316);
362 /* Returns nonzero iff this is a type to which we will want to make
363 back-references (using the `B' code). */
366 is_back_referenceable_type (type
)
369 /* For some reason, the Java folks don't want back refs on these. */
370 if (TYPE_FOR_JAVA (type
))
373 switch (TREE_CODE (type
))
379 /* These types have single-character manglings, so there's no
380 point in generating back-references. */
383 case TEMPLATE_TYPE_PARM
:
384 /* It would be a bit complex to demangle signatures correctly if
385 we generated back-references to these, and the manglings of
386 type parameters are short. */
394 /* Issue the squangling code indicating NREPEATS repetitions of TYPE,
395 which was the last parameter type output. */
398 issue_nrepeats (nrepeats
, type
)
402 if (nrepeats
== 1 && !is_back_referenceable_type (type
))
403 /* For types whose manglings are short, don't bother using the
404 repetition code if there's only one repetition, since the
405 repetition code will be about as long as the ordinary mangling. */
406 build_mangled_name_for_type (type
);
416 /* Check to see if a tree node has been entered into the Kcode typelist.
417 If not, add it. Returns -1 if it isn't found, otherwise returns the
421 check_ktype (node
, add
)
426 tree localnode
= node
;
428 if (ktypelist
== NULL
)
431 if (TREE_CODE (node
) == TYPE_DECL
)
432 localnode
= TREE_TYPE (node
);
434 for (x
=0; x
< maxktype
; x
++)
436 if (same_type_p (localnode
, ktypelist
[x
]))
439 /* Didn't find it, so add it here. */
442 if (maxksize
<= maxktype
)
444 maxksize
= maxksize
* 3 / 2;
445 ktypelist
= (tree
*)xrealloc (ktypelist
, sizeof (tree
) * maxksize
);
447 ktypelist
[maxktype
++] = localnode
;
458 kindex
= check_ktype (decl
, FALSE
);
470 /* Build a representation for DECL, which may be an entity not at
471 global scope. If so, a marker indicating that the name is
472 qualified has already been output, but the qualifying context has
476 build_overload_nested_name (decl
)
481 if (ktypelist
&& issue_ktype (decl
))
484 if (decl
== global_namespace
)
487 context
= CP_DECL_CONTEXT (decl
);
489 /* try to issue a K type, and if we can't continue the normal path */
490 if (!(ktypelist
&& issue_ktype (context
)))
492 /* For a template type parameter, we want to output an 'Xn'
493 rather than 'T' or some such. */
494 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
495 || TREE_CODE (context
) == TEMPLATE_TEMPLATE_PARM
)
496 build_mangled_name_for_type (context
);
499 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
500 context
= TYPE_NAME (context
);
501 build_overload_nested_name (context
);
505 if (TREE_CODE (decl
) == FUNCTION_DECL
)
507 tree name
= DECL_ASSEMBLER_NAME (decl
);
510 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
513 if (numeric_output_need_bar
)
515 icat (strlen (label
));
517 numeric_output_need_bar
= 1;
519 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
520 build_overload_identifier (DECL_NAME (decl
));
522 build_overload_identifier (decl
);
525 /* Output the decimal representation of I. If I > 9, the decimal
526 representation is preceeded and followed by an underscore. */
529 build_underscore_int (i
)
540 build_overload_scope_ref (value
)
544 numeric_output_need_bar
= 0;
545 build_mangled_name_for_type (TREE_OPERAND (value
, 0));
546 build_overload_identifier (TREE_OPERAND (value
, 1));
549 /* Encoding for an INTEGER_CST value. */
552 build_overload_int (value
, in_template
)
556 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
558 if (TREE_CODE (value
) == SCOPE_REF
)
560 build_overload_scope_ref (value
);
565 numeric_output_need_bar
= 0;
567 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value
))))
570 int operands
= tree_code_length
[(int) TREE_CODE (value
)];
574 id
= ansi_opname
[(int) TREE_CODE (value
)];
575 my_friendly_assert (id
!= NULL_TREE
, 0);
576 name
= IDENTIFIER_POINTER (id
);
577 if (name
[0] != '_' || name
[1] != '_')
578 /* On some erroneous inputs, we can get here with VALUE a
579 LOOKUP_EXPR. In that case, the NAME will be the
580 identifier for "<invalid operator>". We must survive
581 this routine in order to issue a sensible error
582 message, so we fall through to the case below. */
585 for (i
= 0; i
< operands
; ++i
)
590 /* We just outputted either the `E' or the name of the
592 numeric_output_need_bar
= 0;
595 /* Skip the leading underscores. */
598 operand
= TREE_OPERAND (value
, i
);
599 tc
= TREE_CODE (operand
);
601 if (TREE_CODE_CLASS (tc
) == 't')
602 /* We can get here with sizeof, e.g.:
604 template <class T> void f(A<sizeof(T)>); */
605 build_mangled_name_for_type (operand
);
606 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc
)))
607 build_overload_int (operand
, in_template
);
609 build_overload_value (TREE_TYPE (operand
),
616 /* We don't ever want this output, but it's
617 inconvenient not to be able to build the string.
618 This should cause assembler errors we'll notice. */
622 sprintf (digit_buffer
, " *%d", n
++);
623 OB_PUTCP (digit_buffer
);
627 numeric_output_need_bar
= 0;
631 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
632 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
634 if (TREE_INT_CST_HIGH (value
)
635 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
637 /* need to print a DImode value in decimal */
638 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
639 numeric_output_need_bar
= 1;
642 /* else fall through to print in smaller mode */
644 /* Wordsize or smaller */
645 icat (TREE_INT_CST_LOW (value
));
646 numeric_output_need_bar
= 1;
650 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
651 supplied in INDEX. */
654 build_mangled_template_parm_index (s
, index
)
659 build_underscore_int (TEMPLATE_PARM_IDX (index
));
660 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
661 representation of the function from the point of view of its
663 build_underscore_int (TEMPLATE_PARM_LEVEL (index
));
667 /* Mangling for C9X integer types (and Cygnus extensions for 128-bit
668 and other types) is based on the letter "I" followed by the hex
669 representations of the bitsize for the type in question. For
670 encodings that result in larger than two digits, a leading and
671 trailing underscore is added.
682 int256_t = 100 = I_100_
683 int512_t = 200 = I_200_
685 Given an integer in decimal format, mangle according to this scheme. */
687 #if HOST_BITS_PER_WIDE_INT >= 64
689 build_mangled_C9x_name (bits
)
692 char mangled
[10] = "";
695 sprintf (mangled
, "I_%x_", bits
);
697 sprintf (mangled
, "I%.2x", bits
);
704 build_overload_value (type
, value
, in_template
)
708 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type
)) == 't', 0);
710 while (TREE_CODE (value
) == NON_LVALUE_EXPR
711 || TREE_CODE (value
) == NOP_EXPR
)
712 value
= TREE_OPERAND (value
, 0);
714 if (numeric_output_need_bar
)
717 numeric_output_need_bar
= 0;
720 if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
722 build_mangled_template_parm_index ("Y", value
);
726 if (TYPE_PTRMEM_P (type
))
728 if (TREE_CODE (value
) != PTRMEM_CST
)
729 /* We should have already rejected this pointer to member,
730 since it is not a constant. */
731 my_friendly_abort (0);
733 /* Get the actual FIELD_DECL. */
734 value
= PTRMEM_CST_MEMBER (value
);
735 my_friendly_assert (TREE_CODE (value
) == FIELD_DECL
, 0);
737 /* Output the name of the field. */
738 build_overload_identifier (DECL_NAME (value
));
742 switch (TREE_CODE (type
))
748 build_overload_int (value
, in_template
);
754 char *bufp
= digit_buffer
;
756 pedwarn ("ANSI C++ forbids floating-point template arguments");
758 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
759 val
= TREE_REAL_CST (value
);
760 if (REAL_VALUE_ISNAN (val
))
762 sprintf (bufp
, "NaN");
766 if (REAL_VALUE_NEGATIVE (val
))
768 val
= REAL_VALUE_NEGATE (val
);
771 if (REAL_VALUE_ISINF (val
))
773 sprintf (bufp
, "Infinity");
777 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
778 bufp
= (char *) index (bufp
, 'e');
780 strcat (digit_buffer
, "e0");
806 #ifdef NO_DOT_IN_LABEL
807 bufp
= (char *) index (bufp
, '.');
813 OB_PUTCP (digit_buffer
);
814 numeric_output_need_bar
= 1;
818 if (TREE_CODE (value
) == INTEGER_CST
)
820 build_overload_int (value
, in_template
);
823 else if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
825 build_mangled_template_parm_index ("", value
);
826 numeric_output_need_bar
= 1;
830 value
= TREE_OPERAND (value
, 0);
835 if (TREE_CODE (value
) == VAR_DECL
)
837 my_friendly_assert (DECL_NAME (value
) != 0, 245);
838 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
841 else if (TREE_CODE (value
) == FUNCTION_DECL
)
843 my_friendly_assert (DECL_NAME (value
) != 0, 246);
844 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
847 else if (TREE_CODE (value
) == SCOPE_REF
)
848 build_overload_scope_ref (value
);
850 my_friendly_abort (71);
851 break; /* not really needed */
860 my_friendly_assert (TYPE_PTRMEMFUNC_P (type
), 0);
861 my_friendly_assert (TREE_CODE (value
) == PTRMEM_CST
, 0);
863 expand_ptrmemfunc_cst (value
, &delta
, &idx
, &pfn
, &delta2
);
864 build_overload_int (delta
, in_template
);
866 build_overload_int (idx
, in_template
);
870 numeric_output_need_bar
= 0;
871 build_overload_identifier (DECL_ASSEMBLER_NAME
872 (PTRMEM_CST_MEMBER (value
)));
877 build_overload_int (delta2
, in_template
);
883 sorry ("conversion of %s as template parameter",
884 tree_code_name
[(int) TREE_CODE (type
)]);
885 my_friendly_abort (72);
890 /* Add encodings for the declaration of template template parameters.
891 PARMLIST must be a TREE_VEC. */
894 build_template_template_parm_names (parmlist
)
899 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
900 nparms
= TREE_VEC_LENGTH (parmlist
);
902 for (i
= 0; i
< nparms
; i
++)
904 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
905 if (TREE_CODE (parm
) == TYPE_DECL
)
907 /* This parameter is a type. */
910 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
912 /* This parameter is a template. */
914 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
917 /* It's a PARM_DECL. */
918 build_mangled_name_for_type (TREE_TYPE (parm
));
923 /* Add encodings for the vector of template parameters in PARMLIST,
924 given the vector of arguments to be substituted in ARGLIST. */
927 build_template_parm_names (parmlist
, arglist
)
932 tree inner_args
= innermost_args (arglist
);
934 nparms
= TREE_VEC_LENGTH (parmlist
);
936 for (i
= 0; i
< nparms
; i
++)
938 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
939 tree arg
= TREE_VEC_ELT (inner_args
, i
);
940 if (TREE_CODE (parm
) == TYPE_DECL
)
942 /* This parameter is a type. */
944 build_mangled_name_for_type (arg
);
946 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
948 /* This parameter is a template. */
949 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
950 /* Output parameter declaration, argument index and level. */
951 build_mangled_name_for_type (arg
);
954 /* A TEMPLATE_DECL node, output the parameter declaration
958 build_template_template_parm_names
959 (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
960 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
961 OB_PUTID (DECL_NAME (arg
));
966 parm
= tsubst (parm
, arglist
, /*complain=*/1, NULL_TREE
);
967 /* It's a PARM_DECL. */
968 build_mangled_name_for_type (TREE_TYPE (parm
));
969 build_overload_value (TREE_TYPE (parm
), arg
,
970 uses_template_parms (arglist
));
975 /* Output the representation for NAME, which is either a TYPE_DECL or
979 build_overload_identifier (name
)
982 if (TREE_CODE (name
) == TYPE_DECL
983 && CLASS_TYPE_P (TREE_TYPE (name
))
984 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
985 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
986 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
990 /* NAME is the TYPE_DECL for a template specialization. */
991 tree
template, parmlist
, arglist
, tname
;
992 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
));
993 arglist
= CLASSTYPE_TI_ARGS (TREE_TYPE (name
));
994 tname
= DECL_NAME (template);
995 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
997 icat (IDENTIFIER_LENGTH (tname
));
999 build_template_parm_names (parmlist
, arglist
);
1003 if (TREE_CODE (name
) == TYPE_DECL
)
1004 name
= DECL_NAME (name
);
1005 if (numeric_output_need_bar
)
1008 numeric_output_need_bar
= 0;
1010 icat (IDENTIFIER_LENGTH (name
));
1015 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
1016 the mangling for it. Used by build_mangled_name and build_static_name. */
1019 build_qualified_name (decl
)
1025 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
1026 decl
= TYPE_NAME (decl
);
1028 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1029 if (TREE_CODE (decl
) == TYPE_DECL
1030 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
) && !flag_do_squangling
)
1032 tree id
= DECL_ASSEMBLER_NAME (decl
);
1034 if (ISDIGIT (IDENTIFIER_POINTER (id
) [IDENTIFIER_LENGTH (id
) - 1]))
1035 numeric_output_need_bar
= 1;
1040 /* If we can't find a Ktype, do it the hard way. */
1041 if (check_ktype (context
, FALSE
) == -1)
1043 /* Count type and namespace scopes. */
1046 context
= CP_DECL_CONTEXT (context
);
1047 if (context
== global_namespace
)
1050 if (check_ktype (context
, FALSE
) != -1)
1053 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
1054 context
= TYPE_NAME (context
);
1061 build_underscore_int (i
);
1062 numeric_output_need_bar
= 0;
1064 build_overload_nested_name (decl
);
1067 /* Output the mangled representation for TYPE. If EXTRA_GCODE is
1068 non-zero, mangled names for structure/union types are intentionally
1069 mangled differently from the method described in the ARM. */
1072 build_mangled_name_for_type_with_Gcode (type
, extra_Gcode
)
1076 if (TYPE_PTRMEMFUNC_P (type
))
1077 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
1078 process_modifiers (type
);
1079 process_overload_item (type
, extra_Gcode
);
1082 /* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1086 build_mangled_name_for_type (type
)
1089 build_mangled_name_for_type_with_Gcode (type
, 0);
1092 /* Given a list of parameters in PARMTYPES, create an unambiguous
1093 overload string. Should distinguish any type that C (or C++) can
1094 distinguish. I.e., pointers to functions are treated correctly.
1096 Caller must deal with whether a final `e' goes on the end or not.
1098 Any default conversions must take place before this function
1101 BEGIN and END control initialization and finalization of the
1102 obstack where we build the string. */
1105 build_overload_name (parmtypes
, begin
, end
)
1110 start_squangling ();
1111 ret
= build_mangled_name (parmtypes
, begin
, end
);
1116 /* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1117 TREE_LIST, then it is a list of parameter types. Otherwise,
1118 PARMTYPES must be a single type. */
1121 build_mangled_name (parmtypes
, begin
, end
)
1128 if (TREE_CODE (parmtypes
) != TREE_LIST
)
1129 /* There is only one type. */
1130 build_mangled_name_for_type (parmtypes
);
1133 /* There are several types in a parameter list. */
1135 int old_style_repeats
= !flag_do_squangling
&& !nofold
&& typevec
;
1136 tree last_type
= NULL_TREE
;
1138 for (; parmtypes
&& parmtypes
!= void_list_node
;
1139 parmtypes
= TREE_CHAIN (parmtypes
))
1141 /* We used to call canonical_type_variant here, but that isn't
1142 good enough; it doesn't handle pointers to typedef types. So
1143 we can't just set TREE_USED to say we've seen a type already;
1144 we have to check each of the earlier types with same_type_p. */
1145 tree parmtype
= TREE_VALUE (parmtypes
);
1147 if (old_style_repeats
)
1149 /* Every argument gets counted. */
1150 my_friendly_assert (maxtype
< typevec_size
, 387);
1151 typevec
[maxtype
++] = parmtype
;
1154 if (last_type
&& same_type_p (parmtype
, last_type
))
1156 if (flag_do_squangling
1157 || (old_style_repeats
1158 && is_back_referenceable_type (parmtype
)))
1160 /* The next type is the same as this one. Keep
1161 track of the repetition, and output the repeat
1167 else if (nrepeats
!= 0)
1169 /* Indicate how many times the previous parameter was
1171 if (old_style_repeats
)
1172 flush_repeats (nrepeats
, last_type
);
1174 issue_nrepeats (nrepeats
, last_type
);
1178 last_type
= parmtype
;
1180 /* Note that for bug-compatibility with 2.7.2, we can't build up
1181 repeats of types other than the most recent one. So we call
1182 flush_repeats every round, if we get this far. */
1183 if (old_style_repeats
&& flush_repeats (0, parmtype
))
1186 /* Output the PARMTYPE. */
1187 build_mangled_name_for_type_with_Gcode (parmtype
, 1);
1190 /* Output the repeat count for the last parameter, if
1194 if (old_style_repeats
)
1195 flush_repeats (nrepeats
, last_type
);
1197 issue_nrepeats (nrepeats
, last_type
);
1202 /* The parameter list ends in an ellipsis. */
1208 return (char *)obstack_base (&scratch_obstack
);
1211 /* Emit modifiers such as constant, read-only, and volatile. */
1214 process_modifiers (parmtype
)
1217 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1218 we describe types recursively; we will get the `const' in
1219 `const int ()[10]' when processing the `const int' part. */
1220 if (TYPE_READONLY (parmtype
))
1222 if (TREE_CODE (parmtype
) == INTEGER_TYPE
1223 && parmtype
!= char_type_node
1224 && parmtype
!= wchar_type_node
1225 && (TYPE_MAIN_VARIANT (parmtype
)
1226 == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
1227 && ! TYPE_FOR_JAVA (parmtype
))
1229 if (TYPE_VOLATILE (parmtype
))
1231 /* It would be better to use `R' for `restrict', but that's already
1232 used for reference types. And `r' is used for `long double'. */
1233 if (TYPE_RESTRICT (parmtype
))
1237 /* Check to see if TYPE has been entered into the Bcode typelist. If
1238 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1239 to the list of back-referenceable types and return 0. */
1247 if (btypelist
== NULL
)
1250 if (!is_back_referenceable_type (type
))
1253 for (x
= 0; x
< maxbtype
; x
++)
1254 if (same_type_p (type
, btypelist
[x
]))
1263 if (maxbsize
<= maxbtype
)
1265 /* Enlarge the table. */
1266 maxbsize
= maxbsize
* 3 / 2;
1267 btypelist
= (tree
*)xrealloc (btypelist
, sizeof (tree
) * maxbsize
);
1270 /* Register the TYPE. */
1271 btypelist
[maxbtype
++] = type
;
1276 /* Emit the correct code for various node types. */
1279 process_overload_item (parmtype
, extra_Gcode
)
1283 numeric_output_need_bar
= 0;
1285 /* Our caller should have already handed any qualifiers, so pull out the
1286 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1287 for arrays, because they are transparent to qualifiers. Sigh. */
1288 if (TREE_CODE (parmtype
) == ARRAY_TYPE
)
1289 parmtype
= canonical_type_variant (parmtype
);
1291 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1293 /* These tree types are considered modifiers for B code squangling,
1294 and therefore should not get entries in the Btypelist. They are,
1295 however, repeatable types. */
1297 switch (TREE_CODE (parmtype
))
1299 case REFERENCE_TYPE
:
1304 #if PARM_CAN_BE_ARRAY_TYPE
1307 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
1311 tree length
= array_type_nelts (parmtype
);
1312 if (TREE_CODE (length
) != INTEGER_CST
|| flag_do_squangling
)
1314 length
= fold (build (PLUS_EXPR
, TREE_TYPE (length
),
1315 length
, integer_one_node
));
1316 STRIP_NOPS (length
);
1318 build_overload_value (sizetype
, length
, 1);
1320 if (numeric_output_need_bar
&& ! flag_do_squangling
)
1332 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1340 if (flag_do_squangling
&& check_btype (parmtype
))
1341 /* If PARMTYPE is already in the list of back-referenceable types,
1342 then check_btype will output the appropriate reference, and
1343 there's nothing more to do. */
1346 switch (TREE_CODE (parmtype
))
1350 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype
));
1352 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1358 tree parms
= TYPE_ARG_TYPES (parmtype
);
1360 /* Rather than implementing a reentrant TYPEVEC, we turn off
1361 repeat codes here, unless we're squangling. Squangling
1362 doesn't make use of the TYPEVEC, so there's no reentrancy
1364 int old_nofold
= nofold
;
1365 if (!flag_do_squangling
)
1368 if (TREE_CODE (parmtype
) == METHOD_TYPE
)
1370 /* Mark this as a method. */
1372 /* Output the class of which this method is a member. */
1373 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype
));
1374 /* Output any qualifiers for the `this' parameter. */
1375 process_modifiers (TREE_TYPE (TREE_VALUE (parms
)));
1378 /* Output the parameter types. */
1380 if (parms
== NULL_TREE
)
1382 else if (parms
== void_list_node
)
1385 build_mangled_name (parms
, 0, 0);
1387 /* Output the return type. */
1389 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1391 nofold
= old_nofold
;
1396 if (parmtype
== integer_type_node
1397 || parmtype
== unsigned_type_node
1398 || parmtype
== java_int_type_node
)
1400 else if (parmtype
== long_integer_type_node
1401 || parmtype
== long_unsigned_type_node
)
1403 else if (parmtype
== short_integer_type_node
1404 || parmtype
== short_unsigned_type_node
1405 || parmtype
== java_short_type_node
)
1407 else if (parmtype
== signed_char_type_node
)
1412 else if (parmtype
== char_type_node
1413 || parmtype
== unsigned_char_type_node
1414 || parmtype
== java_byte_type_node
)
1416 else if (parmtype
== wchar_type_node
1417 || parmtype
== java_char_type_node
)
1419 else if (parmtype
== long_long_integer_type_node
1420 || parmtype
== long_long_unsigned_type_node
1421 || parmtype
== java_long_type_node
)
1423 else if (parmtype
== java_boolean_type_node
)
1425 #if HOST_BITS_PER_WIDE_INT >= 64
1426 else if (parmtype
== intTI_type_node
1427 || parmtype
== unsigned_intTI_type_node
)
1429 /* Should just check a flag here instead of specific
1430 *_type_nodes, because all C9x types could use this. */
1431 int bits
= TREE_INT_CST_LOW (TYPE_SIZE (parmtype
));
1432 build_mangled_C9x_name (bits
);
1436 my_friendly_abort (73);
1444 if (parmtype
== long_double_type_node
)
1446 else if (parmtype
== double_type_node
1447 || parmtype
== java_double_type_node
)
1449 else if (parmtype
== float_type_node
1450 || parmtype
== java_float_type_node
)
1452 else my_friendly_abort (74);
1457 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1464 case ERROR_MARK
: /* not right, but nothing is anyway */
1467 /* have to do these */
1472 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1473 /* drop through into next case */
1477 tree name
= TYPE_NAME (parmtype
);
1479 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1481 build_qualified_name (name
);
1486 /* This will take some work. */
1490 case TEMPLATE_TEMPLATE_PARM
:
1491 /* Find and output the original template parameter
1493 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype
))
1495 build_mangled_template_parm_index ("tzX",
1496 TEMPLATE_TYPE_PARM_INDEX
1498 build_template_parm_names
1499 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype
)),
1500 TYPE_TI_ARGS (parmtype
));
1504 build_mangled_template_parm_index ("ZzX",
1505 TEMPLATE_TYPE_PARM_INDEX
1507 build_template_template_parm_names
1508 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1512 case TEMPLATE_TYPE_PARM
:
1513 build_mangled_template_parm_index ("X",
1514 TEMPLATE_TYPE_PARM_INDEX
1519 /* When mangling the type of a function template whose
1520 declaration looks like:
1522 template <class T> void foo(typename T::U)
1524 we have to mangle these. */
1525 build_qualified_name (parmtype
);
1529 my_friendly_abort (75);
1534 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1535 be either a class TYPE or a FUNCTION_DECL. */
1538 build_static_name (context
, name
)
1542 numeric_output_need_bar
= 0;
1543 start_squangling ();
1546 build_qualified_name (context
);
1549 OB_PUTS ("__static_");
1550 build_qualified_name (context
);
1557 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1560 /* FOR_METHOD should be 1 if the declaration in question is for a member
1561 of a class (including a static member) and 2 if the declaration is
1562 for a constructor. */
1564 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1573 char *name
= IDENTIFIER_POINTER (dname
);
1575 /* member operators new and delete look like methods at this point. */
1576 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1577 && TREE_CHAIN (parms
) == void_list_node
)
1579 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1580 return get_identifier ("__builtin_delete");
1581 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1582 return get_identifier ("__builtin_vec_delete");
1583 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1584 return get_identifier ("__builtin_new");
1585 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1586 return get_identifier ("__builtin_vec_new");
1589 start_squangling ();
1591 if (for_method
!= 2)
1593 /* Otherwise, we can divine that this is a constructor,
1594 and figure out its name without any extra encoding. */
1596 OB_PUTC2 ('_', '_');
1597 numeric_output_need_bar
= 0;
1602 build_template_parm_names (tparms
, targs
);
1605 else if (!for_method
&& current_namespace
== global_namespace
)
1606 /* XXX this works only if we call this in the same namespace
1607 as the declaration. Unfortunately, we don't have the _DECL,
1611 if (!for_method
&& current_namespace
!= global_namespace
)
1612 /* qualify with namespace */
1613 build_qualified_name (current_namespace
);
1615 if (parms
== NULL_TREE
)
1617 else if (parms
== void_list_node
)
1621 if (!flag_do_squangling
)
1623 /* Allocate typevec array. */
1625 typevec_size
= list_length (parms
);
1626 if (!for_method
&& current_namespace
!= global_namespace
)
1627 /* The namespace of a global function needs one slot. */
1629 typevec
= (tree
*)alloca (typevec_size
* sizeof (tree
));
1635 tree this_type
= TREE_VALUE (parms
);
1637 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1638 this_type
= SIGNATURE_TYPE (this_type
);
1640 this_type
= TREE_TYPE (this_type
);
1642 build_mangled_name_for_type (this_type
);
1644 if (!flag_do_squangling
)
1646 my_friendly_assert (maxtype
< typevec_size
, 387);
1647 typevec
[maxtype
++] = this_type
;
1650 if (TREE_CHAIN (parms
))
1651 build_mangled_name (TREE_CHAIN (parms
), 0, 0);
1657 /* the namespace qualifier for a global function
1658 will count as type */
1659 if (current_namespace
!= global_namespace
1660 && !flag_do_squangling
)
1662 my_friendly_assert (maxtype
< typevec_size
, 387);
1663 typevec
[maxtype
++] = current_namespace
;
1665 build_mangled_name (parms
, 0, 0);
1668 if (!flag_do_squangling
)
1669 /* Deallocate typevec array. */
1673 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1675 /* Add the return type. */
1677 build_mangled_name_for_type (ret_type
);
1683 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1684 if (IDENTIFIER_OPNAME_P (dname
))
1685 IDENTIFIER_OPNAME_P (n
) = 1;
1690 /* Change the name of a function definition so that it may be
1691 overloaded. NAME is the name of the function to overload,
1692 PARMS is the parameter list (which determines what name the
1693 final function obtains).
1695 FOR_METHOD is 1 if this overload is being performed
1696 for a method, rather than a function type. It is 2 if
1697 this overload is being performed for a constructor. */
1700 build_decl_overload (dname
, parms
, for_method
)
1705 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1706 NULL_TREE
, for_method
);
1709 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
1712 set_mangled_name_for_decl (decl
)
1717 if (processing_template_decl
)
1718 /* There's no need to mangle the name of a template function. */
1721 parm_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
1723 if (DECL_STATIC_FUNCTION_P (decl
))
1725 hash_tree_chain (build_pointer_type (DECL_CLASS_CONTEXT (decl
)),
1728 /* The only member functions whose type is a FUNCTION_TYPE, rather
1729 than a METHOD_TYPE, should be static members. */
1730 my_friendly_assert (!DECL_CONTEXT (decl
)
1731 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl
)))
1732 || TREE_CODE (TREE_TYPE (decl
)) != FUNCTION_TYPE
,
1735 DECL_ASSEMBLER_NAME (decl
)
1736 = build_decl_overload (DECL_NAME (decl
), parm_types
,
1737 DECL_FUNCTION_MEMBER_P (decl
)
1738 + DECL_CONSTRUCTOR_P (decl
));
1741 /* Build an overload name for the type expression TYPE. */
1744 build_typename_overload (type
)
1750 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1752 start_squangling ();
1753 build_mangled_name (type
, 0, 1);
1754 id
= get_identifier (obstack_base (&scratch_obstack
));
1755 IDENTIFIER_OPNAME_P (id
) = 1;
1757 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1759 TREE_TYPE (id
) = type
;
1765 build_overload_with_type (name
, type
)
1772 start_squangling ();
1773 build_mangled_name (type
, 0, 1);
1775 return get_identifier (obstack_base (&scratch_obstack
));
1779 get_id_2 (name
, name2
)
1787 return get_identifier (obstack_base (&scratch_obstack
));
1790 /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1793 build_destructor_name (type
)
1796 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX
),
1800 /* Given a tree_code CODE, and some arguments (at least one),
1801 attempt to use an overloaded operator on the arguments.
1803 For unary operators, only the first argument need be checked.
1804 For binary operators, both arguments may need to be checked.
1806 Member functions can convert class references to class pointers,
1807 for one-level deep indirection. More than that is not supported.
1808 Operators [](), ()(), and ->() must be member functions.
1810 We call function call building calls with LOOKUP_COMPLAIN if they
1811 are our only hope. This is true when we see a vanilla operator
1812 applied to something of aggregate type. If this fails, we are free
1813 to return `error_mark_node', because we will have reported the
1816 Operators NEW and DELETE overload in funny ways: operator new takes
1817 a single `size' parameter, and operator delete takes a pointer to the
1818 storage being deleted. When overloading these operators, success is
1819 assumed. If there is a failure, report an error message and return
1820 `error_mark_node'. */
1824 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1825 enum tree_code code
;
1827 tree xarg1
, xarg2
, arg3
;
1829 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1832 /* This function takes an identifier, ID, and attempts to figure out what
1833 it means. There are a number of possible scenarios, presented in increasing
1836 1) not in a class's scope
1837 2) in class's scope, member name of the class's method
1838 3) in class's scope, but not a member name of the class
1839 4) in class's scope, member name of a class's variable
1841 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1842 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1844 As a last ditch, try to look up the name as a label and return that
1847 Values which are declared as being of REFERENCE_TYPE are
1848 automatically dereferenced here (as a hack to make the
1849 compiler faster). */
1852 hack_identifier (value
, name
)
1857 if (value
== error_mark_node
)
1859 if (current_class_name
)
1861 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1862 if (fields
== error_mark_node
)
1863 return error_mark_node
;
1868 fndecl
= TREE_VALUE (fields
);
1869 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1870 /* I could not trigger this code. MvL */
1871 my_friendly_abort (980325);
1873 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1875 warning ("methods cannot be converted to function pointers");
1880 error ("ambiguous request for method pointer `%s'",
1881 IDENTIFIER_POINTER (name
));
1882 return error_mark_node
;
1887 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1889 return IDENTIFIER_LABEL_VALUE (name
);
1891 return error_mark_node
;
1894 type
= TREE_TYPE (value
);
1895 if (TREE_CODE (value
) == FIELD_DECL
)
1897 if (current_class_ptr
== NULL_TREE
)
1899 if (current_function_decl
1900 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1901 cp_error ("invalid use of member `%D' in static member function",
1904 /* We can get here when processing a bad default
1906 struct S { int a; void f(int i = a); } */
1907 cp_error ("invalid use of member `%D'", value
);
1909 return error_mark_node
;
1911 TREE_USED (current_class_ptr
) = 1;
1913 /* Mark so that if we are in a constructor, and then find that
1914 this field was initialized by a base initializer,
1915 we can emit an error message. */
1916 TREE_USED (value
) = 1;
1917 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1919 else if (TREE_CODE (value
) == FUNCTION_DECL
1920 && DECL_FUNCTION_MEMBER_P (value
))
1924 if (IS_SIGNATURE (DECL_CLASS_CONTEXT (value
)))
1927 decl
= maybe_dummy_object (DECL_CLASS_CONTEXT (value
), 0);
1928 value
= build_component_ref (decl
, name
, NULL_TREE
, 1);
1930 else if (really_overloaded_fn (value
))
1933 tree t
= get_first_fn (value
);
1934 for (; t
; t
= DECL_CHAIN (t
))
1936 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1939 assemble_external (t
);
1944 else if (TREE_CODE (value
) == OVERLOAD
)
1945 /* not really overloaded function */
1946 mark_used (OVL_FUNCTION (value
));
1947 else if (TREE_CODE (value
) == TREE_LIST
)
1949 /* Ambiguous reference to base members, possibly other cases?. */
1951 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1953 mark_used (TREE_VALUE (t
));
1957 else if (TREE_CODE (value
) == NAMESPACE_DECL
)
1959 cp_error ("use of namespace `%D' as expression", value
);
1960 return error_mark_node
;
1962 else if (DECL_CLASS_TEMPLATE_P (value
))
1964 cp_error ("use of class template `%T' as expression", value
);
1965 return error_mark_node
;
1970 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
1971 || TREE_CODE (value
) == RESULT_DECL
)
1973 tree context
= decl_function_context (value
);
1974 if (context
!= NULL_TREE
&& context
!= current_function_decl
1975 && ! TREE_STATIC (value
))
1977 cp_error ("use of %s from containing function",
1978 (TREE_CODE (value
) == VAR_DECL
1979 ? "`auto' variable" : "parameter"));
1980 cp_error_at (" `%#D' declared here", value
);
1981 value
= error_mark_node
;
1985 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1987 if (DECL_LANG_SPECIFIC (value
)
1988 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1991 register tree context
1992 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1993 ? DECL_CLASS_CONTEXT (value
)
1994 : DECL_CONTEXT (value
);
1996 get_base_distance (context
, current_class_type
, 0, &path
);
1997 if (path
&& !enforce_access (current_class_type
, value
))
1998 return error_mark_node
;
2001 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
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
)
2024 if (TREE_CODE (function
) != ADDR_EXPR
)
2026 func_decl
= TREE_OPERAND (function
, 0);
2027 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
2031 OB_PUTS ("__thunk_");
2040 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl
));
2042 thunk_id
= get_identifier (obstack_base (&scratch_obstack
));
2044 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
2045 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
2047 cp_error ("implementation-reserved name `%D' used", thunk_id
);
2049 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id
, thunk
);
2051 if (thunk
== NULL_TREE
)
2053 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
2054 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
2055 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
2056 comdat_linkage (thunk
);
2057 TREE_SET_CODE (thunk
, THUNK_DECL
);
2058 DECL_INITIAL (thunk
) = function
;
2059 THUNK_DELTA (thunk
) = delta
;
2060 DECL_EXTERNAL (thunk
) = 1;
2061 DECL_ARTIFICIAL (thunk
) = 1;
2062 /* So that finish_file can write out any thunks that need to be: */
2063 pushdecl_top_level (thunk
);
2068 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2071 emit_thunk (thunk_fndecl
)
2074 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
2075 int delta
= THUNK_DELTA (thunk_fndecl
);
2077 if (TREE_ASM_WRITTEN (thunk_fndecl
))
2080 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
2082 TREE_ADDRESSABLE (function
) = 1;
2083 mark_used (function
);
2085 if (current_function_decl
)
2088 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
2091 #ifdef ASM_OUTPUT_MI_THUNK
2093 current_function_decl
= thunk_fndecl
;
2094 /* Make sure we build up its RTL before we go onto the
2095 temporary obstack. */
2096 make_function_rtl (thunk_fndecl
);
2097 temporary_allocation ();
2098 DECL_RESULT (thunk_fndecl
)
2099 = build_decl (RESULT_DECL
, 0, integer_type_node
);
2100 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
2101 init_function_start (thunk_fndecl
, input_filename
, lineno
);
2102 current_function_is_thunk
= 1;
2103 assemble_start_function (thunk_fndecl
, fnname
);
2104 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
2105 assemble_end_function (thunk_fndecl
, fnname
);
2106 permanent_allocation (1);
2107 current_function_decl
= 0;
2108 #else /* ASM_OUTPUT_MI_THUNK */
2109 /* If we don't have the necessary macro for efficient thunks, generate a
2110 thunk function that just makes a call to the real function.
2111 Unfortunately, this doesn't work for varargs. */
2115 if (varargs_function_p (function
))
2116 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2119 /* Set up clone argument trees for the thunk. */
2121 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
2123 tree x
= copy_node (a
);
2125 DECL_CONTEXT (x
) = thunk_fndecl
;
2129 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2130 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2131 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2132 copy_lang_decl (thunk_fndecl
);
2133 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2134 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2136 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
2137 store_parm_decls ();
2138 current_function_is_thunk
= 1;
2140 /* Build up the call to the real function. */
2141 t
= build_int_2 (delta
, -1 * (delta
< 0));
2142 TREE_TYPE (t
) = signed_type (sizetype
);
2143 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2144 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
2145 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2146 t
= expr_tree_cons (NULL_TREE
, a
, t
);
2148 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2149 c_expand_return (t
);
2151 finish_function (lineno
, 0, 0);
2153 /* Don't let the backend defer this function. */
2154 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2156 output_inline_function (thunk_fndecl
);
2157 permanent_allocation (1);
2159 #endif /* ASM_OUTPUT_MI_THUNK */
2162 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2165 /* Code for synthesizing methods which have default semantics defined. */
2167 /* For the anonymous union in TYPE, return the member that is at least as
2168 large as the rest of the members, so we can copy it. */
2171 largest_union_member (type
)
2174 tree f
, type_size
= TYPE_SIZE (type
);
2176 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2177 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2180 /* We should always find one. */
2181 my_friendly_abort (323);
2185 /* Generate code for default X(X&) constructor. */
2188 do_build_copy_constructor (fndecl
)
2191 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2197 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2198 parm
= TREE_CHAIN (parm
);
2199 parm
= convert_from_reference (parm
);
2201 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
)
2202 && is_empty_class (current_class_type
))
2203 /* Don't copy the padding byte; it might not have been allocated
2204 if *this is a base subobject. */;
2205 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2207 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2208 TREE_SIDE_EFFECTS (t
) = 1;
2209 cplus_expand_expr_stmt (t
);
2213 tree fields
= TYPE_FIELDS (current_class_type
);
2214 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2215 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2218 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2221 tree basetype
= BINFO_TYPE (t
);
2222 tree p
= convert_to_reference
2223 (build_reference_type (basetype
), parm
,
2224 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2225 p
= convert_from_reference (p
);
2227 if (p
== error_mark_node
)
2228 cp_error ("in default copy constructor");
2230 current_base_init_list
= tree_cons (basetype
,
2231 p
, current_base_init_list
);
2234 for (i
= 0; i
< n_bases
; ++i
)
2236 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2237 if (TREE_VIA_VIRTUAL (basetype
))
2240 basetype
= BINFO_TYPE (basetype
);
2241 p
= convert_to_reference
2242 (build_reference_type (basetype
), parm
,
2243 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2245 if (p
== error_mark_node
)
2246 cp_error ("in default copy constructor");
2249 p
= convert_from_reference (p
);
2250 current_base_init_list
= tree_cons (basetype
,
2251 p
, current_base_init_list
);
2254 for (; fields
; fields
= TREE_CHAIN (fields
))
2257 tree field
= fields
;
2259 if (TREE_CODE (field
) != FIELD_DECL
)
2263 if (DECL_NAME (field
))
2265 if (VFIELD_NAME_P (DECL_NAME (field
)))
2267 if (VBASE_NAME_P (DECL_NAME (field
)))
2270 /* True for duplicate members. */
2271 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2274 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2275 && ANON_UNION_TYPE_P (t
)
2276 && TYPE_FIELDS (t
) != NULL_TREE
)
2280 init
= build (COMPONENT_REF
, t
, init
, field
);
2281 field
= largest_union_member (t
);
2283 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2284 && ANON_UNION_TYPE_P (t
)
2285 && TYPE_FIELDS (t
) != NULL_TREE
);
2290 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2291 init
= build_tree_list (NULL_TREE
, init
);
2293 current_member_init_list
2294 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2296 current_member_init_list
= nreverse (current_member_init_list
);
2297 current_base_init_list
= nreverse (current_base_init_list
);
2305 do_build_assign_ref (fndecl
)
2308 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2313 parm
= convert_from_reference (parm
);
2315 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
)
2316 && is_empty_class (current_class_type
))
2317 /* Don't copy the padding byte; it might not have been allocated
2318 if *this is a base subobject. */;
2319 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2321 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2322 TREE_SIDE_EFFECTS (t
) = 1;
2323 cplus_expand_expr_stmt (t
);
2327 tree fields
= TYPE_FIELDS (current_class_type
);
2328 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2329 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2332 for (i
= 0; i
< n_bases
; ++i
)
2334 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2335 tree p
= convert_to_reference
2336 (build_reference_type (basetype
), parm
,
2337 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2338 p
= convert_from_reference (p
);
2339 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2340 build_expr_list (NULL_TREE
, p
));
2341 expand_expr_stmt (p
);
2343 for (; fields
; fields
= TREE_CHAIN (fields
))
2346 tree field
= fields
;
2348 if (TREE_CODE (field
) != FIELD_DECL
)
2351 if (TREE_READONLY (field
))
2353 if (DECL_NAME (field
))
2354 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2356 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2359 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2361 if (DECL_NAME (field
))
2362 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2364 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2368 comp
= current_class_ref
;
2371 if (DECL_NAME (field
))
2373 if (VFIELD_NAME_P (DECL_NAME (field
)))
2375 if (VBASE_NAME_P (DECL_NAME (field
)))
2378 /* True for duplicate members. */
2379 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2382 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2383 && ANON_UNION_TYPE_P (t
)
2384 && TYPE_FIELDS (t
) != NULL_TREE
)
2388 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2389 init
= build (COMPONENT_REF
, t
, init
, field
);
2390 field
= largest_union_member (t
);
2392 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2393 && ANON_UNION_TYPE_P (t
)
2394 && TYPE_FIELDS (t
) != NULL_TREE
);
2399 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2400 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2402 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2405 c_expand_return (current_class_ref
);
2410 synthesize_method (fndecl
)
2413 int nested
= (current_function_decl
!= NULL_TREE
);
2414 tree context
= hack_decl_function_context (fndecl
);
2417 import_export_decl (fndecl
);
2420 push_to_top_level ();
2422 push_cp_function_context (context
);
2424 interface_unknown
= 1;
2425 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2426 store_parm_decls ();
2428 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2429 do_build_assign_ref (fndecl
);
2430 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2434 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2435 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2436 arg_chain
= TREE_CHAIN (arg_chain
);
2437 if (arg_chain
!= void_list_node
)
2438 do_build_copy_constructor (fndecl
);
2439 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2443 finish_function (lineno
, 0, nested
);
2445 extract_interface_info ();
2447 pop_from_top_level ();
2449 pop_cp_function_context (context
);