1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #ifndef PARM_CAN_BE_ARRAY_TYPE
29 #define PARM_CAN_BE_ARRAY_TYPE 1
32 /* Handle method declarations. */
41 #include "hard-reg-set.h"
46 /* TREE_LIST of the current inline functions that need to be
48 struct pending_inline
*pending_inlines
;
50 #define obstack_chunk_alloc xmalloc
51 #define obstack_chunk_free free
53 /* Obstack where we build text strings for overloading, etc. */
54 static struct obstack scratch_obstack
;
55 static char *scratch_firstobj
;
57 static void icat
PROTO((HOST_WIDE_INT
));
58 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
59 static int old_backref_index
PROTO((tree
));
60 static int flush_repeats
PROTO((int, tree
));
61 static void build_overload_identifier
PROTO((tree
));
62 static void build_overload_nested_name
PROTO((tree
));
63 static void build_overload_int
PROTO((tree
, int));
64 static void build_overload_identifier
PROTO((tree
));
65 static void build_qualified_name
PROTO((tree
));
66 static void build_overload_value
PROTO((tree
, tree
, int));
67 static void issue_nrepeats
PROTO((int, tree
));
68 static char *build_mangled_name
PROTO((tree
,int,int));
69 static void process_modifiers
PROTO((tree
));
70 static void process_overload_item
PROTO((tree
,int));
71 static void do_build_assign_ref
PROTO((tree
));
72 static void do_build_copy_constructor
PROTO((tree
));
73 static void build_template_template_parm_names
PROTO((tree
));
74 static void build_template_parm_names
PROTO((tree
, tree
));
75 static void build_underscore_int
PROTO((int));
76 static void start_squangling
PROTO((void));
77 static void end_squangling
PROTO((void));
78 static int check_ktype
PROTO((tree
, int));
79 static int issue_ktype
PROTO((tree
));
80 static void build_overload_scope_ref
PROTO((tree
));
81 static void build_mangled_template_parm_index
PROTO((const char *, tree
));
82 #if HOST_BITS_PER_WIDE_INT >= 64
83 static void build_mangled_C9x_name
PROTO((int));
85 static int is_back_referenceable_type
PROTO((tree
));
86 static int check_btype
PROTO((tree
));
87 static void build_mangled_name_for_type
PROTO((tree
));
88 static void build_mangled_name_for_type_with_Gcode
PROTO((tree
, int));
90 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
91 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
92 # define OB_PUTC2(C1,C2) \
93 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
94 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
95 # define OB_PUTID(ID) \
96 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
97 IDENTIFIER_LENGTH (ID)))
98 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
99 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
100 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
102 /* type tables for K and B type compression */
103 static varray_type btypelist
;
104 static varray_type ktypelist
;
106 /* number of each type seen */
107 static size_t maxbtype
;
108 static size_t maxktype
;
110 /* Array of types seen so far in top-level call to `build_mangled_name'.
111 Allocated and deallocated by caller. */
112 static varray_type typevec
;
114 /* Number of types interned by `build_mangled_name' so far. */
115 static size_t maxtype
;
117 /* Called once to initialize method.c. */
122 gcc_obstack_init (&scratch_obstack
);
123 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
124 ggc_add_tree_varray_root (&btypelist
, 1);
125 ggc_add_tree_varray_root (&ktypelist
, 1);
126 ggc_add_tree_varray_root (&typevec
, 1);
129 /* This must be large enough to hold any printed integer or floating-point
131 static char digit_buffer
[128];
133 /* Move inline function definitions out of structure so that they
134 can be processed normally. CNAME is the name of the class
135 we are working from, METHOD_LIST is the list of method lists
136 of the structure. We delete friend methods here, after
137 saving away their inline function definitions (if any). */
140 do_inline_function_hair (type
, friend_list
)
141 tree type
, friend_list
;
143 tree method
= TYPE_METHODS (type
);
145 if (method
&& TREE_CODE (method
) == TREE_VEC
)
147 if (TREE_VEC_ELT (method
, 1))
148 method
= TREE_VEC_ELT (method
, 1);
149 else if (TREE_VEC_ELT (method
, 0))
150 method
= TREE_VEC_ELT (method
, 0);
152 method
= TREE_VEC_ELT (method
, 2);
157 /* Do inline member functions. */
158 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
163 my_friendly_assert (info
->fndecl
== method
, 238);
164 args
= DECL_ARGUMENTS (method
);
167 DECL_CONTEXT (args
) = method
;
168 args
= TREE_CHAIN (args
);
171 method
= TREE_CHAIN (method
);
175 tree fndecl
= TREE_VALUE (friend_list
);
176 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
181 my_friendly_assert (info
->fndecl
== fndecl
, 239);
182 args
= DECL_ARGUMENTS (fndecl
);
185 DECL_CONTEXT (args
) = fndecl
;
186 args
= TREE_CHAIN (args
);
190 friend_list
= TREE_CHAIN (friend_list
);
194 /* Here is where overload code starts. */
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
)
211 VARRAY_TREE_INIT (btypelist
, 50, "btypelist");
212 VARRAY_TREE_INIT (ktypelist
, 50, "ktypelist");
219 if (flag_do_squangling
)
221 VARRAY_FREE (ktypelist
);
222 VARRAY_FREE (btypelist
);
228 /* Code to concatenate an asciified integer to a string. */
234 unsigned HOST_WIDE_INT ui
;
236 /* Handle this case first, to go really quickly. For many common values,
237 the result of ui/10 below is 1. */
255 OB_PUTC ('0' + (ui
% 10));
260 HOST_WIDE_INT lo
, hi
;
262 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
271 uhi
= (lo
== 0 ? -hi
: -hi
-1);
275 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
280 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
283 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
286 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
290 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
295 /* Returns the index of TYPE in the typevec, or -1 if it's not there. */
298 old_backref_index (type
)
303 if (! is_back_referenceable_type (type
))
306 /* The entry for this parm is at maxtype-1, so don't look there for
307 something to repeat. */
308 for (tindex
= 0; tindex
< maxtype
- 1; ++tindex
)
309 if (same_type_p (VARRAY_TREE (typevec
, tindex
), type
))
312 if (tindex
== maxtype
- 1)
318 /* Old mangling style: If TYPE has already been used in the parameter list,
319 emit a backward reference and return non-zero; otherwise, return 0.
321 NREPEATS is the number of repeats we've recorded of this type, or 0 if
322 this is the first time we've seen it and we're just looking to see if
323 it had been used before. */
326 flush_repeats (nrepeats
, type
)
330 int tindex
= old_backref_index (type
);
334 my_friendly_assert (nrepeats
== 0, 990316);
354 /* Returns nonzero iff this is a type to which we will want to make
355 back-references (using the `B' code). */
358 is_back_referenceable_type (type
)
361 /* For some reason, the Java folks don't want back refs on these. */
362 if (TYPE_FOR_JAVA (type
))
365 switch (TREE_CODE (type
))
368 if (!flag_do_squangling
)
369 /* Even though the mangling of this is just `b', we did
370 historically generate back-references for it. */
377 /* These types have single-character manglings, so there's no
378 point in generating back-references. */
381 case TEMPLATE_TYPE_PARM
:
382 /* It would be a bit complex to demangle signatures correctly if
383 we generated back-references to these, and the manglings of
384 type parameters are short. */
392 /* Issue the squangling code indicating NREPEATS repetitions of TYPE,
393 which was the last parameter type output. */
396 issue_nrepeats (nrepeats
, type
)
400 if (nrepeats
== 1 && !is_back_referenceable_type (type
))
401 /* For types whose manglings are short, don't bother using the
402 repetition code if there's only one repetition, since the
403 repetition code will be about as long as the ordinary mangling. */
404 build_mangled_name_for_type (type
);
414 /* Check to see if a tree node has been entered into the Kcode typelist.
415 If not, add it. Returns -1 if it isn't found, otherwise returns the
419 check_ktype (node
, add
)
424 tree localnode
= node
;
426 if (ktypelist
== NULL
)
429 if (TREE_CODE (node
) == TYPE_DECL
)
430 localnode
= TREE_TYPE (node
);
432 for (x
= 0; x
< maxktype
; x
++)
434 if (same_type_p (localnode
, VARRAY_TREE (ktypelist
, x
)))
437 /* Didn't find it, so add it here. */
440 if (VARRAY_SIZE (ktypelist
) <= maxktype
)
441 VARRAY_GROW (ktypelist
,
442 VARRAY_SIZE (ktypelist
) * 3 / 2);
443 VARRAY_TREE (ktypelist
, maxktype
) = localnode
;
455 kindex
= check_ktype (decl
, FALSE
);
467 /* Build a representation for DECL, which may be an entity not at
468 global scope. If so, a marker indicating that the name is
469 qualified has already been output, but the qualifying context has
473 build_overload_nested_name (decl
)
478 if (ktypelist
&& issue_ktype (decl
))
481 if (decl
== global_namespace
)
484 context
= CP_DECL_CONTEXT (decl
);
486 /* try to issue a K type, and if we can't continue the normal path */
487 if (!(ktypelist
&& issue_ktype (context
)))
489 /* For a template type parameter, we want to output an 'Xn'
490 rather than 'T' or some such. */
491 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
492 || TREE_CODE (context
) == TEMPLATE_TEMPLATE_PARM
)
493 build_mangled_name_for_type (context
);
496 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
497 context
= TYPE_NAME (context
);
498 build_overload_nested_name (context
);
502 if (TREE_CODE (decl
) == FUNCTION_DECL
)
504 tree name
= DECL_ASSEMBLER_NAME (decl
);
507 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
510 if (numeric_output_need_bar
)
512 icat (strlen (label
));
514 numeric_output_need_bar
= 1;
516 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
517 build_overload_identifier (DECL_NAME (decl
));
519 build_overload_identifier (decl
);
522 /* Output the decimal representation of I. If I > 9, the decimal
523 representation is preceeded and followed by an underscore. */
526 build_underscore_int (i
)
537 build_overload_scope_ref (value
)
541 numeric_output_need_bar
= 0;
542 build_mangled_name_for_type (TREE_OPERAND (value
, 0));
543 build_overload_identifier (TREE_OPERAND (value
, 1));
546 /* Encoding for an INTEGER_CST value. */
549 build_overload_int (value
, in_template
)
553 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
555 if (TREE_CODE (value
) == SCOPE_REF
)
557 build_overload_scope_ref (value
);
562 numeric_output_need_bar
= 0;
564 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value
))))
567 int operands
= tree_code_length
[(int) TREE_CODE (value
)];
571 id
= ansi_opname
[(int) TREE_CODE (value
)];
572 my_friendly_assert (id
!= NULL_TREE
, 0);
573 name
= IDENTIFIER_POINTER (id
);
574 if (name
[0] != '_' || name
[1] != '_')
575 /* On some erroneous inputs, we can get here with VALUE a
576 LOOKUP_EXPR. In that case, the NAME will be the
577 identifier for "<invalid operator>". We must survive
578 this routine in order to issue a sensible error
579 message, so we fall through to the case below. */
582 for (i
= 0; i
< operands
; ++i
)
587 /* We just outputted either the `E' or the name of the
589 numeric_output_need_bar
= 0;
592 /* Skip the leading underscores. */
595 operand
= TREE_OPERAND (value
, i
);
596 tc
= TREE_CODE (operand
);
598 if (TREE_CODE_CLASS (tc
) == 't')
599 /* We can get here with sizeof, e.g.:
601 template <class T> void f(A<sizeof(T)>); */
602 build_mangled_name_for_type (operand
);
603 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc
)))
604 build_overload_int (operand
, in_template
);
606 build_overload_value (TREE_TYPE (operand
),
613 /* We don't ever want this output, but it's
614 inconvenient not to be able to build the string.
615 This should cause assembler errors we'll notice. */
619 sprintf (digit_buffer
, " *%d", n
++);
620 OB_PUTCP (digit_buffer
);
624 numeric_output_need_bar
= 0;
628 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
629 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
631 if (TREE_INT_CST_HIGH (value
)
632 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
634 /* need to print a DImode value in decimal */
635 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
636 numeric_output_need_bar
= 1;
639 /* else fall through to print in smaller mode */
641 /* Wordsize or smaller */
642 icat (TREE_INT_CST_LOW (value
));
643 numeric_output_need_bar
= 1;
647 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
648 supplied in INDEX. */
651 build_mangled_template_parm_index (s
, index
)
656 build_underscore_int (TEMPLATE_PARM_IDX (index
));
657 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
658 representation of the function from the point of view of its
660 build_underscore_int (TEMPLATE_PARM_LEVEL (index
));
664 /* Mangling for C9X integer types (and Cygnus extensions for 128-bit
665 and other types) is based on the letter "I" followed by the hex
666 representations of the bitsize for the type in question. For
667 encodings that result in larger than two digits, a leading and
668 trailing underscore is added.
679 int256_t = 100 = I_100_
680 int512_t = 200 = I_200_
682 Given an integer in decimal format, mangle according to this scheme. */
684 #if HOST_BITS_PER_WIDE_INT >= 64
686 build_mangled_C9x_name (bits
)
689 char mangled
[10] = "";
692 sprintf (mangled
, "I_%x_", bits
);
694 sprintf (mangled
, "I%.2x", bits
);
701 build_overload_value (type
, value
, in_template
)
705 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type
)) == 't', 0);
707 while (TREE_CODE (value
) == NON_LVALUE_EXPR
708 || TREE_CODE (value
) == NOP_EXPR
)
709 value
= TREE_OPERAND (value
, 0);
711 if (numeric_output_need_bar
)
714 numeric_output_need_bar
= 0;
717 if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
719 build_mangled_template_parm_index ("Y", value
);
723 if (TYPE_PTRMEM_P (type
))
725 if (TREE_CODE (value
) != PTRMEM_CST
)
726 /* We should have already rejected this pointer to member,
727 since it is not a constant. */
728 my_friendly_abort (0);
730 /* Get the actual FIELD_DECL. */
731 value
= PTRMEM_CST_MEMBER (value
);
732 my_friendly_assert (TREE_CODE (value
) == FIELD_DECL
, 0);
734 /* Output the name of the field. */
735 build_overload_identifier (DECL_NAME (value
));
739 switch (TREE_CODE (type
))
745 build_overload_int (value
, in_template
);
751 char *bufp
= digit_buffer
;
753 pedwarn ("ANSI C++ forbids floating-point template arguments");
755 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
756 val
= TREE_REAL_CST (value
);
757 if (REAL_VALUE_ISNAN (val
))
759 sprintf (bufp
, "NaN");
763 if (REAL_VALUE_NEGATIVE (val
))
765 val
= REAL_VALUE_NEGATE (val
);
768 if (REAL_VALUE_ISINF (val
))
770 sprintf (bufp
, "Infinity");
774 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
775 bufp
= (char *) index (bufp
, 'e');
777 strcat (digit_buffer
, "e0");
803 #ifdef NO_DOT_IN_LABEL
804 bufp
= (char *) index (bufp
, '.');
810 OB_PUTCP (digit_buffer
);
811 numeric_output_need_bar
= 1;
815 if (TREE_CODE (value
) == INTEGER_CST
)
817 build_overload_int (value
, in_template
);
820 else if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
822 build_mangled_template_parm_index ("", value
);
823 numeric_output_need_bar
= 1;
827 value
= TREE_OPERAND (value
, 0);
832 if (TREE_CODE (value
) == VAR_DECL
)
834 my_friendly_assert (DECL_NAME (value
) != 0, 245);
835 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
838 else if (TREE_CODE (value
) == FUNCTION_DECL
)
840 my_friendly_assert (DECL_NAME (value
) != 0, 246);
841 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
844 else if (TREE_CODE (value
) == SCOPE_REF
)
845 build_overload_scope_ref (value
);
847 my_friendly_abort (71);
848 break; /* not really needed */
857 my_friendly_assert (TYPE_PTRMEMFUNC_P (type
), 0);
859 /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're
860 mangling, an instantiation of something like:
862 template <class T, void (T::*fp)()> class C {};
863 template <class T> C<T, &T::f> x();
865 We mangle the return type of the function, and that
866 contains template parameters. */
867 if (TREE_CODE (value
) == ADDR_EXPR
868 && TREE_CODE (TREE_OPERAND (value
, 0)) == SCOPE_REF
)
870 build_overload_scope_ref (TREE_OPERAND (value
, 0));
874 my_friendly_assert (TREE_CODE (value
) == PTRMEM_CST
, 0);
876 expand_ptrmemfunc_cst (value
, &delta
, &idx
, &pfn
, &delta2
);
877 build_overload_int (delta
, in_template
);
879 build_overload_int (idx
, in_template
);
883 numeric_output_need_bar
= 0;
884 build_overload_identifier (DECL_ASSEMBLER_NAME
885 (PTRMEM_CST_MEMBER (value
)));
890 build_overload_int (delta2
, in_template
);
896 sorry ("conversion of %s as template parameter",
897 tree_code_name
[(int) TREE_CODE (type
)]);
898 my_friendly_abort (72);
903 /* Add encodings for the declaration of template template parameters.
904 PARMLIST must be a TREE_VEC. */
907 build_template_template_parm_names (parmlist
)
912 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
913 nparms
= TREE_VEC_LENGTH (parmlist
);
915 for (i
= 0; i
< nparms
; i
++)
917 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
918 if (TREE_CODE (parm
) == TYPE_DECL
)
920 /* This parameter is a type. */
923 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
925 /* This parameter is a template. */
927 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
930 /* It's a PARM_DECL. */
931 build_mangled_name_for_type (TREE_TYPE (parm
));
936 /* Add encodings for the vector of template parameters in PARMLIST,
937 given the vector of arguments to be substituted in ARGLIST. */
940 build_template_parm_names (parmlist
, arglist
)
945 tree inner_args
= innermost_args (arglist
);
947 nparms
= TREE_VEC_LENGTH (parmlist
);
949 for (i
= 0; i
< nparms
; i
++)
951 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
952 tree arg
= TREE_VEC_ELT (inner_args
, i
);
953 if (TREE_CODE (parm
) == TYPE_DECL
)
955 /* This parameter is a type. */
957 build_mangled_name_for_type (arg
);
959 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
961 /* This parameter is a template. */
962 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
963 /* Output parameter declaration, argument index and level. */
964 build_mangled_name_for_type (arg
);
967 /* A TEMPLATE_DECL node, output the parameter declaration
971 build_template_template_parm_names
972 (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
973 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
974 OB_PUTID (DECL_NAME (arg
));
979 parm
= tsubst (parm
, arglist
, /*complain=*/1, NULL_TREE
);
980 /* It's a PARM_DECL. */
981 build_mangled_name_for_type (TREE_TYPE (parm
));
982 build_overload_value (TREE_TYPE (parm
), arg
,
983 uses_template_parms (arglist
));
988 /* Output the representation for NAME, which is either a TYPE_DECL or
992 build_overload_identifier (name
)
995 if (TREE_CODE (name
) == TYPE_DECL
996 && CLASS_TYPE_P (TREE_TYPE (name
))
997 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
998 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
999 || (TREE_CODE (CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
1000 (TREE_TYPE (name
))))
1003 /* NAME is the TYPE_DECL for a template specialization. */
1004 tree
template, parmlist
, arglist
, tname
;
1005 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
));
1006 arglist
= CLASSTYPE_TI_ARGS (TREE_TYPE (name
));
1007 tname
= DECL_NAME (template);
1008 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
1010 icat (IDENTIFIER_LENGTH (tname
));
1012 build_template_parm_names (parmlist
, arglist
);
1016 if (TREE_CODE (name
) == TYPE_DECL
)
1017 name
= DECL_NAME (name
);
1018 if (numeric_output_need_bar
)
1021 numeric_output_need_bar
= 0;
1023 icat (IDENTIFIER_LENGTH (name
));
1028 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
1029 the mangling for it. Used by build_mangled_name and build_static_name. */
1032 build_qualified_name (decl
)
1038 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
1039 decl
= TYPE_NAME (decl
);
1041 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1042 if (TREE_CODE (decl
) == TYPE_DECL
1043 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
) && !flag_do_squangling
)
1045 tree id
= DECL_ASSEMBLER_NAME (decl
);
1047 if (ISDIGIT (IDENTIFIER_POINTER (id
) [IDENTIFIER_LENGTH (id
) - 1]))
1048 numeric_output_need_bar
= 1;
1053 /* If we can't find a Ktype, do it the hard way. */
1054 if (check_ktype (context
, FALSE
) == -1)
1056 /* Count type and namespace scopes. */
1059 context
= CP_DECL_CONTEXT (context
);
1060 if (context
== global_namespace
)
1063 if (check_ktype (context
, FALSE
) != -1)
1066 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
1067 context
= TYPE_NAME (context
);
1074 build_underscore_int (i
);
1075 numeric_output_need_bar
= 0;
1077 build_overload_nested_name (decl
);
1080 /* Output the mangled representation for TYPE. If EXTRA_GCODE is
1081 non-zero, mangled names for structure/union types are intentionally
1082 mangled differently from the method described in the ARM. */
1085 build_mangled_name_for_type_with_Gcode (type
, extra_Gcode
)
1089 if (TYPE_PTRMEMFUNC_P (type
))
1090 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
1091 process_modifiers (type
);
1092 process_overload_item (type
, extra_Gcode
);
1095 /* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1099 build_mangled_name_for_type (type
)
1102 build_mangled_name_for_type_with_Gcode (type
, 0);
1105 /* Given a list of parameters in PARMTYPES, create an unambiguous
1106 overload string. Should distinguish any type that C (or C++) can
1107 distinguish. I.e., pointers to functions are treated correctly.
1109 Caller must deal with whether a final `e' goes on the end or not.
1111 Any default conversions must take place before this function
1114 BEGIN and END control initialization and finalization of the
1115 obstack where we build the string. */
1118 build_overload_name (parmtypes
, begin
, end
)
1123 start_squangling ();
1124 ret
= build_mangled_name (parmtypes
, begin
, end
);
1129 /* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1130 TREE_LIST, then it is a list of parameter types. Otherwise,
1131 PARMTYPES must be a single type. */
1134 build_mangled_name (parmtypes
, begin
, end
)
1141 if (TREE_CODE (parmtypes
) != TREE_LIST
)
1142 /* There is only one type. */
1143 build_mangled_name_for_type (parmtypes
);
1146 /* There are several types in a parameter list. */
1148 int old_style_repeats
= !flag_do_squangling
&& !nofold
&& typevec
;
1149 tree last_type
= NULL_TREE
;
1151 for (; parmtypes
&& parmtypes
!= void_list_node
;
1152 parmtypes
= TREE_CHAIN (parmtypes
))
1154 /* We used to call canonical_type_variant here, but that isn't
1155 good enough; it doesn't handle pointers to typedef types. So
1156 we can't just set TREE_USED to say we've seen a type already;
1157 we have to check each of the earlier types with same_type_p. */
1158 tree parmtype
= TREE_VALUE (parmtypes
);
1160 if (old_style_repeats
)
1162 /* Every argument gets counted. */
1163 my_friendly_assert (maxtype
< VARRAY_SIZE (typevec
), 387);
1164 VARRAY_TREE (typevec
, maxtype
) = parmtype
;
1168 if (last_type
&& same_type_p (parmtype
, last_type
))
1170 if (flag_do_squangling
1171 || (old_style_repeats
1172 && is_back_referenceable_type (parmtype
)))
1174 /* The next type is the same as this one. Keep
1175 track of the repetition, and output the repeat
1181 else if (nrepeats
!= 0)
1183 /* Indicate how many times the previous parameter was
1185 if (old_style_repeats
)
1186 flush_repeats (nrepeats
, last_type
);
1188 issue_nrepeats (nrepeats
, last_type
);
1192 last_type
= parmtype
;
1194 /* Note that for bug-compatibility with 2.7.2, we can't build up
1195 repeats of types other than the most recent one. So we call
1196 flush_repeats every round, if we get this far. */
1197 if (old_style_repeats
&& flush_repeats (0, parmtype
))
1200 /* Output the PARMTYPE. */
1201 build_mangled_name_for_type_with_Gcode (parmtype
, 1);
1204 /* Output the repeat count for the last parameter, if
1208 if (old_style_repeats
)
1209 flush_repeats (nrepeats
, last_type
);
1211 issue_nrepeats (nrepeats
, last_type
);
1216 /* The parameter list ends in an ellipsis. */
1222 return (char *)obstack_base (&scratch_obstack
);
1225 /* Emit modifiers such as constant, read-only, and volatile. */
1228 process_modifiers (parmtype
)
1231 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1232 we describe types recursively; we will get the `const' in
1233 `const int ()[10]' when processing the `const int' part. */
1234 if (TYPE_READONLY (parmtype
))
1236 if (TREE_CODE (parmtype
) == INTEGER_TYPE
1237 && parmtype
!= char_type_node
1238 && parmtype
!= wchar_type_node
1239 && (TYPE_MAIN_VARIANT (parmtype
)
1240 == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
1241 && ! TYPE_FOR_JAVA (parmtype
))
1243 if (TYPE_VOLATILE (parmtype
))
1245 /* It would be better to use `R' for `restrict', but that's already
1246 used for reference types. And `r' is used for `long double'. */
1247 if (TYPE_RESTRICT (parmtype
))
1251 /* Check to see if TYPE has been entered into the Bcode typelist. If
1252 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1253 to the list of back-referenceable types and return 0. */
1261 if (btypelist
== NULL
)
1264 if (!is_back_referenceable_type (type
))
1267 for (x
= 0; x
< maxbtype
; x
++)
1268 if (same_type_p (type
, VARRAY_TREE (btypelist
, x
)))
1277 if (VARRAY_SIZE (btypelist
) <= maxbtype
)
1278 /* Enlarge the table. */
1279 VARRAY_GROW (btypelist
,
1280 VARRAY_SIZE (btypelist
) * 3 / 2);
1282 /* Register the TYPE. */
1283 VARRAY_TREE (btypelist
, maxbtype
) = type
;
1289 /* Emit the correct code for various node types. */
1292 process_overload_item (parmtype
, extra_Gcode
)
1296 numeric_output_need_bar
= 0;
1298 /* Our caller should have already handed any qualifiers, so pull out the
1299 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1300 for arrays, because they are transparent to qualifiers. Sigh. */
1301 if (TREE_CODE (parmtype
) == ARRAY_TYPE
)
1302 parmtype
= canonical_type_variant (parmtype
);
1304 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1306 /* These tree types are considered modifiers for B code squangling,
1307 and therefore should not get entries in the Btypelist. They are,
1308 however, repeatable types. */
1310 switch (TREE_CODE (parmtype
))
1312 case REFERENCE_TYPE
:
1317 #if PARM_CAN_BE_ARRAY_TYPE
1320 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
1324 tree length
= array_type_nelts (parmtype
);
1325 if (TREE_CODE (length
) != INTEGER_CST
|| flag_do_squangling
)
1327 length
= fold (build (PLUS_EXPR
, TREE_TYPE (length
),
1328 length
, integer_one_node
));
1329 STRIP_NOPS (length
);
1331 build_overload_value (sizetype
, length
, 1);
1333 if (numeric_output_need_bar
&& ! flag_do_squangling
)
1345 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1353 if (flag_do_squangling
&& check_btype (parmtype
))
1354 /* If PARMTYPE is already in the list of back-referenceable types,
1355 then check_btype will output the appropriate reference, and
1356 there's nothing more to do. */
1359 switch (TREE_CODE (parmtype
))
1363 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype
));
1365 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1371 tree parms
= TYPE_ARG_TYPES (parmtype
);
1373 /* Rather than implementing a reentrant TYPEVEC, we turn off
1374 repeat codes here, unless we're squangling. Squangling
1375 doesn't make use of the TYPEVEC, so there's no reentrancy
1377 int old_nofold
= nofold
;
1378 if (!flag_do_squangling
)
1381 if (TREE_CODE (parmtype
) == METHOD_TYPE
)
1383 /* Mark this as a method. */
1385 /* Output the class of which this method is a member. */
1386 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype
));
1387 /* Output any qualifiers for the `this' parameter. */
1388 process_modifiers (TREE_TYPE (TREE_VALUE (parms
)));
1391 /* Output the parameter types. */
1393 if (parms
== NULL_TREE
)
1395 else if (parms
== void_list_node
)
1398 build_mangled_name (parms
, 0, 0);
1400 /* Output the return type. */
1402 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1404 nofold
= old_nofold
;
1409 if (parmtype
== integer_type_node
1410 || parmtype
== unsigned_type_node
1411 || parmtype
== java_int_type_node
)
1413 else if (parmtype
== long_integer_type_node
1414 || parmtype
== long_unsigned_type_node
)
1416 else if (parmtype
== short_integer_type_node
1417 || parmtype
== short_unsigned_type_node
1418 || parmtype
== java_short_type_node
)
1420 else if (parmtype
== signed_char_type_node
)
1425 else if (parmtype
== char_type_node
1426 || parmtype
== unsigned_char_type_node
1427 || parmtype
== java_byte_type_node
)
1429 else if (parmtype
== wchar_type_node
1430 || parmtype
== java_char_type_node
)
1432 else if (parmtype
== long_long_integer_type_node
1433 || parmtype
== long_long_unsigned_type_node
1434 || parmtype
== java_long_type_node
)
1436 else if (parmtype
== java_boolean_type_node
)
1438 #if HOST_BITS_PER_WIDE_INT >= 64
1441 int bits
= TREE_INT_CST_LOW (TYPE_SIZE (parmtype
));
1442 build_mangled_C9x_name (bits
);
1446 my_friendly_abort (73);
1455 if (parmtype
== long_double_type_node
)
1457 else if (parmtype
== double_type_node
1458 || parmtype
== java_double_type_node
)
1460 else if (parmtype
== float_type_node
1461 || parmtype
== java_float_type_node
)
1463 else my_friendly_abort (74);
1468 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1475 case ERROR_MARK
: /* not right, but nothing is anyway */
1478 /* have to do these */
1483 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1484 /* drop through into next case */
1488 tree name
= TYPE_NAME (parmtype
);
1490 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1492 build_qualified_name (name
);
1497 /* This will take some work. */
1501 case TEMPLATE_TEMPLATE_PARM
:
1502 /* Find and output the original template parameter
1504 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype
))
1506 build_mangled_template_parm_index ("tzX",
1507 TEMPLATE_TYPE_PARM_INDEX
1509 build_template_parm_names
1510 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype
)),
1511 TYPE_TI_ARGS (parmtype
));
1515 build_mangled_template_parm_index ("ZzX",
1516 TEMPLATE_TYPE_PARM_INDEX
1518 build_template_template_parm_names
1519 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1523 case TEMPLATE_TYPE_PARM
:
1524 build_mangled_template_parm_index ("X",
1525 TEMPLATE_TYPE_PARM_INDEX
1530 /* When mangling the type of a function template whose
1531 declaration looks like:
1533 template <class T> void foo(typename T::U)
1535 we have to mangle these. */
1536 build_qualified_name (parmtype
);
1540 my_friendly_abort (75);
1545 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1546 be either a class TYPE or a FUNCTION_DECL. */
1549 build_static_name (context
, name
)
1553 numeric_output_need_bar
= 0;
1554 start_squangling ();
1557 build_qualified_name (context
);
1560 OB_PUTS ("__static_");
1561 build_qualified_name (context
);
1568 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1571 /* FOR_METHOD should be 1 if the declaration in question is for a member
1572 of a class (including a static member) and 2 if the declaration is
1573 for a constructor. */
1575 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1584 const char *name
= IDENTIFIER_POINTER (dname
);
1586 /* member operators new and delete look like methods at this point. */
1587 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1588 && TREE_CHAIN (parms
) == void_list_node
)
1590 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1591 return get_identifier ("__builtin_delete");
1592 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1593 return get_identifier ("__builtin_vec_delete");
1594 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1595 return get_identifier ("__builtin_new");
1596 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1597 return get_identifier ("__builtin_vec_new");
1600 start_squangling ();
1602 if (for_method
!= 2)
1604 /* Otherwise, we can divine that this is a constructor,
1605 and figure out its name without any extra encoding. */
1607 OB_PUTC2 ('_', '_');
1608 numeric_output_need_bar
= 0;
1613 build_template_parm_names (tparms
, targs
);
1616 else if (!for_method
&& current_namespace
== global_namespace
)
1617 /* XXX this works only if we call this in the same namespace
1618 as the declaration. Unfortunately, we don't have the _DECL,
1622 if (!for_method
&& current_namespace
!= global_namespace
)
1623 /* qualify with namespace */
1624 build_qualified_name (current_namespace
);
1626 if (parms
== NULL_TREE
)
1628 else if (parms
== void_list_node
)
1632 if (!flag_do_squangling
)
1634 /* Allocate typevec array. */
1635 size_t typevec_size
= list_length (parms
);
1637 if (!for_method
&& current_namespace
!= global_namespace
)
1638 /* The namespace of a global function needs one slot. */
1640 VARRAY_TREE_INIT (typevec
, typevec_size
, "typevec");
1646 tree this_type
= TREE_TYPE (TREE_VALUE (parms
));
1648 build_mangled_name_for_type (this_type
);
1650 if (!flag_do_squangling
)
1652 my_friendly_assert (maxtype
< VARRAY_SIZE (typevec
), 387);
1653 VARRAY_TREE (typevec
, maxtype
) = this_type
;
1657 if (TREE_CHAIN (parms
))
1658 build_mangled_name (TREE_CHAIN (parms
), 0, 0);
1664 /* the namespace qualifier for a global function
1665 will count as type */
1666 if (current_namespace
!= global_namespace
1667 && !flag_do_squangling
)
1669 my_friendly_assert (maxtype
< VARRAY_SIZE (typevec
), 387);
1670 VARRAY_TREE (typevec
, maxtype
) = current_namespace
;
1673 build_mangled_name (parms
, 0, 0);
1676 if (!flag_do_squangling
)
1677 /* Deallocate typevec array. */
1678 VARRAY_FREE (typevec
);
1681 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1683 /* Add the return type. */
1685 build_mangled_name_for_type (ret_type
);
1691 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1692 if (IDENTIFIER_OPNAME_P (dname
))
1693 IDENTIFIER_OPNAME_P (n
) = 1;
1698 /* Change the name of a function definition so that it may be
1699 overloaded. NAME is the name of the function to overload,
1700 PARMS is the parameter list (which determines what name the
1701 final function obtains).
1703 FOR_METHOD is 1 if this overload is being performed
1704 for a method, rather than a function type. It is 2 if
1705 this overload is being performed for a constructor. */
1708 build_decl_overload (dname
, parms
, for_method
)
1713 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1714 NULL_TREE
, for_method
);
1717 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
1720 set_mangled_name_for_decl (decl
)
1725 if (processing_template_decl
)
1726 /* There's no need to mangle the name of a template function. */
1729 parm_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
1731 if (DECL_STATIC_FUNCTION_P (decl
))
1733 hash_tree_chain (build_pointer_type (DECL_CLASS_CONTEXT (decl
)),
1736 /* The only member functions whose type is a FUNCTION_TYPE, rather
1737 than a METHOD_TYPE, should be static members. */
1738 my_friendly_assert (!DECL_CONTEXT (decl
)
1739 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl
)))
1740 || TREE_CODE (TREE_TYPE (decl
)) != FUNCTION_TYPE
,
1743 DECL_ASSEMBLER_NAME (decl
)
1744 = build_decl_overload (DECL_NAME (decl
), parm_types
,
1745 DECL_FUNCTION_MEMBER_P (decl
)
1746 + DECL_CONSTRUCTOR_P (decl
));
1749 /* Build an overload name for the type expression TYPE. */
1752 build_typename_overload (type
)
1758 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1760 start_squangling ();
1761 build_mangled_name (type
, 0, 1);
1762 id
= get_identifier (obstack_base (&scratch_obstack
));
1763 IDENTIFIER_OPNAME_P (id
) = 1;
1765 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1767 TREE_TYPE (id
) = type
;
1773 build_overload_with_type (name
, type
)
1780 start_squangling ();
1781 build_mangled_name (type
, 0, 1);
1783 return get_identifier (obstack_base (&scratch_obstack
));
1787 get_id_2 (name
, name2
)
1795 return get_identifier (obstack_base (&scratch_obstack
));
1798 /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1801 build_destructor_name (type
)
1804 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX
),
1808 /* Given a tree_code CODE, and some arguments (at least one),
1809 attempt to use an overloaded operator on the arguments.
1811 For unary operators, only the first argument need be checked.
1812 For binary operators, both arguments may need to be checked.
1814 Member functions can convert class references to class pointers,
1815 for one-level deep indirection. More than that is not supported.
1816 Operators [](), ()(), and ->() must be member functions.
1818 We call function call building calls with LOOKUP_COMPLAIN if they
1819 are our only hope. This is true when we see a vanilla operator
1820 applied to something of aggregate type. If this fails, we are free
1821 to return `error_mark_node', because we will have reported the
1824 Operators NEW and DELETE overload in funny ways: operator new takes
1825 a single `size' parameter, and operator delete takes a pointer to the
1826 storage being deleted. When overloading these operators, success is
1827 assumed. If there is a failure, report an error message and return
1828 `error_mark_node'. */
1832 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1833 enum tree_code code
;
1835 tree xarg1
, xarg2
, arg3
;
1837 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1840 /* This function takes an identifier, ID, and attempts to figure out what
1841 it means. There are a number of possible scenarios, presented in increasing
1844 1) not in a class's scope
1845 2) in class's scope, member name of the class's method
1846 3) in class's scope, but not a member name of the class
1847 4) in class's scope, member name of a class's variable
1849 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1850 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1852 As a last ditch, try to look up the name as a label and return that
1855 Values which are declared as being of REFERENCE_TYPE are
1856 automatically dereferenced here (as a hack to make the
1857 compiler faster). */
1860 hack_identifier (value
, name
)
1865 if (value
== error_mark_node
)
1867 if (current_class_name
)
1869 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1870 if (fields
== error_mark_node
)
1871 return error_mark_node
;
1876 fndecl
= TREE_VALUE (fields
);
1877 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1878 /* I could not trigger this code. MvL */
1879 my_friendly_abort (980325);
1881 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1883 warning ("methods cannot be converted to function pointers");
1888 error ("ambiguous request for method pointer `%s'",
1889 IDENTIFIER_POINTER (name
));
1890 return error_mark_node
;
1895 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1897 return IDENTIFIER_LABEL_VALUE (name
);
1899 return error_mark_node
;
1902 type
= TREE_TYPE (value
);
1903 if (TREE_CODE (value
) == FIELD_DECL
)
1905 if (current_class_ptr
== NULL_TREE
)
1907 if (current_function_decl
1908 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1909 cp_error ("invalid use of member `%D' in static member function",
1912 /* We can get here when processing a bad default
1914 struct S { int a; void f(int i = a); } */
1915 cp_error ("invalid use of member `%D'", value
);
1917 return error_mark_node
;
1919 TREE_USED (current_class_ptr
) = 1;
1921 /* Mark so that if we are in a constructor, and then find that
1922 this field was initialized by a base initializer,
1923 we can emit an error message. */
1924 TREE_USED (value
) = 1;
1925 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1927 else if ((TREE_CODE (value
) == FUNCTION_DECL
1928 && DECL_FUNCTION_MEMBER_P (value
))
1929 || (TREE_CODE (value
) == OVERLOAD
1930 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value
))))
1934 if (TREE_CODE (value
) == OVERLOAD
)
1935 value
= OVL_CURRENT (value
);
1937 decl
= maybe_dummy_object (DECL_CLASS_CONTEXT (value
), 0);
1938 value
= build_component_ref (decl
, name
, NULL_TREE
, 1);
1940 else if (really_overloaded_fn (value
))
1942 else if (TREE_CODE (value
) == OVERLOAD
)
1943 /* not really overloaded function */
1944 mark_used (OVL_FUNCTION (value
));
1945 else if (TREE_CODE (value
) == TREE_LIST
)
1947 /* Ambiguous reference to base members, possibly other cases?. */
1949 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1951 mark_used (TREE_VALUE (t
));
1955 else if (TREE_CODE (value
) == NAMESPACE_DECL
)
1957 cp_error ("use of namespace `%D' as expression", value
);
1958 return error_mark_node
;
1960 else if (DECL_CLASS_TEMPLATE_P (value
))
1962 cp_error ("use of class template `%T' as expression", value
);
1963 return error_mark_node
;
1968 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
1969 || TREE_CODE (value
) == RESULT_DECL
)
1971 tree context
= decl_function_context (value
);
1972 if (context
!= NULL_TREE
&& context
!= current_function_decl
1973 && ! TREE_STATIC (value
))
1975 cp_error ("use of %s from containing function",
1976 (TREE_CODE (value
) == VAR_DECL
1977 ? "`auto' variable" : "parameter"));
1978 cp_error_at (" `%#D' declared here", value
);
1979 value
= error_mark_node
;
1983 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1985 if (DECL_LANG_SPECIFIC (value
)
1986 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1989 register tree context
1990 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1991 ? DECL_CLASS_CONTEXT (value
)
1992 : DECL_CONTEXT (value
);
1994 get_base_distance (context
, current_class_type
, 0, &path
);
1995 if (path
&& !enforce_access (current_class_type
, value
))
1996 return error_mark_node
;
1999 else if (TREE_CODE (value
) == TREE_LIST
2000 && TREE_TYPE (value
) == error_mark_node
)
2002 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2003 IDENTIFIER_POINTER (name
));
2004 print_candidates (value
);
2005 return error_mark_node
;
2008 if (! processing_template_decl
)
2009 value
= convert_from_reference (value
);
2015 make_thunk (function
, delta
)
2023 if (TREE_CODE (function
) != ADDR_EXPR
)
2025 func_decl
= TREE_OPERAND (function
, 0);
2026 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
2030 OB_PUTS ("__thunk_");
2039 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl
));
2041 thunk_id
= get_identifier (obstack_base (&scratch_obstack
));
2043 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
2044 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
2046 cp_error ("implementation-reserved name `%D' used", thunk_id
);
2048 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id
, thunk
);
2050 if (thunk
== NULL_TREE
)
2052 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
2053 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
2054 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
2055 comdat_linkage (thunk
);
2056 TREE_SET_CODE (thunk
, THUNK_DECL
);
2057 DECL_INITIAL (thunk
) = function
;
2058 THUNK_DELTA (thunk
) = delta
;
2059 DECL_EXTERNAL (thunk
) = 1;
2060 DECL_ARTIFICIAL (thunk
) = 1;
2061 /* So that finish_file can write out any thunks that need to be: */
2062 pushdecl_top_level (thunk
);
2067 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2070 emit_thunk (thunk_fndecl
)
2073 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
2074 int delta
= THUNK_DELTA (thunk_fndecl
);
2076 if (TREE_ASM_WRITTEN (thunk_fndecl
))
2079 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
2081 TREE_ADDRESSABLE (function
) = 1;
2082 mark_used (function
);
2084 if (current_function_decl
)
2087 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
2090 #ifdef ASM_OUTPUT_MI_THUNK
2092 current_function_decl
= thunk_fndecl
;
2093 /* Make sure we build up its RTL before we go onto the
2094 temporary obstack. */
2095 make_function_rtl (thunk_fndecl
);
2096 temporary_allocation ();
2097 DECL_RESULT (thunk_fndecl
)
2098 = build_decl (RESULT_DECL
, 0, integer_type_node
);
2099 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
2100 init_function_start (thunk_fndecl
, input_filename
, lineno
);
2101 current_function_is_thunk
= 1;
2102 assemble_start_function (thunk_fndecl
, fnname
);
2103 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
2104 assemble_end_function (thunk_fndecl
, fnname
);
2105 permanent_allocation (1);
2106 current_function_decl
= 0;
2107 #else /* ASM_OUTPUT_MI_THUNK */
2108 /* If we don't have the necessary macro for efficient thunks, generate a
2109 thunk function that just makes a call to the real function.
2110 Unfortunately, this doesn't work for varargs. */
2114 if (varargs_function_p (function
))
2115 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2118 /* Set up clone argument trees for the thunk. */
2120 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
2122 tree x
= copy_node (a
);
2124 DECL_CONTEXT (x
) = thunk_fndecl
;
2128 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2129 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2130 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2131 copy_lang_decl (thunk_fndecl
);
2132 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2133 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2135 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
2136 store_parm_decls ();
2137 current_function_is_thunk
= 1;
2139 /* Build up the call to the real function. */
2140 t
= build_int_2 (delta
, -1 * (delta
< 0));
2141 TREE_TYPE (t
) = signed_type (sizetype
);
2142 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2143 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
2144 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2145 t
= expr_tree_cons (NULL_TREE
, a
, t
);
2147 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2148 c_expand_return (t
);
2150 finish_function (lineno
, 0, 0);
2152 /* Don't let the backend defer this function. */
2153 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2155 output_inline_function (thunk_fndecl
);
2156 permanent_allocation (1);
2158 #endif /* ASM_OUTPUT_MI_THUNK */
2161 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2164 /* Code for synthesizing methods which have default semantics defined. */
2166 /* Generate code for default X(X&) constructor. */
2169 do_build_copy_constructor (fndecl
)
2172 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2176 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2177 parm
= TREE_CHAIN (parm
);
2178 parm
= convert_from_reference (parm
);
2180 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
)
2181 && is_empty_class (current_class_type
))
2182 /* Don't copy the padding byte; it might not have been allocated
2183 if *this is a base subobject. */;
2184 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2186 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2187 TREE_SIDE_EFFECTS (t
) = 1;
2188 finish_expr_stmt (t
);
2192 tree fields
= TYPE_FIELDS (current_class_type
);
2193 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2194 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2197 /* Initialize all the base-classes. */
2198 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2200 current_base_init_list
2201 = tree_cons (BINFO_TYPE (t
), parm
, current_base_init_list
);
2202 for (i
= 0; i
< n_bases
; ++i
)
2204 t
= TREE_VEC_ELT (binfos
, i
);
2205 if (TREE_VIA_VIRTUAL (t
))
2208 current_base_init_list
2209 = tree_cons (BINFO_TYPE (t
), parm
, current_base_init_list
);
2212 for (; fields
; fields
= TREE_CHAIN (fields
))
2215 tree field
= fields
;
2217 if (TREE_CODE (field
) != FIELD_DECL
)
2221 if (DECL_NAME (field
))
2223 if (VFIELD_NAME_P (DECL_NAME (field
)))
2225 if (VBASE_NAME_P (DECL_NAME (field
)))
2228 /* True for duplicate members. */
2229 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2232 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2233 && ANON_AGGR_TYPE_P (t
)
2234 && TYPE_FIELDS (t
) != NULL_TREE
)
2235 /* Just use the field; anonymous types can't have
2236 nontrivial copy ctors or assignment ops. */;
2240 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2241 init
= build_tree_list (NULL_TREE
, init
);
2243 current_member_init_list
2244 = tree_cons (field
, init
, current_member_init_list
);
2246 current_member_init_list
= nreverse (current_member_init_list
);
2247 current_base_init_list
= nreverse (current_base_init_list
);
2251 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
2252 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
2256 do_build_assign_ref (fndecl
)
2259 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2262 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
2263 parm
= convert_from_reference (parm
);
2265 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
)
2266 && is_empty_class (current_class_type
))
2267 /* Don't copy the padding byte; it might not have been allocated
2268 if *this is a base subobject. */;
2269 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2271 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2272 TREE_SIDE_EFFECTS (t
) = 1;
2273 finish_expr_stmt (t
);
2277 tree fields
= TYPE_FIELDS (current_class_type
);
2278 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2279 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2282 for (i
= 0; i
< n_bases
; ++i
)
2284 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2285 tree p
= convert_to_reference
2286 (build_reference_type (basetype
), parm
,
2287 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2288 p
= convert_from_reference (p
);
2289 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2290 build_expr_list (NULL_TREE
, p
));
2291 expand_expr_stmt (p
);
2293 for (; fields
; fields
= TREE_CHAIN (fields
))
2296 tree field
= fields
;
2298 if (TREE_CODE (field
) != FIELD_DECL
)
2301 if (CP_TYPE_CONST_P (TREE_TYPE (field
)))
2303 if (DECL_NAME (field
))
2304 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2306 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2309 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2311 if (DECL_NAME (field
))
2312 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2314 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2318 comp
= current_class_ref
;
2321 if (DECL_NAME (field
))
2323 if (VFIELD_NAME_P (DECL_NAME (field
)))
2325 if (VBASE_NAME_P (DECL_NAME (field
)))
2328 /* True for duplicate members. */
2329 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2332 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2333 && ANON_AGGR_TYPE_P (t
)
2334 && TYPE_FIELDS (t
) != NULL_TREE
)
2335 /* Just use the field; anonymous types can't have
2336 nontrivial copy ctors or assignment ops. */;
2340 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2341 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2343 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2346 c_expand_return (current_class_ref
);
2347 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
2351 synthesize_method (fndecl
)
2354 int nested
= (current_function_decl
!= NULL_TREE
);
2355 tree context
= hack_decl_function_context (fndecl
);
2358 import_export_decl (fndecl
);
2361 push_to_top_level ();
2363 push_function_context_to (context
);
2365 interface_unknown
= 1;
2366 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2367 store_parm_decls ();
2370 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2371 do_build_assign_ref (fndecl
);
2372 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2376 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2377 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2378 arg_chain
= TREE_CHAIN (arg_chain
);
2379 if (arg_chain
!= void_list_node
)
2380 do_build_copy_constructor (fndecl
);
2381 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2386 compound_stmt
= begin_compound_stmt (/*has_no_scope=*/0);
2387 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt
);
2391 finish_function (lineno
, 0, nested
);
2393 extract_interface_info ();
2395 pop_from_top_level ();
2397 pop_function_context_from (context
);