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));
1089 get_id_2 (name, name2)
1097 return get_identifier (obstack_base (&scratch_obstack));
1100 /* Top-level interface to explicit overload requests. Allow NAME
1101 to be overloaded. Error if NAME is already declared for the current
1102 scope. Warning if function is redundantly overloaded. */
1105 declare_overloaded (name)
1108 #ifdef NO_AUTO_OVERLOAD
1109 if (is_overloaded (name))
1110 warning ("function `%s' already declared overloaded",
1111 IDENTIFIER_POINTER (name));
1112 else if (IDENTIFIER_GLOBAL_VALUE (name))
1113 error ("overloading function `%s' that is already defined",
1114 IDENTIFIER_POINTER (name));
1117 TREE_OVERLOADED (name) = 1;
1118 IDENTIFIER_GLOBAL_VALUE (name) = build_tree_list (name, NULL_TREE);
1119 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)) = unknown_type_node;
1122 if (current_lang_name == lang_name_cplusplus)
1125 warning ("functions are implicitly overloaded in C++");
1127 else if (current_lang_name == lang_name_c)
1128 error ("overloading function `%s' cannot be done in C language context");
1130 my_friendly_abort (76);
1134 #ifdef NO_AUTO_OVERLOAD
1135 /* Check to see if NAME is overloaded. For first approximation,
1136 check to see if its TREE_OVERLOADED is set. This is used on
1137 IDENTIFIER nodes. */
1139 is_overloaded (name)
1143 return (TREE_OVERLOADED (name)
1144 && (! IDENTIFIER_CLASS_VALUE (name) || current_class_type == 0)
1145 && ! IDENTIFIER_LOCAL_VALUE (name));
1149 /* Given a tree_code CODE, and some arguments (at least one),
1150 attempt to use an overloaded operator on the arguments.
1152 For unary operators, only the first argument need be checked.
1153 For binary operators, both arguments may need to be checked.
1155 Member functions can convert class references to class pointers,
1156 for one-level deep indirection. More than that is not supported.
1157 Operators [](), ()(), and ->() must be member functions.
1159 We call function call building calls with LOOKUP_COMPLAIN if they
1160 are our only hope. This is true when we see a vanilla operator
1161 applied to something of aggregate type. If this fails, we are free
1162 to return `error_mark_node', because we will have reported the
1165 Operators NEW and DELETE overload in funny ways: operator new takes
1166 a single `size' parameter, and operator delete takes a pointer to the
1167 storage being deleted. When overloading these operators, success is
1168 assumed. If there is a failure, report an error message and return
1169 `error_mark_node'. */
1173 build_opfncall (code, flags, xarg1, xarg2, arg3)
1174 enum tree_code code;
1176 tree xarg1, xarg2, arg3;
1180 tree type1, type2, fnname;
1181 tree fields1 = 0, parms = 0;
1184 int binary_is_unary;
1186 if (xarg1 == error_mark_node)
1187 return error_mark_node;
1189 if (code == COND_EXPR)
1191 if (TREE_CODE (xarg2) == ERROR_MARK
1192 || TREE_CODE (arg3) == ERROR_MARK)
1193 return error_mark_node;
1195 if (code == COMPONENT_REF)
1196 if (TREE_CODE (TREE_TYPE (xarg1)) == POINTER_TYPE)
1199 /* First, see if we can work with the first argument */
1200 type1 = TREE_TYPE (xarg1);
1202 /* Some tree codes have length > 1, but we really only want to
1203 overload them if their first argument has a user defined type. */
1206 case PREINCREMENT_EXPR:
1207 case PREDECREMENT_EXPR:
1208 case POSTINCREMENT_EXPR:
1209 case POSTDECREMENT_EXPR:
1211 binary_is_unary = 1;
1215 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1216 If they do not, return error_mark_node instead of NULL_TREE. */
1218 if (xarg2 == error_mark_node)
1219 return error_mark_node;
1221 rval = error_mark_node;
1222 binary_is_unary = 0;
1229 tree args = tree_cons (NULL_TREE, xarg2, arg3);
1230 fnname = ansi_opname[(int) code];
1231 if (flags & LOOKUP_GLOBAL)
1232 return build_overload_call (fnname, args, flags & LOOKUP_COMPLAIN,
1233 (struct candidate *)0);
1235 rval = build_method_call
1236 (build_indirect_ref (build1 (NOP_EXPR, xarg1, error_mark_node),
1238 fnname, args, NULL_TREE, flags);
1239 if (rval == error_mark_node)
1240 /* User might declare fancy operator new, but invoke it
1241 like standard one. */
1244 TREE_TYPE (rval) = xarg1;
1245 TREE_CALLS_NEW (rval) = 1;
1250 case VEC_DELETE_EXPR:
1253 fnname = ansi_opname[(int) code];
1254 if (flags & LOOKUP_GLOBAL)
1255 return build_overload_call (fnname,
1256 build_tree_list (NULL_TREE, xarg1),
1257 flags & LOOKUP_COMPLAIN,
1258 (struct candidate *)0);
1259 arg1 = TREE_TYPE (xarg1);
1261 /* This handles the case where we're trying to delete
1266 if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
1268 /* Strip off the pointer and the array. */
1269 arg1 = TREE_TYPE (TREE_TYPE (arg1));
1271 while (TREE_CODE (arg1) == ARRAY_TYPE)
1272 arg1 = (TREE_TYPE (arg1));
1274 arg1 = build_pointer_type (arg1);
1277 rval = build_method_call
1278 (build_indirect_ref (build1 (NOP_EXPR, arg1,
1281 fnname, tree_cons (NULL_TREE, xarg1,
1282 build_tree_list (NULL_TREE, xarg2)),
1285 /* This can happen when operator delete is protected. */
1286 my_friendly_assert (rval != error_mark_node, 250);
1287 TREE_TYPE (rval) = void_type_node;
1294 binary_is_unary = 0;
1295 try_second = tree_code_length [(int) code] == 2;
1296 if (try_second && xarg2 == error_mark_node)
1297 return error_mark_node;
1301 if (try_second && xarg2 == error_mark_node)
1302 return error_mark_node;
1304 /* What ever it was, we do not know how to deal with it. */
1305 if (type1 == NULL_TREE)
1308 if (TREE_CODE (type1) == OFFSET_TYPE)
1309 type1 = TREE_TYPE (type1);
1311 if (TREE_CODE (type1) == REFERENCE_TYPE)
1313 arg1 = convert_from_reference (xarg1);
1314 type1 = TREE_TYPE (arg1);
1321 if (!IS_AGGR_TYPE (type1) || TYPE_PTRMEMFUNC_P (type1))
1323 /* Try to fail. First, fail if unary */
1326 /* Second, see if second argument is non-aggregate. */
1327 type2 = TREE_TYPE (xarg2);
1328 if (TREE_CODE (type2) == OFFSET_TYPE)
1329 type2 = TREE_TYPE (type2);
1330 if (TREE_CODE (type2) == REFERENCE_TYPE)
1332 arg2 = convert_from_reference (xarg2);
1333 type2 = TREE_TYPE (arg2);
1340 if (!IS_AGGR_TYPE (type2))
1347 /* First arg may succeed; see whether second should. */
1348 type2 = TREE_TYPE (xarg2);
1349 if (TREE_CODE (type2) == OFFSET_TYPE)
1350 type2 = TREE_TYPE (type2);
1351 if (TREE_CODE (type2) == REFERENCE_TYPE)
1353 arg2 = convert_from_reference (xarg2);
1354 type2 = TREE_TYPE (arg2);
1361 if (! IS_AGGR_TYPE (type2))
1365 if (type1 == unknown_type_node
1366 || (try_second && TREE_TYPE (xarg2) == unknown_type_node))
1368 /* This will not be implemented in the foreseeable future. */
1372 if (code == MODIFY_EXPR)
1373 fnname = ansi_assopname[(int) TREE_CODE (arg3)];
1375 fnname = ansi_opname[(int) code];
1377 global_fn = lookup_name_nonclass (fnname);
1379 /* This is the last point where we will accept failure. This
1380 may be too eager if we wish an overloaded operator not to match,
1381 but would rather a normal operator be called on a type-converted
1384 if (IS_AGGR_TYPE (type1))
1386 fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
1387 /* ARM $13.4.7, prefix/postfix ++/--. */
1388 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
1390 xarg2 = integer_zero_node;
1391 binary_is_unary = 0;
1396 int have_postfix = 0;
1398 /* Look for an `operator++ (int)'. If they didn't have
1399 one, then we fall back to the old way of doing things. */
1400 for (t = TREE_VALUE (fields1); t ; t = DECL_CHAIN (t))
1402 t2 = TYPE_ARG_TYPES (TREE_TYPE (t));
1403 if (TREE_CHAIN (t2) != NULL_TREE
1404 && TREE_VALUE (TREE_CHAIN (t2)) == integer_type_node)
1413 char *op = POSTINCREMENT_EXPR ? "++" : "--";
1415 /* There's probably a LOT of code in the world that
1416 relies upon this old behavior. */
1417 if (! flag_traditional)
1418 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1421 binary_is_unary = 1;
1427 if (fields1 == NULL_TREE && global_fn == NULL_TREE)
1430 /* If RVAL winds up being `error_mark_node', we will return
1431 that... There is no way that normal semantics of these
1432 operators will succeed. */
1434 /* This argument may be an uncommitted OFFSET_REF. This is
1435 the case for example when dealing with static class members
1436 which are referenced from their class name rather than
1437 from a class instance. */
1438 if (TREE_CODE (xarg1) == OFFSET_REF
1439 && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL)
1440 xarg1 = TREE_OPERAND (xarg1, 1);
1441 if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF
1442 && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL)
1443 xarg2 = TREE_OPERAND (xarg2, 1);
1446 flags |= LOOKUP_GLOBAL;
1448 if (code == CALL_EXPR)
1450 /* This can only be a member function. */
1451 return build_method_call (xarg1, fnname, xarg2,
1452 NULL_TREE, LOOKUP_NORMAL);
1454 else if (tree_code_length[(int) code] == 1 || binary_is_unary)
1457 rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags);
1459 else if (code == COND_EXPR)
1461 parms = tree_cons (0, xarg2, build_tree_list (NULL_TREE, arg3));
1462 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1464 else if (code == METHOD_CALL_EXPR)
1466 /* must be a member function. */
1467 parms = tree_cons (NULL_TREE, xarg2, arg3);
1468 return build_method_call (xarg1, fnname, parms, NULL_TREE,
1473 parms = build_tree_list (NULL_TREE, xarg2);
1474 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1478 parms = tree_cons (NULL_TREE, xarg1,
1479 build_tree_list (NULL_TREE, xarg2));
1480 rval = build_overload_call (fnname, parms, flags,
1481 (struct candidate *)0);
1487 /* This function takes an identifier, ID, and attempts to figure out what
1488 it means. There are a number of possible scenarios, presented in increasing
1491 1) not in a class's scope
1492 2) in class's scope, member name of the class's method
1493 3) in class's scope, but not a member name of the class
1494 4) in class's scope, member name of a class's variable
1496 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1497 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1499 As a last ditch, try to look up the name as a label and return that
1502 Values which are declared as being of REFERENCE_TYPE are
1503 automatically dereferenced here (as a hack to make the
1504 compiler faster). */
1507 hack_identifier (value, name)
1512 if (TREE_CODE (value) == ERROR_MARK)
1514 if (current_class_name)
1516 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1517 if (fields == error_mark_node)
1518 return error_mark_node;
1523 fndecl = TREE_VALUE (fields);
1524 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1525 if (DECL_CHAIN (fndecl) == NULL_TREE)
1527 warning ("methods cannot be converted to function pointers");
1532 error ("ambiguous request for method pointer `%s'",
1533 IDENTIFIER_POINTER (name));
1534 return error_mark_node;
1538 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1540 return IDENTIFIER_LABEL_VALUE (name);
1542 return error_mark_node;
1545 type = TREE_TYPE (value);
1546 if (TREE_CODE (value) == FIELD_DECL)
1548 if (current_class_decl == NULL_TREE)
1550 error ("request for member `%s' in static member function",
1551 IDENTIFIER_POINTER (DECL_NAME (value)));
1552 return error_mark_node;
1554 TREE_USED (current_class_decl) = 1;
1556 /* Mark so that if we are in a constructor, and then find that
1557 this field was initialized by a base initializer,
1558 we can emit an error message. */
1559 TREE_USED (value) = 1;
1560 value = build_component_ref (C_C_D, name, 0, 1);
1562 else if (really_overloaded_fn (value))
1565 tree t = get_first_fn (value);
1566 for (; t; t = DECL_CHAIN (t))
1568 if (TREE_CODE (t) == TEMPLATE_DECL)
1571 assemble_external (t);
1576 else if (TREE_CODE (value) == TREE_LIST)
1578 /* Ambiguous reference to base members, possibly other cases?. */
1580 while (t && TREE_CODE (t) == TREE_LIST)
1582 mark_used (TREE_VALUE (t));
1589 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL)
1591 tree context = decl_function_context (value);
1592 if (context != NULL_TREE && context != current_function_decl
1593 && ! TREE_STATIC (value))
1595 cp_error ("use of %s from containing function",
1596 (TREE_CODE (value) == VAR_DECL
1597 ? "`auto' variable" : "parameter"));
1598 cp_error_at (" `%#D' declared here", value);
1599 value = error_mark_node;
1603 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1605 if (DECL_LANG_SPECIFIC (value)
1606 && DECL_CLASS_CONTEXT (value) != current_class_type)
1609 register tree context
1610 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1611 ? DECL_CLASS_CONTEXT (value)
1612 : DECL_CONTEXT (value);
1614 get_base_distance (context, current_class_type, 0, &path);
1617 access = compute_access (path, value);
1618 if (access != access_public_node)
1620 if (TREE_CODE (value) == VAR_DECL)
1621 error ("static member `%s' is %s",
1622 IDENTIFIER_POINTER (name),
1623 TREE_PRIVATE (value) ? "private" :
1624 "from a private base class");
1626 error ("enum `%s' is from private base class",
1627 IDENTIFIER_POINTER (name));
1628 return error_mark_node;
1634 if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1638 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1639 IDENTIFIER_POINTER (name));
1640 return error_mark_node;
1646 if (TREE_CODE (type) == REFERENCE_TYPE && ! current_template_parms)
1647 value = convert_from_reference (value);
1653 /* Given an object OF, and a type conversion operator COMPONENT
1654 build a call to the conversion operator, if a call is requested,
1655 or return the address (as a pointer to member function) if one is not.
1657 OF can be a TYPE_DECL or any kind of datum that would normally
1658 be passed to `build_component_ref'. It may also be NULL_TREE,
1659 in which case `current_class_type' and `current_class_decl'
1660 provide default values.
1662 BASETYPE_PATH, if non-null, is the path of basetypes
1663 to go through before we get the the instance of interest.
1665 PROTECT says whether we apply C++ scoping rules or not. */
1667 build_component_type_expr (of, component, basetype_path, protect)
1668 tree of, component, basetype_path;
1671 tree cname = NULL_TREE;
1674 int flags = protect ? LOOKUP_NORMAL : LOOKUP_COMPLAIN;
1677 my_friendly_assert (IS_AGGR_TYPE (TREE_TYPE (of)), 253);
1678 my_friendly_assert (TREE_CODE (component) == TYPE_EXPR, 254);
1680 tmp = TREE_OPERAND (component, 0);
1685 switch (TREE_CODE (tmp))
1689 TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
1691 TREE_OPERAND (component, 0) = TREE_OPERAND (tmp, 0);
1693 last = groktypename (build_tree_list (TREE_TYPE (component),
1694 TREE_OPERAND (component, 0)));
1695 name = build_typename_overload (last);
1696 TREE_TYPE (name) = last;
1698 if (TREE_OPERAND (tmp, 0)
1699 && TREE_OPERAND (tmp, 0) != void_list_node)
1701 cp_error ("`operator %T' requires empty parameter list", last);
1702 TREE_OPERAND (tmp, 0) = NULL_TREE;
1705 if (of && TREE_CODE (of) != TYPE_DECL)
1706 return build_method_call (of, name, NULL_TREE, NULL_TREE, flags);
1711 if (current_class_decl == NULL_TREE)
1713 cp_error ("object required for `operator %T' call",
1715 return error_mark_node;
1718 this_this = convert_pointer_to (TREE_TYPE (of),
1719 current_class_decl);
1720 this_this = build_indirect_ref (this_this, NULL_PTR);
1721 return build_method_call (this_this, name, NULL_TREE,
1722 NULL_TREE, flags | LOOKUP_NONVIRTUAL);
1724 else if (current_class_decl)
1725 return build_method_call (tmp, name, NULL_TREE, NULL_TREE, flags);
1727 cp_error ("object required for `operator %T' call",
1729 return error_mark_node;
1737 my_friendly_assert (cname == 0, 255);
1738 cname = TREE_OPERAND (tmp, 0);
1739 tmp = TREE_OPERAND (tmp, 1);
1743 my_friendly_abort (77);
1746 tmp = TREE_OPERAND (tmp, 0);
1749 last = groktypename (build_tree_list (TREE_TYPE (component), TREE_OPERAND (component, 0)));
1750 name = build_typename_overload (last);
1751 TREE_TYPE (name) = last;
1752 if (of && TREE_CODE (of) == TYPE_DECL)
1754 if (cname == NULL_TREE)
1756 cname = DECL_NAME (of);
1759 else my_friendly_assert (cname == DECL_NAME (of), 256);
1766 if (current_class_decl == NULL_TREE)
1768 cp_error ("object required for `operator %T' call",
1770 return error_mark_node;
1773 this_this = convert_pointer_to (TREE_TYPE (of), current_class_decl);
1774 return build_component_ref (this_this, name, 0, protect);
1777 return build_offset_ref (cname, name);
1778 else if (current_class_name)
1779 return build_offset_ref (current_class_name, name);
1781 cp_error ("object required for `operator %T' member reference",
1783 return error_mark_node;
1788 thunk_printable_name (decl)
1791 return "<thunk function>";
1795 make_thunk (function, delta)
1800 tree thunk_fndecl, thunk_id;
1803 static int thunk_number = 0;
1805 if (TREE_CODE (function) != ADDR_EXPR)
1807 func_decl = TREE_OPERAND (function, 0);
1808 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1810 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1812 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1814 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1815 thunk_id = get_identifier (buffer);
1816 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1817 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1819 cp_error ("implementation-reserved name `%D' used", thunk_id);
1820 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1822 if (thunk == NULL_TREE)
1824 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
1826 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type)));
1827 TREE_READONLY (thunk) = TYPE_READONLY (TREE_TYPE (vtable_entry_type));
1828 TREE_THIS_VOLATILE (thunk) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type));
1829 make_function_rtl (thunk);
1830 TREE_SET_CODE (thunk, THUNK_DECL);
1831 DECL_INITIAL (thunk) = function;
1832 THUNK_DELTA (thunk) = delta;
1833 DECL_EXTERNAL (thunk) = 1;
1834 TREE_PUBLIC (thunk) = 0;
1835 /* So that finish_file can write out any thunks that need to be: */
1836 pushdecl_top_level (thunk);
1842 emit_thunk (thunk_fndecl)
1848 struct args_size stack_args_size;
1849 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1850 int delta = THUNK_DELTA (thunk_fndecl);
1851 char *fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
1855 /* Used to remember which regs we need to emit a USE rtx for. */
1856 rtx need_use[FIRST_PSEUDO_REGISTER];
1857 int need_use_count = 0;
1859 /* rtx for the 'this' parameter. */
1860 rtx this_rtx = 0, this_reg_rtx = 0, fixed_this_rtx;
1862 char *(*save_decl_printable_name) () = decl_printable_name;
1863 /* Data on reg parms scanned so far. */
1864 CUMULATIVE_ARGS args_so_far;
1866 if (TREE_ASM_WRITTEN (thunk_fndecl))
1869 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1871 decl_printable_name = thunk_printable_name;
1872 if (current_function_decl)
1874 current_function_decl = thunk_fndecl;
1875 #ifdef ASM_OUTPUT_MI_THUNK
1876 assemble_start_function (thunk_fndecl, fnname);
1877 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
1879 init_function_start (thunk_fndecl, input_filename, lineno);
1881 expand_start_bindings (1);
1883 /* Start updating where the next arg would go. */
1884 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (function), NULL_RTX, 0);
1885 stack_args_size.constant = 0;
1886 stack_args_size.var = 0;
1887 /* SETUP for possible structure return address FIXME */
1889 /* Now look through all the parameters, make sure that we
1890 don't clobber any registers used for parameters.
1891 Also, pick up an rtx for the first "this" parameter. */
1892 for (argp = TYPE_ARG_TYPES (TREE_TYPE (function));
1894 argp = TREE_CHAIN (argp))
1897 tree passed_type = TREE_VALUE (argp);
1898 register rtx entry_parm;
1899 int named = 1; /* FIXME */
1900 struct args_size stack_offset;
1901 struct args_size arg_size;
1903 if (passed_type == void_type_node)
1906 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
1907 && contains_placeholder_p (TYPE_SIZE (passed_type)))
1908 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1909 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far,
1910 TYPE_MODE (passed_type),
1914 passed_type = build_pointer_type (passed_type);
1916 entry_parm = FUNCTION_ARG (args_so_far,
1917 TYPE_MODE (passed_type),
1920 if (entry_parm != 0)
1921 need_use[need_use_count++] = entry_parm;
1923 locate_and_pad_parm (TYPE_MODE (passed_type), passed_type,
1924 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1930 &stack_args_size, &stack_offset, &arg_size);
1932 /* REGNO (entry_parm);*/
1935 this_reg_rtx = entry_parm;
1938 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
1940 rtx internal_arg_pointer, stack_parm;
1942 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
1943 || ! (fixed_regs[ARG_POINTER_REGNUM]
1944 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
1945 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
1947 internal_arg_pointer = virtual_incoming_args_rtx;
1949 if (offset_rtx == const0_rtx)
1950 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1951 internal_arg_pointer);
1953 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1954 gen_rtx (PLUS, Pmode,
1955 internal_arg_pointer,
1959 this_rtx = entry_parm;
1962 FUNCTION_ARG_ADVANCE (args_so_far,
1963 TYPE_MODE (passed_type),
1968 fixed_this_rtx = plus_constant (this_rtx, delta);
1969 if (this_rtx != fixed_this_rtx)
1970 emit_move_insn (this_rtx, fixed_this_rtx);
1973 emit_insn (gen_rtx (USE, VOIDmode, this_reg_rtx));
1975 emit_indirect_jump (XEXP (DECL_RTL (function), 0));
1977 while (need_use_count > 0)
1978 emit_insn (gen_rtx (USE, VOIDmode, need_use[--need_use_count]));
1980 expand_end_bindings (NULL, 1, 0);
1983 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
1984 Note that that may have been done above, in save_for_inline_copying.
1985 The call to resume_temporary_allocation near the end of this function
1986 goes back to the usual state of affairs. */
1988 rtl_in_current_obstack ();
1990 insns = get_insns ();
1992 /* Copy any shared structure that should not be shared. */
1994 unshare_all_rtl (insns);
1996 /* Instantiate all virtual registers. */
1998 instantiate_virtual_regs (current_function_decl, get_insns ());
2000 /* We are no longer anticipating cse in this function, at least. */
2002 cse_not_expected = 1;
2004 /* Now we choose between stupid (pcc-like) register allocation
2005 (if we got the -noreg switch and not -opt)
2006 and smart register allocation. */
2008 if (optimize > 0) /* Stupid allocation probably won't work */
2009 obey_regdecls = 0; /* if optimizations being done. */
2013 regclass (insns, max_reg_num ());
2016 stupid_life_analysis (insns, max_reg_num (), NULL);
2017 failure = reload (insns, 0, NULL);
2021 /* Do control and data flow analysis,
2022 and write some of the results to dump file. */
2024 flow_analysis (insns, max_reg_num (), NULL);
2026 failure = global_alloc (NULL);
2029 reload_completed = 1;
2031 #ifdef LEAF_REGISTERS
2033 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
2037 /* If a machine dependent reorganization is needed, call it. */
2038 #ifdef MACHINE_DEPENDENT_REORG
2039 MACHINE_DEPENDENT_REORG (insns);
2042 /* Now turn the rtl into assembler code. */
2044 assemble_start_function (thunk_fndecl, fnname);
2045 final (insns, asm_out_file, optimize, 0);
2046 assemble_end_function (thunk_fndecl, fnname);
2048 exit_rest_of_compilation:
2050 reload_completed = 0;
2052 /* Cancel the effect of rtl_in_current_obstack. */
2054 resume_temporary_allocation ();
2056 decl_printable_name = save_decl_printable_name;
2057 #endif /* ASM_OUTPUT_MI_THUNK */
2058 current_function_decl = 0;
2061 /* Code for synthesizing methods which have default semantics defined. */
2063 /* For the anonymous union in TYPE, return the member that is at least as
2064 large as the rest of the members, so we can copy it. */
2066 largest_union_member (type)
2069 tree f, type_size = TYPE_SIZE (type);
2071 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
2072 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
2075 /* We should always find one. */
2076 my_friendly_abort (323);
2080 /* Generate code for default X(X&) constructor. */
2082 do_build_copy_constructor (fndecl)
2085 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2091 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2092 parm = TREE_CHAIN (parm);
2093 parm = convert_from_reference (parm);
2095 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2097 t = build (INIT_EXPR, void_type_node, C_C_D, parm);
2098 TREE_SIDE_EFFECTS (t) = 1;
2099 cplus_expand_expr_stmt (t);
2103 tree fields = TYPE_FIELDS (current_class_type);
2104 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2105 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2108 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2111 tree basetype = BINFO_TYPE (t);
2112 tree p = convert_to_reference
2113 (build_reference_type (basetype), parm,
2114 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2115 p = convert_from_reference (p);
2116 current_base_init_list = tree_cons (basetype,
2117 p, current_base_init_list);
2120 for (i = 0; i < n_bases; ++i)
2122 tree p, basetype = TREE_VEC_ELT (binfos, i);
2123 if (TREE_VIA_VIRTUAL (basetype))
2126 basetype = BINFO_TYPE (basetype);
2127 p = convert_to_reference
2128 (build_reference_type (basetype), parm,
2129 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2130 p = convert_from_reference (p);
2131 current_base_init_list = tree_cons (basetype,
2132 p, current_base_init_list);
2134 for (; fields; fields = TREE_CHAIN (fields))
2137 tree field = fields;
2139 if (TREE_CODE (field) != FIELD_DECL)
2141 if (DECL_NAME (field))
2143 if (VFIELD_NAME_P (DECL_NAME (field)))
2145 if (VBASE_NAME_P (DECL_NAME (field)))
2148 /* True for duplicate members. */
2149 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2152 else if ((t = TREE_TYPE (field)) != NULL_TREE
2153 && TREE_CODE (t) == UNION_TYPE
2154 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2155 && TYPE_FIELDS (t) != NULL_TREE)
2156 field = largest_union_member (t);
2160 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2161 init = build_tree_list (NULL_TREE, init);
2163 current_member_init_list
2164 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2166 current_member_init_list = nreverse (current_member_init_list);
2167 current_base_init_list = nreverse (current_base_init_list);
2175 do_build_assign_ref (fndecl)
2178 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2183 parm = convert_from_reference (parm);
2185 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2187 tree t = build (MODIFY_EXPR, void_type_node, C_C_D, parm);
2188 TREE_SIDE_EFFECTS (t) = 1;
2189 cplus_expand_expr_stmt (t);
2193 tree fields = TYPE_FIELDS (current_class_type);
2194 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2195 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2198 for (i = 0; i < n_bases; ++i)
2200 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2201 if (TYPE_HAS_ASSIGN_REF (basetype))
2203 tree p = convert_to_reference
2204 (build_reference_type (basetype), parm,
2205 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2206 p = convert_from_reference (p);
2207 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2208 build_tree_list (NULL_TREE, p));
2209 expand_expr_stmt (p);
2212 for (; fields; fields = TREE_CHAIN (fields))
2215 tree field = fields;
2217 if (TREE_CODE (field) != FIELD_DECL)
2219 if (DECL_NAME (field))
2221 if (VFIELD_NAME_P (DECL_NAME (field)))
2223 if (VBASE_NAME_P (DECL_NAME (field)))
2226 /* True for duplicate members. */
2227 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2230 else if ((t = TREE_TYPE (field)) != NULL_TREE
2231 && TREE_CODE (t) == UNION_TYPE
2232 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2233 && TYPE_FIELDS (t) != NULL_TREE)
2234 field = largest_union_member (t);
2238 comp = build (COMPONENT_REF, TREE_TYPE (field), C_C_D, field);
2239 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2241 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2244 c_expand_return (C_C_D);
2249 synthesize_method (fndecl)
2252 int nested = (current_function_decl != NULL_TREE);
2253 tree context = hack_decl_function_context (fndecl);
2254 tree base = DECL_CLASS_CONTEXT (fndecl);
2257 push_cp_function_context (context);
2259 interface_unknown = 1;
2260 start_function (NULL_TREE, fndecl, NULL_TREE, NULL_TREE, 1);
2261 store_parm_decls ();
2263 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2264 do_build_assign_ref (fndecl);
2265 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2269 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2270 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2271 arg_chain = TREE_CHAIN (arg_chain);
2272 if (arg_chain != void_list_node)
2273 do_build_copy_constructor (fndecl);
2274 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2278 finish_function (lineno, 0, nested);
2280 /* Do we really *want* to inline this function? */
2281 if (DECL_INLINE (fndecl))
2283 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
2284 will check our size. */
2285 DECL_INLINE (fndecl) = 0;
2286 if (function_cannot_inline_p (fndecl) == 0)
2287 DECL_INLINE (fndecl) = 1;
2290 extract_interface_info ();
2292 pop_cp_function_context (context);