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);
902 extern tree void_list_node;
904 /* See if anybody is wasting memory. */
905 my_friendly_assert (parmtypes == void_list_node, 247);
907 /* This is the end of a parameter list. */
908 if (end) OB_FINISH ();
909 return (char *)obstack_base (&scratch_obstack);
914 case ERROR_MARK: /* not right, but nothing is anyway */
917 /* have to do these */
921 /* Make this type signature look incompatible
928 tree name = TYPE_NAME (parmtype);
931 if (TREE_CODE (name) == TYPE_DECL)
935 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
936 if (DECL_ASSEMBLER_NAME (context) != DECL_NAME (context))
938 OB_PUTID (DECL_ASSEMBLER_NAME (context));
941 while (DECL_CONTEXT (context))
944 context = DECL_CONTEXT (context);
945 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
946 context = TYPE_NAME (context);
948 name = DECL_NAME (name);
950 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 248);
959 numeric_output_need_bar = 0;
960 build_overload_nested_name (TYPE_NAME (parmtype));
963 build_overload_identifier (TYPE_NAME (parmtype));
968 /* This will take some work. */
972 case TEMPLATE_TYPE_PARM:
974 if (TEMPLATE_TYPE_IDX (parmtype) > 9)
976 icat (TEMPLATE_TYPE_IDX (parmtype));
977 if (TEMPLATE_TYPE_IDX (parmtype) > 9)
982 /* We don't ever want this output, but it's inconvenient not to
983 be able to build the string. This should cause assembler
984 errors we'll notice. */
987 sprintf (digit_buffer, " *%d", n++);
988 OB_PUTCP (digit_buffer);
993 my_friendly_abort (75);
998 parmtypes = TREE_CHAIN (parmtypes);
1003 flush_repeats (typevec[maxtype-1]);
1005 /* To get here, parms must end with `...'. */
1009 if (end) OB_FINISH ();
1010 return (char *)obstack_base (&scratch_obstack);
1014 build_static_name (basetype, name)
1015 tree basetype, name;
1017 char *basename = build_overload_name (basetype, 1, 1);
1018 char *buf = (char *) alloca (IDENTIFIER_LENGTH (name)
1019 + sizeof (STATIC_NAME_FORMAT)
1020 + strlen (basename));
1021 sprintf (buf, STATIC_NAME_FORMAT, basename, IDENTIFIER_POINTER (name));
1022 return get_identifier (buf);
1025 /* Change the name of a function definition so that it may be
1026 overloaded. NAME is the name of the function to overload,
1027 PARMS is the parameter list (which determines what name the
1028 final function obtains).
1030 FOR_METHOD is 1 if this overload is being performed
1031 for a method, rather than a function type. It is 2 if
1032 this overload is being performed for a constructor. */
1035 build_decl_overload (dname, parms, for_method)
1040 char *name = IDENTIFIER_POINTER (dname);
1042 /* member operators new and delete look like methods at this point. */
1043 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST)
1045 if (dname == ansi_opname[(int) DELETE_EXPR])
1046 return get_identifier ("__builtin_delete");
1047 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1048 return get_identifier ("__builtin_vec_delete");
1049 else if (TREE_CHAIN (parms) == void_list_node)
1051 if (dname == ansi_opname[(int) NEW_EXPR])
1052 return get_identifier ("__builtin_new");
1053 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1054 return get_identifier ("__builtin_vec_new");
1059 if (for_method != 2)
1061 /* Otherwise, we can divine that this is a constructor,
1062 and figure out its name without any extra encoding. */
1064 OB_PUTC2 ('_', '_');
1068 /* We can get away without doing this. */
1072 tree this_type = TREE_VALUE (parms);
1074 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
1075 parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type),
1076 TREE_CHAIN (parms));
1078 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type),
1079 TREE_CHAIN (parms));
1085 if (parms == NULL_TREE)
1086 OB_PUTC2 ('e', '\0');
1087 else if (parms == void_list_node)
1088 OB_PUTC2 ('v', '\0');
1091 ALLOCATE_TYPEVEC (parms);
1095 build_overload_name (TREE_VALUE (parms), 0, 0);
1097 typevec[maxtype++] = TREE_VALUE (parms);
1098 TREE_USED (TREE_VALUE (parms)) = 1;
1100 if (TREE_CHAIN (parms))
1101 build_overload_name (TREE_CHAIN (parms), 0, 1);
1103 OB_PUTC2 ('e', '\0');
1106 build_overload_name (parms, 0, 1);
1107 DEALLOCATE_TYPEVEC (parms);
1110 tree n = get_identifier (obstack_base (&scratch_obstack));
1111 if (IDENTIFIER_OPNAME_P (dname))
1112 IDENTIFIER_OPNAME_P (n) = 1;
1117 /* Build an overload name for the type expression TYPE. */
1120 build_typename_overload (type)
1126 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1128 build_overload_name (type, 0, 1);
1129 id = get_identifier (obstack_base (&scratch_obstack));
1130 IDENTIFIER_OPNAME_P (id) = 1;
1132 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1134 TREE_TYPE (id) = type;
1139 build_overload_with_type (name, type)
1146 build_overload_name (type, 0, 1);
1147 return get_identifier (obstack_base (&scratch_obstack));
1151 get_id_2 (name, name2)
1159 return get_identifier (obstack_base (&scratch_obstack));
1162 /* Given a tree_code CODE, and some arguments (at least one),
1163 attempt to use an overloaded operator on the arguments.
1165 For unary operators, only the first argument need be checked.
1166 For binary operators, both arguments may need to be checked.
1168 Member functions can convert class references to class pointers,
1169 for one-level deep indirection. More than that is not supported.
1170 Operators [](), ()(), and ->() must be member functions.
1172 We call function call building calls with LOOKUP_COMPLAIN if they
1173 are our only hope. This is true when we see a vanilla operator
1174 applied to something of aggregate type. If this fails, we are free
1175 to return `error_mark_node', because we will have reported the
1178 Operators NEW and DELETE overload in funny ways: operator new takes
1179 a single `size' parameter, and operator delete takes a pointer to the
1180 storage being deleted. When overloading these operators, success is
1181 assumed. If there is a failure, report an error message and return
1182 `error_mark_node'. */
1186 build_opfncall (code, flags, xarg1, xarg2, arg3)
1187 enum tree_code code;
1189 tree xarg1, xarg2, arg3;
1193 tree type1, type2, fnname;
1194 tree fields1 = 0, parms = 0;
1197 int binary_is_unary;
1199 if (flag_ansi_overloading)
1200 return build_new_op (code, flags, xarg1, xarg2, arg3);
1202 if (xarg1 == error_mark_node)
1203 return error_mark_node;
1205 if (code == COND_EXPR)
1207 if (xarg2 == error_mark_node
1208 || arg3 == error_mark_node)
1209 return error_mark_node;
1211 if (code == COMPONENT_REF)
1212 if (TREE_CODE (TREE_TYPE (xarg1)) == POINTER_TYPE)
1215 /* First, see if we can work with the first argument */
1216 type1 = TREE_TYPE (xarg1);
1218 /* Some tree codes have length > 1, but we really only want to
1219 overload them if their first argument has a user defined type. */
1222 case PREINCREMENT_EXPR:
1223 case PREDECREMENT_EXPR:
1224 case POSTINCREMENT_EXPR:
1225 case POSTDECREMENT_EXPR:
1227 binary_is_unary = 1;
1231 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1232 If they do not, return error_mark_node instead of NULL_TREE. */
1234 if (xarg2 == error_mark_node)
1235 return error_mark_node;
1237 rval = error_mark_node;
1238 binary_is_unary = 0;
1245 tree args = tree_cons (NULL_TREE, xarg2, arg3);
1246 fnname = ansi_opname[(int) code];
1247 if (flags & LOOKUP_GLOBAL)
1248 return build_overload_call (fnname, args, flags & LOOKUP_COMPLAIN);
1250 rval = build_method_call
1251 (build_indirect_ref (build1 (NOP_EXPR, xarg1, error_mark_node),
1253 fnname, args, NULL_TREE, flags);
1254 if (rval == error_mark_node)
1255 /* User might declare fancy operator new, but invoke it
1256 like standard one. */
1259 TREE_TYPE (rval) = xarg1;
1260 TREE_CALLS_NEW (rval) = 1;
1265 case VEC_DELETE_EXPR:
1268 fnname = ansi_opname[(int) code];
1269 if (flags & LOOKUP_GLOBAL)
1270 return build_overload_call (fnname,
1271 build_tree_list (NULL_TREE, xarg1),
1272 flags & LOOKUP_COMPLAIN);
1273 arg1 = TREE_TYPE (xarg1);
1275 /* This handles the case where we're trying to delete
1280 if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
1282 /* Strip off the pointer and the array. */
1283 arg1 = TREE_TYPE (TREE_TYPE (arg1));
1285 while (TREE_CODE (arg1) == ARRAY_TYPE)
1286 arg1 = (TREE_TYPE (arg1));
1288 arg1 = build_pointer_type (arg1);
1291 rval = build_method_call
1292 (build_indirect_ref (build1 (NOP_EXPR, arg1,
1295 fnname, tree_cons (NULL_TREE, xarg1,
1296 build_tree_list (NULL_TREE, xarg2)),
1299 /* This can happen when operator delete is protected. */
1300 my_friendly_assert (rval != error_mark_node, 250);
1301 TREE_TYPE (rval) = void_type_node;
1308 binary_is_unary = 0;
1309 try_second = tree_code_length [(int) code] == 2;
1310 if (try_second && xarg2 == error_mark_node)
1311 return error_mark_node;
1315 if (try_second && xarg2 == error_mark_node)
1316 return error_mark_node;
1318 /* What ever it was, we do not know how to deal with it. */
1319 if (type1 == NULL_TREE)
1322 if (TREE_CODE (type1) == OFFSET_TYPE)
1323 type1 = TREE_TYPE (type1);
1325 if (TREE_CODE (type1) == REFERENCE_TYPE)
1327 arg1 = convert_from_reference (xarg1);
1328 type1 = TREE_TYPE (arg1);
1335 if (!IS_AGGR_TYPE (type1) || TYPE_PTRMEMFUNC_P (type1))
1337 /* Try to fail. First, fail if unary */
1340 /* Second, see if second argument is non-aggregate. */
1341 type2 = TREE_TYPE (xarg2);
1342 if (TREE_CODE (type2) == OFFSET_TYPE)
1343 type2 = TREE_TYPE (type2);
1344 if (TREE_CODE (type2) == REFERENCE_TYPE)
1346 arg2 = convert_from_reference (xarg2);
1347 type2 = TREE_TYPE (arg2);
1354 if (!IS_AGGR_TYPE (type2))
1361 /* First arg may succeed; see whether second should. */
1362 type2 = TREE_TYPE (xarg2);
1363 if (TREE_CODE (type2) == OFFSET_TYPE)
1364 type2 = TREE_TYPE (type2);
1365 if (TREE_CODE (type2) == REFERENCE_TYPE)
1367 arg2 = convert_from_reference (xarg2);
1368 type2 = TREE_TYPE (arg2);
1375 if (! IS_AGGR_TYPE (type2))
1379 if (type1 == unknown_type_node
1380 || (try_second && TREE_TYPE (xarg2) == unknown_type_node))
1382 /* This will not be implemented in the foreseeable future. */
1386 if (code == MODIFY_EXPR)
1387 fnname = ansi_assopname[(int) TREE_CODE (arg3)];
1389 fnname = ansi_opname[(int) code];
1391 global_fn = lookup_name_nonclass (fnname);
1393 /* This is the last point where we will accept failure. This
1394 may be too eager if we wish an overloaded operator not to match,
1395 but would rather a normal operator be called on a type-converted
1398 if (IS_AGGR_TYPE (type1))
1400 fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
1401 /* ARM $13.4.7, prefix/postfix ++/--. */
1402 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
1404 xarg2 = integer_zero_node;
1405 binary_is_unary = 0;
1410 int have_postfix = 0;
1412 /* Look for an `operator++ (int)'. If they didn't have
1413 one, then we fall back to the old way of doing things. */
1414 for (t = TREE_VALUE (fields1); t ; t = DECL_CHAIN (t))
1416 t2 = TYPE_ARG_TYPES (TREE_TYPE (t));
1417 if (TREE_CHAIN (t2) != NULL_TREE
1418 && TREE_VALUE (TREE_CHAIN (t2)) == integer_type_node)
1427 char *op = POSTINCREMENT_EXPR ? "++" : "--";
1429 /* There's probably a LOT of code in the world that
1430 relies upon this old behavior. */
1431 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1434 binary_is_unary = 1;
1440 if (fields1 == NULL_TREE && global_fn == NULL_TREE)
1443 /* If RVAL winds up being `error_mark_node', we will return
1444 that... There is no way that normal semantics of these
1445 operators will succeed. */
1447 /* This argument may be an uncommitted OFFSET_REF. This is
1448 the case for example when dealing with static class members
1449 which are referenced from their class name rather than
1450 from a class instance. */
1451 if (TREE_CODE (xarg1) == OFFSET_REF
1452 && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL)
1453 xarg1 = TREE_OPERAND (xarg1, 1);
1454 if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF
1455 && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL)
1456 xarg2 = TREE_OPERAND (xarg2, 1);
1459 flags |= LOOKUP_GLOBAL;
1461 if (code == CALL_EXPR)
1463 /* This can only be a member function. */
1464 return build_method_call (xarg1, fnname, xarg2,
1465 NULL_TREE, LOOKUP_NORMAL);
1467 else if (tree_code_length[(int) code] == 1 || binary_is_unary)
1470 rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags);
1472 else if (code == COND_EXPR)
1474 parms = tree_cons (NULL_TREE, xarg2, build_tree_list (NULL_TREE, arg3));
1475 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1477 else if (code == METHOD_CALL_EXPR)
1479 /* must be a member function. */
1480 parms = tree_cons (NULL_TREE, xarg2, arg3);
1481 return build_method_call (xarg1, fnname, parms, NULL_TREE,
1486 parms = build_tree_list (NULL_TREE, xarg2);
1487 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1491 parms = tree_cons (NULL_TREE, xarg1,
1492 build_tree_list (NULL_TREE, xarg2));
1493 rval = build_overload_call (fnname, parms, flags);
1499 /* This function takes an identifier, ID, and attempts to figure out what
1500 it means. There are a number of possible scenarios, presented in increasing
1503 1) not in a class's scope
1504 2) in class's scope, member name of the class's method
1505 3) in class's scope, but not a member name of the class
1506 4) in class's scope, member name of a class's variable
1508 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1509 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1511 As a last ditch, try to look up the name as a label and return that
1514 Values which are declared as being of REFERENCE_TYPE are
1515 automatically dereferenced here (as a hack to make the
1516 compiler faster). */
1519 hack_identifier (value, name)
1524 if (value == error_mark_node)
1526 if (current_class_name)
1528 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1529 if (fields == error_mark_node)
1530 return error_mark_node;
1535 fndecl = TREE_VALUE (fields);
1536 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1537 if (DECL_CHAIN (fndecl) == NULL_TREE)
1539 warning ("methods cannot be converted to function pointers");
1544 error ("ambiguous request for method pointer `%s'",
1545 IDENTIFIER_POINTER (name));
1546 return error_mark_node;
1550 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1552 return IDENTIFIER_LABEL_VALUE (name);
1554 return error_mark_node;
1557 type = TREE_TYPE (value);
1558 if (TREE_CODE (value) == FIELD_DECL)
1560 if (current_class_ptr == NULL_TREE)
1562 error ("request for member `%s' in static member function",
1563 IDENTIFIER_POINTER (DECL_NAME (value)));
1564 return error_mark_node;
1566 TREE_USED (current_class_ptr) = 1;
1568 /* Mark so that if we are in a constructor, and then find that
1569 this field was initialized by a base initializer,
1570 we can emit an error message. */
1571 TREE_USED (value) = 1;
1572 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
1574 else if (really_overloaded_fn (value))
1577 tree t = get_first_fn (value);
1578 for (; t; t = DECL_CHAIN (t))
1580 if (TREE_CODE (t) == TEMPLATE_DECL)
1583 assemble_external (t);
1588 else if (TREE_CODE (value) == TREE_LIST)
1590 /* Ambiguous reference to base members, possibly other cases?. */
1592 while (t && TREE_CODE (t) == TREE_LIST)
1594 mark_used (TREE_VALUE (t));
1601 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL)
1603 tree context = decl_function_context (value);
1604 if (context != NULL_TREE && context != current_function_decl
1605 && ! TREE_STATIC (value))
1607 cp_error ("use of %s from containing function",
1608 (TREE_CODE (value) == VAR_DECL
1609 ? "`auto' variable" : "parameter"));
1610 cp_error_at (" `%#D' declared here", value);
1611 value = error_mark_node;
1615 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1617 if (DECL_LANG_SPECIFIC (value)
1618 && DECL_CLASS_CONTEXT (value) != current_class_type)
1621 register tree context
1622 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1623 ? DECL_CLASS_CONTEXT (value)
1624 : DECL_CONTEXT (value);
1626 get_base_distance (context, current_class_type, 0, &path);
1629 access = compute_access (path, value);
1630 if (access != access_public_node)
1632 if (TREE_CODE (value) == VAR_DECL)
1633 error ("static member `%s' is %s",
1634 IDENTIFIER_POINTER (name),
1635 TREE_PRIVATE (value) ? "private"
1636 : "from a private base class");
1638 error ("enum `%s' is from private base class",
1639 IDENTIFIER_POINTER (name));
1640 return error_mark_node;
1646 if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1650 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1651 IDENTIFIER_POINTER (name));
1652 return error_mark_node;
1658 if (TREE_CODE (type) == REFERENCE_TYPE && ! processing_template_decl)
1659 value = convert_from_reference (value);
1665 thunk_printable_name (decl)
1668 return "<thunk function>";
1672 make_thunk (function, delta)
1677 tree thunk_fndecl, thunk_id;
1680 static int thunk_number = 0;
1682 if (TREE_CODE (function) != ADDR_EXPR)
1684 func_decl = TREE_OPERAND (function, 0);
1685 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1687 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1689 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1691 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1692 thunk_id = get_identifier (buffer);
1693 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1694 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1696 cp_error ("implementation-reserved name `%D' used", thunk_id);
1697 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1699 if (thunk == NULL_TREE)
1701 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
1702 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
1703 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
1704 comdat_linkage (thunk);
1705 TREE_SET_CODE (thunk, THUNK_DECL);
1706 DECL_INITIAL (thunk) = function;
1707 THUNK_DELTA (thunk) = delta;
1708 DECL_EXTERNAL (thunk) = 1;
1709 DECL_ARTIFICIAL (thunk) = 1;
1710 /* So that finish_file can write out any thunks that need to be: */
1711 pushdecl_top_level (thunk);
1716 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1719 emit_thunk (thunk_fndecl)
1722 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1723 int delta = THUNK_DELTA (thunk_fndecl);
1725 if (TREE_ASM_WRITTEN (thunk_fndecl))
1728 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1730 TREE_ADDRESSABLE (function) = 1;
1731 mark_used (function);
1733 if (current_function_decl)
1736 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
1739 #ifdef ASM_OUTPUT_MI_THUNK
1741 current_function_decl = thunk_fndecl;
1742 temporary_allocation ();
1743 DECL_RESULT (thunk_fndecl)
1744 = build_decl (RESULT_DECL, 0, integer_type_node);
1745 make_function_rtl (thunk_fndecl);
1746 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
1747 assemble_start_function (thunk_fndecl, fnname);
1748 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
1749 assemble_end_function (thunk_fndecl, fnname);
1750 permanent_allocation (1);
1751 current_function_decl = 0;
1752 #else /* ASM_OUTPUT_MI_THUNK */
1753 /* If we don't have the necessary macro for efficient thunks, generate a
1754 thunk function that just makes a call to the real function.
1755 Unfortunately, this doesn't work for varargs. */
1759 if (varargs_function_p (function))
1760 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1763 /* Set up clone argument trees for the thunk. */
1765 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
1767 tree x = copy_node (a);
1769 DECL_CONTEXT (x) = thunk_fndecl;
1773 DECL_ARGUMENTS (thunk_fndecl) = a;
1774 DECL_RESULT (thunk_fndecl) = NULL_TREE;
1775 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
1776 copy_lang_decl (thunk_fndecl);
1777 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
1778 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
1780 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, 1);
1781 store_parm_decls ();
1782 current_function_is_thunk = 1;
1784 /* Build up the call to the real function. */
1785 t = build_int_2 (delta, -1 * (delta < 0));
1786 TREE_TYPE (t) = signed_type (sizetype);
1787 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
1788 t = tree_cons (NULL_TREE, t, NULL_TREE);
1789 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
1790 t = tree_cons (NULL_TREE, a, t);
1792 t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t);
1793 c_expand_return (t);
1795 finish_function (lineno, 0, 0);
1796 #endif /* ASM_OUTPUT_MI_THUNK */
1799 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
1802 /* Code for synthesizing methods which have default semantics defined. */
1804 /* For the anonymous union in TYPE, return the member that is at least as
1805 large as the rest of the members, so we can copy it. */
1808 largest_union_member (type)
1811 tree f, type_size = TYPE_SIZE (type);
1813 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
1814 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
1817 /* We should always find one. */
1818 my_friendly_abort (323);
1822 /* Generate code for default X(X&) constructor. */
1825 do_build_copy_constructor (fndecl)
1828 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
1834 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
1835 parm = TREE_CHAIN (parm);
1836 parm = convert_from_reference (parm);
1838 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
1840 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
1841 TREE_SIDE_EFFECTS (t) = 1;
1842 cplus_expand_expr_stmt (t);
1846 tree fields = TYPE_FIELDS (current_class_type);
1847 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
1848 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
1851 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
1854 tree basetype = BINFO_TYPE (t);
1855 tree p = convert_to_reference
1856 (build_reference_type (basetype), parm,
1857 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
1858 p = convert_from_reference (p);
1860 if (p == error_mark_node)
1861 cp_error ("in default copy constructor");
1863 current_base_init_list = tree_cons (basetype,
1864 p, current_base_init_list);
1867 for (i = 0; i < n_bases; ++i)
1869 tree p, basetype = TREE_VEC_ELT (binfos, i);
1870 if (TREE_VIA_VIRTUAL (basetype))
1873 basetype = BINFO_TYPE (basetype);
1874 p = convert_to_reference
1875 (build_reference_type (basetype), parm,
1876 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
1878 if (p == error_mark_node)
1879 cp_error ("in default copy constructor");
1882 p = convert_from_reference (p);
1883 current_base_init_list = tree_cons (basetype,
1884 p, current_base_init_list);
1887 for (; fields; fields = TREE_CHAIN (fields))
1890 tree field = fields;
1892 if (TREE_CODE (field) != FIELD_DECL)
1894 if (DECL_NAME (field))
1896 if (VFIELD_NAME_P (DECL_NAME (field)))
1898 if (VBASE_NAME_P (DECL_NAME (field)))
1901 /* True for duplicate members. */
1902 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
1905 else if ((t = TREE_TYPE (field)) != NULL_TREE
1906 && TREE_CODE (t) == UNION_TYPE
1907 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
1908 && TYPE_FIELDS (t) != NULL_TREE)
1909 field = largest_union_member (t);
1913 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
1914 init = build_tree_list (NULL_TREE, init);
1916 current_member_init_list
1917 = tree_cons (DECL_NAME (field), init, current_member_init_list);
1919 current_member_init_list = nreverse (current_member_init_list);
1920 current_base_init_list = nreverse (current_base_init_list);
1928 do_build_assign_ref (fndecl)
1931 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
1936 parm = convert_from_reference (parm);
1938 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
1940 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
1941 TREE_SIDE_EFFECTS (t) = 1;
1942 cplus_expand_expr_stmt (t);
1946 tree fields = TYPE_FIELDS (current_class_type);
1947 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
1948 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
1951 for (i = 0; i < n_bases; ++i)
1953 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1954 tree p = convert_to_reference
1955 (build_reference_type (basetype), parm,
1956 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
1957 p = convert_from_reference (p);
1958 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
1959 build_tree_list (NULL_TREE, p));
1960 expand_expr_stmt (p);
1962 for (; fields; fields = TREE_CHAIN (fields))
1965 tree field = fields;
1967 if (TREE_CODE (field) != FIELD_DECL)
1970 if (TREE_READONLY (field))
1972 if (DECL_NAME (field))
1973 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
1975 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
1978 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
1980 if (DECL_NAME (field))
1981 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
1983 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
1987 if (DECL_NAME (field))
1989 if (VFIELD_NAME_P (DECL_NAME (field)))
1991 if (VBASE_NAME_P (DECL_NAME (field)))
1994 /* True for duplicate members. */
1995 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
1998 else if ((t = TREE_TYPE (field)) != NULL_TREE
1999 && TREE_CODE (t) == UNION_TYPE
2000 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2001 && TYPE_FIELDS (t) != NULL_TREE)
2002 field = largest_union_member (t);
2006 comp = build (COMPONENT_REF, TREE_TYPE (field), current_class_ref, field);
2007 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2009 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2012 c_expand_return (current_class_ref);
2017 synthesize_method (fndecl)
2020 int nested = (current_function_decl != NULL_TREE);
2021 tree context = hack_decl_function_context (fndecl);
2024 push_to_top_level ();
2026 push_cp_function_context (context);
2028 interface_unknown = 1;
2029 start_function (NULL_TREE, fndecl, NULL_TREE, 1);
2030 store_parm_decls ();
2032 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2033 do_build_assign_ref (fndecl);
2034 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2038 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2039 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2040 arg_chain = TREE_CHAIN (arg_chain);
2041 if (arg_chain != void_list_node)
2042 do_build_copy_constructor (fndecl);
2043 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2047 finish_function (lineno, 0, nested);
2049 /* Do we really *want* to inline this function? */
2050 if (DECL_INLINE (fndecl))
2052 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
2053 will check our size. */
2054 DECL_INLINE (fndecl) = 0;
2056 /* We say !at_eof because at the end of the file some of the rtl
2057 for fndecl may have been allocated on the temporary obstack.
2058 (The function_obstack is the temporary one if we're not in a
2060 if ((! at_eof) && function_cannot_inline_p (fndecl) == 0)
2061 DECL_INLINE (fndecl) = 1;
2064 extract_interface_info ();
2066 pop_from_top_level ();
2068 pop_cp_function_context (context);