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-96, 1997 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 #ifndef PARM_CAN_BE_ARRAY_TYPE
25 #define PARM_CAN_BE_ARRAY_TYPE 1
28 /* Handle method declarations. */
39 #include "hard-reg-set.h"
50 #ifdef NEED_DECLARATION_INDEX
51 extern char *index ();
54 /* TREE_LIST of the current inline functions that need to be
56 struct pending_inline
*pending_inlines
;
60 #define obstack_chunk_alloc xmalloc
61 #define obstack_chunk_free free
63 /* Obstack where we build text strings for overloading, etc. */
64 static struct obstack scratch_obstack
;
65 static char *scratch_firstobj
;
67 static void icat
PROTO((HOST_WIDE_INT
));
68 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
69 static void flush_repeats
PROTO((tree
));
70 static void build_overload_identifier
PROTO((tree
));
71 static void build_overload_nested_name
PROTO((tree
));
72 static void build_overload_int
PROTO((tree
, int));
73 static void build_overload_identifier
PROTO((tree
));
74 static void build_qualified_name
PROTO((tree
));
75 static void build_overload_value
PROTO((tree
, tree
, int));
76 static char *thunk_printable_name
PROTO((tree
));
77 static void do_build_assign_ref
PROTO((tree
));
78 static void do_build_copy_constructor
PROTO((tree
));
79 static tree largest_union_member
PROTO((tree
));
80 static tree build_decl_overload_real
PROTO((tree
, tree
, tree
, tree
,
82 static void build_template_template_parm_names
PROTO((tree
));
83 static void build_template_parm_names
PROTO((tree
, tree
));
84 static void build_underscore_int
PROTO((int));
86 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
87 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
88 # define OB_PUTC2(C1,C2) \
89 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
90 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
91 # define OB_PUTID(ID) \
92 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
93 IDENTIFIER_LENGTH (ID)))
94 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
95 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
96 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
101 gcc_obstack_init (&scratch_obstack
);
102 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
105 /* This must be large enough to hold any printed integer or floating-point
107 static char digit_buffer
[128];
109 /* Move inline function definitions out of structure so that they
110 can be processed normally. CNAME is the name of the class
111 we are working from, METHOD_LIST is the list of method lists
112 of the structure. We delete friend methods here, after
113 saving away their inline function definitions (if any). */
116 do_inline_function_hair (type
, friend_list
)
117 tree type
, friend_list
;
119 tree method
= TYPE_METHODS (type
);
121 if (method
&& TREE_CODE (method
) == TREE_VEC
)
123 if (TREE_VEC_ELT (method
, 1))
124 method
= TREE_VEC_ELT (method
, 1);
125 else if (TREE_VEC_ELT (method
, 0))
126 method
= TREE_VEC_ELT (method
, 0);
128 method
= TREE_VEC_ELT (method
, 2);
133 /* Do inline member functions. */
134 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
139 my_friendly_assert (info
->fndecl
== method
, 238);
140 args
= DECL_ARGUMENTS (method
);
143 DECL_CONTEXT (args
) = method
;
144 args
= TREE_CHAIN (args
);
147 /* Allow this decl to be seen in global scope. Don't do this for
148 local class methods, though. */
149 if (! current_function_decl
)
150 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method
)) = method
;
152 method
= TREE_CHAIN (method
);
156 tree fndecl
= TREE_VALUE (friend_list
);
157 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
162 my_friendly_assert (info
->fndecl
== fndecl
, 239);
163 args
= DECL_ARGUMENTS (fndecl
);
166 DECL_CONTEXT (args
) = fndecl
;
167 args
= TREE_CHAIN (args
);
170 /* Allow this decl to be seen in global scope */
171 if (! current_function_decl
)
172 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl
)) = fndecl
;
175 friend_list
= TREE_CHAIN (friend_list
);
179 /* Report an argument type mismatch between the best declared function
180 we could find and the current argument list that we have. */
183 report_type_mismatch (cp
, parmtypes
, name_kind
)
184 struct candidate
*cp
;
188 int i
= cp
->u
.bad_arg
;
195 my_friendly_assert (TREE_CODE (cp
->function
) == TEMPLATE_DECL
, 240);
196 cp_error ("type unification failed for function template `%#D'",
201 cp_error ("too few arguments for %s `%#D'", name_kind
, cp
->function
);
204 cp_error ("too many arguments for %s `%#D'", name_kind
, cp
->function
);
207 if (TREE_CODE (TREE_TYPE (cp
->function
)) != METHOD_TYPE
)
210 /* Happens when the implicit object parameter is rejected. */
211 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))),
213 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
214 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
215 cp_error ("call to non-volatile %s `%#D' with volatile object",
216 name_kind
, cp
->function
);
218 cp_error ("call to non-const %s `%#D' with const object",
219 name_kind
, cp
->function
);
223 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
228 ttf
= TREE_CHAIN (ttf
);
229 tta
= TREE_CHAIN (tta
);
233 OB_PUTS ("bad argument ");
234 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
235 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
237 OB_PUTCP (digit_buffer
);
239 OB_PUTS (" for function `");
240 OB_PUTCP (decl_as_string (cp
->function
, 1));
241 OB_PUTS ("' (type was ");
243 /* Reset `i' so that type printing routines do the right thing. */
246 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
247 if (code
== ERROR_MARK
)
248 OB_PUTS ("(failed type instantiation)");
251 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
252 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
255 else OB_PUTS ("void");
259 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
260 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
261 obstack_object_size (&scratch_obstack
));
262 error (tmp_firstobj
);
265 /* Here is where overload code starts. */
267 /* Array of types seen so far in top-level call to `build_overload_name'.
268 Allocated and deallocated by caller. */
269 static tree
*typevec
;
271 /* Number of types interned by `build_overload_name' so far. */
274 /* Number of occurrences of last type seen. */
277 /* Nonzero if we should not try folding parameter types. */
280 #define ALLOCATE_TYPEVEC(PARMTYPES) \
281 do { maxtype = 0, nrepeats = 0; \
282 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
284 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
285 do { tree t = (PARMTYPES); \
286 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
289 /* Code to concatenate an asciified integer to a string. */
299 unsigned HOST_WIDE_INT ui
;
301 /* Handle this case first, to go really quickly. For many common values,
302 the result of ui/10 below is 1. */
320 OB_PUTC ('0' + (ui
% 10));
325 HOST_WIDE_INT lo
, hi
;
327 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
336 uhi
= (lo
== 0 ? -hi
: -hi
-1);
340 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
345 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
348 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
351 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
355 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
370 while (typevec
[tindex
] != type
)
388 static int numeric_output_need_bar
;
391 build_overload_nested_name (decl
)
394 if (DECL_CONTEXT (decl
))
396 tree context
= DECL_CONTEXT (decl
);
397 /* For a template type parameter, we want to output an 'Xn'
398 rather than 'T' or some such. For a template template
399 parameter, we also want an extra prefix 'z' and the
401 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
402 || TREE_CODE (context
) == TEMPLATE_TEMPLATE_PARM
)
403 build_overload_name (context
, 0, 0);
406 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
407 context
= TYPE_NAME (context
);
408 build_overload_nested_name (context
);
412 if (TREE_CODE (decl
) == FUNCTION_DECL
)
414 tree name
= DECL_ASSEMBLER_NAME (decl
);
417 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
420 if (numeric_output_need_bar
)
422 icat (strlen (label
));
424 numeric_output_need_bar
= 1;
427 build_overload_identifier (decl
);
431 build_underscore_int (i
)
441 /* Encoding for an INTEGER_CST value. */
444 build_overload_int (value
, in_template
)
448 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
449 /* We don't ever want this output, but it's inconvenient not to
450 be able to build the string. This should cause assembler
451 errors we'll notice. */
454 sprintf (digit_buffer
, " *%d", n
++);
455 OB_PUTCP (digit_buffer
);
459 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
460 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
462 if (TREE_INT_CST_HIGH (value
)
463 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
465 /* need to print a DImode value in decimal */
466 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
469 /* else fall through to print in smaller mode */
471 /* Wordsize or smaller */
472 icat (TREE_INT_CST_LOW (value
));
476 build_overload_value (type
, value
, in_template
)
480 while (TREE_CODE (value
) == NON_LVALUE_EXPR
481 || TREE_CODE (value
) == NOP_EXPR
)
482 value
= TREE_OPERAND (value
, 0);
483 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
484 type
= TREE_TYPE (type
);
486 if (numeric_output_need_bar
)
489 numeric_output_need_bar
= 0;
492 if (TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
495 build_underscore_int (TEMPLATE_CONST_IDX (value
));
496 build_underscore_int (TEMPLATE_CONST_LEVEL (value
));
500 if (TREE_CODE (type
) == POINTER_TYPE
501 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
503 /* Handle a pointer to data member as a template instantiation
504 parameter, boy, what fun! */
505 type
= integer_type_node
;
506 if (TREE_CODE (value
) != INTEGER_CST
)
508 sorry ("unknown pointer to member constant");
513 if (TYPE_PTRMEMFUNC_P (type
))
514 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
516 switch (TREE_CODE (type
))
522 build_overload_int (value
, in_template
);
523 numeric_output_need_bar
= 1;
529 char *bufp
= digit_buffer
;
531 pedwarn ("ANSI C++ forbids floating-point template arguments");
533 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
534 val
= TREE_REAL_CST (value
);
535 if (REAL_VALUE_ISNAN (val
))
537 sprintf (bufp
, "NaN");
541 if (REAL_VALUE_NEGATIVE (val
))
543 val
= REAL_VALUE_NEGATE (val
);
546 if (REAL_VALUE_ISINF (val
))
548 sprintf (bufp
, "Infinity");
552 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
553 bufp
= (char *) index (bufp
, 'e');
555 strcat (digit_buffer
, "e0");
581 #ifdef NO_DOT_IN_LABEL
582 bufp
= (char *) index (bufp
, '.');
588 OB_PUTCP (digit_buffer
);
589 numeric_output_need_bar
= 1;
593 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
594 && TREE_CODE (value
) != ADDR_EXPR
)
596 if (TREE_CODE (value
) == CONSTRUCTOR
)
598 /* This is dangerous code, crack built up pointer to members. */
599 tree args
= CONSTRUCTOR_ELTS (value
);
600 tree a1
= TREE_VALUE (args
);
601 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
602 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
603 a3
= TREE_VALUE (a3
);
605 if (TREE_CODE (a1
) == INTEGER_CST
606 && TREE_CODE (a2
) == INTEGER_CST
)
608 build_overload_int (a1
, in_template
);
610 build_overload_int (a2
, in_template
);
612 if (TREE_CODE (a3
) == ADDR_EXPR
)
614 a3
= TREE_OPERAND (a3
, 0);
615 if (TREE_CODE (a3
) == FUNCTION_DECL
)
617 numeric_output_need_bar
= 0;
618 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
622 else if (TREE_CODE (a3
) == INTEGER_CST
)
625 build_overload_int (a3
, in_template
);
626 numeric_output_need_bar
= 1;
631 sorry ("template instantiation with pointer to method that is too complex");
634 if (TREE_CODE (value
) == INTEGER_CST
635 || TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
637 build_overload_int (value
, in_template
);
638 numeric_output_need_bar
= 1;
641 value
= TREE_OPERAND (value
, 0);
642 if (TREE_CODE (value
) == VAR_DECL
)
644 my_friendly_assert (DECL_NAME (value
) != 0, 245);
645 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
648 else if (TREE_CODE (value
) == FUNCTION_DECL
)
650 my_friendly_assert (DECL_NAME (value
) != 0, 246);
651 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
654 else if (TREE_CODE (value
) == SCOPE_REF
)
657 numeric_output_need_bar
= 0;
658 build_overload_name (TREE_OPERAND (value
, 0), 0, 0);
659 build_overload_identifier (TREE_OPERAND (value
, 1));
663 my_friendly_abort (71);
664 break; /* not really needed */
667 sorry ("conversion of %s as template parameter",
668 tree_code_name
[(int) TREE_CODE (type
)]);
669 my_friendly_abort (72);
674 /* Add encodings for the declaration of template template parameters.
675 PARMLIST must be a TREE_VEC */
678 build_template_template_parm_names (parmlist
)
683 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
684 nparms
= TREE_VEC_LENGTH (parmlist
);
686 for (i
= 0; i
< nparms
; i
++)
688 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
689 if (TREE_CODE (parm
) == TYPE_DECL
)
691 /* This parameter is a type. */
694 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
696 /* This parameter is a template. */
698 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
702 /* It's a PARM_DECL. */
703 build_overload_name (TREE_TYPE (parm
), 0, 0);
709 /* Add encodings for the vector of template parameters in PARMLIST,
710 given the vector of arguments to be substituted in ARGLIST. */
713 build_template_parm_names (parmlist
, arglist
)
719 nparms
= TREE_VEC_LENGTH (parmlist
);
721 for (i
= 0; i
< nparms
; i
++)
723 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
724 tree arg
= TREE_VEC_ELT (arglist
, i
);
725 if (TREE_CODE (parm
) == TYPE_DECL
)
727 /* This parameter is a type. */
729 build_overload_name (arg
, 0, 0);
731 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
733 /* This parameter is a template. */
734 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
735 /* Output parameter declaration, argument index and level */
736 build_overload_name (arg
, 0, 0);
739 /* A TEMPLATE_DECL node, output the parameter declaration
743 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
744 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
745 OB_PUTID (DECL_NAME (arg
));
750 parm
= tsubst (parm
, arglist
,
751 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
752 /* It's a PARM_DECL. */
753 build_overload_name (TREE_TYPE (parm
), 0, 0);
754 build_overload_value (parm
, arg
, uses_template_parms (arglist
));
761 build_overload_identifier (name
)
764 if (TREE_CODE (name
) == TYPE_DECL
765 && IS_AGGR_TYPE (TREE_TYPE (name
))
766 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
767 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
768 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
772 tree
template, parmlist
, arglist
, tname
;
773 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
774 arglist
= TREE_VALUE (template);
775 template = TREE_PURPOSE (template);
776 tname
= DECL_NAME (template);
777 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
779 icat (IDENTIFIER_LENGTH (tname
));
781 build_template_parm_names (parmlist
, arglist
);
785 if (TREE_CODE (name
) == TYPE_DECL
)
786 name
= DECL_NAME (name
);
787 if (numeric_output_need_bar
)
790 numeric_output_need_bar
= 0;
792 icat (IDENTIFIER_LENGTH (name
));
797 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
798 the mangling for it. Used by build_overload_name and build_static_name. */
801 build_qualified_name (decl
)
807 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
808 decl
= TYPE_NAME (decl
);
810 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
811 if (TREE_CODE (decl
) == TYPE_DECL
812 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
814 OB_PUTID (DECL_ASSEMBLER_NAME (decl
));
819 while (DECL_CONTEXT (context
))
822 context
= DECL_CONTEXT (context
);
823 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
824 context
= TYPE_NAME (context
);
835 numeric_output_need_bar
= 0;
837 build_overload_nested_name (decl
);
840 /* Given a list of parameters in PARMTYPES, create an unambiguous
841 overload string. Should distinguish any type that C (or C++) can
842 distinguish. I.e., pointers to functions are treated correctly.
844 Caller must deal with whether a final `e' goes on the end or not.
846 Any default conversions must take place before this function
849 BEGIN and END control initialization and finalization of the
850 obstack where we build the string. */
853 build_overload_name (parmtypes
, begin
, end
)
860 if (begin
) OB_INIT ();
861 numeric_output_need_bar
= 0;
863 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
865 parmtype
= parmtypes
;
871 parmtype
= TREE_VALUE (parmtypes
);
875 if (! nofold
&& ! just_one
)
877 /* Every argument gets counted. */
878 typevec
[maxtype
++] = parmtype
;
880 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
887 flush_repeats (typevec
[maxtype
-2]);
889 if (TREE_USED (parmtype
))
892 /* We can turn this on at some point when we want
893 improved symbol mangling. */
896 /* This is bug compatible with 2.7.x */
897 flush_repeats (parmtype
);
902 /* Only cache types which take more than one character. */
903 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
904 || (TREE_CODE (parmtype
) != INTEGER_TYPE
905 && TREE_CODE (parmtype
) != REAL_TYPE
))
906 TREE_USED (parmtype
) = 1;
909 if (TYPE_PTRMEMFUNC_P (parmtype
))
910 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
912 if (TREE_READONLY (parmtype
))
914 if (TREE_CODE (parmtype
) == INTEGER_TYPE
915 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
917 if (TYPE_VOLATILE (parmtype
))
920 switch (TREE_CODE (parmtype
))
924 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
926 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
934 #if PARM_CAN_BE_ARRAY_TYPE
939 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
940 error ("pointer or reference to array of unknown bound in parm type");
943 length
= array_type_nelts (parmtype
);
944 if (TREE_CODE (length
) == INTEGER_CST
)
945 icat (TREE_INT_CST_LOW (length
) + 1);
958 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
964 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
965 /* Otherwise have to implement reentrant typevecs,
966 unmark and remark types, etc. */
967 int old_nofold
= nofold
;
971 flush_repeats (typevec
[maxtype
-1]);
973 /* @@ It may be possible to pass a function type in
974 which is not preceded by a 'P'. */
975 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
978 if (firstarg
== NULL_TREE
)
980 else if (firstarg
== void_list_node
)
983 build_overload_name (firstarg
, 0, 0);
987 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
988 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
990 firstarg
= TREE_CHAIN (firstarg
);
992 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
998 /* For cfront 2.0 compatibility. */
1001 if (firstarg
== NULL_TREE
)
1003 else if (firstarg
== void_list_node
)
1006 build_overload_name (firstarg
, 0, 0);
1009 /* Separate args from return type. */
1011 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
1012 nofold
= old_nofold
;
1017 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1018 if (parmtype
== integer_type_node
1019 || parmtype
== unsigned_type_node
)
1021 else if (parmtype
== long_integer_type_node
1022 || parmtype
== long_unsigned_type_node
)
1024 else if (parmtype
== short_integer_type_node
1025 || parmtype
== short_unsigned_type_node
)
1027 else if (parmtype
== signed_char_type_node
)
1032 else if (parmtype
== char_type_node
1033 || parmtype
== unsigned_char_type_node
)
1035 else if (parmtype
== wchar_type_node
)
1037 else if (parmtype
== long_long_integer_type_node
1038 || parmtype
== long_long_unsigned_type_node
)
1041 /* it would seem there is no way to enter these in source code,
1043 else if (parmtype
== long_long_long_integer_type_node
1044 || parmtype
== long_long_long_unsigned_type_node
)
1048 my_friendly_abort (73);
1056 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1057 if (parmtype
== long_double_type_node
)
1059 else if (parmtype
== double_type_node
)
1061 else if (parmtype
== float_type_node
)
1063 else my_friendly_abort (74);
1068 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
1075 extern tree void_list_node
;
1077 /* See if anybody is wasting memory. */
1078 my_friendly_assert (parmtypes
== void_list_node
, 247);
1080 /* This is the end of a parameter list. */
1081 if (end
) OB_FINISH ();
1082 return (char *)obstack_base (&scratch_obstack
);
1087 case ERROR_MARK
: /* not right, but nothing is anyway */
1090 /* have to do these */
1094 /* Make this type signature look incompatible
1101 tree name
= TYPE_NAME (parmtype
);
1103 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
1105 build_overload_identifier (TYPE_NAME (parmtype
));
1108 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1110 build_qualified_name (name
);
1115 /* We can get here if __null is defined to have type ({unkown
1116 type}*), which it is if -ansi is not used. Treat this
1121 case TEMPLATE_TEMPLATE_PARM
:
1122 /* Find and output the original template parameter
1124 if (CLASSTYPE_TEMPLATE_INFO (parmtype
))
1129 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1130 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1132 build_template_parm_names (
1133 DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype
)),
1134 CLASSTYPE_TI_ARGS (parmtype
));
1141 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1142 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1144 build_template_template_parm_names (
1145 DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1149 case TEMPLATE_TYPE_PARM
:
1151 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1152 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1156 /* When mangling the type of a function template whose
1157 declaration looks like:
1159 template <class T> void foo(typename T::U)
1161 we have to mangle these. */
1162 build_qualified_name (parmtype
);
1166 my_friendly_abort (75);
1170 if (just_one
) break;
1171 parmtypes
= TREE_CHAIN (parmtypes
);
1176 flush_repeats (typevec
[maxtype
-1]);
1178 /* To get here, parms must end with `...'. */
1182 if (end
) OB_FINISH ();
1183 return (char *)obstack_base (&scratch_obstack
);
1186 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1187 be either a class TYPE or a FUNCTION_DECL. */
1190 build_static_name (context
, name
)
1194 numeric_output_need_bar
= 0;
1197 build_qualified_name (context
);
1200 OB_PUTS ("__static_");
1201 build_qualified_name (context
);
1207 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1211 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1220 char *name
= IDENTIFIER_POINTER (dname
);
1222 /* member operators new and delete look like methods at this point. */
1223 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1224 && TREE_CHAIN (parms
) == void_list_node
)
1226 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1227 return get_identifier ("__builtin_delete");
1228 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1229 return get_identifier ("__builtin_vec_delete");
1230 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1231 return get_identifier ("__builtin_new");
1232 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1233 return get_identifier ("__builtin_vec_new");
1237 if (for_method
!= 2)
1239 /* Otherwise, we can divine that this is a constructor,
1240 and figure out its name without any extra encoding. */
1242 OB_PUTC2 ('_', '_');
1246 /* We can get away without doing this. */
1249 if (tparms
!= NULL_TREE
)
1252 tree this_type
= TREE_VALUE (parms
);
1254 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1255 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1256 TREE_CHAIN (parms
));
1258 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1259 TREE_CHAIN (parms
));
1269 build_template_parm_names (tparms
, targs
);
1273 if (parms
== NULL_TREE
)
1275 else if (parms
== void_list_node
)
1279 ALLOCATE_TYPEVEC (parms
);
1283 build_overload_name (TREE_VALUE (parms
), 0, 0);
1285 typevec
[maxtype
++] = TREE_VALUE (parms
);
1286 TREE_USED (TREE_VALUE (parms
)) = 1;
1288 if (TREE_CHAIN (parms
))
1289 build_overload_name (TREE_CHAIN (parms
), 0, 0);
1294 build_overload_name (parms
, 0, 0);
1295 DEALLOCATE_TYPEVEC (parms
);
1298 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1300 /* Add the return type. */
1302 build_overload_name (ret_type
, 0, 0);
1307 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1308 if (IDENTIFIER_OPNAME_P (dname
))
1309 IDENTIFIER_OPNAME_P (n
) = 1;
1314 /* Change the name of a function definition so that it may be
1315 overloaded. NAME is the name of the function to overload,
1316 PARMS is the parameter list (which determines what name the
1317 final function obtains).
1319 FOR_METHOD is 1 if this overload is being performed
1320 for a method, rather than a function type. It is 2 if
1321 this overload is being performed for a constructor. */
1324 build_decl_overload (dname
, parms
, for_method
)
1329 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1330 NULL_TREE
, for_method
);
1334 /* Like build_decl_overload, but for template functions. */
1337 build_template_decl_overload (dname
, parms
, ret_type
, tparms
, targs
,
1346 return build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1351 /* Build an overload name for the type expression TYPE. */
1354 build_typename_overload (type
)
1360 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1362 build_overload_name (type
, 0, 1);
1363 id
= get_identifier (obstack_base (&scratch_obstack
));
1364 IDENTIFIER_OPNAME_P (id
) = 1;
1366 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1368 TREE_TYPE (id
) = type
;
1373 build_overload_with_type (name
, type
)
1380 build_overload_name (type
, 0, 1);
1381 return get_identifier (obstack_base (&scratch_obstack
));
1385 get_id_2 (name
, name2
)
1393 return get_identifier (obstack_base (&scratch_obstack
));
1396 /* Given a tree_code CODE, and some arguments (at least one),
1397 attempt to use an overloaded operator on the arguments.
1399 For unary operators, only the first argument need be checked.
1400 For binary operators, both arguments may need to be checked.
1402 Member functions can convert class references to class pointers,
1403 for one-level deep indirection. More than that is not supported.
1404 Operators [](), ()(), and ->() must be member functions.
1406 We call function call building calls with LOOKUP_COMPLAIN if they
1407 are our only hope. This is true when we see a vanilla operator
1408 applied to something of aggregate type. If this fails, we are free
1409 to return `error_mark_node', because we will have reported the
1412 Operators NEW and DELETE overload in funny ways: operator new takes
1413 a single `size' parameter, and operator delete takes a pointer to the
1414 storage being deleted. When overloading these operators, success is
1415 assumed. If there is a failure, report an error message and return
1416 `error_mark_node'. */
1420 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1421 enum tree_code code
;
1423 tree xarg1
, xarg2
, arg3
;
1427 tree type1
, type2
, fnname
;
1428 tree fields1
= 0, parms
= 0;
1431 int binary_is_unary
;
1433 if (flag_ansi_overloading
)
1434 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1436 if (xarg1
== error_mark_node
)
1437 return error_mark_node
;
1439 if (code
== COND_EXPR
)
1441 if (xarg2
== error_mark_node
1442 || arg3
== error_mark_node
)
1443 return error_mark_node
;
1445 if (code
== COMPONENT_REF
)
1446 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1449 /* First, see if we can work with the first argument */
1450 type1
= TREE_TYPE (xarg1
);
1452 /* Some tree codes have length > 1, but we really only want to
1453 overload them if their first argument has a user defined type. */
1456 case PREINCREMENT_EXPR
:
1457 case PREDECREMENT_EXPR
:
1458 case POSTINCREMENT_EXPR
:
1459 case POSTDECREMENT_EXPR
:
1461 binary_is_unary
= 1;
1465 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1466 If they do not, return error_mark_node instead of NULL_TREE. */
1468 if (xarg2
== error_mark_node
)
1469 return error_mark_node
;
1471 rval
= error_mark_node
;
1472 binary_is_unary
= 0;
1479 tree args
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1480 fnname
= ansi_opname
[(int) code
];
1481 if (flags
& LOOKUP_GLOBAL
)
1482 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
);
1484 rval
= build_method_call
1485 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1487 fnname
, args
, NULL_TREE
, flags
);
1488 if (rval
== error_mark_node
)
1489 /* User might declare fancy operator new, but invoke it
1490 like standard one. */
1493 TREE_TYPE (rval
) = xarg1
;
1498 case VEC_DELETE_EXPR
:
1501 fnname
= ansi_opname
[(int) code
];
1502 if (flags
& LOOKUP_GLOBAL
)
1503 return build_overload_call (fnname
,
1504 build_expr_list (NULL_TREE
, xarg1
),
1505 flags
& LOOKUP_COMPLAIN
);
1506 arg1
= TREE_TYPE (xarg1
);
1508 /* This handles the case where we're trying to delete
1513 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
1515 /* Strip off the pointer and the array. */
1516 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
1518 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
1519 arg1
= (TREE_TYPE (arg1
));
1521 arg1
= build_pointer_type (arg1
);
1524 rval
= build_method_call
1525 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
1528 fnname
, expr_tree_cons (NULL_TREE
, xarg1
,
1529 build_expr_list (NULL_TREE
, xarg2
)),
1532 /* This can happen when operator delete is protected. */
1533 my_friendly_assert (rval
!= error_mark_node
, 250);
1534 TREE_TYPE (rval
) = void_type_node
;
1541 binary_is_unary
= 0;
1542 try_second
= tree_code_length
[(int) code
] == 2;
1543 if (try_second
&& xarg2
== error_mark_node
)
1544 return error_mark_node
;
1548 if (try_second
&& xarg2
== error_mark_node
)
1549 return error_mark_node
;
1551 /* What ever it was, we do not know how to deal with it. */
1552 if (type1
== NULL_TREE
)
1555 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1556 type1
= TREE_TYPE (type1
);
1558 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1560 arg1
= convert_from_reference (xarg1
);
1561 type1
= TREE_TYPE (arg1
);
1568 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1570 /* Try to fail. First, fail if unary */
1573 /* Second, see if second argument is non-aggregate. */
1574 type2
= TREE_TYPE (xarg2
);
1575 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1576 type2
= TREE_TYPE (type2
);
1577 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1579 arg2
= convert_from_reference (xarg2
);
1580 type2
= TREE_TYPE (arg2
);
1587 if (!IS_AGGR_TYPE (type2
))
1594 /* First arg may succeed; see whether second should. */
1595 type2
= TREE_TYPE (xarg2
);
1596 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1597 type2
= TREE_TYPE (type2
);
1598 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1600 arg2
= convert_from_reference (xarg2
);
1601 type2
= TREE_TYPE (arg2
);
1608 if (! IS_AGGR_TYPE (type2
))
1612 if (type1
== unknown_type_node
1613 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1615 /* This will not be implemented in the foreseeable future. */
1619 if (code
== MODIFY_EXPR
)
1620 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1622 fnname
= ansi_opname
[(int) code
];
1624 global_fn
= lookup_name_nonclass (fnname
);
1626 /* This is the last point where we will accept failure. This
1627 may be too eager if we wish an overloaded operator not to match,
1628 but would rather a normal operator be called on a type-converted
1631 if (IS_AGGR_TYPE (type1
))
1633 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1634 /* ARM $13.4.7, prefix/postfix ++/--. */
1635 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1637 xarg2
= integer_zero_node
;
1638 binary_is_unary
= 0;
1643 int have_postfix
= 0;
1645 /* Look for an `operator++ (int)'. If they didn't have
1646 one, then we fall back to the old way of doing things. */
1647 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1649 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1650 if (TREE_CHAIN (t2
) != NULL_TREE
1651 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1660 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1662 /* There's probably a LOT of code in the world that
1663 relies upon this old behavior. */
1664 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1667 binary_is_unary
= 1;
1673 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1676 /* If RVAL winds up being `error_mark_node', we will return
1677 that... There is no way that normal semantics of these
1678 operators will succeed. */
1680 /* This argument may be an uncommitted OFFSET_REF. This is
1681 the case for example when dealing with static class members
1682 which are referenced from their class name rather than
1683 from a class instance. */
1684 if (TREE_CODE (xarg1
) == OFFSET_REF
1685 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1686 xarg1
= TREE_OPERAND (xarg1
, 1);
1687 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1688 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1689 xarg2
= TREE_OPERAND (xarg2
, 1);
1692 flags
|= LOOKUP_GLOBAL
;
1694 if (code
== CALL_EXPR
)
1696 /* This can only be a member function. */
1697 return build_method_call (xarg1
, fnname
, xarg2
,
1698 NULL_TREE
, LOOKUP_NORMAL
);
1700 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1703 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1705 else if (code
== COND_EXPR
)
1707 parms
= expr_tree_cons (NULL_TREE
, xarg2
, build_expr_list (NULL_TREE
, arg3
));
1708 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1710 else if (code
== METHOD_CALL_EXPR
)
1712 /* must be a member function. */
1713 parms
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1714 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1719 parms
= build_expr_list (NULL_TREE
, xarg2
);
1720 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1724 parms
= expr_tree_cons (NULL_TREE
, xarg1
,
1725 build_expr_list (NULL_TREE
, xarg2
));
1726 rval
= build_overload_call (fnname
, parms
, flags
);
1732 /* This function takes an identifier, ID, and attempts to figure out what
1733 it means. There are a number of possible scenarios, presented in increasing
1736 1) not in a class's scope
1737 2) in class's scope, member name of the class's method
1738 3) in class's scope, but not a member name of the class
1739 4) in class's scope, member name of a class's variable
1741 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1742 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1744 As a last ditch, try to look up the name as a label and return that
1747 Values which are declared as being of REFERENCE_TYPE are
1748 automatically dereferenced here (as a hack to make the
1749 compiler faster). */
1752 hack_identifier (value
, name
)
1757 if (value
== error_mark_node
)
1759 if (current_class_name
)
1761 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1762 if (fields
== error_mark_node
)
1763 return error_mark_node
;
1768 fndecl
= TREE_VALUE (fields
);
1769 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1770 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1772 warning ("methods cannot be converted to function pointers");
1777 error ("ambiguous request for method pointer `%s'",
1778 IDENTIFIER_POINTER (name
));
1779 return error_mark_node
;
1783 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1785 return IDENTIFIER_LABEL_VALUE (name
);
1787 return error_mark_node
;
1790 type
= TREE_TYPE (value
);
1791 if (TREE_CODE (value
) == FIELD_DECL
)
1793 if (current_class_ptr
== NULL_TREE
)
1795 error ("request for member `%s' in static member function",
1796 IDENTIFIER_POINTER (DECL_NAME (value
)));
1797 return error_mark_node
;
1799 TREE_USED (current_class_ptr
) = 1;
1801 /* Mark so that if we are in a constructor, and then find that
1802 this field was initialized by a base initializer,
1803 we can emit an error message. */
1804 TREE_USED (value
) = 1;
1805 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1807 else if (really_overloaded_fn (value
))
1810 tree t
= get_first_fn (value
);
1811 for (; t
; t
= DECL_CHAIN (t
))
1813 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1816 assemble_external (t
);
1821 else if (TREE_CODE (value
) == TREE_LIST
)
1823 /* Ambiguous reference to base members, possibly other cases?. */
1825 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1827 mark_used (TREE_VALUE (t
));
1834 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1836 tree context
= decl_function_context (value
);
1837 if (context
!= NULL_TREE
&& context
!= current_function_decl
1838 && ! TREE_STATIC (value
))
1840 cp_error ("use of %s from containing function",
1841 (TREE_CODE (value
) == VAR_DECL
1842 ? "`auto' variable" : "parameter"));
1843 cp_error_at (" `%#D' declared here", value
);
1844 value
= error_mark_node
;
1848 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1850 if (DECL_LANG_SPECIFIC (value
)
1851 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1854 register tree context
1855 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1856 ? DECL_CLASS_CONTEXT (value
)
1857 : DECL_CONTEXT (value
);
1859 get_base_distance (context
, current_class_type
, 0, &path
);
1862 access
= compute_access (path
, value
);
1863 if (access
!= access_public_node
)
1865 if (TREE_CODE (value
) == VAR_DECL
)
1866 error ("static member `%s' is %s",
1867 IDENTIFIER_POINTER (name
),
1868 TREE_PRIVATE (value
) ? "private"
1869 : "from a private base class");
1871 error ("enum `%s' is from private base class",
1872 IDENTIFIER_POINTER (name
));
1873 return error_mark_node
;
1878 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1882 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1883 IDENTIFIER_POINTER (name
));
1884 return error_mark_node
;
1890 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1891 value
= convert_from_reference (value
);
1897 thunk_printable_name (decl
)
1900 return "<thunk function>";
1904 make_thunk (function
, delta
)
1913 if (TREE_CODE (function
) != ADDR_EXPR
)
1915 func_decl
= TREE_OPERAND (function
, 0);
1916 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1918 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1920 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1922 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1923 thunk_id
= get_identifier (buffer
);
1924 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1925 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1927 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1928 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1930 if (thunk
== NULL_TREE
)
1932 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1933 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1934 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1935 comdat_linkage (thunk
);
1936 TREE_SET_CODE (thunk
, THUNK_DECL
);
1937 DECL_INITIAL (thunk
) = function
;
1938 THUNK_DELTA (thunk
) = delta
;
1939 DECL_EXTERNAL (thunk
) = 1;
1940 DECL_ARTIFICIAL (thunk
) = 1;
1941 /* So that finish_file can write out any thunks that need to be: */
1942 pushdecl_top_level (thunk
);
1947 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1950 emit_thunk (thunk_fndecl
)
1953 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1954 int delta
= THUNK_DELTA (thunk_fndecl
);
1956 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1959 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1961 TREE_ADDRESSABLE (function
) = 1;
1962 mark_used (function
);
1964 if (current_function_decl
)
1967 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1970 #ifdef ASM_OUTPUT_MI_THUNK
1972 current_function_decl
= thunk_fndecl
;
1973 /* Make sure we build up its RTL before we go onto the
1974 temporary obstack. */
1975 make_function_rtl (thunk_fndecl
);
1976 temporary_allocation ();
1977 DECL_RESULT (thunk_fndecl
)
1978 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1979 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1980 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1981 assemble_start_function (thunk_fndecl
, fnname
);
1982 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
1983 assemble_end_function (thunk_fndecl
, fnname
);
1984 permanent_allocation (1);
1985 current_function_decl
= 0;
1986 #else /* ASM_OUTPUT_MI_THUNK */
1987 /* If we don't have the necessary macro for efficient thunks, generate a
1988 thunk function that just makes a call to the real function.
1989 Unfortunately, this doesn't work for varargs. */
1993 if (varargs_function_p (function
))
1994 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1997 /* Set up clone argument trees for the thunk. */
1999 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
2001 tree x
= copy_node (a
);
2003 DECL_CONTEXT (x
) = thunk_fndecl
;
2007 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2008 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2009 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2010 copy_lang_decl (thunk_fndecl
);
2011 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2012 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2014 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
2015 store_parm_decls ();
2016 current_function_is_thunk
= 1;
2018 /* Build up the call to the real function. */
2019 t
= build_int_2 (delta
, -1 * (delta
< 0));
2020 TREE_TYPE (t
) = signed_type (sizetype
);
2021 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2022 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
2023 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2024 t
= expr_tree_cons (NULL_TREE
, a
, t
);
2026 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2027 c_expand_return (t
);
2029 finish_function (lineno
, 0, 0);
2031 /* Don't let the backend defer this function. */
2032 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2034 output_inline_function (thunk_fndecl
);
2035 permanent_allocation (1);
2037 #endif /* ASM_OUTPUT_MI_THUNK */
2040 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2043 /* Code for synthesizing methods which have default semantics defined. */
2045 /* For the anonymous union in TYPE, return the member that is at least as
2046 large as the rest of the members, so we can copy it. */
2049 largest_union_member (type
)
2052 tree f
, type_size
= TYPE_SIZE (type
);
2054 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2055 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2058 /* We should always find one. */
2059 my_friendly_abort (323);
2063 /* Generate code for default X(X&) constructor. */
2066 do_build_copy_constructor (fndecl
)
2069 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2075 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2076 parm
= TREE_CHAIN (parm
);
2077 parm
= convert_from_reference (parm
);
2079 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2081 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2082 TREE_SIDE_EFFECTS (t
) = 1;
2083 cplus_expand_expr_stmt (t
);
2087 tree fields
= TYPE_FIELDS (current_class_type
);
2088 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2089 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2092 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2095 tree basetype
= BINFO_TYPE (t
);
2096 tree p
= convert_to_reference
2097 (build_reference_type (basetype
), parm
,
2098 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2099 p
= convert_from_reference (p
);
2101 if (p
== error_mark_node
)
2102 cp_error ("in default copy constructor");
2104 current_base_init_list
= tree_cons (basetype
,
2105 p
, current_base_init_list
);
2108 for (i
= 0; i
< n_bases
; ++i
)
2110 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2111 if (TREE_VIA_VIRTUAL (basetype
))
2114 basetype
= BINFO_TYPE (basetype
);
2115 p
= convert_to_reference
2116 (build_reference_type (basetype
), parm
,
2117 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2119 if (p
== error_mark_node
)
2120 cp_error ("in default copy constructor");
2123 p
= convert_from_reference (p
);
2124 current_base_init_list
= tree_cons (basetype
,
2125 p
, current_base_init_list
);
2128 for (; fields
; fields
= TREE_CHAIN (fields
))
2131 tree field
= fields
;
2133 if (TREE_CODE (field
) != FIELD_DECL
)
2137 if (DECL_NAME (field
))
2139 if (VFIELD_NAME_P (DECL_NAME (field
)))
2141 if (VBASE_NAME_P (DECL_NAME (field
)))
2144 /* True for duplicate members. */
2145 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2148 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2149 && TREE_CODE (t
) == UNION_TYPE
2150 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2151 && TYPE_FIELDS (t
) != NULL_TREE
)
2155 init
= build (COMPONENT_REF
, t
, init
, field
);
2156 field
= largest_union_member (t
);
2158 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2159 && TREE_CODE (t
) == UNION_TYPE
2160 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2161 && TYPE_FIELDS (t
) != NULL_TREE
);
2166 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2167 init
= build_tree_list (NULL_TREE
, init
);
2169 current_member_init_list
2170 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2172 current_member_init_list
= nreverse (current_member_init_list
);
2173 current_base_init_list
= nreverse (current_base_init_list
);
2181 do_build_assign_ref (fndecl
)
2184 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2189 parm
= convert_from_reference (parm
);
2191 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2193 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2194 TREE_SIDE_EFFECTS (t
) = 1;
2195 cplus_expand_expr_stmt (t
);
2199 tree fields
= TYPE_FIELDS (current_class_type
);
2200 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2201 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2204 for (i
= 0; i
< n_bases
; ++i
)
2206 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2207 tree p
= convert_to_reference
2208 (build_reference_type (basetype
), parm
,
2209 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2210 p
= convert_from_reference (p
);
2211 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2212 build_expr_list (NULL_TREE
, p
));
2213 expand_expr_stmt (p
);
2215 for (; fields
; fields
= TREE_CHAIN (fields
))
2218 tree field
= fields
;
2220 if (TREE_CODE (field
) != FIELD_DECL
)
2223 if (TREE_READONLY (field
))
2225 if (DECL_NAME (field
))
2226 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2228 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2231 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2233 if (DECL_NAME (field
))
2234 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2236 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2240 comp
= current_class_ref
;
2243 if (DECL_NAME (field
))
2245 if (VFIELD_NAME_P (DECL_NAME (field
)))
2247 if (VBASE_NAME_P (DECL_NAME (field
)))
2250 /* True for duplicate members. */
2251 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2254 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2255 && TREE_CODE (t
) == UNION_TYPE
2256 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2257 && TYPE_FIELDS (t
) != NULL_TREE
)
2261 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2262 init
= build (COMPONENT_REF
, t
, init
, field
);
2263 field
= largest_union_member (t
);
2265 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2266 && TREE_CODE (t
) == UNION_TYPE
2267 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2268 && TYPE_FIELDS (t
) != NULL_TREE
);
2273 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2274 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2276 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2279 c_expand_return (current_class_ref
);
2284 synthesize_method (fndecl
)
2287 int nested
= (current_function_decl
!= NULL_TREE
);
2288 tree context
= hack_decl_function_context (fndecl
);
2291 import_export_decl (fndecl
);
2294 push_to_top_level ();
2296 push_cp_function_context (context
);
2298 interface_unknown
= 1;
2299 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2300 store_parm_decls ();
2302 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2303 do_build_assign_ref (fndecl
);
2304 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2308 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2309 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2310 arg_chain
= TREE_CHAIN (arg_chain
);
2311 if (arg_chain
!= void_list_node
)
2312 do_build_copy_constructor (fndecl
);
2313 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2317 finish_function (lineno
, 0, nested
);
2319 extract_interface_info ();
2321 pop_from_top_level ();
2323 pop_cp_function_context (context
);