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, 93, 94, 95, 1996 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"
42 /* TREE_LIST of the current inline functions that need to be
44 struct pending_inline
*pending_inlines
;
46 #define obstack_chunk_alloc xmalloc
47 #define obstack_chunk_free free
49 /* Obstack where we build text strings for overloading, etc. */
50 static struct obstack scratch_obstack
;
51 static char *scratch_firstobj
;
53 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
54 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
55 # define OB_PUTC2(C1,C2) \
56 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
57 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
58 # define OB_PUTID(ID) \
59 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
60 IDENTIFIER_LENGTH (ID)))
61 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
62 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
63 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
68 gcc_obstack_init (&scratch_obstack
);
69 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
72 /* This must be large enough to hold any printed integer or floating-point
74 static char digit_buffer
[128];
76 /* Move inline function definitions out of structure so that they
77 can be processed normally. CNAME is the name of the class
78 we are working from, METHOD_LIST is the list of method lists
79 of the structure. We delete friend methods here, after
80 saving away their inline function definitions (if any). */
83 do_inline_function_hair (type
, friend_list
)
84 tree type
, friend_list
;
86 tree method
= TYPE_METHODS (type
);
88 if (method
&& TREE_CODE (method
) == TREE_VEC
)
90 if (TREE_VEC_ELT (method
, 1))
91 method
= TREE_VEC_ELT (method
, 1);
92 else if (TREE_VEC_ELT (method
, 0))
93 method
= TREE_VEC_ELT (method
, 0);
95 method
= TREE_VEC_ELT (method
, 2);
100 /* Do inline member functions. */
101 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
106 my_friendly_assert (info
->fndecl
== method
, 238);
107 args
= DECL_ARGUMENTS (method
);
110 DECL_CONTEXT (args
) = method
;
111 args
= TREE_CHAIN (args
);
114 /* Allow this decl to be seen in global scope. Don't do this for
115 local class methods, though. */
116 if (! current_function_decl
)
117 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method
)) = method
;
119 method
= TREE_CHAIN (method
);
123 tree fndecl
= TREE_VALUE (friend_list
);
124 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
129 my_friendly_assert (info
->fndecl
== fndecl
, 239);
130 args
= DECL_ARGUMENTS (fndecl
);
133 DECL_CONTEXT (args
) = fndecl
;
134 args
= TREE_CHAIN (args
);
137 /* Allow this decl to be seen in global scope */
138 if (! current_function_decl
)
139 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl
)) = fndecl
;
142 friend_list
= TREE_CHAIN (friend_list
);
146 /* Report an argument type mismatch between the best declared function
147 we could find and the current argument list that we have. */
150 report_type_mismatch (cp
, parmtypes
, name_kind
)
151 struct candidate
*cp
;
155 int i
= cp
->u
.bad_arg
;
162 my_friendly_assert (TREE_CODE (cp
->function
) == TEMPLATE_DECL
, 240);
163 cp_error ("type unification failed for function template `%#D'",
168 cp_error ("too few arguments for %s `%#D'", name_kind
, cp
->function
);
171 cp_error ("too many arguments for %s `%#D'", name_kind
, cp
->function
);
174 if (TREE_CODE (TREE_TYPE (cp
->function
)) != METHOD_TYPE
)
177 /* Happens when the implicit object parameter is rejected. */
178 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))),
180 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
181 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
182 cp_error ("call to non-volatile %s `%#D' with volatile object",
183 name_kind
, cp
->function
);
185 cp_error ("call to non-const %s `%#D' with const object",
186 name_kind
, cp
->function
);
190 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
195 ttf
= TREE_CHAIN (ttf
);
196 tta
= TREE_CHAIN (tta
);
200 OB_PUTS ("bad argument ");
201 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
202 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
204 OB_PUTCP (digit_buffer
);
206 OB_PUTS (" for function `");
207 OB_PUTCP (decl_as_string (cp
->function
, 1));
208 OB_PUTS ("' (type was ");
210 /* Reset `i' so that type printing routines do the right thing. */
213 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
214 if (code
== ERROR_MARK
)
215 OB_PUTS ("(failed type instantiation)");
218 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
219 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
222 else OB_PUTS ("void");
226 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
227 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
228 obstack_object_size (&scratch_obstack
));
229 error (tmp_firstobj
);
232 /* Here is where overload code starts. */
234 /* Array of types seen so far in top-level call to `build_overload_name'.
235 Allocated and deallocated by caller. */
236 static tree
*typevec
;
238 /* Number of types interned by `build_overload_name' so far. */
241 /* Number of occurrences of last type seen. */
244 /* Nonzero if we should not try folding parameter types. */
247 #define ALLOCATE_TYPEVEC(PARMTYPES) \
248 do { maxtype = 0, nrepeats = 0; \
249 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
251 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
252 do { tree t = (PARMTYPES); \
253 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
256 /* Code to concatenate an asciified integer to a string. */
266 unsigned HOST_WIDE_INT ui
;
268 /* Handle this case first, to go really quickly. For many common values,
269 the result of ui/10 below is 1. */
287 OB_PUTC ('0' + (ui
% 10));
292 HOST_WIDE_INT lo
, hi
;
294 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
303 uhi
= (lo
== 0 ? -hi
: -hi
-1);
307 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
312 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
315 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
318 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
322 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
337 while (typevec
[tindex
] != type
)
355 static int numeric_output_need_bar
;
356 static void build_overload_identifier ();
359 build_overload_nested_name (decl
)
362 if (DECL_CONTEXT (decl
))
364 tree context
= DECL_CONTEXT (decl
);
365 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
366 context
= TYPE_NAME (context
);
367 build_overload_nested_name (context
);
370 if (TREE_CODE (decl
) == FUNCTION_DECL
)
372 tree name
= DECL_ASSEMBLER_NAME (decl
);
374 extern int var_labelno
;
376 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), var_labelno
);
379 if (numeric_output_need_bar
)
382 numeric_output_need_bar
= 0;
384 icat (strlen (label
));
388 build_overload_identifier (decl
);
391 /* Encoding for an INTEGER_CST value. */
394 build_overload_int (value
)
397 if (TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
400 if (TEMPLATE_CONST_IDX (value
) > 9)
402 icat (TEMPLATE_CONST_IDX (value
));
403 if (TEMPLATE_CONST_IDX (value
) > 9)
407 else if (processing_template_decl
408 && TREE_CODE (value
) != INTEGER_CST
)
409 /* We don't ever want this output, but it's inconvenient not to
410 be able to build the string. This should cause assembler
411 errors we'll notice. */
414 sprintf (digit_buffer
, " *%d", n
++);
415 OB_PUTCP (digit_buffer
);
419 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
420 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
422 if (TREE_INT_CST_HIGH (value
)
423 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
425 /* need to print a DImode value in decimal */
426 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
429 /* else fall through to print in smaller mode */
431 /* Wordsize or smaller */
432 icat (TREE_INT_CST_LOW (value
));
436 build_overload_value (type
, value
)
439 while (TREE_CODE (value
) == NON_LVALUE_EXPR
440 || TREE_CODE (value
) == NOP_EXPR
)
441 value
= TREE_OPERAND (value
, 0);
442 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
443 type
= TREE_TYPE (type
);
445 if (numeric_output_need_bar
)
448 numeric_output_need_bar
= 0;
451 if (TREE_CODE (type
) == POINTER_TYPE
452 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
454 /* Handle a pointer to data member as a template instantiation
455 parameter, boy, what fun! */
456 type
= integer_type_node
;
457 if (TREE_CODE (value
) != INTEGER_CST
)
459 sorry ("unknown pointer to member constant");
464 if (TYPE_PTRMEMFUNC_P (type
))
465 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
467 switch (TREE_CODE (type
))
473 build_overload_int (value
);
474 numeric_output_need_bar
= 1;
480 char *bufp
= digit_buffer
;
481 extern char *index ();
483 pedwarn ("ANSI C++ forbids floating-point template arguments");
485 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
486 val
= TREE_REAL_CST (value
);
487 if (REAL_VALUE_ISNAN (val
))
489 sprintf (bufp
, "NaN");
493 if (REAL_VALUE_NEGATIVE (val
))
495 val
= REAL_VALUE_NEGATE (val
);
498 if (REAL_VALUE_ISINF (val
))
500 sprintf (bufp
, "Infinity");
504 ereal_to_decimal (val
, bufp
);
505 bufp
= (char *) index (bufp
, 'e');
507 strcat (digit_buffer
, "e0");
533 #ifdef NO_DOT_IN_LABEL
534 bufp
= (char *) index (bufp
, '.');
540 OB_PUTCP (digit_buffer
);
541 numeric_output_need_bar
= 1;
545 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
546 && TREE_CODE (value
) != ADDR_EXPR
)
548 if (TREE_CODE (value
) == CONSTRUCTOR
)
550 /* This is dangerous code, crack built up pointer to members. */
551 tree args
= CONSTRUCTOR_ELTS (value
);
552 tree a1
= TREE_VALUE (args
);
553 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
554 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
555 a3
= TREE_VALUE (a3
);
557 if (TREE_CODE (a1
) == INTEGER_CST
558 && TREE_CODE (a2
) == INTEGER_CST
)
560 build_overload_int (a1
);
562 build_overload_int (a2
);
564 if (TREE_CODE (a3
) == ADDR_EXPR
)
566 a3
= TREE_OPERAND (a3
, 0);
567 if (TREE_CODE (a3
) == FUNCTION_DECL
)
569 numeric_output_need_bar
= 0;
570 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
574 else if (TREE_CODE (a3
) == INTEGER_CST
)
577 build_overload_int (a3
);
578 numeric_output_need_bar
= 1;
583 sorry ("template instantiation with pointer to method that is too complex");
586 if (TREE_CODE (value
) == INTEGER_CST
587 || TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
589 build_overload_int (value
);
590 numeric_output_need_bar
= 1;
593 value
= TREE_OPERAND (value
, 0);
594 if (TREE_CODE (value
) == VAR_DECL
)
596 my_friendly_assert (DECL_NAME (value
) != 0, 245);
597 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
600 else if (TREE_CODE (value
) == FUNCTION_DECL
)
602 my_friendly_assert (DECL_NAME (value
) != 0, 246);
603 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
607 my_friendly_abort (71);
608 break; /* not really needed */
611 sorry ("conversion of %s as template parameter",
612 tree_code_name
[(int) TREE_CODE (type
)]);
613 my_friendly_abort (72);
618 build_overload_identifier (name
)
621 if (TREE_CODE (name
) == TYPE_DECL
622 && IS_AGGR_TYPE (TREE_TYPE (name
))
623 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
624 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
))))
626 tree
template, parmlist
, arglist
, tname
;
628 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
629 arglist
= TREE_VALUE (template);
630 template = TREE_PURPOSE (template);
631 tname
= DECL_NAME (template);
632 parmlist
= DECL_ARGUMENTS (template);
633 nparms
= TREE_VEC_LENGTH (parmlist
);
635 icat (IDENTIFIER_LENGTH (tname
));
638 for (i
= 0; i
< nparms
; i
++)
640 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
641 tree arg
= TREE_VEC_ELT (arglist
, i
);
642 if (TREE_CODE (parm
) == TYPE_DECL
)
644 /* This parameter is a type. */
646 build_overload_name (arg
, 0, 0);
650 parm
= tsubst (parm
, &TREE_VEC_ELT (arglist
, 0),
651 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
652 /* It's a PARM_DECL. */
653 build_overload_name (TREE_TYPE (parm
), 0, 0);
654 build_overload_value (parm
, arg
);
660 if (TREE_CODE (name
) == TYPE_DECL
)
661 name
= DECL_NAME (name
);
662 if (numeric_output_need_bar
)
665 numeric_output_need_bar
= 0;
667 icat (IDENTIFIER_LENGTH (name
));
672 /* Given a list of parameters in PARMTYPES, create an unambiguous
673 overload string. Should distinguish any type that C (or C++) can
674 distinguish. I.e., pointers to functions are treated correctly.
676 Caller must deal with whether a final `e' goes on the end or not.
678 Any default conversions must take place before this function
681 BEGIN and END control initialization and finalization of the
682 obstack where we build the string. */
685 build_overload_name (parmtypes
, begin
, end
)
692 if (begin
) OB_INIT ();
693 numeric_output_need_bar
= 0;
695 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
697 parmtype
= parmtypes
;
703 parmtype
= TREE_VALUE (parmtypes
);
707 if (! nofold
&& ! just_one
)
709 /* Every argument gets counted. */
710 typevec
[maxtype
++] = parmtype
;
712 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
719 flush_repeats (typevec
[maxtype
-2]);
721 if (TREE_USED (parmtype
))
724 /* We can turn this on at some point when we want
725 improved symbol mangling. */
728 /* This is bug compatible with 2.7.x */
729 flush_repeats (parmtype
);
734 /* Only cache types which take more than one character. */
735 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
736 || (TREE_CODE (parmtype
) != INTEGER_TYPE
737 && TREE_CODE (parmtype
) != REAL_TYPE
))
738 TREE_USED (parmtype
) = 1;
741 if (TYPE_PTRMEMFUNC_P (parmtype
))
742 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
744 if (TREE_READONLY (parmtype
))
746 if (TREE_CODE (parmtype
) == INTEGER_TYPE
747 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
749 if (TYPE_VOLATILE (parmtype
))
752 switch (TREE_CODE (parmtype
))
756 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
758 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
766 #if PARM_CAN_BE_ARRAY_TYPE
771 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
772 error ("pointer or reference to array of unknown bound in parm type");
775 length
= array_type_nelts (parmtype
);
776 if (TREE_CODE (length
) == INTEGER_CST
)
777 icat (TREE_INT_CST_LOW (length
) + 1);
790 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
796 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
797 /* Otherwise have to implement reentrant typevecs,
798 unmark and remark types, etc. */
799 int old_nofold
= nofold
;
803 flush_repeats (typevec
[maxtype
-1]);
805 /* @@ It may be possible to pass a function type in
806 which is not preceded by a 'P'. */
807 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
810 if (firstarg
== NULL_TREE
)
812 else if (firstarg
== void_list_node
)
815 build_overload_name (firstarg
, 0, 0);
819 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
820 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
822 firstarg
= TREE_CHAIN (firstarg
);
824 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
830 /* For cfront 2.0 compatibility. */
833 if (firstarg
== NULL_TREE
)
835 else if (firstarg
== void_list_node
)
838 build_overload_name (firstarg
, 0, 0);
841 /* Separate args from return type. */
843 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
849 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
850 if (parmtype
== integer_type_node
851 || parmtype
== unsigned_type_node
)
853 else if (parmtype
== long_integer_type_node
854 || parmtype
== long_unsigned_type_node
)
856 else if (parmtype
== short_integer_type_node
857 || parmtype
== short_unsigned_type_node
)
859 else if (parmtype
== signed_char_type_node
)
864 else if (parmtype
== char_type_node
865 || parmtype
== unsigned_char_type_node
)
867 else if (parmtype
== wchar_type_node
)
869 else if (parmtype
== long_long_integer_type_node
870 || parmtype
== long_long_unsigned_type_node
)
873 /* it would seem there is no way to enter these in source code,
875 else if (parmtype
== long_long_long_integer_type_node
876 || parmtype
== long_long_long_unsigned_type_node
)
880 my_friendly_abort (73);
888 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
889 if (parmtype
== long_double_type_node
)
891 else if (parmtype
== double_type_node
)
893 else if (parmtype
== float_type_node
)
895 else my_friendly_abort (74);
900 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
907 extern tree void_list_node
;
909 /* See if anybody is wasting memory. */
910 my_friendly_assert (parmtypes
== void_list_node
, 247);
912 /* This is the end of a parameter list. */
913 if (end
) OB_FINISH ();
914 return (char *)obstack_base (&scratch_obstack
);
919 case ERROR_MARK
: /* not right, but nothing is anyway */
922 /* have to do these */
926 /* Make this type signature look incompatible
933 tree name
= TYPE_NAME (parmtype
);
936 if (TREE_CODE (name
) == TYPE_DECL
)
940 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
941 if (DECL_ASSEMBLER_NAME (context
) != DECL_NAME (context
))
943 OB_PUTID (DECL_ASSEMBLER_NAME (context
));
946 while (DECL_CONTEXT (context
))
949 context
= DECL_CONTEXT (context
);
950 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
951 context
= TYPE_NAME (context
);
953 name
= DECL_NAME (name
);
955 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 248);
964 numeric_output_need_bar
= 0;
965 build_overload_nested_name (TYPE_NAME (parmtype
));
968 build_overload_identifier (TYPE_NAME (parmtype
));
973 /* This will take some work. */
977 case TEMPLATE_TYPE_PARM
:
979 if (TEMPLATE_TYPE_IDX (parmtype
) > 9)
981 icat (TEMPLATE_TYPE_IDX (parmtype
));
982 if (TEMPLATE_TYPE_IDX (parmtype
) > 9)
987 /* We don't ever want this output, but it's inconvenient not to
988 be able to build the string. This should cause assembler
989 errors we'll notice. */
992 sprintf (digit_buffer
, " *%d", n
++);
993 OB_PUTCP (digit_buffer
);
998 my_friendly_abort (75);
1002 if (just_one
) break;
1003 parmtypes
= TREE_CHAIN (parmtypes
);
1008 flush_repeats (typevec
[maxtype
-1]);
1010 /* To get here, parms must end with `...'. */
1014 if (end
) OB_FINISH ();
1015 return (char *)obstack_base (&scratch_obstack
);
1019 build_static_name (basetype
, name
)
1020 tree basetype
, name
;
1022 char *basename
= build_overload_name (basetype
, 1, 1);
1023 char *buf
= (char *) alloca (IDENTIFIER_LENGTH (name
)
1024 + sizeof (STATIC_NAME_FORMAT
)
1025 + strlen (basename
));
1026 sprintf (buf
, STATIC_NAME_FORMAT
, basename
, IDENTIFIER_POINTER (name
));
1027 return get_identifier (buf
);
1030 /* Change the name of a function definition so that it may be
1031 overloaded. NAME is the name of the function to overload,
1032 PARMS is the parameter list (which determines what name the
1033 final function obtains).
1035 FOR_METHOD is 1 if this overload is being performed
1036 for a method, rather than a function type. It is 2 if
1037 this overload is being performed for a constructor. */
1040 build_decl_overload (dname
, parms
, for_method
)
1045 char *name
= IDENTIFIER_POINTER (dname
);
1047 /* member operators new and delete look like methods at this point. */
1048 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
)
1050 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1051 return get_identifier ("__builtin_delete");
1052 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1053 return get_identifier ("__builtin_vec_delete");
1054 else if (TREE_CHAIN (parms
) == void_list_node
)
1056 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1057 return get_identifier ("__builtin_new");
1058 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1059 return get_identifier ("__builtin_vec_new");
1064 if (for_method
!= 2)
1066 /* Otherwise, we can divine that this is a constructor,
1067 and figure out its name without any extra encoding. */
1069 OB_PUTC2 ('_', '_');
1073 /* We can get away without doing this. */
1077 tree this_type
= TREE_VALUE (parms
);
1079 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1080 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1081 TREE_CHAIN (parms
));
1083 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1084 TREE_CHAIN (parms
));
1090 if (parms
== NULL_TREE
)
1091 OB_PUTC2 ('e', '\0');
1092 else if (parms
== void_list_node
)
1093 OB_PUTC2 ('v', '\0');
1096 ALLOCATE_TYPEVEC (parms
);
1100 build_overload_name (TREE_VALUE (parms
), 0, 0);
1102 typevec
[maxtype
++] = TREE_VALUE (parms
);
1103 TREE_USED (TREE_VALUE (parms
)) = 1;
1105 if (TREE_CHAIN (parms
))
1106 build_overload_name (TREE_CHAIN (parms
), 0, 1);
1108 OB_PUTC2 ('e', '\0');
1111 build_overload_name (parms
, 0, 1);
1112 DEALLOCATE_TYPEVEC (parms
);
1115 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1116 if (IDENTIFIER_OPNAME_P (dname
))
1117 IDENTIFIER_OPNAME_P (n
) = 1;
1122 /* Build an overload name for the type expression TYPE. */
1125 build_typename_overload (type
)
1131 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1133 build_overload_name (type
, 0, 1);
1134 id
= get_identifier (obstack_base (&scratch_obstack
));
1135 IDENTIFIER_OPNAME_P (id
) = 1;
1137 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1139 TREE_TYPE (id
) = type
;
1144 build_overload_with_type (name
, type
)
1151 build_overload_name (type
, 0, 1);
1152 return get_identifier (obstack_base (&scratch_obstack
));
1156 get_id_2 (name
, name2
)
1164 return get_identifier (obstack_base (&scratch_obstack
));
1167 /* Given a tree_code CODE, and some arguments (at least one),
1168 attempt to use an overloaded operator on the arguments.
1170 For unary operators, only the first argument need be checked.
1171 For binary operators, both arguments may need to be checked.
1173 Member functions can convert class references to class pointers,
1174 for one-level deep indirection. More than that is not supported.
1175 Operators [](), ()(), and ->() must be member functions.
1177 We call function call building calls with LOOKUP_COMPLAIN if they
1178 are our only hope. This is true when we see a vanilla operator
1179 applied to something of aggregate type. If this fails, we are free
1180 to return `error_mark_node', because we will have reported the
1183 Operators NEW and DELETE overload in funny ways: operator new takes
1184 a single `size' parameter, and operator delete takes a pointer to the
1185 storage being deleted. When overloading these operators, success is
1186 assumed. If there is a failure, report an error message and return
1187 `error_mark_node'. */
1191 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1192 enum tree_code code
;
1194 tree xarg1
, xarg2
, arg3
;
1198 tree type1
, type2
, fnname
;
1199 tree fields1
= 0, parms
= 0;
1202 int binary_is_unary
;
1204 if (flag_ansi_overloading
)
1205 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1207 if (xarg1
== error_mark_node
)
1208 return error_mark_node
;
1210 if (code
== COND_EXPR
)
1212 if (xarg2
== error_mark_node
1213 || arg3
== error_mark_node
)
1214 return error_mark_node
;
1216 if (code
== COMPONENT_REF
)
1217 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1220 /* First, see if we can work with the first argument */
1221 type1
= TREE_TYPE (xarg1
);
1223 /* Some tree codes have length > 1, but we really only want to
1224 overload them if their first argument has a user defined type. */
1227 case PREINCREMENT_EXPR
:
1228 case PREDECREMENT_EXPR
:
1229 case POSTINCREMENT_EXPR
:
1230 case POSTDECREMENT_EXPR
:
1232 binary_is_unary
= 1;
1236 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1237 If they do not, return error_mark_node instead of NULL_TREE. */
1239 if (xarg2
== error_mark_node
)
1240 return error_mark_node
;
1242 rval
= error_mark_node
;
1243 binary_is_unary
= 0;
1250 tree args
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1251 fnname
= ansi_opname
[(int) code
];
1252 if (flags
& LOOKUP_GLOBAL
)
1253 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
);
1255 rval
= build_method_call
1256 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1258 fnname
, args
, NULL_TREE
, flags
);
1259 if (rval
== error_mark_node
)
1260 /* User might declare fancy operator new, but invoke it
1261 like standard one. */
1264 TREE_TYPE (rval
) = xarg1
;
1265 TREE_CALLS_NEW (rval
) = 1;
1270 case VEC_DELETE_EXPR
:
1273 fnname
= ansi_opname
[(int) code
];
1274 if (flags
& LOOKUP_GLOBAL
)
1275 return build_overload_call (fnname
,
1276 build_tree_list (NULL_TREE
, xarg1
),
1277 flags
& LOOKUP_COMPLAIN
);
1278 arg1
= TREE_TYPE (xarg1
);
1280 /* This handles the case where we're trying to delete
1285 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
1287 /* Strip off the pointer and the array. */
1288 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
1290 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
1291 arg1
= (TREE_TYPE (arg1
));
1293 arg1
= build_pointer_type (arg1
);
1296 rval
= build_method_call
1297 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
1300 fnname
, tree_cons (NULL_TREE
, xarg1
,
1301 build_tree_list (NULL_TREE
, xarg2
)),
1304 /* This can happen when operator delete is protected. */
1305 my_friendly_assert (rval
!= error_mark_node
, 250);
1306 TREE_TYPE (rval
) = void_type_node
;
1313 binary_is_unary
= 0;
1314 try_second
= tree_code_length
[(int) code
] == 2;
1315 if (try_second
&& xarg2
== error_mark_node
)
1316 return error_mark_node
;
1320 if (try_second
&& xarg2
== error_mark_node
)
1321 return error_mark_node
;
1323 /* What ever it was, we do not know how to deal with it. */
1324 if (type1
== NULL_TREE
)
1327 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1328 type1
= TREE_TYPE (type1
);
1330 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1332 arg1
= convert_from_reference (xarg1
);
1333 type1
= TREE_TYPE (arg1
);
1340 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1342 /* Try to fail. First, fail if unary */
1345 /* Second, see if second argument is non-aggregate. */
1346 type2
= TREE_TYPE (xarg2
);
1347 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1348 type2
= TREE_TYPE (type2
);
1349 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1351 arg2
= convert_from_reference (xarg2
);
1352 type2
= TREE_TYPE (arg2
);
1359 if (!IS_AGGR_TYPE (type2
))
1366 /* First arg may succeed; see whether second should. */
1367 type2
= TREE_TYPE (xarg2
);
1368 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1369 type2
= TREE_TYPE (type2
);
1370 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1372 arg2
= convert_from_reference (xarg2
);
1373 type2
= TREE_TYPE (arg2
);
1380 if (! IS_AGGR_TYPE (type2
))
1384 if (type1
== unknown_type_node
1385 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1387 /* This will not be implemented in the foreseeable future. */
1391 if (code
== MODIFY_EXPR
)
1392 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1394 fnname
= ansi_opname
[(int) code
];
1396 global_fn
= lookup_name_nonclass (fnname
);
1398 /* This is the last point where we will accept failure. This
1399 may be too eager if we wish an overloaded operator not to match,
1400 but would rather a normal operator be called on a type-converted
1403 if (IS_AGGR_TYPE (type1
))
1405 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1406 /* ARM $13.4.7, prefix/postfix ++/--. */
1407 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1409 xarg2
= integer_zero_node
;
1410 binary_is_unary
= 0;
1415 int have_postfix
= 0;
1417 /* Look for an `operator++ (int)'. If they didn't have
1418 one, then we fall back to the old way of doing things. */
1419 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1421 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1422 if (TREE_CHAIN (t2
) != NULL_TREE
1423 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1432 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1434 /* There's probably a LOT of code in the world that
1435 relies upon this old behavior. */
1436 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1439 binary_is_unary
= 1;
1445 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1448 /* If RVAL winds up being `error_mark_node', we will return
1449 that... There is no way that normal semantics of these
1450 operators will succeed. */
1452 /* This argument may be an uncommitted OFFSET_REF. This is
1453 the case for example when dealing with static class members
1454 which are referenced from their class name rather than
1455 from a class instance. */
1456 if (TREE_CODE (xarg1
) == OFFSET_REF
1457 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1458 xarg1
= TREE_OPERAND (xarg1
, 1);
1459 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1460 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1461 xarg2
= TREE_OPERAND (xarg2
, 1);
1464 flags
|= LOOKUP_GLOBAL
;
1466 if (code
== CALL_EXPR
)
1468 /* This can only be a member function. */
1469 return build_method_call (xarg1
, fnname
, xarg2
,
1470 NULL_TREE
, LOOKUP_NORMAL
);
1472 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1475 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1477 else if (code
== COND_EXPR
)
1479 parms
= tree_cons (NULL_TREE
, xarg2
, build_tree_list (NULL_TREE
, arg3
));
1480 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1482 else if (code
== METHOD_CALL_EXPR
)
1484 /* must be a member function. */
1485 parms
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1486 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1491 parms
= build_tree_list (NULL_TREE
, xarg2
);
1492 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1496 parms
= tree_cons (NULL_TREE
, xarg1
,
1497 build_tree_list (NULL_TREE
, xarg2
));
1498 rval
= build_overload_call (fnname
, parms
, flags
);
1504 /* This function takes an identifier, ID, and attempts to figure out what
1505 it means. There are a number of possible scenarios, presented in increasing
1508 1) not in a class's scope
1509 2) in class's scope, member name of the class's method
1510 3) in class's scope, but not a member name of the class
1511 4) in class's scope, member name of a class's variable
1513 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1514 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1516 As a last ditch, try to look up the name as a label and return that
1519 Values which are declared as being of REFERENCE_TYPE are
1520 automatically dereferenced here (as a hack to make the
1521 compiler faster). */
1524 hack_identifier (value
, name
)
1529 if (value
== error_mark_node
)
1531 if (current_class_name
)
1533 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1534 if (fields
== error_mark_node
)
1535 return error_mark_node
;
1540 fndecl
= TREE_VALUE (fields
);
1541 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1542 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1544 warning ("methods cannot be converted to function pointers");
1549 error ("ambiguous request for method pointer `%s'",
1550 IDENTIFIER_POINTER (name
));
1551 return error_mark_node
;
1555 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1557 return IDENTIFIER_LABEL_VALUE (name
);
1559 return error_mark_node
;
1562 type
= TREE_TYPE (value
);
1563 if (TREE_CODE (value
) == FIELD_DECL
)
1565 if (current_class_ptr
== NULL_TREE
)
1567 error ("request for member `%s' in static member function",
1568 IDENTIFIER_POINTER (DECL_NAME (value
)));
1569 return error_mark_node
;
1571 TREE_USED (current_class_ptr
) = 1;
1573 /* Mark so that if we are in a constructor, and then find that
1574 this field was initialized by a base initializer,
1575 we can emit an error message. */
1576 TREE_USED (value
) = 1;
1577 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1579 else if (really_overloaded_fn (value
))
1582 tree t
= get_first_fn (value
);
1583 for (; t
; t
= DECL_CHAIN (t
))
1585 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1588 assemble_external (t
);
1593 else if (TREE_CODE (value
) == TREE_LIST
)
1595 /* Ambiguous reference to base members, possibly other cases?. */
1597 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1599 mark_used (TREE_VALUE (t
));
1606 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1608 tree context
= decl_function_context (value
);
1609 if (context
!= NULL_TREE
&& context
!= current_function_decl
1610 && ! TREE_STATIC (value
))
1612 cp_error ("use of %s from containing function",
1613 (TREE_CODE (value
) == VAR_DECL
1614 ? "`auto' variable" : "parameter"));
1615 cp_error_at (" `%#D' declared here", value
);
1616 value
= error_mark_node
;
1620 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1622 if (DECL_LANG_SPECIFIC (value
)
1623 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1626 register tree context
1627 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1628 ? DECL_CLASS_CONTEXT (value
)
1629 : DECL_CONTEXT (value
);
1631 get_base_distance (context
, current_class_type
, 0, &path
);
1634 access
= compute_access (path
, value
);
1635 if (access
!= access_public_node
)
1637 if (TREE_CODE (value
) == VAR_DECL
)
1638 error ("static member `%s' is %s",
1639 IDENTIFIER_POINTER (name
),
1640 TREE_PRIVATE (value
) ? "private"
1641 : "from a private base class");
1643 error ("enum `%s' is from private base class",
1644 IDENTIFIER_POINTER (name
));
1645 return error_mark_node
;
1651 if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1655 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1656 IDENTIFIER_POINTER (name
));
1657 return error_mark_node
;
1663 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1664 value
= convert_from_reference (value
);
1670 thunk_printable_name (decl
)
1673 return "<thunk function>";
1677 make_thunk (function
, delta
)
1686 if (TREE_CODE (function
) != ADDR_EXPR
)
1688 func_decl
= TREE_OPERAND (function
, 0);
1689 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1691 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1693 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1695 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1696 thunk_id
= get_identifier (buffer
);
1697 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1698 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1700 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1701 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1703 if (thunk
== NULL_TREE
)
1705 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1706 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1707 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1708 comdat_linkage (thunk
);
1709 TREE_SET_CODE (thunk
, THUNK_DECL
);
1710 DECL_INITIAL (thunk
) = function
;
1711 THUNK_DELTA (thunk
) = delta
;
1712 DECL_EXTERNAL (thunk
) = 1;
1713 DECL_ARTIFICIAL (thunk
) = 1;
1714 /* So that finish_file can write out any thunks that need to be: */
1715 pushdecl_top_level (thunk
);
1720 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1723 emit_thunk (thunk_fndecl
)
1726 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1727 int delta
= THUNK_DELTA (thunk_fndecl
);
1729 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1732 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1734 TREE_ADDRESSABLE (function
) = 1;
1735 mark_used (function
);
1737 if (current_function_decl
)
1740 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1743 #ifdef ASM_OUTPUT_MI_THUNK
1745 current_function_decl
= thunk_fndecl
;
1746 /* Make sure we build up its RTL before we go onto the
1747 temporary obstack. */
1748 make_function_rtl (thunk_fndecl
);
1749 temporary_allocation ();
1750 DECL_RESULT (thunk_fndecl
)
1751 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1752 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1753 assemble_start_function (thunk_fndecl
, fnname
);
1754 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
1755 assemble_end_function (thunk_fndecl
, fnname
);
1756 permanent_allocation (1);
1757 current_function_decl
= 0;
1758 #else /* ASM_OUTPUT_MI_THUNK */
1759 /* If we don't have the necessary macro for efficient thunks, generate a
1760 thunk function that just makes a call to the real function.
1761 Unfortunately, this doesn't work for varargs. */
1765 if (varargs_function_p (function
))
1766 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1769 /* Set up clone argument trees for the thunk. */
1771 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
1773 tree x
= copy_node (a
);
1775 DECL_CONTEXT (x
) = thunk_fndecl
;
1779 DECL_ARGUMENTS (thunk_fndecl
) = a
;
1780 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
1781 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
1782 copy_lang_decl (thunk_fndecl
);
1783 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
1784 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
1786 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
1787 store_parm_decls ();
1788 current_function_is_thunk
= 1;
1790 /* Build up the call to the real function. */
1791 t
= build_int_2 (delta
, -1 * (delta
< 0));
1792 TREE_TYPE (t
) = signed_type (sizetype
);
1793 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
1794 t
= tree_cons (NULL_TREE
, t
, NULL_TREE
);
1795 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
1796 t
= tree_cons (NULL_TREE
, a
, t
);
1798 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
1799 c_expand_return (t
);
1801 finish_function (lineno
, 0, 0);
1802 #endif /* ASM_OUTPUT_MI_THUNK */
1805 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
1808 /* Code for synthesizing methods which have default semantics defined. */
1810 /* For the anonymous union in TYPE, return the member that is at least as
1811 large as the rest of the members, so we can copy it. */
1814 largest_union_member (type
)
1817 tree f
, type_size
= TYPE_SIZE (type
);
1819 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
1820 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
1823 /* We should always find one. */
1824 my_friendly_abort (323);
1828 /* Generate code for default X(X&) constructor. */
1831 do_build_copy_constructor (fndecl
)
1834 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
1840 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1841 parm
= TREE_CHAIN (parm
);
1842 parm
= convert_from_reference (parm
);
1844 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
1846 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
1847 TREE_SIDE_EFFECTS (t
) = 1;
1848 cplus_expand_expr_stmt (t
);
1852 tree fields
= TYPE_FIELDS (current_class_type
);
1853 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
1854 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
1857 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
1860 tree basetype
= BINFO_TYPE (t
);
1861 tree p
= convert_to_reference
1862 (build_reference_type (basetype
), parm
,
1863 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
1864 p
= convert_from_reference (p
);
1866 if (p
== error_mark_node
)
1867 cp_error ("in default copy constructor");
1869 current_base_init_list
= tree_cons (basetype
,
1870 p
, current_base_init_list
);
1873 for (i
= 0; i
< n_bases
; ++i
)
1875 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
1876 if (TREE_VIA_VIRTUAL (basetype
))
1879 basetype
= BINFO_TYPE (basetype
);
1880 p
= convert_to_reference
1881 (build_reference_type (basetype
), parm
,
1882 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
1884 if (p
== error_mark_node
)
1885 cp_error ("in default copy constructor");
1888 p
= convert_from_reference (p
);
1889 current_base_init_list
= tree_cons (basetype
,
1890 p
, current_base_init_list
);
1893 for (; fields
; fields
= TREE_CHAIN (fields
))
1896 tree field
= fields
;
1898 if (TREE_CODE (field
) != FIELD_DECL
)
1900 if (DECL_NAME (field
))
1902 if (VFIELD_NAME_P (DECL_NAME (field
)))
1904 if (VBASE_NAME_P (DECL_NAME (field
)))
1907 /* True for duplicate members. */
1908 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
1911 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
1912 && TREE_CODE (t
) == UNION_TYPE
1913 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
1914 && TYPE_FIELDS (t
) != NULL_TREE
)
1915 field
= largest_union_member (t
);
1919 init
= build (COMPONENT_REF
, TREE_TYPE (field
), parm
, field
);
1920 init
= build_tree_list (NULL_TREE
, init
);
1922 current_member_init_list
1923 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
1925 current_member_init_list
= nreverse (current_member_init_list
);
1926 current_base_init_list
= nreverse (current_base_init_list
);
1934 do_build_assign_ref (fndecl
)
1937 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
1942 parm
= convert_from_reference (parm
);
1944 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
1946 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
1947 TREE_SIDE_EFFECTS (t
) = 1;
1948 cplus_expand_expr_stmt (t
);
1952 tree fields
= TYPE_FIELDS (current_class_type
);
1953 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
1954 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
1957 for (i
= 0; i
< n_bases
; ++i
)
1959 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
1960 tree p
= convert_to_reference
1961 (build_reference_type (basetype
), parm
,
1962 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
1963 p
= convert_from_reference (p
);
1964 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
1965 build_tree_list (NULL_TREE
, p
));
1966 expand_expr_stmt (p
);
1968 for (; fields
; fields
= TREE_CHAIN (fields
))
1971 tree field
= fields
;
1973 if (TREE_CODE (field
) != FIELD_DECL
)
1976 if (TREE_READONLY (field
))
1978 if (DECL_NAME (field
))
1979 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
1981 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
1984 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
1986 if (DECL_NAME (field
))
1987 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
1989 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
1993 if (DECL_NAME (field
))
1995 if (VFIELD_NAME_P (DECL_NAME (field
)))
1997 if (VBASE_NAME_P (DECL_NAME (field
)))
2000 /* True for duplicate members. */
2001 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2004 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2005 && TREE_CODE (t
) == UNION_TYPE
2006 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2007 && TYPE_FIELDS (t
) != NULL_TREE
)
2008 field
= largest_union_member (t
);
2012 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), current_class_ref
, field
);
2013 init
= build (COMPONENT_REF
, TREE_TYPE (field
), parm
, field
);
2015 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2018 c_expand_return (current_class_ref
);
2023 synthesize_method (fndecl
)
2026 int nested
= (current_function_decl
!= NULL_TREE
);
2027 tree context
= hack_decl_function_context (fndecl
);
2030 push_to_top_level ();
2032 push_cp_function_context (context
);
2034 interface_unknown
= 1;
2035 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2036 store_parm_decls ();
2038 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2039 do_build_assign_ref (fndecl
);
2040 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2044 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2045 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2046 arg_chain
= TREE_CHAIN (arg_chain
);
2047 if (arg_chain
!= void_list_node
)
2048 do_build_copy_constructor (fndecl
);
2049 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2053 finish_function (lineno
, 0, nested
);
2055 extract_interface_info ();
2057 pop_from_top_level ();
2059 pop_cp_function_context (context
);