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 /* Handle this case first, to go really quickly. For many common values,
267 the result of i/10 below is 1. */
284 OB_PUTC ('0' + (i % 10));
298 while (typevec[tindex] != type)
316 static int numeric_output_need_bar;
317 static void build_overload_identifier ();
320 build_overload_nested_name (decl)
323 if (DECL_CONTEXT (decl))
325 tree context = DECL_CONTEXT (decl);
326 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
327 context = TYPE_NAME (context);
328 build_overload_nested_name (context);
331 if (TREE_CODE (decl) == FUNCTION_DECL)
333 tree name = DECL_ASSEMBLER_NAME (decl);
335 extern int var_labelno;
337 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), var_labelno);
340 if (numeric_output_need_bar)
343 numeric_output_need_bar = 0;
345 icat (strlen (label));
349 build_overload_identifier (decl);
352 /* Encoding for an INTEGER_CST value. */
355 build_overload_int (value)
358 if (TREE_CODE (value) == TEMPLATE_CONST_PARM)
361 if (TEMPLATE_CONST_IDX (value) > 9)
363 icat (TEMPLATE_CONST_IDX (value));
364 if (TEMPLATE_CONST_IDX (value) > 9)
368 else if (processing_template_decl
369 && TREE_CODE (value) != INTEGER_CST)
370 /* We don't ever want this output, but it's inconvenient not to
371 be able to build the string. This should cause assembler
372 errors we'll notice. */
375 sprintf (digit_buffer, " *%d", n++);
376 OB_PUTCP (digit_buffer);
380 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
381 if (TYPE_PRECISION (TREE_TYPE (value)) == 2 * HOST_BITS_PER_WIDE_INT)
383 if (tree_int_cst_lt (value, integer_zero_node))
386 value = build_int_2 (~ TREE_INT_CST_LOW (value),
387 - TREE_INT_CST_HIGH (value));
389 if (TREE_INT_CST_HIGH (value)
390 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
392 /* need to print a DImode value in decimal */
393 sorry ("conversion of long long as PT parameter");
395 /* else fall through to print in smaller mode */
397 /* Wordsize or smaller */
398 icat (TREE_INT_CST_LOW (value));
402 build_overload_value (type, value)
405 while (TREE_CODE (value) == NON_LVALUE_EXPR
406 || TREE_CODE (value) == NOP_EXPR)
407 value = TREE_OPERAND (value, 0);
408 my_friendly_assert (TREE_CODE (type) == PARM_DECL, 242);
409 type = TREE_TYPE (type);
411 if (numeric_output_need_bar)
414 numeric_output_need_bar = 0;
417 if (TREE_CODE (type) == POINTER_TYPE
418 && TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE)
420 /* Handle a pointer to data member as a template instantiation
421 parameter, boy, what fun! */
422 type = integer_type_node;
423 if (TREE_CODE (value) != INTEGER_CST)
425 sorry ("unknown pointer to member constant");
430 if (TYPE_PTRMEMFUNC_P (type))
431 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
433 switch (TREE_CODE (type))
439 build_overload_int (value);
440 numeric_output_need_bar = 1;
443 #ifndef REAL_IS_NOT_DOUBLE
447 char *bufp = digit_buffer;
448 extern char *index ();
450 my_friendly_assert (TREE_CODE (value) == REAL_CST, 244);
451 val = TREE_REAL_CST (value);
457 sprintf (bufp, "%e", val);
458 bufp = (char *) index (bufp, 'e');
460 strcat (digit_buffer, "e0");
486 OB_PUTCP (digit_buffer);
487 numeric_output_need_bar = 1;
492 if (TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
493 && TREE_CODE (value) != ADDR_EXPR)
495 if (TREE_CODE (value) == CONSTRUCTOR)
497 /* This is dangerous code, crack built up pointer to members. */
498 tree args = CONSTRUCTOR_ELTS (value);
499 tree a1 = TREE_VALUE (args);
500 tree a2 = TREE_VALUE (TREE_CHAIN (args));
501 tree a3 = CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args))));
502 a3 = TREE_VALUE (a3);
504 if (TREE_CODE (a1) == INTEGER_CST
505 && TREE_CODE (a2) == INTEGER_CST)
507 build_overload_int (a1);
509 build_overload_int (a2);
511 if (TREE_CODE (a3) == ADDR_EXPR)
513 a3 = TREE_OPERAND (a3, 0);
514 if (TREE_CODE (a3) == FUNCTION_DECL)
516 numeric_output_need_bar = 0;
517 build_overload_identifier (DECL_ASSEMBLER_NAME (a3));
521 else if (TREE_CODE (a3) == INTEGER_CST)
524 build_overload_int (a3);
525 numeric_output_need_bar = 1;
530 sorry ("template instantiation with pointer to method that is too complex");
533 if (TREE_CODE (value) == INTEGER_CST
534 || TREE_CODE (value) == TEMPLATE_CONST_PARM)
536 build_overload_int (value);
537 numeric_output_need_bar = 1;
540 value = TREE_OPERAND (value, 0);
541 if (TREE_CODE (value) == VAR_DECL)
543 my_friendly_assert (DECL_NAME (value) != 0, 245);
544 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
547 else if (TREE_CODE (value) == FUNCTION_DECL)
549 my_friendly_assert (DECL_NAME (value) != 0, 246);
550 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
554 my_friendly_abort (71);
555 break; /* not really needed */
558 sorry ("conversion of %s as template parameter",
559 tree_code_name [(int) TREE_CODE (type)]);
560 my_friendly_abort (72);
565 build_overload_identifier (name)
568 if (TREE_CODE (name) == TYPE_DECL
569 && IS_AGGR_TYPE (TREE_TYPE (name))
570 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
571 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name))))
573 tree template, parmlist, arglist, tname;
575 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name));
576 arglist = TREE_VALUE (template);
577 template = TREE_PURPOSE (template);
578 tname = DECL_NAME (template);
579 parmlist = DECL_ARGUMENTS (template);
580 nparms = TREE_VEC_LENGTH (parmlist);
582 icat (IDENTIFIER_LENGTH (tname));
585 for (i = 0; i < nparms; i++)
587 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
588 tree arg = TREE_VEC_ELT (arglist, i);
589 if (TREE_CODE (parm) == TYPE_DECL)
591 /* This parameter is a type. */
593 build_overload_name (arg, 0, 0);
597 parm = tsubst (parm, &TREE_VEC_ELT (arglist, 0),
598 TREE_VEC_LENGTH (arglist), NULL_TREE);
599 /* It's a PARM_DECL. */
600 build_overload_name (TREE_TYPE (parm), 0, 0);
601 build_overload_value (parm, arg);
607 if (TREE_CODE (name) == TYPE_DECL)
608 name = DECL_NAME (name);
609 if (numeric_output_need_bar)
612 numeric_output_need_bar = 0;
614 icat (IDENTIFIER_LENGTH (name));
619 /* Given a list of parameters in PARMTYPES, create an unambiguous
620 overload string. Should distinguish any type that C (or C++) can
621 distinguish. I.e., pointers to functions are treated correctly.
623 Caller must deal with whether a final `e' goes on the end or not.
625 Any default conversions must take place before this function
628 BEGIN and END control initialization and finalization of the
629 obstack where we build the string. */
632 build_overload_name (parmtypes, begin, end)
639 if (begin) OB_INIT ();
640 numeric_output_need_bar = 0;
642 if ((just_one = (TREE_CODE (parmtypes) != TREE_LIST)))
644 parmtype = parmtypes;
650 parmtype = TREE_VALUE (parmtypes);
654 if (! nofold && ! just_one)
656 /* Every argument gets counted. */
657 typevec[maxtype++] = parmtype;
659 if (TREE_USED (parmtype) && parmtype == typevec[maxtype-2])
666 flush_repeats (typevec[maxtype-2]);
668 if (TREE_USED (parmtype))
671 /* We can turn this on at some point when we want
672 improved symbol mangling. */
675 /* This is bug compatible with 2.7.x */
676 flush_repeats (parmtype);
681 /* Only cache types which take more than one character. */
682 if (parmtype != TYPE_MAIN_VARIANT (parmtype)
683 || (TREE_CODE (parmtype) != INTEGER_TYPE
684 && TREE_CODE (parmtype) != REAL_TYPE))
685 TREE_USED (parmtype) = 1;
688 if (TYPE_PTRMEMFUNC_P (parmtype))
689 parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype);
691 if (TREE_READONLY (parmtype))
693 if (TREE_CODE (parmtype) == INTEGER_TYPE
694 && TYPE_MAIN_VARIANT (parmtype) == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
696 if (TYPE_VOLATILE (parmtype))
699 switch (TREE_CODE (parmtype))
703 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0);
705 build_overload_name (TREE_TYPE (parmtype), 0, 0);
713 #if PARM_CAN_BE_ARRAY_TYPE
718 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
719 error ("pointer or reference to array of unknown bound in parm type");
722 length = array_type_nelts (parmtype);
723 if (TREE_CODE (length) == INTEGER_CST)
724 icat (TREE_INT_CST_LOW (length) + 1);
737 build_overload_name (TREE_TYPE (parmtype), 0, 0);
743 tree firstarg = TYPE_ARG_TYPES (parmtype);
744 /* Otherwise have to implement reentrant typevecs,
745 unmark and remark types, etc. */
746 int old_nofold = nofold;
750 flush_repeats (typevec[maxtype-1]);
752 /* @@ It may be possible to pass a function type in
753 which is not preceded by a 'P'. */
754 if (TREE_CODE (parmtype) == FUNCTION_TYPE)
757 if (firstarg == NULL_TREE)
759 else if (firstarg == void_list_node)
762 build_overload_name (firstarg, 0, 0);
766 int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
767 int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
769 firstarg = TREE_CHAIN (firstarg);
771 build_overload_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0);
777 /* For cfront 2.0 compatibility. */
780 if (firstarg == NULL_TREE)
782 else if (firstarg == void_list_node)
785 build_overload_name (firstarg, 0, 0);
788 /* Separate args from return type. */
790 build_overload_name (TREE_TYPE (parmtype), 0, 0);
796 parmtype = TYPE_MAIN_VARIANT (parmtype);
797 if (parmtype == integer_type_node
798 || parmtype == unsigned_type_node)
800 else if (parmtype == long_integer_type_node
801 || parmtype == long_unsigned_type_node)
803 else if (parmtype == short_integer_type_node
804 || parmtype == short_unsigned_type_node)
806 else if (parmtype == signed_char_type_node)
811 else if (parmtype == char_type_node
812 || parmtype == unsigned_char_type_node)
814 else if (parmtype == wchar_type_node)
816 else if (parmtype == long_long_integer_type_node
817 || parmtype == long_long_unsigned_type_node)
820 /* it would seem there is no way to enter these in source code,
822 else if (parmtype == long_long_long_integer_type_node
823 || parmtype == long_long_long_unsigned_type_node)
827 my_friendly_abort (73);
835 parmtype = TYPE_MAIN_VARIANT (parmtype);
836 if (parmtype == long_double_type_node)
838 else if (parmtype == double_type_node)
840 else if (parmtype == float_type_node)
842 else my_friendly_abort (74);
849 extern tree void_list_node;
851 /* See if anybody is wasting memory. */
852 my_friendly_assert (parmtypes == void_list_node, 247);
854 /* This is the end of a parameter list. */
855 if (end) OB_FINISH ();
856 return (char *)obstack_base (&scratch_obstack);
861 case ERROR_MARK: /* not right, but nothing is anyway */
864 /* have to do these */
868 /* Make this type signature look incompatible
875 tree name = TYPE_NAME (parmtype);
878 if (TREE_CODE (name) == TYPE_DECL)
882 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
883 if (DECL_ASSEMBLER_NAME (context) != DECL_NAME (context))
885 OB_PUTID (DECL_ASSEMBLER_NAME (context));
888 while (DECL_CONTEXT (context))
891 context = DECL_CONTEXT (context);
892 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
893 context = TYPE_NAME (context);
895 name = DECL_NAME (name);
897 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 248);
906 numeric_output_need_bar = 0;
907 build_overload_nested_name (TYPE_NAME (parmtype));
910 build_overload_identifier (TYPE_NAME (parmtype));
915 /* This will take some work. */
919 case TEMPLATE_TYPE_PARM:
921 if (TEMPLATE_TYPE_IDX (parmtype) > 9)
923 icat (TEMPLATE_TYPE_IDX (parmtype));
924 if (TEMPLATE_TYPE_IDX (parmtype) > 9)
929 /* We don't ever want this output, but it's inconvenient not to
930 be able to build the string. This should cause assembler
931 errors we'll notice. */
934 sprintf (digit_buffer, " *%d", n++);
935 OB_PUTCP (digit_buffer);
940 my_friendly_abort (75);
945 parmtypes = TREE_CHAIN (parmtypes);
950 flush_repeats (typevec[maxtype-1]);
952 /* To get here, parms must end with `...'. */
956 if (end) OB_FINISH ();
957 return (char *)obstack_base (&scratch_obstack);
961 build_static_name (basetype, name)
964 char *basename = build_overload_name (basetype, 1, 1);
965 char *buf = (char *) alloca (IDENTIFIER_LENGTH (name)
966 + sizeof (STATIC_NAME_FORMAT)
967 + strlen (basename));
968 sprintf (buf, STATIC_NAME_FORMAT, basename, IDENTIFIER_POINTER (name));
969 return get_identifier (buf);
972 /* Change the name of a function definition so that it may be
973 overloaded. NAME is the name of the function to overload,
974 PARMS is the parameter list (which determines what name the
975 final function obtains).
977 FOR_METHOD is 1 if this overload is being performed
978 for a method, rather than a function type. It is 2 if
979 this overload is being performed for a constructor. */
982 build_decl_overload (dname, parms, for_method)
987 char *name = IDENTIFIER_POINTER (dname);
989 /* member operators new and delete look like methods at this point. */
990 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST)
992 if (dname == ansi_opname[(int) DELETE_EXPR])
993 return get_identifier ("__builtin_delete");
994 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
995 return get_identifier ("__builtin_vec_delete");
996 else if (TREE_CHAIN (parms) == void_list_node)
998 if (dname == ansi_opname[(int) NEW_EXPR])
999 return get_identifier ("__builtin_new");
1000 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1001 return get_identifier ("__builtin_vec_new");
1006 if (for_method != 2)
1008 /* Otherwise, we can divine that this is a constructor,
1009 and figure out its name without any extra encoding. */
1011 OB_PUTC2 ('_', '_');
1015 /* We can get away without doing this. */
1019 tree this_type = TREE_VALUE (parms);
1021 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
1022 parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type),
1023 TREE_CHAIN (parms));
1025 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type),
1026 TREE_CHAIN (parms));
1032 if (parms == NULL_TREE)
1033 OB_PUTC2 ('e', '\0');
1034 else if (parms == void_list_node)
1035 OB_PUTC2 ('v', '\0');
1038 ALLOCATE_TYPEVEC (parms);
1042 build_overload_name (TREE_VALUE (parms), 0, 0);
1044 typevec[maxtype++] = TREE_VALUE (parms);
1045 TREE_USED (TREE_VALUE (parms)) = 1;
1047 if (TREE_CHAIN (parms))
1048 build_overload_name (TREE_CHAIN (parms), 0, 1);
1050 OB_PUTC2 ('e', '\0');
1053 build_overload_name (parms, 0, 1);
1054 DEALLOCATE_TYPEVEC (parms);
1057 tree n = get_identifier (obstack_base (&scratch_obstack));
1058 if (IDENTIFIER_OPNAME_P (dname))
1059 IDENTIFIER_OPNAME_P (n) = 1;
1064 /* Build an overload name for the type expression TYPE. */
1067 build_typename_overload (type)
1073 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1075 build_overload_name (type, 0, 1);
1076 id = get_identifier (obstack_base (&scratch_obstack));
1077 IDENTIFIER_OPNAME_P (id) = 1;
1079 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1081 TREE_TYPE (id) = type;
1086 build_overload_with_type (name, type)
1093 build_overload_name (type, 0, 1);
1094 return get_identifier (obstack_base (&scratch_obstack));
1098 get_id_2 (name, name2)
1106 return get_identifier (obstack_base (&scratch_obstack));
1109 /* Given a tree_code CODE, and some arguments (at least one),
1110 attempt to use an overloaded operator on the arguments.
1112 For unary operators, only the first argument need be checked.
1113 For binary operators, both arguments may need to be checked.
1115 Member functions can convert class references to class pointers,
1116 for one-level deep indirection. More than that is not supported.
1117 Operators [](), ()(), and ->() must be member functions.
1119 We call function call building calls with LOOKUP_COMPLAIN if they
1120 are our only hope. This is true when we see a vanilla operator
1121 applied to something of aggregate type. If this fails, we are free
1122 to return `error_mark_node', because we will have reported the
1125 Operators NEW and DELETE overload in funny ways: operator new takes
1126 a single `size' parameter, and operator delete takes a pointer to the
1127 storage being deleted. When overloading these operators, success is
1128 assumed. If there is a failure, report an error message and return
1129 `error_mark_node'. */
1133 build_opfncall (code, flags, xarg1, xarg2, arg3)
1134 enum tree_code code;
1136 tree xarg1, xarg2, arg3;
1140 tree type1, type2, fnname;
1141 tree fields1 = 0, parms = 0;
1144 int binary_is_unary;
1146 if (flag_ansi_overloading)
1147 return build_new_op (code, flags, xarg1, xarg2, arg3);
1149 if (xarg1 == error_mark_node)
1150 return error_mark_node;
1152 if (code == COND_EXPR)
1154 if (TREE_CODE (xarg2) == ERROR_MARK
1155 || TREE_CODE (arg3) == ERROR_MARK)
1156 return error_mark_node;
1158 if (code == COMPONENT_REF)
1159 if (TREE_CODE (TREE_TYPE (xarg1)) == POINTER_TYPE)
1162 /* First, see if we can work with the first argument */
1163 type1 = TREE_TYPE (xarg1);
1165 /* Some tree codes have length > 1, but we really only want to
1166 overload them if their first argument has a user defined type. */
1169 case PREINCREMENT_EXPR:
1170 case PREDECREMENT_EXPR:
1171 case POSTINCREMENT_EXPR:
1172 case POSTDECREMENT_EXPR:
1174 binary_is_unary = 1;
1178 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1179 If they do not, return error_mark_node instead of NULL_TREE. */
1181 if (xarg2 == error_mark_node)
1182 return error_mark_node;
1184 rval = error_mark_node;
1185 binary_is_unary = 0;
1192 tree args = tree_cons (NULL_TREE, xarg2, arg3);
1193 fnname = ansi_opname[(int) code];
1194 if (flags & LOOKUP_GLOBAL)
1195 return build_overload_call (fnname, args, flags & LOOKUP_COMPLAIN);
1197 rval = build_method_call
1198 (build_indirect_ref (build1 (NOP_EXPR, xarg1, error_mark_node),
1200 fnname, args, NULL_TREE, flags);
1201 if (rval == error_mark_node)
1202 /* User might declare fancy operator new, but invoke it
1203 like standard one. */
1206 TREE_TYPE (rval) = xarg1;
1207 TREE_CALLS_NEW (rval) = 1;
1212 case VEC_DELETE_EXPR:
1215 fnname = ansi_opname[(int) code];
1216 if (flags & LOOKUP_GLOBAL)
1217 return build_overload_call (fnname,
1218 build_tree_list (NULL_TREE, xarg1),
1219 flags & LOOKUP_COMPLAIN);
1220 arg1 = TREE_TYPE (xarg1);
1222 /* This handles the case where we're trying to delete
1227 if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
1229 /* Strip off the pointer and the array. */
1230 arg1 = TREE_TYPE (TREE_TYPE (arg1));
1232 while (TREE_CODE (arg1) == ARRAY_TYPE)
1233 arg1 = (TREE_TYPE (arg1));
1235 arg1 = build_pointer_type (arg1);
1238 rval = build_method_call
1239 (build_indirect_ref (build1 (NOP_EXPR, arg1,
1242 fnname, tree_cons (NULL_TREE, xarg1,
1243 build_tree_list (NULL_TREE, xarg2)),
1246 /* This can happen when operator delete is protected. */
1247 my_friendly_assert (rval != error_mark_node, 250);
1248 TREE_TYPE (rval) = void_type_node;
1255 binary_is_unary = 0;
1256 try_second = tree_code_length [(int) code] == 2;
1257 if (try_second && xarg2 == error_mark_node)
1258 return error_mark_node;
1262 if (try_second && xarg2 == error_mark_node)
1263 return error_mark_node;
1265 /* What ever it was, we do not know how to deal with it. */
1266 if (type1 == NULL_TREE)
1269 if (TREE_CODE (type1) == OFFSET_TYPE)
1270 type1 = TREE_TYPE (type1);
1272 if (TREE_CODE (type1) == REFERENCE_TYPE)
1274 arg1 = convert_from_reference (xarg1);
1275 type1 = TREE_TYPE (arg1);
1282 if (!IS_AGGR_TYPE (type1) || TYPE_PTRMEMFUNC_P (type1))
1284 /* Try to fail. First, fail if unary */
1287 /* Second, see if second argument is non-aggregate. */
1288 type2 = TREE_TYPE (xarg2);
1289 if (TREE_CODE (type2) == OFFSET_TYPE)
1290 type2 = TREE_TYPE (type2);
1291 if (TREE_CODE (type2) == REFERENCE_TYPE)
1293 arg2 = convert_from_reference (xarg2);
1294 type2 = TREE_TYPE (arg2);
1301 if (!IS_AGGR_TYPE (type2))
1308 /* First arg may succeed; see whether second should. */
1309 type2 = TREE_TYPE (xarg2);
1310 if (TREE_CODE (type2) == OFFSET_TYPE)
1311 type2 = TREE_TYPE (type2);
1312 if (TREE_CODE (type2) == REFERENCE_TYPE)
1314 arg2 = convert_from_reference (xarg2);
1315 type2 = TREE_TYPE (arg2);
1322 if (! IS_AGGR_TYPE (type2))
1326 if (type1 == unknown_type_node
1327 || (try_second && TREE_TYPE (xarg2) == unknown_type_node))
1329 /* This will not be implemented in the foreseeable future. */
1333 if (code == MODIFY_EXPR)
1334 fnname = ansi_assopname[(int) TREE_CODE (arg3)];
1336 fnname = ansi_opname[(int) code];
1338 global_fn = lookup_name_nonclass (fnname);
1340 /* This is the last point where we will accept failure. This
1341 may be too eager if we wish an overloaded operator not to match,
1342 but would rather a normal operator be called on a type-converted
1345 if (IS_AGGR_TYPE (type1))
1347 fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
1348 /* ARM $13.4.7, prefix/postfix ++/--. */
1349 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
1351 xarg2 = integer_zero_node;
1352 binary_is_unary = 0;
1357 int have_postfix = 0;
1359 /* Look for an `operator++ (int)'. If they didn't have
1360 one, then we fall back to the old way of doing things. */
1361 for (t = TREE_VALUE (fields1); t ; t = DECL_CHAIN (t))
1363 t2 = TYPE_ARG_TYPES (TREE_TYPE (t));
1364 if (TREE_CHAIN (t2) != NULL_TREE
1365 && TREE_VALUE (TREE_CHAIN (t2)) == integer_type_node)
1374 char *op = POSTINCREMENT_EXPR ? "++" : "--";
1376 /* There's probably a LOT of code in the world that
1377 relies upon this old behavior. */
1378 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1381 binary_is_unary = 1;
1387 if (fields1 == NULL_TREE && global_fn == NULL_TREE)
1390 /* If RVAL winds up being `error_mark_node', we will return
1391 that... There is no way that normal semantics of these
1392 operators will succeed. */
1394 /* This argument may be an uncommitted OFFSET_REF. This is
1395 the case for example when dealing with static class members
1396 which are referenced from their class name rather than
1397 from a class instance. */
1398 if (TREE_CODE (xarg1) == OFFSET_REF
1399 && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL)
1400 xarg1 = TREE_OPERAND (xarg1, 1);
1401 if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF
1402 && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL)
1403 xarg2 = TREE_OPERAND (xarg2, 1);
1406 flags |= LOOKUP_GLOBAL;
1408 if (code == CALL_EXPR)
1410 /* This can only be a member function. */
1411 return build_method_call (xarg1, fnname, xarg2,
1412 NULL_TREE, LOOKUP_NORMAL);
1414 else if (tree_code_length[(int) code] == 1 || binary_is_unary)
1417 rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags);
1419 else if (code == COND_EXPR)
1421 parms = tree_cons (NULL_TREE, xarg2, build_tree_list (NULL_TREE, arg3));
1422 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1424 else if (code == METHOD_CALL_EXPR)
1426 /* must be a member function. */
1427 parms = tree_cons (NULL_TREE, xarg2, arg3);
1428 return build_method_call (xarg1, fnname, parms, NULL_TREE,
1433 parms = build_tree_list (NULL_TREE, xarg2);
1434 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1438 parms = tree_cons (NULL_TREE, xarg1,
1439 build_tree_list (NULL_TREE, xarg2));
1440 rval = build_overload_call (fnname, parms, flags);
1446 /* This function takes an identifier, ID, and attempts to figure out what
1447 it means. There are a number of possible scenarios, presented in increasing
1450 1) not in a class's scope
1451 2) in class's scope, member name of the class's method
1452 3) in class's scope, but not a member name of the class
1453 4) in class's scope, member name of a class's variable
1455 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1456 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1458 As a last ditch, try to look up the name as a label and return that
1461 Values which are declared as being of REFERENCE_TYPE are
1462 automatically dereferenced here (as a hack to make the
1463 compiler faster). */
1466 hack_identifier (value, name)
1471 if (TREE_CODE (value) == ERROR_MARK)
1473 if (current_class_name)
1475 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1476 if (fields == error_mark_node)
1477 return error_mark_node;
1482 fndecl = TREE_VALUE (fields);
1483 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1484 if (DECL_CHAIN (fndecl) == NULL_TREE)
1486 warning ("methods cannot be converted to function pointers");
1491 error ("ambiguous request for method pointer `%s'",
1492 IDENTIFIER_POINTER (name));
1493 return error_mark_node;
1497 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1499 return IDENTIFIER_LABEL_VALUE (name);
1501 return error_mark_node;
1504 type = TREE_TYPE (value);
1505 if (TREE_CODE (value) == FIELD_DECL)
1507 if (current_class_ptr == NULL_TREE)
1509 error ("request for member `%s' in static member function",
1510 IDENTIFIER_POINTER (DECL_NAME (value)));
1511 return error_mark_node;
1513 TREE_USED (current_class_ptr) = 1;
1515 /* Mark so that if we are in a constructor, and then find that
1516 this field was initialized by a base initializer,
1517 we can emit an error message. */
1518 TREE_USED (value) = 1;
1519 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
1521 else if (really_overloaded_fn (value))
1524 tree t = get_first_fn (value);
1525 for (; t; t = DECL_CHAIN (t))
1527 if (TREE_CODE (t) == TEMPLATE_DECL)
1530 assemble_external (t);
1535 else if (TREE_CODE (value) == TREE_LIST)
1537 /* Ambiguous reference to base members, possibly other cases?. */
1539 while (t && TREE_CODE (t) == TREE_LIST)
1541 mark_used (TREE_VALUE (t));
1548 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL)
1550 tree context = decl_function_context (value);
1551 if (context != NULL_TREE && context != current_function_decl
1552 && ! TREE_STATIC (value))
1554 cp_error ("use of %s from containing function",
1555 (TREE_CODE (value) == VAR_DECL
1556 ? "`auto' variable" : "parameter"));
1557 cp_error_at (" `%#D' declared here", value);
1558 value = error_mark_node;
1562 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1564 if (DECL_LANG_SPECIFIC (value)
1565 && DECL_CLASS_CONTEXT (value) != current_class_type)
1568 register tree context
1569 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1570 ? DECL_CLASS_CONTEXT (value)
1571 : DECL_CONTEXT (value);
1573 get_base_distance (context, current_class_type, 0, &path);
1576 access = compute_access (path, value);
1577 if (access != access_public_node)
1579 if (TREE_CODE (value) == VAR_DECL)
1580 error ("static member `%s' is %s",
1581 IDENTIFIER_POINTER (name),
1582 TREE_PRIVATE (value) ? "private" :
1583 "from a private base class");
1585 error ("enum `%s' is from private base class",
1586 IDENTIFIER_POINTER (name));
1587 return error_mark_node;
1593 if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1597 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1598 IDENTIFIER_POINTER (name));
1599 return error_mark_node;
1605 if (TREE_CODE (type) == REFERENCE_TYPE && ! processing_template_decl)
1606 value = convert_from_reference (value);
1612 thunk_printable_name (decl)
1615 return "<thunk function>";
1619 make_thunk (function, delta)
1624 tree thunk_fndecl, thunk_id;
1627 static int thunk_number = 0;
1629 if (TREE_CODE (function) != ADDR_EXPR)
1631 func_decl = TREE_OPERAND (function, 0);
1632 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1634 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1636 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1638 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1639 thunk_id = get_identifier (buffer);
1640 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1641 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1643 cp_error ("implementation-reserved name `%D' used", thunk_id);
1644 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1646 if (thunk == NULL_TREE)
1648 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
1650 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type)));
1651 TREE_READONLY (thunk) = TYPE_READONLY (TREE_TYPE (vtable_entry_type));
1652 TREE_THIS_VOLATILE (thunk) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type));
1653 make_function_rtl (thunk);
1654 comdat_linkage (thunk);
1655 TREE_SET_CODE (thunk, THUNK_DECL);
1656 DECL_INITIAL (thunk) = function;
1657 THUNK_DELTA (thunk) = delta;
1658 DECL_EXTERNAL (thunk) = 1;
1659 /* So that finish_file can write out any thunks that need to be: */
1660 pushdecl_top_level (thunk);
1666 emit_thunk (thunk_fndecl)
1672 struct args_size stack_args_size;
1673 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1674 int delta = THUNK_DELTA (thunk_fndecl);
1675 char *fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
1680 /* Used to remember which regs we need to emit a USE rtx for. */
1681 rtx need_use[FIRST_PSEUDO_REGISTER];
1682 int need_use_count = 0;
1684 /* rtx for the 'this' parameter. */
1685 rtx this_rtx = 0, this_reg_rtx = 0, fixed_this_rtx;
1687 char *(*save_decl_printable_name) () = decl_printable_name;
1688 /* Data on reg parms scanned so far. */
1689 CUMULATIVE_ARGS args_so_far;
1691 if (TREE_ASM_WRITTEN (thunk_fndecl))
1694 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1696 TREE_ADDRESSABLE (function) = 1;
1697 mark_used (function);
1699 decl_printable_name = thunk_printable_name;
1700 if (current_function_decl)
1702 current_function_decl = thunk_fndecl;
1704 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
1705 #ifdef ASM_OUTPUT_MI_THUNK
1706 temporary_allocation ();
1707 assemble_start_function (thunk_fndecl, fnname);
1708 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
1709 assemble_end_function (thunk_fndecl, fnname);
1710 permanent_allocation (1);
1712 save_ofp = flag_omit_frame_pointer;
1713 flag_omit_frame_pointer = 1;
1714 init_function_start (thunk_fndecl, input_filename, lineno);
1716 expand_start_bindings (1);
1718 temporary_allocation ();
1720 /* Start updating where the next arg would go. */
1721 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (function), NULL_RTX, 0);
1722 stack_args_size.constant = 0;
1723 stack_args_size.var = 0;
1724 /* SETUP for possible structure return address FIXME */
1726 /* Now look through all the parameters, make sure that we
1727 don't clobber any registers used for parameters.
1728 Also, pick up an rtx for the first "this" parameter. */
1729 for (argp = TYPE_ARG_TYPES (TREE_TYPE (function));
1731 argp = TREE_CHAIN (argp))
1734 tree passed_type = TREE_VALUE (argp);
1735 register rtx entry_parm;
1736 int named = 1; /* FIXME */
1737 struct args_size stack_offset;
1738 struct args_size arg_size;
1740 if (passed_type == void_type_node)
1743 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
1744 && contains_placeholder_p (TYPE_SIZE (passed_type)))
1745 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1746 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far,
1747 TYPE_MODE (passed_type),
1751 passed_type = build_pointer_type (passed_type);
1753 entry_parm = FUNCTION_ARG (args_so_far,
1754 TYPE_MODE (passed_type),
1757 if (entry_parm != 0)
1758 need_use[need_use_count++] = entry_parm;
1760 locate_and_pad_parm (TYPE_MODE (passed_type), passed_type,
1761 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1767 &stack_args_size, &stack_offset, &arg_size);
1769 /* REGNO (entry_parm);*/
1772 this_reg_rtx = entry_parm;
1775 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
1777 rtx internal_arg_pointer, stack_parm;
1779 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
1780 || ! (fixed_regs[ARG_POINTER_REGNUM]
1781 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
1782 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
1784 internal_arg_pointer = virtual_incoming_args_rtx;
1786 if (offset_rtx == const0_rtx)
1787 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1788 internal_arg_pointer);
1790 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1791 gen_rtx (PLUS, Pmode,
1792 internal_arg_pointer,
1796 this_rtx = entry_parm;
1799 FUNCTION_ARG_ADVANCE (args_so_far,
1800 TYPE_MODE (passed_type),
1805 fixed_this_rtx = plus_constant (this_rtx, delta);
1806 if (this_rtx != fixed_this_rtx)
1807 emit_move_insn (this_rtx, fixed_this_rtx);
1810 emit_insn (gen_rtx (USE, VOIDmode, this_reg_rtx));
1812 emit_indirect_jump (XEXP (DECL_RTL (function), 0));
1814 while (need_use_count > 0)
1815 emit_insn (gen_rtx (USE, VOIDmode, need_use[--need_use_count]));
1817 expand_end_bindings (NULL, 1, 0);
1820 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
1821 Note that that may have been done above, in save_for_inline_copying.
1822 The call to resume_temporary_allocation near the end of this function
1823 goes back to the usual state of affairs. */
1825 rtl_in_current_obstack ();
1827 insns = get_insns ();
1829 /* Copy any shared structure that should not be shared. */
1831 unshare_all_rtl (insns);
1833 /* Instantiate all virtual registers. */
1835 instantiate_virtual_regs (current_function_decl, get_insns ());
1837 /* We are no longer anticipating cse in this function, at least. */
1839 cse_not_expected = 1;
1841 /* Now we choose between stupid (pcc-like) register allocation
1842 (if we got the -noreg switch and not -opt)
1843 and smart register allocation. */
1845 if (optimize > 0) /* Stupid allocation probably won't work */
1846 obey_regdecls = 0; /* if optimizations being done. */
1850 regclass (insns, max_reg_num ());
1853 stupid_life_analysis (insns, max_reg_num (), NULL);
1854 failure = reload (insns, 0, NULL);
1858 /* Do control and data flow analysis,
1859 and write some of the results to dump file. */
1861 flow_analysis (insns, max_reg_num (), NULL);
1863 failure = global_alloc (NULL);
1866 reload_completed = 1;
1868 #ifdef LEAF_REGISTERS
1870 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
1874 /* If a machine dependent reorganization is needed, call it. */
1875 #ifdef MACHINE_DEPENDENT_REORG
1876 MACHINE_DEPENDENT_REORG (insns);
1879 /* Now turn the rtl into assembler code. */
1881 assemble_start_function (thunk_fndecl, fnname);
1882 final (insns, asm_out_file, optimize, 0);
1883 assemble_end_function (thunk_fndecl, fnname);
1885 reload_completed = 0;
1887 /* Cancel the effect of rtl_in_current_obstack. */
1889 permanent_allocation (1);
1890 flag_omit_frame_pointer = save_ofp;
1891 #endif /* ASM_OUTPUT_MI_THUNK */
1892 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
1894 decl_printable_name = save_decl_printable_name;
1895 current_function_decl = 0;
1898 /* Code for synthesizing methods which have default semantics defined. */
1900 /* For the anonymous union in TYPE, return the member that is at least as
1901 large as the rest of the members, so we can copy it. */
1904 largest_union_member (type)
1907 tree f, type_size = TYPE_SIZE (type);
1909 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
1910 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
1913 /* We should always find one. */
1914 my_friendly_abort (323);
1918 /* Generate code for default X(X&) constructor. */
1921 do_build_copy_constructor (fndecl)
1924 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
1930 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
1931 parm = TREE_CHAIN (parm);
1932 parm = convert_from_reference (parm);
1934 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
1936 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
1937 TREE_SIDE_EFFECTS (t) = 1;
1938 cplus_expand_expr_stmt (t);
1942 tree fields = TYPE_FIELDS (current_class_type);
1943 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
1944 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
1947 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
1950 tree basetype = BINFO_TYPE (t);
1951 tree p = convert_to_reference
1952 (build_reference_type (basetype), parm,
1953 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
1954 p = convert_from_reference (p);
1956 if (p == error_mark_node)
1957 cp_error ("in default copy constructor");
1959 current_base_init_list = tree_cons (basetype,
1960 p, current_base_init_list);
1963 for (i = 0; i < n_bases; ++i)
1965 tree p, basetype = TREE_VEC_ELT (binfos, i);
1966 if (TREE_VIA_VIRTUAL (basetype))
1969 basetype = BINFO_TYPE (basetype);
1970 p = convert_to_reference
1971 (build_reference_type (basetype), parm,
1972 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
1974 if (p == error_mark_node)
1975 cp_error ("in default copy constructor");
1978 p = convert_from_reference (p);
1979 current_base_init_list = tree_cons (basetype,
1980 p, current_base_init_list);
1983 for (; fields; fields = TREE_CHAIN (fields))
1986 tree field = fields;
1988 if (TREE_CODE (field) != FIELD_DECL)
1990 if (DECL_NAME (field))
1992 if (VFIELD_NAME_P (DECL_NAME (field)))
1994 if (VBASE_NAME_P (DECL_NAME (field)))
1997 /* True for duplicate members. */
1998 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2001 else if ((t = TREE_TYPE (field)) != NULL_TREE
2002 && TREE_CODE (t) == UNION_TYPE
2003 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2004 && TYPE_FIELDS (t) != NULL_TREE)
2005 field = largest_union_member (t);
2009 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2010 init = build_tree_list (NULL_TREE, init);
2012 current_member_init_list
2013 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2015 current_member_init_list = nreverse (current_member_init_list);
2016 current_base_init_list = nreverse (current_base_init_list);
2024 do_build_assign_ref (fndecl)
2027 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2032 parm = convert_from_reference (parm);
2034 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2036 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
2037 TREE_SIDE_EFFECTS (t) = 1;
2038 cplus_expand_expr_stmt (t);
2042 tree fields = TYPE_FIELDS (current_class_type);
2043 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2044 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2047 for (i = 0; i < n_bases; ++i)
2049 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2050 tree p = convert_to_reference
2051 (build_reference_type (basetype), parm,
2052 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2053 p = convert_from_reference (p);
2054 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2055 build_tree_list (NULL_TREE, p));
2056 expand_expr_stmt (p);
2058 for (; fields; fields = TREE_CHAIN (fields))
2061 tree field = fields;
2063 if (TREE_CODE (field) != FIELD_DECL)
2066 if (TREE_READONLY (field))
2068 if (DECL_NAME (field))
2069 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
2071 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
2074 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2076 if (DECL_NAME (field))
2077 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
2079 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
2083 if (DECL_NAME (field))
2085 if (VFIELD_NAME_P (DECL_NAME (field)))
2087 if (VBASE_NAME_P (DECL_NAME (field)))
2090 /* True for duplicate members. */
2091 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2094 else if ((t = TREE_TYPE (field)) != NULL_TREE
2095 && TREE_CODE (t) == UNION_TYPE
2096 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2097 && TYPE_FIELDS (t) != NULL_TREE)
2098 field = largest_union_member (t);
2102 comp = build (COMPONENT_REF, TREE_TYPE (field), current_class_ref, field);
2103 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2105 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2108 c_expand_return (current_class_ref);
2113 synthesize_method (fndecl)
2116 int nested = (current_function_decl != NULL_TREE);
2117 tree context = hack_decl_function_context (fndecl);
2120 push_to_top_level ();
2122 push_cp_function_context (context);
2124 interface_unknown = 1;
2125 start_function (NULL_TREE, fndecl, NULL_TREE, 1);
2126 store_parm_decls ();
2128 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2129 do_build_assign_ref (fndecl);
2130 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2134 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2135 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2136 arg_chain = TREE_CHAIN (arg_chain);
2137 if (arg_chain != void_list_node)
2138 do_build_copy_constructor (fndecl);
2139 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2143 finish_function (lineno, 0, nested);
2145 /* Do we really *want* to inline this function? */
2146 if (DECL_INLINE (fndecl))
2148 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
2149 will check our size. */
2150 DECL_INLINE (fndecl) = 0;
2152 /* We say !at_eof because at the end of the file some of the rtl
2153 for fndecl may have been allocated on the temporary obstack.
2154 (The function_obstack is the temporary one if we're not in a
2156 if ((! at_eof) && function_cannot_inline_p (fndecl) == 0)
2157 DECL_INLINE (fndecl) = 1;
2160 extract_interface_info ();
2162 pop_from_top_level ();
2164 pop_cp_function_context (context);