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. */
24 /* Handle method declarations. */
33 #include "hard-reg-set.h"
39 /* Various flags to control the mangling process. */
45 /* The thing we are presently mangling is part of a template type,
46 rather than a fully instantiated type. Therefore, we may see
47 complex expressions where we would normally expect to see a
48 simple integer constant. */
49 mf_maybe_uninstantiated
= 1,
50 /* When mangling a numeric value, use the form `_XX_' (instead of
51 just `XX') if the value has more than one digit. */
52 mf_use_underscores_around_value
= 2,
55 typedef enum mangling_flags mangling_flags
;
57 /* TREE_LIST of the current inline functions that need to be
59 struct pending_inline
*pending_inlines
;
61 #define obstack_chunk_alloc xmalloc
62 #define obstack_chunk_free free
64 /* Obstack where we build text strings for overloading, etc. */
65 static struct obstack scratch_obstack
;
66 static char *scratch_firstobj
;
68 static void icat
PROTO((HOST_WIDE_INT
));
69 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
70 static int old_backref_index
PROTO((tree
));
71 static int flush_repeats
PROTO((int, tree
));
72 static void build_overload_identifier
PROTO((tree
));
73 static void build_overload_nested_name
PROTO((tree
));
74 static void mangle_expression
PROTO((tree
));
75 static void build_overload_int
PROTO((tree
, mangling_flags
));
76 static void build_overload_identifier
PROTO((tree
));
77 static void build_qualified_name
PROTO((tree
));
78 static void build_overload_value
PROTO((tree
, tree
, mangling_flags
));
79 static void issue_nrepeats
PROTO((int, tree
));
80 static char *build_mangled_name
PROTO((tree
,int,int));
81 static void process_modifiers
PROTO((tree
));
82 static void process_overload_item
PROTO((tree
,int));
83 static void do_build_assign_ref
PROTO((tree
));
84 static void do_build_copy_constructor
PROTO((tree
));
85 static void build_template_template_parm_names
PROTO((tree
));
86 static void build_template_parm_names
PROTO((tree
, tree
));
87 static void build_underscore_int
PROTO((int));
88 static void start_squangling
PROTO((void));
89 static void end_squangling
PROTO((void));
90 static int check_ktype
PROTO((tree
, int));
91 static int issue_ktype
PROTO((tree
));
92 static void build_overload_scope_ref
PROTO((tree
));
93 static void build_mangled_template_parm_index
PROTO((const char *, tree
));
94 #if HOST_BITS_PER_WIDE_INT >= 64
95 static void build_mangled_C9x_name
PROTO((int));
97 static int is_back_referenceable_type
PROTO((tree
));
98 static int check_btype
PROTO((tree
));
99 static void build_mangled_name_for_type
PROTO((tree
));
100 static void build_mangled_name_for_type_with_Gcode
PROTO((tree
, int));
102 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
103 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
104 # define OB_PUTC2(C1,C2) \
105 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
106 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
107 # define OB_PUTID(ID) \
108 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
109 IDENTIFIER_LENGTH (ID)))
110 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
111 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
112 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
114 /* type tables for K and B type compression */
115 static varray_type btypelist
;
116 static varray_type ktypelist
;
118 /* number of each type seen */
119 static size_t maxbtype
;
120 static size_t maxktype
;
122 /* Array of types seen so far in top-level call to `build_mangled_name'.
123 Allocated and deallocated by caller. */
124 static varray_type typevec
;
126 /* Number of types interned by `build_mangled_name' so far. */
127 static size_t maxtype
;
129 /* Called once to initialize method.c. */
134 gcc_obstack_init (&scratch_obstack
);
135 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
136 ggc_add_tree_varray_root (&btypelist
, 1);
137 ggc_add_tree_varray_root (&ktypelist
, 1);
138 ggc_add_tree_varray_root (&typevec
, 1);
141 /* This must be large enough to hold any printed integer or floating-point
143 static char digit_buffer
[128];
145 /* Move inline function definitions out of structure so that they
146 can be processed normally. CNAME is the name of the class
147 we are working from, METHOD_LIST is the list of method lists
148 of the structure. We delete friend methods here, after
149 saving away their inline function definitions (if any). */
152 do_inline_function_hair (type
, friend_list
)
153 tree type
, friend_list
;
155 tree method
= TYPE_METHODS (type
);
157 if (method
&& TREE_CODE (method
) == TREE_VEC
)
159 if (TREE_VEC_ELT (method
, 1))
160 method
= TREE_VEC_ELT (method
, 1);
161 else if (TREE_VEC_ELT (method
, 0))
162 method
= TREE_VEC_ELT (method
, 0);
164 method
= TREE_VEC_ELT (method
, 2);
169 /* Do inline member functions. */
170 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
175 my_friendly_assert (info
->fndecl
== method
, 238);
176 args
= DECL_ARGUMENTS (method
);
179 DECL_CONTEXT (args
) = method
;
180 args
= TREE_CHAIN (args
);
183 method
= TREE_CHAIN (method
);
187 tree fndecl
= TREE_VALUE (friend_list
);
188 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
193 my_friendly_assert (info
->fndecl
== fndecl
, 239);
194 args
= DECL_ARGUMENTS (fndecl
);
197 DECL_CONTEXT (args
) = fndecl
;
198 args
= TREE_CHAIN (args
);
202 friend_list
= TREE_CHAIN (friend_list
);
206 /* Here is where overload code starts. */
208 /* Nonzero if we should not try folding parameter types. */
211 /* Nonzero if an underscore is required before adding a digit to the
212 mangled name currently being built. */
213 static int numeric_output_need_bar
;
218 if (flag_do_squangling
)
223 VARRAY_TREE_INIT (btypelist
, 50, "btypelist");
224 VARRAY_TREE_INIT (ktypelist
, 50, "ktypelist");
231 if (flag_do_squangling
)
233 VARRAY_FREE (ktypelist
);
234 VARRAY_FREE (btypelist
);
240 /* Code to concatenate an asciified integer to a string. */
246 unsigned HOST_WIDE_INT ui
;
248 /* Handle this case first, to go really quickly. For many common values,
249 the result of ui/10 below is 1. */
267 OB_PUTC ('0' + (ui
% 10));
272 HOST_WIDE_INT lo
, hi
;
274 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
283 uhi
= (lo
== 0 ? -hi
: -hi
-1);
287 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
292 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
295 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
298 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
302 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
307 /* Returns the index of TYPE in the typevec, or -1 if it's not there. */
310 old_backref_index (type
)
315 if (! is_back_referenceable_type (type
))
318 /* The entry for this parm is at maxtype-1, so don't look there for
319 something to repeat. */
320 for (tindex
= 0; tindex
< maxtype
- 1; ++tindex
)
321 if (same_type_p (VARRAY_TREE (typevec
, tindex
), type
))
324 if (tindex
== maxtype
- 1)
330 /* Old mangling style: If TYPE has already been used in the parameter list,
331 emit a backward reference and return non-zero; otherwise, return 0.
333 NREPEATS is the number of repeats we've recorded of this type, or 0 if
334 this is the first time we've seen it and we're just looking to see if
335 it had been used before. */
338 flush_repeats (nrepeats
, type
)
342 int tindex
= old_backref_index (type
);
346 my_friendly_assert (nrepeats
== 0, 990316);
366 /* Returns nonzero iff this is a type to which we will want to make
367 back-references (using the `B' code). */
370 is_back_referenceable_type (type
)
373 /* For some reason, the Java folks don't want back refs on these. */
374 if (TYPE_FOR_JAVA (type
))
377 switch (TREE_CODE (type
))
380 if (!flag_do_squangling
)
381 /* Even though the mangling of this is just `b', we did
382 historically generate back-references for it. */
389 /* These types have single-character manglings, so there's no
390 point in generating back-references. */
393 case TEMPLATE_TYPE_PARM
:
394 /* It would be a bit complex to demangle signatures correctly if
395 we generated back-references to these, and the manglings of
396 type parameters are short. */
404 /* Issue the squangling code indicating NREPEATS repetitions of TYPE,
405 which was the last parameter type output. */
408 issue_nrepeats (nrepeats
, type
)
412 if (nrepeats
== 1 && !is_back_referenceable_type (type
))
413 /* For types whose manglings are short, don't bother using the
414 repetition code if there's only one repetition, since the
415 repetition code will be about as long as the ordinary mangling. */
416 build_mangled_name_for_type (type
);
426 /* Check to see if a tree node has been entered into the Kcode typelist.
427 If not, add it. Returns -1 if it isn't found, otherwise returns the
431 check_ktype (node
, add
)
436 tree localnode
= node
;
438 if (ktypelist
== NULL
)
441 if (TREE_CODE (node
) == TYPE_DECL
)
442 localnode
= TREE_TYPE (node
);
444 for (x
= 0; x
< maxktype
; x
++)
446 if (same_type_p (localnode
, VARRAY_TREE (ktypelist
, x
)))
449 /* Didn't find it, so add it here. */
452 if (VARRAY_SIZE (ktypelist
) <= maxktype
)
453 VARRAY_GROW (ktypelist
,
454 VARRAY_SIZE (ktypelist
) * 3 / 2);
455 VARRAY_TREE (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 static int static_labelno
;
518 tree name
= DECL_ASSEMBLER_NAME (decl
);
521 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
524 if (numeric_output_need_bar
)
526 icat (strlen (label
));
528 numeric_output_need_bar
= 1;
530 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
531 build_overload_identifier (DECL_NAME (decl
));
533 build_overload_identifier (decl
);
536 /* Output the decimal representation of I. If I > 9, the decimal
537 representation is preceeded and followed by an underscore. */
540 build_underscore_int (i
)
551 build_overload_scope_ref (value
)
555 numeric_output_need_bar
= 0;
556 build_mangled_name_for_type (TREE_OPERAND (value
, 0));
557 build_overload_identifier (TREE_OPERAND (value
, 1));
560 /* VALUE is a complex expression. Produce an appropriate mangling.
561 (We are forced to mangle complex expressions when dealing with
562 templates, and an expression involving template parameters appears
563 in the type of a function parameter.) */
566 mangle_expression (value
)
569 if (TREE_CODE (value
) == SCOPE_REF
)
571 build_overload_scope_ref (value
);
576 numeric_output_need_bar
= 0;
578 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value
))))
581 int operands
= tree_code_length
[(int) TREE_CODE (value
)];
585 id
= ansi_opname
[(int) TREE_CODE (value
)];
586 my_friendly_assert (id
!= NULL_TREE
, 0);
587 name
= IDENTIFIER_POINTER (id
);
588 if (name
[0] != '_' || name
[1] != '_')
589 /* On some erroneous inputs, we can get here with VALUE a
590 LOOKUP_EXPR. In that case, the NAME will be the
591 identifier for "<invalid operator>". We must survive
592 this routine in order to issue a sensible error
593 message, so we fall through to the case below. */
596 for (i
= 0; i
< operands
; ++i
)
601 /* We just outputted either the `E' or the name of the
603 numeric_output_need_bar
= 0;
606 /* Skip the leading underscores. */
609 operand
= TREE_OPERAND (value
, i
);
610 tc
= TREE_CODE (operand
);
612 if (TREE_CODE_CLASS (tc
) == 't')
613 /* We can get here with sizeof, e.g.:
615 template <class T> void f(A<sizeof(T)>); */
616 build_mangled_name_for_type (operand
);
618 build_overload_value (TREE_TYPE (operand
),
620 mf_maybe_uninstantiated
);
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;
639 /* Encoding for an INTEGER_CST value. */
642 build_overload_int (value
, flags
)
644 mangling_flags flags
;
646 int multiple_words_p
= 0;
647 int multiple_digits_p
= 0;
649 if ((flags
& mf_maybe_uninstantiated
) && TREE_CODE (value
) != INTEGER_CST
)
651 mangle_expression (value
);
655 /* Unless we were looking at an uninstantiated template, integers
656 should always be represented by constants. */
657 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
659 /* If the high-order word is not merely a sign-extension of the
660 low-order word, we must use a special output routine that can
662 if (TREE_INT_CST_HIGH (value
)
663 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
665 multiple_words_p
= 1;
666 /* And there is certainly going to be more than one digit. */
667 multiple_digits_p
= 1;
670 multiple_digits_p
= (TREE_INT_CST_LOW (value
) > 9
671 || TREE_INT_CST_LOW (value
) < -9);
673 /* If necessary, add a leading underscore. */
674 if (multiple_digits_p
&& (flags
& mf_use_underscores_around_value
))
677 /* Output the number itself. */
678 if (multiple_words_p
)
679 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
681 icat (TREE_INT_CST_LOW (value
));
683 if (flags
& mf_use_underscores_around_value
)
685 if (multiple_digits_p
)
687 /* Whether or not there were multiple digits, we don't need an
688 underscore. We've either terminated the number with an
689 underscore, or else it only had one digit. */
690 numeric_output_need_bar
= 0;
693 /* We just output a numeric value. */
694 numeric_output_need_bar
= 1;
698 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
699 supplied in INDEX. */
702 build_mangled_template_parm_index (s
, index
)
707 build_underscore_int (TEMPLATE_PARM_IDX (index
));
708 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
709 representation of the function from the point of view of its
711 build_underscore_int (TEMPLATE_PARM_LEVEL (index
));
715 /* Mangling for C9X integer types (and Cygnus extensions for 128-bit
716 and other types) is based on the letter "I" followed by the hex
717 representations of the bitsize for the type in question. For
718 encodings that result in larger than two digits, a leading and
719 trailing underscore is added.
730 int256_t = 100 = I_100_
731 int512_t = 200 = I_200_
733 Given an integer in decimal format, mangle according to this scheme. */
735 #if HOST_BITS_PER_WIDE_INT >= 64
737 build_mangled_C9x_name (bits
)
740 char mangled
[10] = "";
743 sprintf (mangled
, "I_%x_", bits
);
745 sprintf (mangled
, "I%.2x", bits
);
752 build_overload_value (type
, value
, flags
)
754 mangling_flags flags
;
756 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type
)) == 't', 0);
758 while (TREE_CODE (value
) == NON_LVALUE_EXPR
759 || TREE_CODE (value
) == NOP_EXPR
)
760 value
= TREE_OPERAND (value
, 0);
762 if (numeric_output_need_bar
)
765 numeric_output_need_bar
= 0;
768 if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
770 build_mangled_template_parm_index ("Y", value
);
774 if (TYPE_PTRMEM_P (type
))
776 if (TREE_CODE (value
) != PTRMEM_CST
)
777 /* We should have already rejected this pointer to member,
778 since it is not a constant. */
779 my_friendly_abort (0);
781 /* Get the actual FIELD_DECL. */
782 value
= PTRMEM_CST_MEMBER (value
);
783 my_friendly_assert (TREE_CODE (value
) == FIELD_DECL
, 0);
785 /* Output the name of the field. */
786 build_overload_identifier (DECL_NAME (value
));
789 else if (INTEGRAL_TYPE_P (type
))
791 build_overload_int (value
, flags
);
795 /* The only case where we use the extra underscores here is when
796 forming the mangling for an integral non-type template argument.
797 If that didn't happen, stop now. */
798 flags
&= ~mf_use_underscores_around_value
;
800 switch (TREE_CODE (type
))
805 char *bufp
= digit_buffer
;
807 /* We must handle non-constants in templates. */
808 if (TREE_CODE (value
) != REAL_CST
)
810 mangle_expression (value
);
814 val
= TREE_REAL_CST (value
);
815 if (REAL_VALUE_ISNAN (val
))
817 sprintf (bufp
, "NaN");
821 if (REAL_VALUE_NEGATIVE (val
))
823 val
= REAL_VALUE_NEGATE (val
);
826 if (REAL_VALUE_ISINF (val
))
828 sprintf (bufp
, "Infinity");
832 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
833 bufp
= (char *) index (bufp
, 'e');
835 strcat (digit_buffer
, "e0");
861 #ifdef NO_DOT_IN_LABEL
862 bufp
= (char *) index (bufp
, '.');
868 OB_PUTCP (digit_buffer
);
869 numeric_output_need_bar
= 1;
873 if (TREE_CODE (value
) == INTEGER_CST
)
875 build_overload_int (value
, flags
);
878 else if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
880 build_mangled_template_parm_index ("", value
);
881 numeric_output_need_bar
= 1;
885 value
= TREE_OPERAND (value
, 0);
890 if (TREE_CODE (value
) == VAR_DECL
)
892 my_friendly_assert (DECL_NAME (value
) != 0, 245);
893 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
896 else if (TREE_CODE (value
) == FUNCTION_DECL
)
898 my_friendly_assert (DECL_NAME (value
) != 0, 246);
899 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
902 else if (TREE_CODE (value
) == SCOPE_REF
)
903 build_overload_scope_ref (value
);
905 my_friendly_abort (71);
906 break; /* not really needed */
915 my_friendly_assert (TYPE_PTRMEMFUNC_P (type
), 0);
917 /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're
918 mangling, an instantiation of something like:
920 template <class T, void (T::*fp)()> class C {};
921 template <class T> C<T, &T::f> x();
923 We mangle the return type of the function, and that
924 contains template parameters. */
925 if (TREE_CODE (value
) == ADDR_EXPR
926 && TREE_CODE (TREE_OPERAND (value
, 0)) == SCOPE_REF
)
928 build_overload_scope_ref (TREE_OPERAND (value
, 0));
932 my_friendly_assert (TREE_CODE (value
) == PTRMEM_CST
, 0);
934 expand_ptrmemfunc_cst (value
, &delta
, &idx
, &pfn
, &delta2
);
935 build_overload_int (delta
, flags
);
937 build_overload_int (idx
, flags
);
941 numeric_output_need_bar
= 0;
942 build_overload_identifier (DECL_ASSEMBLER_NAME
943 (PTRMEM_CST_MEMBER (value
)));
948 build_overload_int (delta2
, flags
);
954 sorry ("conversion of %s as template parameter",
955 tree_code_name
[(int) TREE_CODE (type
)]);
956 my_friendly_abort (72);
961 /* Add encodings for the declaration of template template parameters.
962 PARMLIST must be a TREE_VEC. */
965 build_template_template_parm_names (parmlist
)
970 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
971 nparms
= TREE_VEC_LENGTH (parmlist
);
973 for (i
= 0; i
< nparms
; i
++)
975 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
976 if (TREE_CODE (parm
) == TYPE_DECL
)
978 /* This parameter is a type. */
981 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
983 /* This parameter is a template. */
985 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
988 /* It's a PARM_DECL. */
989 build_mangled_name_for_type (TREE_TYPE (parm
));
994 /* Add encodings for the vector of template parameters in PARMLIST,
995 given the vector of arguments to be substituted in ARGLIST. */
998 build_template_parm_names (parmlist
, arglist
)
1003 tree inner_args
= innermost_args (arglist
);
1005 nparms
= TREE_VEC_LENGTH (parmlist
);
1007 for (i
= 0; i
< nparms
; i
++)
1009 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
1010 tree arg
= TREE_VEC_ELT (inner_args
, i
);
1011 if (TREE_CODE (parm
) == TYPE_DECL
)
1013 /* This parameter is a type. */
1015 build_mangled_name_for_type (arg
);
1017 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
1019 /* This parameter is a template. */
1020 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
1021 /* Output parameter declaration, argument index and level. */
1022 build_mangled_name_for_type (arg
);
1025 /* A TEMPLATE_DECL node, output the parameter declaration
1026 and template name */
1029 build_template_template_parm_names
1030 (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
1031 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
1032 OB_PUTID (DECL_NAME (arg
));
1037 parm
= tsubst (parm
, arglist
, /*complain=*/1, NULL_TREE
);
1038 /* It's a PARM_DECL. */
1039 build_mangled_name_for_type (TREE_TYPE (parm
));
1040 build_overload_value (TREE_TYPE (parm
), arg
,
1041 ((mf_maybe_uninstantiated
1042 * uses_template_parms (arglist
))
1043 | mf_use_underscores_around_value
));
1048 /* Output the representation for NAME, which is either a TYPE_DECL or
1052 build_overload_identifier (name
)
1055 if (TREE_CODE (name
) == TYPE_DECL
1056 && CLASS_TYPE_P (TREE_TYPE (name
))
1057 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
1058 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
1059 || (TREE_CODE (CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
1060 (TREE_TYPE (name
))))
1063 /* NAME is the TYPE_DECL for a template specialization. */
1064 tree
template, parmlist
, arglist
, tname
;
1065 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
));
1066 arglist
= CLASSTYPE_TI_ARGS (TREE_TYPE (name
));
1067 tname
= DECL_NAME (template);
1068 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
1070 icat (IDENTIFIER_LENGTH (tname
));
1072 build_template_parm_names (parmlist
, arglist
);
1076 if (TREE_CODE (name
) == TYPE_DECL
)
1077 name
= DECL_NAME (name
);
1078 if (numeric_output_need_bar
)
1081 numeric_output_need_bar
= 0;
1083 icat (IDENTIFIER_LENGTH (name
));
1088 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
1089 the mangling for it. Used by build_mangled_name and build_static_name. */
1092 build_qualified_name (decl
)
1098 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
1099 decl
= TYPE_NAME (decl
);
1101 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1102 if (TREE_CODE (decl
) == TYPE_DECL
1103 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
) && !flag_do_squangling
)
1105 tree id
= DECL_ASSEMBLER_NAME (decl
);
1107 if (ISDIGIT (IDENTIFIER_POINTER (id
) [IDENTIFIER_LENGTH (id
) - 1]))
1108 numeric_output_need_bar
= 1;
1113 /* If we can't find a Ktype, do it the hard way. */
1114 if (check_ktype (context
, FALSE
) == -1)
1116 /* Count type and namespace scopes. */
1119 context
= CP_DECL_CONTEXT (context
);
1120 if (context
== global_namespace
)
1123 if (check_ktype (context
, FALSE
) != -1)
1126 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
1127 context
= TYPE_NAME (context
);
1134 build_underscore_int (i
);
1135 numeric_output_need_bar
= 0;
1137 build_overload_nested_name (decl
);
1140 /* Output the mangled representation for TYPE. If EXTRA_GCODE is
1141 non-zero, mangled names for structure/union types are intentionally
1142 mangled differently from the method described in the ARM. */
1145 build_mangled_name_for_type_with_Gcode (type
, extra_Gcode
)
1149 if (TYPE_PTRMEMFUNC_P (type
))
1150 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
1151 process_modifiers (type
);
1152 process_overload_item (type
, extra_Gcode
);
1155 /* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1159 build_mangled_name_for_type (type
)
1162 build_mangled_name_for_type_with_Gcode (type
, 0);
1165 /* Given a list of parameters in PARMTYPES, create an unambiguous
1166 overload string. Should distinguish any type that C (or C++) can
1167 distinguish. I.e., pointers to functions are treated correctly.
1169 Caller must deal with whether a final `e' goes on the end or not.
1171 Any default conversions must take place before this function
1174 BEGIN and END control initialization and finalization of the
1175 obstack where we build the string. */
1178 build_overload_name (parmtypes
, begin
, end
)
1183 start_squangling ();
1184 ret
= build_mangled_name (parmtypes
, begin
, end
);
1189 /* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1190 TREE_LIST, then it is a list of parameter types. Otherwise,
1191 PARMTYPES must be a single type. */
1194 build_mangled_name (parmtypes
, begin
, end
)
1201 if (TREE_CODE (parmtypes
) != TREE_LIST
)
1202 /* There is only one type. */
1203 build_mangled_name_for_type (parmtypes
);
1206 /* There are several types in a parameter list. */
1208 int old_style_repeats
= !flag_do_squangling
&& !nofold
&& typevec
;
1209 tree last_type
= NULL_TREE
;
1211 for (; parmtypes
&& parmtypes
!= void_list_node
;
1212 parmtypes
= TREE_CHAIN (parmtypes
))
1214 /* We used to call canonical_type_variant here, but that isn't
1215 good enough; it doesn't handle pointers to typedef types. So
1216 we can't just set TREE_USED to say we've seen a type already;
1217 we have to check each of the earlier types with same_type_p. */
1218 tree parmtype
= TREE_VALUE (parmtypes
);
1220 if (old_style_repeats
)
1222 /* Every argument gets counted. */
1223 my_friendly_assert (maxtype
< VARRAY_SIZE (typevec
), 387);
1224 VARRAY_TREE (typevec
, maxtype
) = parmtype
;
1228 if (last_type
&& same_type_p (parmtype
, last_type
))
1230 if (flag_do_squangling
1231 || (old_style_repeats
1232 && is_back_referenceable_type (parmtype
)))
1234 /* The next type is the same as this one. Keep
1235 track of the repetition, and output the repeat
1241 else if (nrepeats
!= 0)
1243 /* Indicate how many times the previous parameter was
1245 if (old_style_repeats
)
1246 flush_repeats (nrepeats
, last_type
);
1248 issue_nrepeats (nrepeats
, last_type
);
1252 last_type
= parmtype
;
1254 /* Note that for bug-compatibility with 2.7.2, we can't build up
1255 repeats of types other than the most recent one. So we call
1256 flush_repeats every round, if we get this far. */
1257 if (old_style_repeats
&& flush_repeats (0, parmtype
))
1260 /* Output the PARMTYPE. */
1261 build_mangled_name_for_type_with_Gcode (parmtype
, 1);
1264 /* Output the repeat count for the last parameter, if
1268 if (old_style_repeats
)
1269 flush_repeats (nrepeats
, last_type
);
1271 issue_nrepeats (nrepeats
, last_type
);
1276 /* The parameter list ends in an ellipsis. */
1282 return (char *)obstack_base (&scratch_obstack
);
1285 /* Emit modifiers such as constant, read-only, and volatile. */
1288 process_modifiers (parmtype
)
1291 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1292 we describe types recursively; we will get the `const' in
1293 `const int ()[10]' when processing the `const int' part. */
1294 if (TYPE_READONLY (parmtype
))
1296 if (TREE_CODE (parmtype
) == INTEGER_TYPE
1297 && parmtype
!= char_type_node
1298 && parmtype
!= wchar_type_node
1299 && (TYPE_MAIN_VARIANT (parmtype
)
1300 == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
1301 && ! TYPE_FOR_JAVA (parmtype
))
1303 if (TYPE_VOLATILE (parmtype
))
1305 /* It would be better to use `R' for `restrict', but that's already
1306 used for reference types. And `r' is used for `long double'. */
1307 if (TYPE_RESTRICT (parmtype
))
1311 /* Check to see if TYPE has been entered into the Bcode typelist. If
1312 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1313 to the list of back-referenceable types and return 0. */
1321 if (btypelist
== NULL
)
1324 if (!is_back_referenceable_type (type
))
1327 for (x
= 0; x
< maxbtype
; x
++)
1328 if (same_type_p (type
, VARRAY_TREE (btypelist
, x
)))
1337 if (VARRAY_SIZE (btypelist
) <= maxbtype
)
1338 /* Enlarge the table. */
1339 VARRAY_GROW (btypelist
,
1340 VARRAY_SIZE (btypelist
) * 3 / 2);
1342 /* Register the TYPE. */
1343 VARRAY_TREE (btypelist
, maxbtype
) = type
;
1349 /* Emit the correct code for various node types. */
1352 process_overload_item (parmtype
, extra_Gcode
)
1356 numeric_output_need_bar
= 0;
1358 /* Our caller should have already handed any qualifiers, so pull out the
1359 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1360 for arrays, because they are transparent to qualifiers. Sigh. */
1361 if (TREE_CODE (parmtype
) == ARRAY_TYPE
)
1362 parmtype
= canonical_type_variant (parmtype
);
1364 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1366 /* These tree types are considered modifiers for B code squangling,
1367 and therefore should not get entries in the Btypelist. They are,
1368 however, repeatable types. */
1370 switch (TREE_CODE (parmtype
))
1372 case REFERENCE_TYPE
:
1379 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
1383 tree length
= array_type_nelts (parmtype
);
1384 if (TREE_CODE (length
) != INTEGER_CST
|| flag_do_squangling
)
1386 length
= fold (build (PLUS_EXPR
, TREE_TYPE (length
),
1387 length
, integer_one_node
));
1388 STRIP_NOPS (length
);
1390 build_overload_value (sizetype
, length
, 1);
1392 if (numeric_output_need_bar
&& ! flag_do_squangling
)
1400 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1408 if (flag_do_squangling
&& check_btype (parmtype
))
1409 /* If PARMTYPE is already in the list of back-referenceable types,
1410 then check_btype will output the appropriate reference, and
1411 there's nothing more to do. */
1414 switch (TREE_CODE (parmtype
))
1418 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype
));
1420 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1426 tree parms
= TYPE_ARG_TYPES (parmtype
);
1428 /* Rather than implementing a reentrant TYPEVEC, we turn off
1429 repeat codes here, unless we're squangling. Squangling
1430 doesn't make use of the TYPEVEC, so there's no reentrancy
1432 int old_nofold
= nofold
;
1433 if (!flag_do_squangling
)
1436 if (TREE_CODE (parmtype
) == METHOD_TYPE
)
1438 /* Mark this as a method. */
1440 /* Output the class of which this method is a member. */
1441 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype
));
1442 /* Output any qualifiers for the `this' parameter. */
1443 process_modifiers (TREE_TYPE (TREE_VALUE (parms
)));
1446 /* Output the parameter types. */
1448 if (parms
== NULL_TREE
)
1450 else if (parms
== void_list_node
)
1453 build_mangled_name (parms
, 0, 0);
1455 /* Output the return type. */
1457 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1459 nofold
= old_nofold
;
1464 if (parmtype
== integer_type_node
1465 || parmtype
== unsigned_type_node
1466 || parmtype
== java_int_type_node
)
1468 else if (parmtype
== long_integer_type_node
1469 || parmtype
== long_unsigned_type_node
)
1471 else if (parmtype
== short_integer_type_node
1472 || parmtype
== short_unsigned_type_node
1473 || parmtype
== java_short_type_node
)
1475 else if (parmtype
== signed_char_type_node
)
1480 else if (parmtype
== char_type_node
1481 || parmtype
== unsigned_char_type_node
1482 || parmtype
== java_byte_type_node
)
1484 else if (parmtype
== wchar_type_node
1485 || parmtype
== java_char_type_node
)
1487 else if (parmtype
== long_long_integer_type_node
1488 || parmtype
== long_long_unsigned_type_node
1489 || parmtype
== java_long_type_node
)
1491 else if (parmtype
== java_boolean_type_node
)
1493 #if HOST_BITS_PER_WIDE_INT >= 64
1496 int bits
= TREE_INT_CST_LOW (TYPE_SIZE (parmtype
));
1497 build_mangled_C9x_name (bits
);
1501 my_friendly_abort (73);
1510 if (parmtype
== long_double_type_node
)
1512 else if (parmtype
== double_type_node
1513 || parmtype
== java_double_type_node
)
1515 else if (parmtype
== float_type_node
1516 || parmtype
== java_float_type_node
)
1518 else my_friendly_abort (74);
1523 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1530 case ERROR_MARK
: /* not right, but nothing is anyway */
1533 /* have to do these */
1538 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1539 /* drop through into next case */
1543 tree name
= TYPE_NAME (parmtype
);
1545 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1547 build_qualified_name (name
);
1552 /* This will take some work. */
1556 case TEMPLATE_TEMPLATE_PARM
:
1557 /* Find and output the original template parameter
1559 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype
))
1561 build_mangled_template_parm_index ("tzX",
1562 TEMPLATE_TYPE_PARM_INDEX
1564 build_template_parm_names
1565 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype
)),
1566 TYPE_TI_ARGS (parmtype
));
1570 build_mangled_template_parm_index ("ZzX",
1571 TEMPLATE_TYPE_PARM_INDEX
1573 build_template_template_parm_names
1574 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1578 case TEMPLATE_TYPE_PARM
:
1579 build_mangled_template_parm_index ("X",
1580 TEMPLATE_TYPE_PARM_INDEX
1585 /* When mangling the type of a function template whose
1586 declaration looks like:
1588 template <class T> void foo(typename T::U)
1590 we have to mangle these. */
1591 build_qualified_name (parmtype
);
1595 my_friendly_abort (75);
1600 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1601 be either a class TYPE or a FUNCTION_DECL. */
1604 build_static_name (context
, name
)
1608 numeric_output_need_bar
= 0;
1609 start_squangling ();
1612 build_qualified_name (context
);
1615 OB_PUTS ("__static_");
1616 build_qualified_name (context
);
1623 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1626 /* FOR_METHOD should be 1 if the declaration in question is for a member
1627 of a class (including a static member) and 2 if the declaration is
1628 for a constructor. */
1630 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1639 const char *name
= IDENTIFIER_POINTER (dname
);
1641 /* member operators new and delete look like methods at this point. */
1642 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1643 && TREE_CHAIN (parms
) == void_list_node
)
1645 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1646 return get_identifier ("__builtin_delete");
1647 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1648 return get_identifier ("__builtin_vec_delete");
1649 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1650 return get_identifier ("__builtin_new");
1651 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1652 return get_identifier ("__builtin_vec_new");
1655 start_squangling ();
1657 if (for_method
!= 2)
1659 /* Otherwise, we can divine that this is a constructor,
1660 and figure out its name without any extra encoding. */
1662 OB_PUTC2 ('_', '_');
1663 numeric_output_need_bar
= 0;
1668 build_template_parm_names (tparms
, targs
);
1671 else if (!for_method
&& current_namespace
== global_namespace
)
1672 /* XXX this works only if we call this in the same namespace
1673 as the declaration. Unfortunately, we don't have the _DECL,
1677 if (!for_method
&& current_namespace
!= global_namespace
)
1678 /* qualify with namespace */
1679 build_qualified_name (current_namespace
);
1681 if (parms
== NULL_TREE
)
1683 else if (parms
== void_list_node
)
1687 if (!flag_do_squangling
)
1689 /* Allocate typevec array. */
1690 size_t typevec_size
= list_length (parms
);
1692 if (!for_method
&& current_namespace
!= global_namespace
)
1693 /* The namespace of a global function needs one slot. */
1695 VARRAY_TREE_INIT (typevec
, typevec_size
, "typevec");
1701 tree this_type
= TREE_TYPE (TREE_VALUE (parms
));
1703 build_mangled_name_for_type (this_type
);
1705 if (!flag_do_squangling
)
1707 my_friendly_assert (maxtype
< VARRAY_SIZE (typevec
), 387);
1708 VARRAY_TREE (typevec
, maxtype
) = this_type
;
1712 if (TREE_CHAIN (parms
))
1713 build_mangled_name (TREE_CHAIN (parms
), 0, 0);
1719 /* the namespace qualifier for a global function
1720 will count as type */
1721 if (current_namespace
!= global_namespace
1722 && !flag_do_squangling
)
1724 my_friendly_assert (maxtype
< VARRAY_SIZE (typevec
), 387);
1725 VARRAY_TREE (typevec
, maxtype
) = current_namespace
;
1728 build_mangled_name (parms
, 0, 0);
1731 if (!flag_do_squangling
)
1732 /* Deallocate typevec array. */
1733 VARRAY_FREE (typevec
);
1736 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1738 /* Add the return type. */
1740 build_mangled_name_for_type (ret_type
);
1746 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1747 if (IDENTIFIER_OPNAME_P (dname
))
1748 IDENTIFIER_OPNAME_P (n
) = 1;
1753 /* Change the name of a function definition so that it may be
1754 overloaded. NAME is the name of the function to overload,
1755 PARMS is the parameter list (which determines what name the
1756 final function obtains).
1758 FOR_METHOD is 1 if this overload is being performed
1759 for a method, rather than a function type. It is 2 if
1760 this overload is being performed for a constructor. */
1763 build_decl_overload (dname
, parms
, for_method
)
1768 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1769 NULL_TREE
, for_method
);
1772 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
1775 set_mangled_name_for_decl (decl
)
1780 if (processing_template_decl
)
1781 /* There's no need to mangle the name of a template function. */
1784 parm_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
1786 if (DECL_STATIC_FUNCTION_P (decl
))
1788 hash_tree_chain (build_pointer_type (DECL_CLASS_CONTEXT (decl
)),
1791 /* The only member functions whose type is a FUNCTION_TYPE, rather
1792 than a METHOD_TYPE, should be static members. */
1793 my_friendly_assert (!DECL_CONTEXT (decl
)
1794 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl
)))
1795 || TREE_CODE (TREE_TYPE (decl
)) != FUNCTION_TYPE
,
1798 DECL_ASSEMBLER_NAME (decl
)
1799 = build_decl_overload (DECL_NAME (decl
), parm_types
,
1800 DECL_FUNCTION_MEMBER_P (decl
)
1801 + DECL_CONSTRUCTOR_P (decl
));
1804 /* Build an overload name for the type expression TYPE. */
1807 build_typename_overload (type
)
1813 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1815 start_squangling ();
1816 build_mangled_name (type
, 0, 1);
1817 id
= get_identifier (obstack_base (&scratch_obstack
));
1818 IDENTIFIER_OPNAME_P (id
) = 1;
1820 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1822 TREE_TYPE (id
) = type
;
1828 build_overload_with_type (name
, type
)
1835 start_squangling ();
1836 build_mangled_name (type
, 0, 1);
1838 return get_identifier (obstack_base (&scratch_obstack
));
1842 get_id_2 (name
, name2
)
1850 return get_identifier (obstack_base (&scratch_obstack
));
1853 /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1856 build_destructor_name (type
)
1859 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX
),
1863 /* Given a tree_code CODE, and some arguments (at least one),
1864 attempt to use an overloaded operator on the arguments.
1866 For unary operators, only the first argument need be checked.
1867 For binary operators, both arguments may need to be checked.
1869 Member functions can convert class references to class pointers,
1870 for one-level deep indirection. More than that is not supported.
1871 Operators [](), ()(), and ->() must be member functions.
1873 We call function call building calls with LOOKUP_COMPLAIN if they
1874 are our only hope. This is true when we see a vanilla operator
1875 applied to something of aggregate type. If this fails, we are free
1876 to return `error_mark_node', because we will have reported the
1879 Operators NEW and DELETE overload in funny ways: operator new takes
1880 a single `size' parameter, and operator delete takes a pointer to the
1881 storage being deleted. When overloading these operators, success is
1882 assumed. If there is a failure, report an error message and return
1883 `error_mark_node'. */
1887 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1888 enum tree_code code
;
1890 tree xarg1
, xarg2
, arg3
;
1892 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1895 /* This function takes an identifier, ID, and attempts to figure out what
1896 it means. There are a number of possible scenarios, presented in increasing
1899 1) not in a class's scope
1900 2) in class's scope, member name of the class's method
1901 3) in class's scope, but not a member name of the class
1902 4) in class's scope, member name of a class's variable
1904 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1905 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1907 As a last ditch, try to look up the name as a label and return that
1910 Values which are declared as being of REFERENCE_TYPE are
1911 automatically dereferenced here (as a hack to make the
1912 compiler faster). */
1915 hack_identifier (value
, name
)
1920 if (value
== error_mark_node
)
1922 if (current_class_name
)
1924 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1925 if (fields
== error_mark_node
)
1926 return error_mark_node
;
1931 fndecl
= TREE_VALUE (fields
);
1932 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1933 /* I could not trigger this code. MvL */
1934 my_friendly_abort (980325);
1936 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1938 warning ("methods cannot be converted to function pointers");
1943 error ("ambiguous request for method pointer `%s'",
1944 IDENTIFIER_POINTER (name
));
1945 return error_mark_node
;
1950 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1952 return IDENTIFIER_LABEL_VALUE (name
);
1954 return error_mark_node
;
1957 type
= TREE_TYPE (value
);
1958 if (TREE_CODE (value
) == FIELD_DECL
)
1960 if (current_class_ptr
== NULL_TREE
)
1962 if (current_function_decl
1963 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1964 cp_error ("invalid use of member `%D' in static member function",
1967 /* We can get here when processing a bad default
1969 struct S { int a; void f(int i = a); } */
1970 cp_error ("invalid use of member `%D'", value
);
1972 return error_mark_node
;
1974 TREE_USED (current_class_ptr
) = 1;
1976 /* Mark so that if we are in a constructor, and then find that
1977 this field was initialized by a base initializer,
1978 we can emit an error message. */
1979 TREE_USED (value
) = 1;
1980 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1982 else if ((TREE_CODE (value
) == FUNCTION_DECL
1983 && DECL_FUNCTION_MEMBER_P (value
))
1984 || (TREE_CODE (value
) == OVERLOAD
1985 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value
))))
1989 if (TREE_CODE (value
) == OVERLOAD
)
1990 value
= OVL_CURRENT (value
);
1992 decl
= maybe_dummy_object (DECL_CLASS_CONTEXT (value
), 0);
1993 value
= build_component_ref (decl
, name
, NULL_TREE
, 1);
1995 else if (really_overloaded_fn (value
))
1997 else if (TREE_CODE (value
) == OVERLOAD
)
1998 /* not really overloaded function */
1999 mark_used (OVL_FUNCTION (value
));
2000 else if (TREE_CODE (value
) == TREE_LIST
)
2002 /* Ambiguous reference to base members, possibly other cases?. */
2004 while (t
&& TREE_CODE (t
) == TREE_LIST
)
2006 mark_used (TREE_VALUE (t
));
2010 else if (TREE_CODE (value
) == NAMESPACE_DECL
)
2012 cp_error ("use of namespace `%D' as expression", value
);
2013 return error_mark_node
;
2015 else if (DECL_CLASS_TEMPLATE_P (value
))
2017 cp_error ("use of class template `%T' as expression", value
);
2018 return error_mark_node
;
2023 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
2024 || TREE_CODE (value
) == RESULT_DECL
)
2026 tree context
= decl_function_context (value
);
2027 if (context
!= NULL_TREE
&& context
!= current_function_decl
2028 && ! TREE_STATIC (value
))
2030 cp_error ("use of %s from containing function",
2031 (TREE_CODE (value
) == VAR_DECL
2032 ? "`auto' variable" : "parameter"));
2033 cp_error_at (" `%#D' declared here", value
);
2034 value
= error_mark_node
;
2038 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
2040 if (DECL_LANG_SPECIFIC (value
)
2041 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
2044 register tree context
2045 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
2046 ? DECL_CLASS_CONTEXT (value
)
2047 : DECL_CONTEXT (value
);
2049 get_base_distance (context
, current_class_type
, 0, &path
);
2050 if (path
&& !enforce_access (current_class_type
, value
))
2051 return error_mark_node
;
2054 else if (TREE_CODE (value
) == TREE_LIST
2055 && TREE_TYPE (value
) == error_mark_node
)
2057 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2058 IDENTIFIER_POINTER (name
));
2059 print_candidates (value
);
2060 return error_mark_node
;
2063 if (! processing_template_decl
)
2064 value
= convert_from_reference (value
);
2070 make_thunk (function
, delta
)
2078 if (TREE_CODE (function
) != ADDR_EXPR
)
2080 func_decl
= TREE_OPERAND (function
, 0);
2081 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
2085 OB_PUTS ("__thunk_");
2094 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl
));
2096 thunk_id
= get_identifier (obstack_base (&scratch_obstack
));
2098 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
2099 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
2101 cp_error ("implementation-reserved name `%D' used", thunk_id
);
2103 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id
, thunk
);
2105 if (thunk
== NULL_TREE
)
2107 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
2108 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
2109 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
2110 comdat_linkage (thunk
);
2111 TREE_SET_CODE (thunk
, THUNK_DECL
);
2112 DECL_INITIAL (thunk
) = function
;
2113 THUNK_DELTA (thunk
) = delta
;
2114 DECL_EXTERNAL (thunk
) = 1;
2115 DECL_ARTIFICIAL (thunk
) = 1;
2116 /* So that finish_file can write out any thunks that need to be: */
2117 pushdecl_top_level (thunk
);
2122 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2125 emit_thunk (thunk_fndecl
)
2128 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
2129 int delta
= THUNK_DELTA (thunk_fndecl
);
2131 if (TREE_ASM_WRITTEN (thunk_fndecl
))
2134 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
2136 TREE_ADDRESSABLE (function
) = 1;
2137 mark_used (function
);
2139 if (current_function_decl
)
2142 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
2144 #ifdef ASM_OUTPUT_MI_THUNK
2145 if (!flag_syntax_only
)
2148 current_function_decl
= thunk_fndecl
;
2149 /* Make sure we build up its RTL before we go onto the
2150 temporary obstack. */
2151 make_function_rtl (thunk_fndecl
);
2152 temporary_allocation ();
2153 DECL_RESULT (thunk_fndecl
)
2154 = build_decl (RESULT_DECL
, 0, integer_type_node
);
2155 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
2156 init_function_start (thunk_fndecl
, input_filename
, lineno
);
2157 current_function_is_thunk
= 1;
2158 assemble_start_function (thunk_fndecl
, fnname
);
2159 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
2160 assemble_end_function (thunk_fndecl
, fnname
);
2161 permanent_allocation (1);
2162 current_function_decl
= 0;
2163 current_function
= 0;
2165 #else /* ASM_OUTPUT_MI_THUNK */
2167 /* If we don't have the necessary macro for efficient thunks, generate a
2168 thunk function that just makes a call to the real function.
2169 Unfortunately, this doesn't work for varargs. */
2173 if (varargs_function_p (function
))
2174 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2177 /* Set up clone argument trees for the thunk. */
2179 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
2181 tree x
= copy_node (a
);
2183 DECL_CONTEXT (x
) = thunk_fndecl
;
2187 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2188 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2189 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2190 copy_lang_decl (thunk_fndecl
);
2191 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2192 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2194 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
,
2195 SF_DEFAULT
| SF_PRE_PARSED
);
2196 store_parm_decls ();
2197 current_function_is_thunk
= 1;
2199 /* Build up the call to the real function. */
2200 t
= build_int_2 (delta
, -1 * (delta
< 0));
2201 TREE_TYPE (t
) = signed_type (sizetype
);
2202 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2203 t
= tree_cons (NULL_TREE
, t
, NULL_TREE
);
2204 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2205 t
= tree_cons (NULL_TREE
, a
, t
);
2207 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2208 finish_return_stmt (t
);
2210 expand_body (finish_function (lineno
, 0));
2212 /* Don't let the backend defer this function. */
2213 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2215 output_inline_function (thunk_fndecl
);
2216 permanent_allocation (1);
2219 #endif /* ASM_OUTPUT_MI_THUNK */
2221 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2224 /* Code for synthesizing methods which have default semantics defined. */
2226 /* Generate code for default X(X&) constructor. */
2229 do_build_copy_constructor (fndecl
)
2232 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2235 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2236 parm
= TREE_CHAIN (parm
);
2237 parm
= convert_from_reference (parm
);
2239 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
)
2240 && is_empty_class (current_class_type
))
2241 /* Don't copy the padding byte; it might not have been allocated
2242 if *this is a base subobject. */;
2243 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2245 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2246 finish_expr_stmt (t
);
2250 tree fields
= TYPE_FIELDS (current_class_type
);
2251 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2252 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2255 /* Initialize all the base-classes. */
2256 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2258 current_base_init_list
2259 = tree_cons (BINFO_TYPE (t
), parm
, current_base_init_list
);
2260 for (i
= 0; i
< n_bases
; ++i
)
2262 t
= TREE_VEC_ELT (binfos
, i
);
2263 if (TREE_VIA_VIRTUAL (t
))
2266 current_base_init_list
2267 = tree_cons (BINFO_TYPE (t
), parm
, current_base_init_list
);
2270 for (; fields
; fields
= TREE_CHAIN (fields
))
2273 tree field
= fields
;
2275 if (TREE_CODE (field
) != FIELD_DECL
)
2279 if (DECL_NAME (field
))
2281 if (VFIELD_NAME_P (DECL_NAME (field
)))
2283 if (VBASE_NAME_P (DECL_NAME (field
)))
2286 /* True for duplicate members. */
2287 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2290 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2291 && ANON_AGGR_TYPE_P (t
)
2292 && TYPE_FIELDS (t
) != NULL_TREE
)
2293 /* Just use the field; anonymous types can't have
2294 nontrivial copy ctors or assignment ops. */;
2298 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2299 init
= build_tree_list (NULL_TREE
, init
);
2301 current_member_init_list
2302 = tree_cons (field
, init
, current_member_init_list
);
2304 current_member_init_list
= nreverse (current_member_init_list
);
2305 current_base_init_list
= nreverse (current_base_init_list
);
2311 do_build_assign_ref (fndecl
)
2314 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2317 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
2318 parm
= convert_from_reference (parm
);
2320 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
)
2321 && is_empty_class (current_class_type
))
2322 /* Don't copy the padding byte; it might not have been allocated
2323 if *this is a base subobject. */;
2324 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2326 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2327 finish_expr_stmt (t
);
2331 tree fields
= TYPE_FIELDS (current_class_type
);
2332 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2333 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2336 for (i
= 0; i
< n_bases
; ++i
)
2338 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2339 tree p
= convert_to_reference
2340 (build_reference_type (basetype
), parm
,
2341 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2342 p
= convert_from_reference (p
);
2343 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2344 build_expr_list (NULL_TREE
, p
));
2345 finish_expr_stmt (p
);
2347 for (; fields
; fields
= TREE_CHAIN (fields
))
2350 tree field
= fields
;
2352 if (TREE_CODE (field
) != FIELD_DECL
)
2355 if (CP_TYPE_CONST_P (TREE_TYPE (field
)))
2357 if (DECL_NAME (field
))
2358 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2360 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2363 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2365 if (DECL_NAME (field
))
2366 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2368 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2372 comp
= current_class_ref
;
2375 if (DECL_NAME (field
))
2377 if (VFIELD_NAME_P (DECL_NAME (field
)))
2379 if (VBASE_NAME_P (DECL_NAME (field
)))
2382 /* True for duplicate members. */
2383 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2386 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2387 && ANON_AGGR_TYPE_P (t
)
2388 && TYPE_FIELDS (t
) != NULL_TREE
)
2389 /* Just use the field; anonymous types can't have
2390 nontrivial copy ctors or assignment ops. */;
2394 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2395 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2397 finish_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2400 finish_return_stmt (current_class_ref
);
2401 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
2405 synthesize_method (fndecl
)
2408 int nested
= (current_function_decl
!= NULL_TREE
);
2409 tree context
= hack_decl_function_context (fndecl
);
2413 import_export_decl (fndecl
);
2416 push_to_top_level ();
2418 push_function_context_to (context
);
2420 /* Put the function definition at the position where it is needed,
2421 rather than within the body of the class. That way, an error
2422 during the generation of the implicit body points at the place
2423 where the attempt to generate the function occurs, giving the
2424 user a hint as to why we are attempting to generate the
2426 DECL_SOURCE_LINE (fndecl
) = lineno
;
2427 DECL_SOURCE_FILE (fndecl
) = input_filename
;
2429 interface_unknown
= 1;
2430 start_function (NULL_TREE
, fndecl
, NULL_TREE
, SF_DEFAULT
| SF_PRE_PARSED
);
2431 store_parm_decls ();
2434 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2436 do_build_assign_ref (fndecl
);
2439 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2443 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2444 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2445 arg_chain
= TREE_CHAIN (arg_chain
);
2446 if (arg_chain
!= void_list_node
)
2447 do_build_copy_constructor (fndecl
);
2448 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2452 /* If we haven't yet generated the body of the function, just
2453 generate an empty compound statement. */
2457 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
2458 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
2461 expand_body (finish_function (lineno
, 0));
2463 extract_interface_info ();
2465 pop_from_top_level ();
2467 pop_function_context_from (context
);