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])
65 #ifdef NO_AUTO_OVERLOAD
72 gcc_obstack_init (&scratch_obstack);
73 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
76 /* This must be large enough to hold any printed integer or floating-point
78 static char digit_buffer[128];
80 /* Move inline function definitions out of structure so that they
81 can be processed normally. CNAME is the name of the class
82 we are working from, METHOD_LIST is the list of method lists
83 of the structure. We delete friend methods here, after
84 saving away their inline function definitions (if any). */
87 do_inline_function_hair (type, friend_list)
88 tree type, friend_list;
90 tree method = TYPE_METHODS (type);
92 if (method && TREE_CODE (method) == TREE_VEC)
94 if (TREE_VEC_ELT (method, 1))
95 method = TREE_VEC_ELT (method, 1);
96 else if (TREE_VEC_ELT (method, 0))
97 method = TREE_VEC_ELT (method, 0);
99 method = TREE_VEC_ELT (method, 2);
104 /* Do inline member functions. */
105 struct pending_inline *info = DECL_PENDING_INLINE_INFO (method);
110 my_friendly_assert (info->fndecl == method, 238);
111 args = DECL_ARGUMENTS (method);
114 DECL_CONTEXT (args) = method;
115 args = TREE_CHAIN (args);
118 /* Allow this decl to be seen in global scope. Don't do this for
119 local class methods, though. */
120 if (! current_function_decl)
121 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method)) = method;
123 method = TREE_CHAIN (method);
127 tree fndecl = TREE_VALUE (friend_list);
128 struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl);
133 my_friendly_assert (info->fndecl == fndecl, 239);
134 args = DECL_ARGUMENTS (fndecl);
137 DECL_CONTEXT (args) = fndecl;
138 args = TREE_CHAIN (args);
141 /* Allow this decl to be seen in global scope */
142 if (! current_function_decl)
143 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl)) = fndecl;
146 friend_list = TREE_CHAIN (friend_list);
150 /* Report an argument type mismatch between the best declared function
151 we could find and the current argument list that we have. */
153 report_type_mismatch (cp, parmtypes, name_kind)
154 struct candidate *cp;
158 int i = cp->u.bad_arg;
165 my_friendly_assert (TREE_CODE (cp->function) == TEMPLATE_DECL, 240);
166 cp_error ("type unification failed for function template `%#D'",
171 cp_error ("too few arguments for %s `%#D'", name_kind, cp->function);
174 cp_error ("too many arguments for %s `%#D'", name_kind, cp->function);
177 if (TREE_CODE (TREE_TYPE (cp->function)) != METHOD_TYPE)
180 /* Happens when the implicit object parameter is rejected. */
181 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes))),
183 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes))))
184 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp->function))))))
185 cp_error ("call to non-volatile %s `%#D' with volatile object",
186 name_kind, cp->function);
188 cp_error ("call to non-const %s `%#D' with const object",
189 name_kind, cp->function);
193 ttf = TYPE_ARG_TYPES (TREE_TYPE (cp->function));
198 ttf = TREE_CHAIN (ttf);
199 tta = TREE_CHAIN (tta);
203 OB_PUTS ("bad argument ");
204 sprintf (digit_buffer, "%d", cp->u.bad_arg
205 - (TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE)
207 OB_PUTCP (digit_buffer);
209 OB_PUTS (" for function `");
210 OB_PUTCP (decl_as_string (cp->function, 1));
211 OB_PUTS ("' (type was ");
213 /* Reset `i' so that type printing routines do the right thing. */
216 enum tree_code code = TREE_CODE (TREE_TYPE (TREE_VALUE (tta)));
217 if (code == ERROR_MARK)
218 OB_PUTS ("(failed type instantiation)");
221 i = (code == FUNCTION_TYPE || code == METHOD_TYPE);
222 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta)), 1));
225 else OB_PUTS ("void");
229 tmp_firstobj = (char *)alloca (obstack_object_size (&scratch_obstack));
230 bcopy (obstack_base (&scratch_obstack), tmp_firstobj,
231 obstack_object_size (&scratch_obstack));
232 error (tmp_firstobj);
235 /* Here is where overload code starts. */
237 /* Array of types seen so far in top-level call to `build_overload_name'.
238 Allocated and deallocated by caller. */
239 static tree *typevec;
241 /* Number of types interned by `build_overload_name' so far. */
244 /* Number of occurrences of last type seen. */
247 /* Nonzero if we should not try folding parameter types. */
250 #define ALLOCATE_TYPEVEC(PARMTYPES) \
251 do { maxtype = 0, nrepeats = 0; \
252 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
254 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
255 do { tree t = (PARMTYPES); \
256 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
259 /* Code to concatenate an asciified integer to a string. */
268 /* Handle this case first, to go really quickly. For many common values,
269 the result of i/10 below is 1. */
286 OB_PUTC ('0' + (i % 10));
300 while (typevec[tindex] != type)
318 static int numeric_output_need_bar;
319 static void build_overload_identifier ();
322 build_overload_nested_name (decl)
325 if (DECL_CONTEXT (decl))
327 tree context = DECL_CONTEXT (decl);
328 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
329 context = TYPE_MAIN_DECL (context);
330 build_overload_nested_name (context);
333 if (TREE_CODE (decl) == FUNCTION_DECL)
335 tree name = DECL_ASSEMBLER_NAME (decl);
337 extern int var_labelno;
339 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), var_labelno);
342 if (numeric_output_need_bar)
345 numeric_output_need_bar = 0;
347 icat (strlen (label));
351 build_overload_identifier (decl);
354 /* Encoding for an INTEGER_CST value. */
356 build_overload_int (value)
359 if (TREE_CODE (value) == TEMPLATE_CONST_PARM)
362 if (TEMPLATE_CONST_IDX (value) > 9)
364 icat (TEMPLATE_CONST_IDX (value));
365 if (TEMPLATE_CONST_IDX (value) > 9)
369 else if (current_template_parms
370 && TREE_CODE (value) != INTEGER_CST)
371 /* We don't ever want this output, but it's inconvenient not to
372 be able to build the string. This should cause assembler
373 errors we'll notice. */
376 sprintf (digit_buffer, " *%d", n++);
377 OB_PUTCP (digit_buffer);
381 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
382 if (TYPE_PRECISION (value) == 2 * HOST_BITS_PER_WIDE_INT)
384 if (tree_int_cst_lt (value, integer_zero_node))
387 value = build_int_2 (~ TREE_INT_CST_LOW (value),
388 - TREE_INT_CST_HIGH (value));
390 if (TREE_INT_CST_HIGH (value)
391 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
393 /* need to print a DImode value in decimal */
394 sorry ("conversion of long long as PT parameter");
396 /* else fall through to print in smaller mode */
398 /* Wordsize or smaller */
399 icat (TREE_INT_CST_LOW (value));
403 build_overload_value (type, value)
406 while (TREE_CODE (value) == NON_LVALUE_EXPR
407 || TREE_CODE (value) == NOP_EXPR)
408 value = TREE_OPERAND (value, 0);
409 my_friendly_assert (TREE_CODE (type) == PARM_DECL, 242);
410 type = TREE_TYPE (type);
412 if (numeric_output_need_bar)
415 numeric_output_need_bar = 0;
418 if (TREE_CODE (type) == POINTER_TYPE
419 && TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE)
421 /* Handle a pointer to data member as a template instantiation
422 parameter, boy, what fun! */
423 type = integer_type_node;
424 if (TREE_CODE (value) != INTEGER_CST)
426 sorry ("unknown pointer to member constant");
431 if (TYPE_PTRMEMFUNC_P (type))
432 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
434 switch (TREE_CODE (type))
440 build_overload_int (value);
441 numeric_output_need_bar = 1;
444 #ifndef REAL_IS_NOT_DOUBLE
448 char *bufp = digit_buffer;
449 extern char *index ();
451 my_friendly_assert (TREE_CODE (value) == REAL_CST, 244);
452 val = TREE_REAL_CST (value);
458 sprintf (bufp, "%e", val);
459 bufp = (char *) index (bufp, 'e');
461 strcat (digit_buffer, "e0");
487 OB_PUTCP (digit_buffer);
488 numeric_output_need_bar = 1;
493 if (TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
494 && TREE_CODE (value) != ADDR_EXPR)
496 if (TREE_CODE (value) == CONSTRUCTOR)
498 /* This is dangerous code, crack built up pointer to members. */
499 tree args = CONSTRUCTOR_ELTS (value);
500 tree a1 = TREE_VALUE (args);
501 tree a2 = TREE_VALUE (TREE_CHAIN (args));
502 tree a3 = CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args))));
503 a3 = TREE_VALUE (a3);
505 if (TREE_CODE (a1) == INTEGER_CST
506 && TREE_CODE (a2) == INTEGER_CST)
508 build_overload_int (a1);
510 build_overload_int (a2);
512 if (TREE_CODE (a3) == ADDR_EXPR)
514 a3 = TREE_OPERAND (a3, 0);
515 if (TREE_CODE (a3) == FUNCTION_DECL)
517 numeric_output_need_bar = 0;
518 build_overload_identifier (DECL_ASSEMBLER_NAME (a3));
522 else if (TREE_CODE (a3) == INTEGER_CST)
525 build_overload_int (a3);
526 numeric_output_need_bar = 1;
531 sorry ("template instantiation with pointer to method that is too complex");
534 if (TREE_CODE (value) == INTEGER_CST)
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))
670 flush_repeats (parmtype);
674 /* Only cache types which take more than one character. */
675 if (parmtype != TYPE_MAIN_VARIANT (parmtype)
676 || (TREE_CODE (parmtype) != INTEGER_TYPE
677 && TREE_CODE (parmtype) != REAL_TYPE))
678 TREE_USED (parmtype) = 1;
681 if (TYPE_PTRMEMFUNC_P (parmtype))
682 parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype);
684 if (TREE_READONLY (parmtype))
686 if (TREE_CODE (parmtype) == INTEGER_TYPE
687 && TYPE_MAIN_VARIANT (parmtype) == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
689 if (TYPE_VOLATILE (parmtype))
692 switch (TREE_CODE (parmtype))
696 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0);
698 build_overload_name (TREE_TYPE (parmtype), 0, 0);
706 #if PARM_CAN_BE_ARRAY_TYPE
711 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
712 error ("pointer or reference to array of unknown bound in parm type");
715 length = array_type_nelts (parmtype);
716 if (TREE_CODE (length) == INTEGER_CST)
717 icat (TREE_INT_CST_LOW (length) + 1);
730 build_overload_name (TREE_TYPE (parmtype), 0, 0);
736 tree firstarg = TYPE_ARG_TYPES (parmtype);
737 /* Otherwise have to implement reentrant typevecs,
738 unmark and remark types, etc. */
739 int old_nofold = nofold;
743 flush_repeats (typevec[maxtype-1]);
745 /* @@ It may be possible to pass a function type in
746 which is not preceded by a 'P'. */
747 if (TREE_CODE (parmtype) == FUNCTION_TYPE)
750 if (firstarg == NULL_TREE)
752 else if (firstarg == void_list_node)
755 build_overload_name (firstarg, 0, 0);
759 int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
760 int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
762 firstarg = TREE_CHAIN (firstarg);
764 build_overload_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0);
770 /* For cfront 2.0 compatibility. */
773 if (firstarg == NULL_TREE)
775 else if (firstarg == void_list_node)
778 build_overload_name (firstarg, 0, 0);
781 /* Separate args from return type. */
783 build_overload_name (TREE_TYPE (parmtype), 0, 0);
789 parmtype = TYPE_MAIN_VARIANT (parmtype);
790 if (parmtype == integer_type_node
791 || parmtype == unsigned_type_node)
793 else if (parmtype == long_integer_type_node
794 || parmtype == long_unsigned_type_node)
796 else if (parmtype == short_integer_type_node
797 || parmtype == short_unsigned_type_node)
799 else if (parmtype == signed_char_type_node)
804 else if (parmtype == char_type_node
805 || parmtype == unsigned_char_type_node)
807 else if (parmtype == wchar_type_node)
809 else if (parmtype == long_long_integer_type_node
810 || parmtype == long_long_unsigned_type_node)
813 /* it would seem there is no way to enter these in source code,
815 else if (parmtype == long_long_long_integer_type_node
816 || parmtype == long_long_long_unsigned_type_node)
820 my_friendly_abort (73);
828 parmtype = TYPE_MAIN_VARIANT (parmtype);
829 if (parmtype == long_double_type_node)
831 else if (parmtype == double_type_node)
833 else if (parmtype == float_type_node)
835 else my_friendly_abort (74);
842 extern tree void_list_node;
844 /* See if anybody is wasting memory. */
845 my_friendly_assert (parmtypes == void_list_node, 247);
847 /* This is the end of a parameter list. */
848 if (end) OB_FINISH ();
849 return (char *)obstack_base (&scratch_obstack);
854 case ERROR_MARK: /* not right, but nothing is anyway */
857 /* have to do these */
861 /* Make this type signature look incompatible
868 tree name = TYPE_NAME (parmtype);
871 if (TREE_CODE (name) == TYPE_DECL)
875 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
876 if (DECL_ASSEMBLER_NAME (context) != DECL_NAME (context))
878 OB_PUTID (DECL_ASSEMBLER_NAME (context));
881 while (DECL_CONTEXT (context))
884 context = DECL_CONTEXT (context);
885 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
886 context = TYPE_NAME (context);
888 name = DECL_NAME (name);
890 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 248);
899 numeric_output_need_bar = 0;
900 build_overload_nested_name (TYPE_MAIN_DECL (parmtype));
903 build_overload_identifier (TYPE_MAIN_DECL (parmtype));
908 /* This will take some work. */
912 case TEMPLATE_TYPE_PARM:
914 if (TEMPLATE_TYPE_IDX (parmtype) > 9)
916 icat (TEMPLATE_TYPE_IDX (parmtype));
917 if (TEMPLATE_TYPE_IDX (parmtype) > 9)
922 /* We don't ever want this output, but it's inconvenient not to
923 be able to build the string. This should cause assembler
924 errors we'll notice. */
927 sprintf (digit_buffer, " *%d", n++);
928 OB_PUTCP (digit_buffer);
933 my_friendly_abort (75);
938 parmtypes = TREE_CHAIN (parmtypes);
943 flush_repeats (typevec[maxtype-1]);
945 /* To get here, parms must end with `...'. */
949 if (end) OB_FINISH ();
950 return (char *)obstack_base (&scratch_obstack);
954 build_static_name (basetype, name)
957 char *basename = build_overload_name (basetype, 1, 1);
958 char *buf = (char *) alloca (IDENTIFIER_LENGTH (name)
959 + sizeof (STATIC_NAME_FORMAT)
960 + strlen (basename));
961 sprintf (buf, STATIC_NAME_FORMAT, basename, IDENTIFIER_POINTER (name));
962 return get_identifier (buf);
965 /* Change the name of a function definition so that it may be
966 overloaded. NAME is the name of the function to overload,
967 PARMS is the parameter list (which determines what name the
968 final function obtains).
970 FOR_METHOD is 1 if this overload is being performed
971 for a method, rather than a function type. It is 2 if
972 this overload is being performed for a constructor. */
974 build_decl_overload (dname, parms, for_method)
979 char *name = IDENTIFIER_POINTER (dname);
981 /* member operators new and delete look like methods at this point. */
982 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST)
984 if (dname == ansi_opname[(int) DELETE_EXPR])
985 return get_identifier ("__builtin_delete");
986 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
987 return get_identifier ("__builtin_vec_delete");
988 else if (TREE_CHAIN (parms) == void_list_node)
990 if (dname == ansi_opname[(int) NEW_EXPR])
991 return get_identifier ("__builtin_new");
992 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
993 return get_identifier ("__builtin_vec_new");
1000 /* Otherwise, we can divine that this is a constructor,
1001 and figure out its name without any extra encoding. */
1003 OB_PUTC2 ('_', '_');
1007 /* We can get away without doing this. */
1011 tree this_type = TREE_VALUE (parms);
1013 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
1014 parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type),
1015 TREE_CHAIN (parms));
1017 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type),
1018 TREE_CHAIN (parms));
1024 if (parms == NULL_TREE)
1025 OB_PUTC2 ('e', '\0');
1026 else if (parms == void_list_node)
1027 OB_PUTC2 ('v', '\0');
1030 ALLOCATE_TYPEVEC (parms);
1034 build_overload_name (TREE_VALUE (parms), 0, 0);
1036 typevec[maxtype++] = TREE_VALUE (parms);
1037 TREE_USED (TREE_VALUE (parms)) = 1;
1039 if (TREE_CHAIN (parms))
1040 build_overload_name (TREE_CHAIN (parms), 0, 1);
1042 OB_PUTC2 ('e', '\0');
1045 build_overload_name (parms, 0, 1);
1046 DEALLOCATE_TYPEVEC (parms);
1049 tree n = get_identifier (obstack_base (&scratch_obstack));
1050 if (IDENTIFIER_OPNAME_P (dname))
1051 IDENTIFIER_OPNAME_P (n) = 1;
1056 /* Build an overload name for the type expression TYPE. */
1058 build_typename_overload (type)
1064 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1066 build_overload_name (type, 0, 1);
1067 id = get_identifier (obstack_base (&scratch_obstack));
1068 IDENTIFIER_OPNAME_P (id) = 1;
1070 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_NAME (type);
1072 TREE_TYPE (id) = type;
1077 build_overload_with_type (name, type)
1084 build_overload_name (type, 0, 1);
1085 return get_identifier (obstack_base (&scratch_obstack));
1088 /* Top-level interface to explicit overload requests. Allow NAME
1089 to be overloaded. Error if NAME is already declared for the current
1090 scope. Warning if function is redundantly overloaded. */
1093 declare_overloaded (name)
1096 #ifdef NO_AUTO_OVERLOAD
1097 if (is_overloaded (name))
1098 warning ("function `%s' already declared overloaded",
1099 IDENTIFIER_POINTER (name));
1100 else if (IDENTIFIER_GLOBAL_VALUE (name))
1101 error ("overloading function `%s' that is already defined",
1102 IDENTIFIER_POINTER (name));
1105 TREE_OVERLOADED (name) = 1;
1106 IDENTIFIER_GLOBAL_VALUE (name) = build_tree_list (name, NULL_TREE);
1107 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)) = unknown_type_node;
1110 if (current_lang_name == lang_name_cplusplus)
1113 warning ("functions are implicitly overloaded in C++");
1115 else if (current_lang_name == lang_name_c)
1116 error ("overloading function `%s' cannot be done in C language context");
1118 my_friendly_abort (76);
1122 #ifdef NO_AUTO_OVERLOAD
1123 /* Check to see if NAME is overloaded. For first approximation,
1124 check to see if its TREE_OVERLOADED is set. This is used on
1125 IDENTIFIER nodes. */
1127 is_overloaded (name)
1131 return (TREE_OVERLOADED (name)
1132 && (! IDENTIFIER_CLASS_VALUE (name) || current_class_type == 0)
1133 && ! IDENTIFIER_LOCAL_VALUE (name));
1137 /* Given a tree_code CODE, and some arguments (at least one),
1138 attempt to use an overloaded operator on the arguments.
1140 For unary operators, only the first argument need be checked.
1141 For binary operators, both arguments may need to be checked.
1143 Member functions can convert class references to class pointers,
1144 for one-level deep indirection. More than that is not supported.
1145 Operators [](), ()(), and ->() must be member functions.
1147 We call function call building calls with LOOKUP_COMPLAIN if they
1148 are our only hope. This is true when we see a vanilla operator
1149 applied to something of aggregate type. If this fails, we are free
1150 to return `error_mark_node', because we will have reported the
1153 Operators NEW and DELETE overload in funny ways: operator new takes
1154 a single `size' parameter, and operator delete takes a pointer to the
1155 storage being deleted. When overloading these operators, success is
1156 assumed. If there is a failure, report an error message and return
1157 `error_mark_node'. */
1161 build_opfncall (code, flags, xarg1, xarg2, arg3)
1162 enum tree_code code;
1164 tree xarg1, xarg2, arg3;
1168 tree type1, type2, fnname;
1169 tree fields1 = 0, parms = 0;
1172 int binary_is_unary;
1174 if (xarg1 == error_mark_node)
1175 return error_mark_node;
1177 if (code == COND_EXPR)
1179 if (TREE_CODE (xarg2) == ERROR_MARK
1180 || TREE_CODE (arg3) == ERROR_MARK)
1181 return error_mark_node;
1183 if (code == COMPONENT_REF)
1184 if (TREE_CODE (TREE_TYPE (xarg1)) == POINTER_TYPE)
1187 /* First, see if we can work with the first argument */
1188 type1 = TREE_TYPE (xarg1);
1190 /* Some tree codes have length > 1, but we really only want to
1191 overload them if their first argument has a user defined type. */
1194 case PREINCREMENT_EXPR:
1195 case PREDECREMENT_EXPR:
1196 case POSTINCREMENT_EXPR:
1197 case POSTDECREMENT_EXPR:
1199 binary_is_unary = 1;
1203 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1204 If they do not, return error_mark_node instead of NULL_TREE. */
1206 if (xarg2 == error_mark_node)
1207 return error_mark_node;
1209 rval = error_mark_node;
1210 binary_is_unary = 0;
1217 tree args = tree_cons (NULL_TREE, xarg2, arg3);
1218 fnname = ansi_opname[(int) code];
1219 if (flags & LOOKUP_GLOBAL)
1220 return build_overload_call (fnname, args, flags & LOOKUP_COMPLAIN,
1221 (struct candidate *)0);
1223 rval = build_method_call
1224 (build_indirect_ref (build1 (NOP_EXPR, xarg1, error_mark_node),
1226 fnname, args, NULL_TREE, flags);
1227 if (rval == error_mark_node)
1228 /* User might declare fancy operator new, but invoke it
1229 like standard one. */
1232 TREE_TYPE (rval) = xarg1;
1233 TREE_CALLS_NEW (rval) = 1;
1238 case VEC_DELETE_EXPR:
1241 fnname = ansi_opname[(int) code];
1242 if (flags & LOOKUP_GLOBAL)
1243 return build_overload_call (fnname,
1244 build_tree_list (NULL_TREE, xarg1),
1245 flags & LOOKUP_COMPLAIN,
1246 (struct candidate *)0);
1247 arg1 = TREE_TYPE (xarg1);
1249 /* This handles the case where we're trying to delete
1254 if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
1256 /* Strip off the pointer and the array. */
1257 arg1 = TREE_TYPE (TREE_TYPE (arg1));
1259 while (TREE_CODE (arg1) == ARRAY_TYPE)
1260 arg1 = (TREE_TYPE (arg1));
1262 arg1 = build_pointer_type (arg1);
1265 rval = build_method_call
1266 (build_indirect_ref (build1 (NOP_EXPR, arg1,
1269 fnname, tree_cons (NULL_TREE, xarg1,
1270 build_tree_list (NULL_TREE, xarg2)),
1273 /* This can happen when operator delete is protected. */
1274 my_friendly_assert (rval != error_mark_node, 250);
1275 TREE_TYPE (rval) = void_type_node;
1282 binary_is_unary = 0;
1283 try_second = tree_code_length [(int) code] == 2;
1284 if (try_second && xarg2 == error_mark_node)
1285 return error_mark_node;
1289 if (try_second && xarg2 == error_mark_node)
1290 return error_mark_node;
1292 /* What ever it was, we do not know how to deal with it. */
1293 if (type1 == NULL_TREE)
1296 if (TREE_CODE (type1) == OFFSET_TYPE)
1297 type1 = TREE_TYPE (type1);
1299 if (TREE_CODE (type1) == REFERENCE_TYPE)
1301 arg1 = convert_from_reference (xarg1);
1302 type1 = TREE_TYPE (arg1);
1309 if (!IS_AGGR_TYPE (type1) || TYPE_PTRMEMFUNC_P (type1))
1311 /* Try to fail. First, fail if unary */
1314 /* Second, see if second argument is non-aggregate. */
1315 type2 = TREE_TYPE (xarg2);
1316 if (TREE_CODE (type2) == OFFSET_TYPE)
1317 type2 = TREE_TYPE (type2);
1318 if (TREE_CODE (type2) == REFERENCE_TYPE)
1320 arg2 = convert_from_reference (xarg2);
1321 type2 = TREE_TYPE (arg2);
1328 if (!IS_AGGR_TYPE (type2))
1335 /* First arg may succeed; see whether second should. */
1336 type2 = TREE_TYPE (xarg2);
1337 if (TREE_CODE (type2) == OFFSET_TYPE)
1338 type2 = TREE_TYPE (type2);
1339 if (TREE_CODE (type2) == REFERENCE_TYPE)
1341 arg2 = convert_from_reference (xarg2);
1342 type2 = TREE_TYPE (arg2);
1349 if (! IS_AGGR_TYPE (type2))
1353 if (type1 == unknown_type_node
1354 || (try_second && TREE_TYPE (xarg2) == unknown_type_node))
1356 /* This will not be implemented in the foreseeable future. */
1360 if (code == MODIFY_EXPR)
1361 fnname = ansi_assopname[(int) TREE_CODE (arg3)];
1363 fnname = ansi_opname[(int) code];
1365 global_fn = lookup_name_nonclass (fnname);
1367 /* This is the last point where we will accept failure. This
1368 may be too eager if we wish an overloaded operator not to match,
1369 but would rather a normal operator be called on a type-converted
1372 if (IS_AGGR_TYPE (type1))
1374 fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
1375 /* ARM $13.4.7, prefix/postfix ++/--. */
1376 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
1378 xarg2 = integer_zero_node;
1379 binary_is_unary = 0;
1384 int have_postfix = 0;
1386 /* Look for an `operator++ (int)'. If they didn't have
1387 one, then we fall back to the old way of doing things. */
1388 for (t = TREE_VALUE (fields1); t ; t = DECL_CHAIN (t))
1390 t2 = TYPE_ARG_TYPES (TREE_TYPE (t));
1391 if (TREE_CHAIN (t2) != NULL_TREE
1392 && TREE_VALUE (TREE_CHAIN (t2)) == integer_type_node)
1401 char *op = POSTINCREMENT_EXPR ? "++" : "--";
1403 /* There's probably a LOT of code in the world that
1404 relies upon this old behavior. */
1405 if (! flag_traditional)
1406 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1409 binary_is_unary = 1;
1415 if (fields1 == NULL_TREE && global_fn == NULL_TREE)
1418 /* If RVAL winds up being `error_mark_node', we will return
1419 that... There is no way that normal semantics of these
1420 operators will succeed. */
1422 /* This argument may be an uncommitted OFFSET_REF. This is
1423 the case for example when dealing with static class members
1424 which are referenced from their class name rather than
1425 from a class instance. */
1426 if (TREE_CODE (xarg1) == OFFSET_REF
1427 && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL)
1428 xarg1 = TREE_OPERAND (xarg1, 1);
1429 if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF
1430 && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL)
1431 xarg2 = TREE_OPERAND (xarg2, 1);
1434 flags |= LOOKUP_GLOBAL;
1436 if (code == CALL_EXPR)
1438 /* This can only be a member function. */
1439 return build_method_call (xarg1, fnname, xarg2,
1440 NULL_TREE, LOOKUP_NORMAL);
1442 else if (tree_code_length[(int) code] == 1 || binary_is_unary)
1445 rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags);
1447 else if (code == COND_EXPR)
1449 parms = tree_cons (0, xarg2, build_tree_list (NULL_TREE, arg3));
1450 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1452 else if (code == METHOD_CALL_EXPR)
1454 /* must be a member function. */
1455 parms = tree_cons (NULL_TREE, xarg2, arg3);
1456 return build_method_call (xarg1, fnname, parms, NULL_TREE,
1461 parms = build_tree_list (NULL_TREE, xarg2);
1462 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1466 parms = tree_cons (NULL_TREE, xarg1,
1467 build_tree_list (NULL_TREE, xarg2));
1468 rval = build_overload_call (fnname, parms, flags,
1469 (struct candidate *)0);
1475 /* This function takes an identifier, ID, and attempts to figure out what
1476 it means. There are a number of possible scenarios, presented in increasing
1479 1) not in a class's scope
1480 2) in class's scope, member name of the class's method
1481 3) in class's scope, but not a member name of the class
1482 4) in class's scope, member name of a class's variable
1484 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1485 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1487 As a last ditch, try to look up the name as a label and return that
1490 Values which are declared as being of REFERENCE_TYPE are
1491 automatically dereferenced here (as a hack to make the
1492 compiler faster). */
1495 hack_identifier (value, name)
1500 if (TREE_CODE (value) == ERROR_MARK)
1502 if (current_class_name)
1504 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1505 if (fields == error_mark_node)
1506 return error_mark_node;
1511 fndecl = TREE_VALUE (fields);
1512 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1513 if (DECL_CHAIN (fndecl) == NULL_TREE)
1515 warning ("methods cannot be converted to function pointers");
1520 error ("ambiguous request for method pointer `%s'",
1521 IDENTIFIER_POINTER (name));
1522 return error_mark_node;
1526 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1528 return IDENTIFIER_LABEL_VALUE (name);
1530 return error_mark_node;
1533 type = TREE_TYPE (value);
1534 if (TREE_CODE (value) == FIELD_DECL)
1536 if (current_class_decl == NULL_TREE)
1538 error ("request for member `%s' in static member function",
1539 IDENTIFIER_POINTER (DECL_NAME (value)));
1540 return error_mark_node;
1542 TREE_USED (current_class_decl) = 1;
1544 /* Mark so that if we are in a constructor, and then find that
1545 this field was initialized by a base initializer,
1546 we can emit an error message. */
1547 TREE_USED (value) = 1;
1548 value = build_component_ref (C_C_D, name, 0, 1);
1550 else if (really_overloaded_fn (value))
1553 tree t = get_first_fn (value);
1554 for (; t; t = DECL_CHAIN (t))
1556 if (TREE_CODE (t) == TEMPLATE_DECL)
1559 assemble_external (t);
1564 else if (TREE_CODE (value) == TREE_LIST)
1566 /* Ambiguous reference to base members, possibly other cases?. */
1568 while (t && TREE_CODE (t) == TREE_LIST)
1570 mark_used (TREE_VALUE (t));
1577 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL)
1579 tree context = decl_function_context (value);
1580 if (context != NULL_TREE && context != current_function_decl
1581 && ! TREE_STATIC (value))
1583 cp_error ("use of %s from containing function",
1584 (TREE_CODE (value) == VAR_DECL
1585 ? "`auto' variable" : "parameter"));
1586 cp_error_at (" `%#D' declared here", value);
1587 value = error_mark_node;
1591 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1593 if (DECL_LANG_SPECIFIC (value)
1594 && DECL_CLASS_CONTEXT (value) != current_class_type)
1597 register tree context
1598 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1599 ? DECL_CLASS_CONTEXT (value)
1600 : DECL_CONTEXT (value);
1602 get_base_distance (context, current_class_type, 0, &path);
1605 access = compute_access (path, value);
1606 if (access != access_public_node)
1608 if (TREE_CODE (value) == VAR_DECL)
1609 error ("static member `%s' is %s",
1610 IDENTIFIER_POINTER (name),
1611 TREE_PRIVATE (value) ? "private" :
1612 "from a private base class");
1614 error ("enum `%s' is from private base class",
1615 IDENTIFIER_POINTER (name));
1616 return error_mark_node;
1622 if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1626 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1627 IDENTIFIER_POINTER (name));
1628 return error_mark_node;
1634 if (TREE_CODE (type) == REFERENCE_TYPE && ! current_template_parms)
1635 value = convert_from_reference (value);
1641 /* Given an object OF, and a type conversion operator COMPONENT
1642 build a call to the conversion operator, if a call is requested,
1643 or return the address (as a pointer to member function) if one is not.
1645 OF can be a TYPE_DECL or any kind of datum that would normally
1646 be passed to `build_component_ref'. It may also be NULL_TREE,
1647 in which case `current_class_type' and `current_class_decl'
1648 provide default values.
1650 BASETYPE_PATH, if non-null, is the path of basetypes
1651 to go through before we get the the instance of interest.
1653 PROTECT says whether we apply C++ scoping rules or not. */
1655 build_component_type_expr (of, component, basetype_path, protect)
1656 tree of, component, basetype_path;
1659 tree cname = NULL_TREE;
1662 int flags = protect ? LOOKUP_NORMAL : LOOKUP_COMPLAIN;
1665 my_friendly_assert (IS_AGGR_TYPE (TREE_TYPE (of)), 253);
1666 my_friendly_assert (TREE_CODE (component) == TYPE_EXPR, 254);
1668 tmp = TREE_OPERAND (component, 0);
1673 switch (TREE_CODE (tmp))
1677 TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
1679 TREE_OPERAND (component, 0) = TREE_OPERAND (tmp, 0);
1681 last = groktypename (build_tree_list (TREE_TYPE (component),
1682 TREE_OPERAND (component, 0)));
1683 name = build_typename_overload (last);
1684 TREE_TYPE (name) = last;
1686 if (TREE_OPERAND (tmp, 0)
1687 && TREE_OPERAND (tmp, 0) != void_list_node)
1689 cp_error ("`operator %T' requires empty parameter list", last);
1690 TREE_OPERAND (tmp, 0) = NULL_TREE;
1693 if (of && TREE_CODE (of) != TYPE_DECL)
1694 return build_method_call (of, name, NULL_TREE, NULL_TREE, flags);
1699 if (current_class_decl == NULL_TREE)
1701 cp_error ("object required for `operator %T' call",
1703 return error_mark_node;
1706 this_this = convert_pointer_to (TREE_TYPE (of),
1707 current_class_decl);
1708 this_this = build_indirect_ref (this_this, NULL_PTR);
1709 return build_method_call (this_this, name, NULL_TREE,
1710 NULL_TREE, flags | LOOKUP_NONVIRTUAL);
1712 else if (current_class_decl)
1713 return build_method_call (tmp, name, NULL_TREE, NULL_TREE, flags);
1715 cp_error ("object required for `operator %T' call",
1717 return error_mark_node;
1725 my_friendly_assert (cname == 0, 255);
1726 cname = TREE_OPERAND (tmp, 0);
1727 tmp = TREE_OPERAND (tmp, 1);
1731 my_friendly_abort (77);
1734 tmp = TREE_OPERAND (tmp, 0);
1737 last = groktypename (build_tree_list (TREE_TYPE (component), TREE_OPERAND (component, 0)));
1738 name = build_typename_overload (last);
1739 TREE_TYPE (name) = last;
1740 if (of && TREE_CODE (of) == TYPE_DECL)
1742 if (cname == NULL_TREE)
1744 cname = DECL_NAME (of);
1747 else my_friendly_assert (cname == DECL_NAME (of), 256);
1754 if (current_class_decl == NULL_TREE)
1756 cp_error ("object required for `operator %T' call",
1758 return error_mark_node;
1761 this_this = convert_pointer_to (TREE_TYPE (of), current_class_decl);
1762 return build_component_ref (this_this, name, 0, protect);
1765 return build_offset_ref (cname, name);
1766 else if (current_class_name)
1767 return build_offset_ref (current_class_name, name);
1769 cp_error ("object required for `operator %T' member reference",
1771 return error_mark_node;
1776 thunk_printable_name (decl)
1779 return "<thunk function>";
1783 make_thunk (function, delta)
1788 tree thunk_fndecl, thunk_id;
1791 static int thunk_number = 0;
1793 if (TREE_CODE (function) != ADDR_EXPR)
1795 func_decl = TREE_OPERAND (function, 0);
1796 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1798 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1800 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1802 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1803 thunk_id = get_identifier (buffer);
1804 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1805 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1807 cp_error ("implementation-reserved name `%D' used", thunk_id);
1808 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1810 if (thunk == NULL_TREE)
1812 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
1814 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type)));
1815 TREE_READONLY (thunk) = TYPE_READONLY (TREE_TYPE (vtable_entry_type));
1816 TREE_THIS_VOLATILE (thunk) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type));
1817 make_function_rtl (thunk);
1818 TREE_SET_CODE (thunk, THUNK_DECL);
1819 DECL_INITIAL (thunk) = function;
1820 THUNK_DELTA (thunk) = delta;
1821 DECL_EXTERNAL (thunk) = 1;
1822 TREE_PUBLIC (thunk) = 1;
1823 /* So that finish_file can write out any thunks that need to be: */
1824 pushdecl_top_level (thunk);
1830 emit_thunk (thunk_fndecl)
1837 struct args_size stack_args_size;
1838 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1839 int delta = THUNK_DELTA (thunk_fndecl);
1843 /* Used to remember which regs we need to emit a USE rtx for. */
1844 rtx need_use[FIRST_PSEUDO_REGISTER];
1845 int need_use_count = 0;
1847 /* rtx for the 'this' parameter. */
1848 rtx this_rtx = 0, this_reg_rtx = 0, fixed_this_rtx;
1850 char *(*save_decl_printable_name) () = decl_printable_name;
1851 /* Data on reg parms scanned so far. */
1852 CUMULATIVE_ARGS args_so_far;
1854 if (TREE_ASM_WRITTEN (thunk_fndecl))
1857 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1859 if (! TREE_PUBLIC (function))
1860 TREE_PUBLIC (thunk_fndecl) = 0;
1861 if (DECL_EXTERNAL (function))
1863 DECL_EXTERNAL (thunk_fndecl) = 0;
1865 decl_printable_name = thunk_printable_name;
1866 if (current_function_decl)
1868 current_function_decl = thunk_fndecl;
1869 init_function_start (thunk_fndecl, input_filename, lineno);
1871 expand_start_bindings (1);
1873 /* Start updating where the next arg would go. */
1874 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (function), NULL_RTX, 0);
1875 stack_args_size.constant = 0;
1876 stack_args_size.var = 0;
1877 /* SETUP for possible structure return address FIXME */
1879 /* Now look through all the parameters, make sure that we
1880 don't clobber any registers used for parameters.
1881 Also, pick up an rtx for the first "this" parameter. */
1882 for (argp = TYPE_ARG_TYPES (TREE_TYPE (function));
1884 argp = TREE_CHAIN (argp))
1887 tree passed_type = TREE_VALUE (argp);
1888 register rtx entry_parm;
1889 int named = 1; /* FIXME */
1890 struct args_size stack_offset;
1891 struct args_size arg_size;
1893 if (passed_type == void_type_node)
1896 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
1897 && contains_placeholder_p (TYPE_SIZE (passed_type)))
1898 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1899 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far,
1900 TYPE_MODE (passed_type),
1904 passed_type = build_pointer_type (passed_type);
1906 entry_parm = FUNCTION_ARG (args_so_far,
1907 TYPE_MODE (passed_type),
1910 if (entry_parm != 0)
1911 need_use[need_use_count++] = entry_parm;
1913 locate_and_pad_parm (TYPE_MODE (passed_type), passed_type,
1914 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1920 &stack_args_size, &stack_offset, &arg_size);
1922 /* REGNO (entry_parm);*/
1925 this_reg_rtx = entry_parm;
1928 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
1930 rtx internal_arg_pointer, stack_parm;
1932 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
1933 || ! (fixed_regs[ARG_POINTER_REGNUM]
1934 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
1935 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
1937 internal_arg_pointer = virtual_incoming_args_rtx;
1939 if (offset_rtx == const0_rtx)
1940 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1941 internal_arg_pointer);
1943 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1944 gen_rtx (PLUS, Pmode,
1945 internal_arg_pointer,
1949 this_rtx = entry_parm;
1952 FUNCTION_ARG_ADVANCE (args_so_far,
1953 TYPE_MODE (passed_type),
1958 fixed_this_rtx = plus_constant (this_rtx, delta);
1959 if (this_rtx != fixed_this_rtx)
1960 emit_move_insn (this_rtx, fixed_this_rtx);
1963 emit_insn (gen_rtx (USE, VOIDmode, this_reg_rtx));
1965 emit_indirect_jump (XEXP (DECL_RTL (function), 0));
1967 while (need_use_count > 0)
1968 emit_insn (gen_rtx (USE, VOIDmode, need_use[--need_use_count]));
1970 expand_end_bindings (NULL, 1, 0);
1973 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
1974 Note that that may have been done above, in save_for_inline_copying.
1975 The call to resume_temporary_allocation near the end of this function
1976 goes back to the usual state of affairs. */
1978 rtl_in_current_obstack ();
1980 insns = get_insns ();
1982 /* Copy any shared structure that should not be shared. */
1984 unshare_all_rtl (insns);
1986 /* Instantiate all virtual registers. */
1988 instantiate_virtual_regs (current_function_decl, get_insns ());
1990 /* We are no longer anticipating cse in this function, at least. */
1992 cse_not_expected = 1;
1994 /* Now we choose between stupid (pcc-like) register allocation
1995 (if we got the -noreg switch and not -opt)
1996 and smart register allocation. */
1998 if (optimize > 0) /* Stupid allocation probably won't work */
1999 obey_regdecls = 0; /* if optimizations being done. */
2003 regclass (insns, max_reg_num ());
2006 stupid_life_analysis (insns, max_reg_num (), NULL);
2007 failure = reload (insns, 0, NULL);
2011 /* Do control and data flow analysis,
2012 and write some of the results to dump file. */
2014 flow_analysis (insns, max_reg_num (), NULL);
2016 failure = global_alloc (NULL);
2019 reload_completed = 1;
2021 #ifdef LEAF_REGISTERS
2023 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
2027 /* If a machine dependent reorganization is needed, call it. */
2028 #ifdef MACHINE_DEPENDENT_REORG
2029 MACHINE_DEPENDENT_REORG (insns);
2032 /* Now turn the rtl into assembler code. */
2035 char *fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2036 assemble_start_function (thunk_fndecl, fnname);
2037 final (insns, asm_out_file, optimize, 0);
2038 assemble_end_function (thunk_fndecl, fnname);
2041 exit_rest_of_compilation:
2043 reload_completed = 0;
2045 /* Cancel the effect of rtl_in_current_obstack. */
2047 resume_temporary_allocation ();
2049 decl_printable_name = save_decl_printable_name;
2050 current_function_decl = 0;
2053 /* Code for synthesizing methods which have default semantics defined. */
2055 /* For the anonymous union in TYPE, return the member that is at least as
2056 large as the rest of the members, so we can copy it. */
2058 largest_union_member (type)
2061 tree f, type_size = TYPE_SIZE (type);
2063 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
2064 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
2067 /* We should always find one. */
2068 my_friendly_abort (323);
2072 /* Generate code for default X(X&) constructor. */
2074 do_build_copy_constructor (fndecl)
2077 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2083 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2084 parm = TREE_CHAIN (parm);
2085 parm = convert_from_reference (parm);
2087 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2089 t = build (INIT_EXPR, void_type_node, C_C_D, parm);
2090 TREE_SIDE_EFFECTS (t) = 1;
2091 cplus_expand_expr_stmt (t);
2095 tree fields = TYPE_FIELDS (current_class_type);
2096 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2097 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2100 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2103 tree basetype = BINFO_TYPE (t);
2104 tree p = convert_to_reference
2105 (build_reference_type (basetype), parm,
2106 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2107 p = convert_from_reference (p);
2108 current_base_init_list = tree_cons (basetype,
2109 p, current_base_init_list);
2112 for (i = 0; i < n_bases; ++i)
2114 tree p, basetype = TREE_VEC_ELT (binfos, i);
2115 if (TREE_VIA_VIRTUAL (basetype))
2118 basetype = BINFO_TYPE (basetype);
2119 p = convert_to_reference
2120 (build_reference_type (basetype), parm,
2121 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2122 p = convert_from_reference (p);
2123 current_base_init_list = tree_cons (basetype,
2124 p, current_base_init_list);
2126 for (; fields; fields = TREE_CHAIN (fields))
2129 tree field = fields;
2131 if (TREE_CODE (field) != FIELD_DECL)
2133 if (DECL_NAME (field))
2135 if (VFIELD_NAME_P (DECL_NAME (field)))
2137 if (VBASE_NAME_P (DECL_NAME (field)))
2140 /* True for duplicate members. */
2141 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2144 else if ((t = TREE_TYPE (field)) != NULL_TREE
2145 && TREE_CODE (t) == UNION_TYPE
2146 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2147 && TYPE_FIELDS (t) != NULL_TREE)
2148 field = largest_union_member (t);
2152 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2153 init = build_tree_list (NULL_TREE, init);
2155 current_member_init_list
2156 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2158 current_member_init_list = nreverse (current_member_init_list);
2159 current_base_init_list = nreverse (current_base_init_list);
2167 do_build_assign_ref (fndecl)
2170 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2175 parm = convert_from_reference (parm);
2177 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2179 tree t = build (MODIFY_EXPR, void_type_node, C_C_D, parm);
2180 TREE_SIDE_EFFECTS (t) = 1;
2181 cplus_expand_expr_stmt (t);
2185 tree fields = TYPE_FIELDS (current_class_type);
2186 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2187 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2190 for (i = 0; i < n_bases; ++i)
2192 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2193 if (TYPE_HAS_ASSIGN_REF (basetype))
2195 tree p = convert_to_reference
2196 (build_reference_type (basetype), parm,
2197 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2198 p = convert_from_reference (p);
2199 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2200 build_tree_list (NULL_TREE, p));
2201 expand_expr_stmt (p);
2204 for (; fields; fields = TREE_CHAIN (fields))
2207 tree field = fields;
2209 if (TREE_CODE (field) != FIELD_DECL)
2211 if (DECL_NAME (field))
2213 if (VFIELD_NAME_P (DECL_NAME (field)))
2215 if (VBASE_NAME_P (DECL_NAME (field)))
2218 /* True for duplicate members. */
2219 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2222 else if ((t = TREE_TYPE (field)) != NULL_TREE
2223 && TREE_CODE (t) == UNION_TYPE
2224 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2225 && TYPE_FIELDS (t) != NULL_TREE)
2226 field = largest_union_member (t);
2230 comp = build (COMPONENT_REF, TREE_TYPE (field), C_C_D, field);
2231 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2233 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2236 c_expand_return (C_C_D);
2241 synthesize_method (fndecl)
2244 int nested = (current_function_decl != NULL_TREE);
2245 tree context = hack_decl_function_context (fndecl);
2246 tree base = DECL_CLASS_CONTEXT (fndecl);
2249 push_cp_function_context (context);
2251 interface_unknown = 1;
2252 start_function (NULL_TREE, fndecl, NULL_TREE, NULL_TREE, 1);
2253 store_parm_decls ();
2255 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2256 do_build_assign_ref (fndecl);
2257 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2261 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2262 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2263 arg_chain = TREE_CHAIN (arg_chain);
2264 if (arg_chain != void_list_node)
2265 do_build_copy_constructor (fndecl);
2266 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2270 finish_function (lineno, 0, nested);
2272 /* Do we really *want* to inline this function? */
2273 if (DECL_INLINE (fndecl))
2275 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
2276 will check our size. */
2277 DECL_INLINE (fndecl) = 0;
2278 if (function_cannot_inline_p (fndecl) == 0)
2279 DECL_INLINE (fndecl) = 1;
2282 extract_interface_info ();
2284 pop_cp_function_context (context);