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, 1995 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, 0))
95 method = TREE_VEC_ELT (method, 0);
97 method = TREE_VEC_ELT (method, 1);
102 /* Do inline member functions. */
103 struct pending_inline *info = DECL_PENDING_INLINE_INFO (method);
108 my_friendly_assert (info->fndecl == method, 238);
109 args = DECL_ARGUMENTS (method);
112 DECL_CONTEXT (args) = method;
113 args = TREE_CHAIN (args);
116 /* Allow this decl to be seen in global scope. Don't do this for
117 local class methods, though. */
118 if (! current_function_decl)
119 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method)) = method;
121 method = TREE_CHAIN (method);
125 tree fndecl = TREE_VALUE (friend_list);
126 struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl);
131 my_friendly_assert (info->fndecl == fndecl, 239);
132 args = DECL_ARGUMENTS (fndecl);
135 DECL_CONTEXT (args) = fndecl;
136 args = TREE_CHAIN (args);
139 /* Allow this decl to be seen in global scope */
140 if (! current_function_decl)
141 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl)) = fndecl;
144 friend_list = TREE_CHAIN (friend_list);
148 /* Report an argument type mismatch between the best declared function
149 we could find and the current argument list that we have. */
151 report_type_mismatch (cp, parmtypes, name_kind)
152 struct candidate *cp;
156 int i = cp->u.bad_arg;
163 my_friendly_assert (TREE_CODE (cp->function) == TEMPLATE_DECL, 240);
164 cp_error ("type unification failed for function template `%#D'",
169 cp_error ("too few arguments for %s `%#D'", name_kind, cp->function);
172 cp_error ("too many arguments for %s `%#D'", name_kind, cp->function);
175 if (TREE_CODE (TREE_TYPE (cp->function)) != METHOD_TYPE)
178 /* Happens when the implicit object parameter is rejected. */
179 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes))),
181 cp_error ("call to non-const %s `%#D' with const object",
182 name_kind, cp->function);
186 ttf = TYPE_ARG_TYPES (TREE_TYPE (cp->function));
191 ttf = TREE_CHAIN (ttf);
192 tta = TREE_CHAIN (tta);
196 OB_PUTS ("bad argument ");
197 sprintf (digit_buffer, "%d", cp->u.bad_arg
198 - (TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE)
200 OB_PUTCP (digit_buffer);
202 OB_PUTS (" for function `");
203 OB_PUTCP (decl_as_string (cp->function, 1));
204 OB_PUTS ("' (type was ");
206 /* Reset `i' so that type printing routines do the right thing. */
209 enum tree_code code = TREE_CODE (TREE_TYPE (TREE_VALUE (tta)));
210 if (code == ERROR_MARK)
211 OB_PUTS ("(failed type instantiation)");
214 i = (code == FUNCTION_TYPE || code == METHOD_TYPE);
215 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta)), 1));
218 else OB_PUTS ("void");
222 tmp_firstobj = (char *)alloca (obstack_object_size (&scratch_obstack));
223 bcopy (obstack_base (&scratch_obstack), tmp_firstobj,
224 obstack_object_size (&scratch_obstack));
225 error (tmp_firstobj);
228 /* Here is where overload code starts. */
230 /* Array of types seen so far in top-level call to `build_overload_name'.
231 Allocated and deallocated by caller. */
232 static tree *typevec;
234 /* Number of types interned by `build_overload_name' so far. */
237 /* Number of occurrences of last type seen. */
240 /* Nonzero if we should not try folding parameter types. */
243 #define ALLOCATE_TYPEVEC(PARMTYPES) \
244 do { maxtype = 0, nrepeats = 0; \
245 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
247 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
248 do { tree t = (PARMTYPES); \
249 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
252 /* Code to concatenate an asciified integer to a string. */
261 /* Handle this case first, to go really quickly. For many common values,
262 the result of i/10 below is 1. */
279 OB_PUTC ('0' + (i % 10));
293 while (typevec[tindex] != type)
311 static int numeric_output_need_bar;
312 static void build_overload_identifier ();
315 build_overload_nested_name (decl)
318 if (DECL_CONTEXT (decl))
320 tree context = DECL_CONTEXT (decl);
321 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
322 context = TYPE_MAIN_DECL (context);
323 build_overload_nested_name (context);
326 if (TREE_CODE (decl) == FUNCTION_DECL)
328 tree name = DECL_ASSEMBLER_NAME (decl);
330 extern int var_labelno;
332 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), var_labelno);
335 if (numeric_output_need_bar)
338 numeric_output_need_bar = 0;
340 icat (strlen (label));
345 tree name = DECL_NAME (decl);
346 build_overload_identifier (name);
350 /* Encoding for an INTEGER_CST value. */
352 build_overload_int (value)
355 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
356 if (TYPE_PRECISION (value) == 2 * HOST_BITS_PER_WIDE_INT)
358 if (tree_int_cst_lt (value, integer_zero_node))
361 value = build_int_2 (~ TREE_INT_CST_LOW (value),
362 - TREE_INT_CST_HIGH (value));
364 if (TREE_INT_CST_HIGH (value)
365 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
367 /* need to print a DImode value in decimal */
368 sorry ("conversion of long long as PT parameter");
370 /* else fall through to print in smaller mode */
372 /* Wordsize or smaller */
373 icat (TREE_INT_CST_LOW (value));
377 build_overload_value (type, value)
380 while (TREE_CODE (value) == NON_LVALUE_EXPR
381 || TREE_CODE (value) == NOP_EXPR)
382 value = TREE_OPERAND (value, 0);
383 my_friendly_assert (TREE_CODE (type) == PARM_DECL, 242);
384 type = TREE_TYPE (type);
386 if (numeric_output_need_bar)
389 numeric_output_need_bar = 0;
392 if (TREE_CODE (type) == POINTER_TYPE
393 && TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE)
395 /* Handle a pointer to data member as a template instantiation
396 parameter, boy, what fun! */
397 type = integer_type_node;
398 if (TREE_CODE (value) != INTEGER_CST)
400 sorry ("unknown pointer to member constant");
405 if (TYPE_PTRMEMFUNC_P (type))
406 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
408 switch (TREE_CODE (type))
414 build_overload_int (value);
415 numeric_output_need_bar = 1;
418 #ifndef REAL_IS_NOT_DOUBLE
422 char *bufp = digit_buffer;
423 extern char *index ();
425 my_friendly_assert (TREE_CODE (value) == REAL_CST, 244);
426 val = TREE_REAL_CST (value);
432 sprintf (bufp, "%e", val);
433 bufp = (char *) index (bufp, 'e');
435 strcat (digit_buffer, "e0");
461 OB_PUTCP (digit_buffer);
462 numeric_output_need_bar = 1;
467 if (TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
468 && TREE_CODE (value) != ADDR_EXPR)
470 if (TREE_CODE (value) == CONSTRUCTOR)
472 /* This is dangerous code, crack built up pointer to members. */
473 tree args = CONSTRUCTOR_ELTS (value);
474 tree a1 = TREE_VALUE (args);
475 tree a2 = TREE_VALUE (TREE_CHAIN (args));
476 tree a3 = CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args))));
477 a3 = TREE_VALUE (a3);
479 if (TREE_CODE (a1) == INTEGER_CST
480 && TREE_CODE (a2) == INTEGER_CST)
482 build_overload_int (a1);
484 build_overload_int (a2);
486 if (TREE_CODE (a3) == ADDR_EXPR)
488 a3 = TREE_OPERAND (a3, 0);
489 if (TREE_CODE (a3) == FUNCTION_DECL)
491 numeric_output_need_bar = 0;
492 build_overload_identifier (DECL_ASSEMBLER_NAME (a3));
496 else if (TREE_CODE (a3) == INTEGER_CST)
499 build_overload_int (a3);
500 numeric_output_need_bar = 1;
505 sorry ("template instantiation with pointer to method that is too complex");
508 if (TREE_CODE (value) == INTEGER_CST)
510 build_overload_int (value);
511 numeric_output_need_bar = 1;
514 value = TREE_OPERAND (value, 0);
515 if (TREE_CODE (value) == VAR_DECL)
517 my_friendly_assert (DECL_NAME (value) != 0, 245);
518 build_overload_identifier (DECL_NAME (value));
521 else if (TREE_CODE (value) == FUNCTION_DECL)
523 my_friendly_assert (DECL_NAME (value) != 0, 246);
524 build_overload_identifier (DECL_NAME (value));
528 my_friendly_abort (71);
529 break; /* not really needed */
532 sorry ("conversion of %s as template parameter",
533 tree_code_name [(int) TREE_CODE (type)]);
534 my_friendly_abort (72);
539 build_overload_identifier (name)
542 if (IDENTIFIER_TEMPLATE (name))
544 tree template, parmlist, arglist, tname;
546 template = IDENTIFIER_TEMPLATE (name);
547 arglist = TREE_VALUE (template);
548 template = TREE_PURPOSE (template);
549 tname = DECL_NAME (template);
550 parmlist = DECL_ARGUMENTS (template);
551 nparms = TREE_VEC_LENGTH (parmlist);
553 icat (IDENTIFIER_LENGTH (tname));
556 for (i = 0; i < nparms; i++)
558 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
559 tree arg = TREE_VEC_ELT (arglist, i);
560 if (TREE_CODE (parm) == TYPE_DECL)
562 /* This parameter is a type. */
564 build_overload_name (arg, 0, 0);
568 parm = tsubst (parm, &TREE_VEC_ELT (arglist, 0),
569 TREE_VEC_LENGTH (arglist), NULL_TREE);
570 /* It's a PARM_DECL. */
571 build_overload_name (TREE_TYPE (parm), 0, 0);
572 build_overload_value (parm, arg);
578 if (numeric_output_need_bar)
581 numeric_output_need_bar = 0;
583 icat (IDENTIFIER_LENGTH (name));
588 /* Given a list of parameters in PARMTYPES, create an unambiguous
589 overload string. Should distinguish any type that C (or C++) can
590 distinguish. I.e., pointers to functions are treated correctly.
592 Caller must deal with whether a final `e' goes on the end or not.
594 Any default conversions must take place before this function
597 BEGIN and END control initialization and finalization of the
598 obstack where we build the string. */
601 build_overload_name (parmtypes, begin, end)
608 if (begin) OB_INIT ();
609 numeric_output_need_bar = 0;
611 if ((just_one = (TREE_CODE (parmtypes) != TREE_LIST)))
613 parmtype = parmtypes;
619 parmtype = TREE_VALUE (parmtypes);
623 if (! nofold && ! just_one)
625 /* Every argument gets counted. */
626 typevec[maxtype++] = parmtype;
628 if (TREE_USED (parmtype) && parmtype == typevec[maxtype-2])
635 flush_repeats (typevec[maxtype-2]);
637 if (TREE_USED (parmtype))
639 flush_repeats (parmtype);
643 /* Only cache types which take more than one character. */
644 if (parmtype != TYPE_MAIN_VARIANT (parmtype)
645 || (TREE_CODE (parmtype) != INTEGER_TYPE
646 && TREE_CODE (parmtype) != REAL_TYPE))
647 TREE_USED (parmtype) = 1;
650 if (TYPE_PTRMEMFUNC_P (parmtype))
651 parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype);
653 if (TREE_READONLY (parmtype))
655 if (TREE_CODE (parmtype) == INTEGER_TYPE
656 && TYPE_MAIN_VARIANT (parmtype) == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
658 if (TYPE_VOLATILE (parmtype))
661 switch (TREE_CODE (parmtype))
665 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0);
667 build_overload_name (TREE_TYPE (parmtype), 0, 0);
675 #if PARM_CAN_BE_ARRAY_TYPE
680 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
681 error ("pointer or reference to array of unknown bound in parm type");
684 length = array_type_nelts (parmtype);
685 if (TREE_CODE (length) == INTEGER_CST)
686 icat (TREE_INT_CST_LOW (length) + 1);
699 build_overload_name (TREE_TYPE (parmtype), 0, 0);
705 tree firstarg = TYPE_ARG_TYPES (parmtype);
706 /* Otherwise have to implement reentrant typevecs,
707 unmark and remark types, etc. */
708 int old_nofold = nofold;
712 flush_repeats (typevec[maxtype-1]);
714 /* @@ It may be possible to pass a function type in
715 which is not preceded by a 'P'. */
716 if (TREE_CODE (parmtype) == FUNCTION_TYPE)
719 if (firstarg == NULL_TREE)
721 else if (firstarg == void_list_node)
724 build_overload_name (firstarg, 0, 0);
728 int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
729 int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
731 firstarg = TREE_CHAIN (firstarg);
733 build_overload_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0);
739 /* For cfront 2.0 compatibility. */
742 if (firstarg == NULL_TREE)
744 else if (firstarg == void_list_node)
747 build_overload_name (firstarg, 0, 0);
750 /* Separate args from return type. */
752 build_overload_name (TREE_TYPE (parmtype), 0, 0);
758 parmtype = TYPE_MAIN_VARIANT (parmtype);
759 if (parmtype == integer_type_node
760 || parmtype == unsigned_type_node)
762 else if (parmtype == long_integer_type_node
763 || parmtype == long_unsigned_type_node)
765 else if (parmtype == short_integer_type_node
766 || parmtype == short_unsigned_type_node)
768 else if (parmtype == signed_char_type_node)
773 else if (parmtype == char_type_node
774 || parmtype == unsigned_char_type_node)
776 else if (parmtype == wchar_type_node)
778 else if (parmtype == long_long_integer_type_node
779 || parmtype == long_long_unsigned_type_node)
782 /* it would seem there is no way to enter these in source code,
784 else if (parmtype == long_long_long_integer_type_node
785 || parmtype == long_long_long_unsigned_type_node)
789 my_friendly_abort (73);
797 parmtype = TYPE_MAIN_VARIANT (parmtype);
798 if (parmtype == long_double_type_node)
800 else if (parmtype == double_type_node)
802 else if (parmtype == float_type_node)
804 else my_friendly_abort (74);
811 extern tree void_list_node;
813 /* See if anybody is wasting memory. */
814 my_friendly_assert (parmtypes == void_list_node, 247);
816 /* This is the end of a parameter list. */
817 if (end) OB_FINISH ();
818 return (char *)obstack_base (&scratch_obstack);
823 case ERROR_MARK: /* not right, but nothing is anyway */
826 /* have to do these */
830 /* Make this type signature look incompatible
837 tree name = TYPE_NAME (parmtype);
840 if (TREE_CODE (name) == TYPE_DECL)
844 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
845 if (DECL_ASSEMBLER_NAME (context) != DECL_NAME (context))
847 OB_PUTID (DECL_ASSEMBLER_NAME (context));
850 while (DECL_CONTEXT (context))
853 context = DECL_CONTEXT (context);
854 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
855 context = TYPE_NAME (context);
857 name = DECL_NAME (name);
859 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 248);
868 numeric_output_need_bar = 0;
869 build_overload_nested_name (TYPE_MAIN_DECL (parmtype));
872 build_overload_identifier (name);
877 /* This will take some work. */
881 case TEMPLATE_TYPE_PARM:
882 case TEMPLATE_CONST_PARM:
883 case UNINSTANTIATED_P_TYPE:
884 /* We don't ever want this output, but it's inconvenient not to
885 be able to build the string. This should cause assembler
886 errors we'll notice. */
889 sprintf (digit_buffer, " *%d", n++);
890 OB_PUTCP (digit_buffer);
895 my_friendly_abort (75);
900 parmtypes = TREE_CHAIN (parmtypes);
905 flush_repeats (typevec[maxtype-1]);
907 /* To get here, parms must end with `...'. */
911 if (end) OB_FINISH ();
912 return (char *)obstack_base (&scratch_obstack);
916 build_static_name (basetype, name)
919 char *basename = build_overload_name (basetype, 1, 1);
920 char *buf = (char *) alloca (IDENTIFIER_LENGTH (name)
921 + sizeof (STATIC_NAME_FORMAT)
922 + strlen (basename));
923 sprintf (buf, STATIC_NAME_FORMAT, basename, IDENTIFIER_POINTER (name));
924 return get_identifier (buf);
927 /* Generate an identifier that encodes the (ANSI) exception TYPE. */
929 /* This should be part of `ansi_opname', or at least be defined by the std. */
930 #define EXCEPTION_NAME_PREFIX "__ex"
931 #define EXCEPTION_NAME_LENGTH 4
934 cplus_exception_name (type)
938 OB_PUTS (EXCEPTION_NAME_PREFIX);
939 return get_identifier (build_overload_name (type, 0, 1));
942 /* Change the name of a function definition so that it may be
943 overloaded. NAME is the name of the function to overload,
944 PARMS is the parameter list (which determines what name the
945 final function obtains).
947 FOR_METHOD is 1 if this overload is being performed
948 for a method, rather than a function type. It is 2 if
949 this overload is being performed for a constructor. */
951 build_decl_overload (dname, parms, for_method)
956 char *name = IDENTIFIER_POINTER (dname);
958 /* member operators new and delete look like methods at this point. */
959 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST)
961 if (dname == ansi_opname[(int) DELETE_EXPR])
962 return get_identifier ("__builtin_delete");
963 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
964 return get_identifier ("__builtin_vec_delete");
965 else if (TREE_CHAIN (parms) == void_list_node)
967 if (dname == ansi_opname[(int) NEW_EXPR])
968 return get_identifier ("__builtin_new");
969 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
970 return get_identifier ("__builtin_vec_new");
977 /* Otherwise, we can divine that this is a constructor,
978 and figure out its name without any extra encoding. */
984 /* We can get away without doing this. */
988 tree this_type = TREE_VALUE (parms);
990 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
991 parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type),
994 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type),
1001 if (parms == NULL_TREE)
1002 OB_PUTC2 ('e', '\0');
1003 else if (parms == void_list_node)
1004 OB_PUTC2 ('v', '\0');
1007 ALLOCATE_TYPEVEC (parms);
1011 build_overload_name (TREE_VALUE (parms), 0, 0);
1013 typevec[maxtype++] = TREE_VALUE (parms);
1014 TREE_USED (TREE_VALUE (parms)) = 1;
1016 if (TREE_CHAIN (parms))
1017 build_overload_name (TREE_CHAIN (parms), 0, 1);
1019 OB_PUTC2 ('e', '\0');
1022 build_overload_name (parms, 0, 1);
1023 DEALLOCATE_TYPEVEC (parms);
1026 tree n = get_identifier (obstack_base (&scratch_obstack));
1027 if (IDENTIFIER_OPNAME_P (dname))
1028 IDENTIFIER_OPNAME_P (n) = 1;
1033 /* Build an overload name for the type expression TYPE. */
1035 build_typename_overload (type)
1041 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1043 build_overload_name (type, 0, 1);
1044 id = get_identifier (obstack_base (&scratch_obstack));
1045 IDENTIFIER_OPNAME_P (id) = 1;
1047 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_NAME (type);
1049 TREE_TYPE (id) = type;
1053 #ifndef NO_DOLLAR_IN_LABEL
1054 #define T_DESC_FORMAT "TD$"
1055 #define I_DESC_FORMAT "ID$"
1056 #define M_DESC_FORMAT "MD$"
1058 #if !defined(NO_DOT_IN_LABEL)
1059 #define T_DESC_FORMAT "TD."
1060 #define I_DESC_FORMAT "ID."
1061 #define M_DESC_FORMAT "MD."
1063 #define T_DESC_FORMAT "__t_desc_"
1064 #define I_DESC_FORMAT "__i_desc_"
1065 #define M_DESC_FORMAT "__m_desc_"
1069 /* Build an overload name for the type expression TYPE. */
1071 build_t_desc_overload (type)
1075 OB_PUTS (T_DESC_FORMAT);
1079 /* Use a different format if the type isn't defined yet. */
1080 if (TYPE_SIZE (type) == NULL_TREE)
1085 for (p = tname; *p; p++)
1091 /* If there's no change, we have an inappropriate T_DESC_FORMAT. */
1092 my_friendly_assert (changed != 0, 249);
1096 build_overload_name (type, 0, 1);
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);
1260 rval = build_method_call
1261 (build_indirect_ref (build1 (NOP_EXPR, TREE_TYPE (xarg1),
1264 fnname, tree_cons (NULL_TREE, xarg1,
1265 build_tree_list (NULL_TREE, xarg2)),
1268 /* This can happen when operator delete is protected. */
1269 my_friendly_assert (rval != error_mark_node, 250);
1270 TREE_TYPE (rval) = void_type_node;
1277 binary_is_unary = 0;
1278 try_second = tree_code_length [(int) code] == 2;
1279 if (try_second && xarg2 == error_mark_node)
1280 return error_mark_node;
1284 if (try_second && xarg2 == error_mark_node)
1285 return error_mark_node;
1287 /* What ever it was, we do not know how to deal with it. */
1288 if (type1 == NULL_TREE)
1291 if (TREE_CODE (type1) == OFFSET_TYPE)
1292 type1 = TREE_TYPE (type1);
1294 if (TREE_CODE (type1) == REFERENCE_TYPE)
1296 arg1 = convert_from_reference (xarg1);
1297 type1 = TREE_TYPE (arg1);
1304 if (!IS_AGGR_TYPE (type1) || TYPE_PTRMEMFUNC_P (type1))
1306 /* Try to fail. First, fail if unary */
1309 /* Second, see if second argument is non-aggregate. */
1310 type2 = TREE_TYPE (xarg2);
1311 if (TREE_CODE (type2) == OFFSET_TYPE)
1312 type2 = TREE_TYPE (type2);
1313 if (TREE_CODE (type2) == REFERENCE_TYPE)
1315 arg2 = convert_from_reference (xarg2);
1316 type2 = TREE_TYPE (arg2);
1323 if (!IS_AGGR_TYPE (type2))
1330 /* First arg may succeed; see whether second should. */
1331 type2 = TREE_TYPE (xarg2);
1332 if (TREE_CODE (type2) == OFFSET_TYPE)
1333 type2 = TREE_TYPE (type2);
1334 if (TREE_CODE (type2) == REFERENCE_TYPE)
1336 arg2 = convert_from_reference (xarg2);
1337 type2 = TREE_TYPE (arg2);
1344 if (! IS_AGGR_TYPE (type2))
1348 if (type1 == unknown_type_node
1349 || (try_second && TREE_TYPE (xarg2) == unknown_type_node))
1351 /* This will not be implemented in the foreseeable future. */
1355 if (code == MODIFY_EXPR)
1356 fnname = ansi_assopname[(int) TREE_CODE (arg3)];
1358 fnname = ansi_opname[(int) code];
1360 global_fn = lookup_name_nonclass (fnname);
1362 /* This is the last point where we will accept failure. This
1363 may be too eager if we wish an overloaded operator not to match,
1364 but would rather a normal operator be called on a type-converted
1367 if (IS_AGGR_TYPE (type1))
1369 fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0);
1370 /* ARM $13.4.7, prefix/postfix ++/--. */
1371 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
1373 xarg2 = integer_zero_node;
1374 binary_is_unary = 0;
1379 int have_postfix = 0;
1381 /* Look for an `operator++ (int)'. If they didn't have
1382 one, then we fall back to the old way of doing things. */
1383 for (t = TREE_VALUE (fields1); t ; t = DECL_CHAIN (t))
1385 t2 = TYPE_ARG_TYPES (TREE_TYPE (t));
1386 if (TREE_CHAIN (t2) != NULL_TREE
1387 && TREE_VALUE (TREE_CHAIN (t2)) == integer_type_node)
1396 char *op = POSTINCREMENT_EXPR ? "++" : "--";
1398 /* There's probably a LOT of code in the world that
1399 relies upon this old behavior. */
1400 if (! flag_traditional)
1401 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1404 binary_is_unary = 1;
1410 if (fields1 == NULL_TREE && global_fn == NULL_TREE)
1413 /* If RVAL winds up being `error_mark_node', we will return
1414 that... There is no way that normal semantics of these
1415 operators will succeed. */
1417 /* This argument may be an uncommitted OFFSET_REF. This is
1418 the case for example when dealing with static class members
1419 which are referenced from their class name rather than
1420 from a class instance. */
1421 if (TREE_CODE (xarg1) == OFFSET_REF
1422 && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL)
1423 xarg1 = TREE_OPERAND (xarg1, 1);
1424 if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF
1425 && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL)
1426 xarg2 = TREE_OPERAND (xarg2, 1);
1429 flags |= LOOKUP_GLOBAL;
1431 if (code == CALL_EXPR)
1433 /* This can only be a member function. */
1434 return build_method_call (xarg1, fnname, xarg2,
1435 NULL_TREE, LOOKUP_NORMAL);
1437 else if (tree_code_length[(int) code] == 1 || binary_is_unary)
1440 rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags);
1442 else if (code == COND_EXPR)
1444 parms = tree_cons (0, xarg2, build_tree_list (NULL_TREE, arg3));
1445 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1447 else if (code == METHOD_CALL_EXPR)
1449 /* must be a member function. */
1450 parms = tree_cons (NULL_TREE, xarg2, arg3);
1451 return build_method_call (xarg1, fnname, parms, NULL_TREE,
1456 parms = build_tree_list (NULL_TREE, xarg2);
1457 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
1461 parms = tree_cons (NULL_TREE, xarg1,
1462 build_tree_list (NULL_TREE, xarg2));
1463 rval = build_overload_call (fnname, parms, flags,
1464 (struct candidate *)0);
1470 /* This function takes an identifier, ID, and attempts to figure out what
1471 it means. There are a number of possible scenarios, presented in increasing
1474 1) not in a class's scope
1475 2) in class's scope, member name of the class's method
1476 3) in class's scope, but not a member name of the class
1477 4) in class's scope, member name of a class's variable
1479 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1480 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1481 yychar is the pending input character (suitably encoded :-).
1483 As a last ditch, try to look up the name as a label and return that
1486 Values which are declared as being of REFERENCE_TYPE are
1487 automatically dereferenced here (as a hack to make the
1488 compiler faster). */
1491 hack_identifier (value, name, yychar)
1497 if (TREE_CODE (value) == ERROR_MARK)
1499 if (current_class_name)
1501 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1502 if (fields == error_mark_node)
1503 return error_mark_node;
1508 fndecl = TREE_VALUE (fields);
1509 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1510 if (DECL_CHAIN (fndecl) == NULL_TREE)
1512 warning ("methods cannot be converted to function pointers");
1517 error ("ambiguous request for method pointer `%s'",
1518 IDENTIFIER_POINTER (name));
1519 return error_mark_node;
1523 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1525 return IDENTIFIER_LABEL_VALUE (name);
1527 return error_mark_node;
1530 type = TREE_TYPE (value);
1531 if (TREE_CODE (value) == FIELD_DECL)
1533 if (current_class_decl == NULL_TREE)
1535 error ("request for member `%s' in static member function",
1536 IDENTIFIER_POINTER (DECL_NAME (value)));
1537 return error_mark_node;
1539 TREE_USED (current_class_decl) = 1;
1541 /* Mark so that if we are in a constructor, and then find that
1542 this field was initialized by a base initializer,
1543 we can emit an error message. */
1544 TREE_USED (value) = 1;
1545 return build_component_ref (C_C_D, name, 0, 1);
1548 if (really_overloaded_fn (value))
1550 tree t = get_first_fn (value);
1551 for (; t; t = DECL_CHAIN (t))
1553 if (TREE_CODE (t) == TEMPLATE_DECL)
1556 assemble_external (t);
1560 else if (TREE_CODE (value) == TREE_LIST)
1563 while (t && TREE_CODE (t) == TREE_LIST)
1565 assemble_external (TREE_VALUE (t));
1572 assemble_external (value);
1573 TREE_USED (value) = 1;
1576 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1578 if (DECL_LANG_SPECIFIC (value)
1579 && DECL_CLASS_CONTEXT (value) != current_class_type)
1582 enum access_type access;
1583 register tree context
1584 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1585 ? DECL_CLASS_CONTEXT (value)
1586 : DECL_CONTEXT (value);
1588 get_base_distance (context, current_class_type, 0, &path);
1591 access = compute_access (path, value);
1592 if (access != access_public)
1594 if (TREE_CODE (value) == VAR_DECL)
1595 error ("static member `%s' is %s",
1596 IDENTIFIER_POINTER (name),
1597 TREE_PRIVATE (value) ? "private" :
1598 "from a private base class");
1600 error ("enum `%s' is from private base class",
1601 IDENTIFIER_POINTER (name));
1602 return error_mark_node;
1608 if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1612 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1613 IDENTIFIER_POINTER (name));
1614 return error_mark_node;
1620 if (TREE_CODE (type) == REFERENCE_TYPE)
1622 my_friendly_assert (TREE_CODE (value) == VAR_DECL
1623 || TREE_CODE (value) == PARM_DECL
1624 || TREE_CODE (value) == RESULT_DECL, 252);
1625 return convert_from_reference (value);
1632 /* Given an object OF, and a type conversion operator COMPONENT
1633 build a call to the conversion operator, if a call is requested,
1634 or return the address (as a pointer to member function) if one is not.
1636 OF can be a TYPE_DECL or any kind of datum that would normally
1637 be passed to `build_component_ref'. It may also be NULL_TREE,
1638 in which case `current_class_type' and `current_class_decl'
1639 provide default values.
1641 BASETYPE_PATH, if non-null, is the path of basetypes
1642 to go through before we get the the instance of interest.
1644 PROTECT says whether we apply C++ scoping rules or not. */
1646 build_component_type_expr (of, component, basetype_path, protect)
1647 tree of, component, basetype_path;
1650 tree cname = NULL_TREE;
1653 int flags = protect ? LOOKUP_NORMAL : LOOKUP_COMPLAIN;
1656 my_friendly_assert (IS_AGGR_TYPE (TREE_TYPE (of)), 253);
1657 my_friendly_assert (TREE_CODE (component) == TYPE_EXPR, 254);
1659 tmp = TREE_OPERAND (component, 0);
1664 switch (TREE_CODE (tmp))
1668 TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
1670 TREE_OPERAND (component, 0) = TREE_OPERAND (tmp, 0);
1672 last = groktypename (build_tree_list (TREE_TYPE (component),
1673 TREE_OPERAND (component, 0)));
1674 name = build_typename_overload (last);
1675 TREE_TYPE (name) = last;
1677 if (TREE_OPERAND (tmp, 0)
1678 && TREE_OPERAND (tmp, 0) != void_list_node)
1680 cp_error ("`operator %T' requires empty parameter list", last);
1681 TREE_OPERAND (tmp, 0) = NULL_TREE;
1684 if (of && TREE_CODE (of) != TYPE_DECL)
1685 return build_method_call (of, name, NULL_TREE, NULL_TREE, flags);
1690 if (current_class_decl == NULL_TREE)
1692 cp_error ("object required for `operator %T' call",
1694 return error_mark_node;
1697 this_this = convert_pointer_to (TREE_TYPE (of),
1698 current_class_decl);
1699 this_this = build_indirect_ref (this_this, NULL_PTR);
1700 return build_method_call (this_this, name, NULL_TREE,
1701 NULL_TREE, flags | LOOKUP_NONVIRTUAL);
1703 else if (current_class_decl)
1704 return build_method_call (tmp, name, NULL_TREE, NULL_TREE, flags);
1706 cp_error ("object required for `operator %T' call",
1708 return error_mark_node;
1716 my_friendly_assert (cname == 0, 255);
1717 cname = TREE_OPERAND (tmp, 0);
1718 tmp = TREE_OPERAND (tmp, 1);
1722 my_friendly_abort (77);
1725 tmp = TREE_OPERAND (tmp, 0);
1728 last = groktypename (build_tree_list (TREE_TYPE (component), TREE_OPERAND (component, 0)));
1729 name = build_typename_overload (last);
1730 TREE_TYPE (name) = last;
1731 if (of && TREE_CODE (of) == TYPE_DECL)
1733 if (cname == NULL_TREE)
1735 cname = DECL_NAME (of);
1738 else my_friendly_assert (cname == DECL_NAME (of), 256);
1745 if (current_class_decl == NULL_TREE)
1747 cp_error ("object required for `operator %T' call",
1749 return error_mark_node;
1752 this_this = convert_pointer_to (TREE_TYPE (of), current_class_decl);
1753 return build_component_ref (this_this, name, 0, protect);
1756 return build_offset_ref (cname, name);
1757 else if (current_class_name)
1758 return build_offset_ref (current_class_name, name);
1760 cp_error ("object required for `operator %T' member reference",
1762 return error_mark_node;
1767 thunk_printable_name (decl)
1770 return "<thunk function>";
1774 make_thunk (function, delta)
1779 tree thunk_fndecl, thunk_id;
1782 static int thunk_number = 0;
1784 if (TREE_CODE (function) != ADDR_EXPR)
1786 func_decl = TREE_OPERAND (function, 0);
1787 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1789 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1791 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1793 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1794 thunk_id = get_identifier (buffer);
1795 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1796 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1798 error_with_decl ("implementation-reserved name `%s' used");
1799 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1801 if (thunk == NULL_TREE)
1803 thunk = build_decl (THUNK_DECL, thunk_id, TREE_TYPE (func_decl));
1805 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type)));
1806 TREE_READONLY (thunk) = TYPE_READONLY (TREE_TYPE (vtable_entry_type));
1807 TREE_THIS_VOLATILE (thunk) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type));
1808 make_function_rtl (thunk);
1809 DECL_INITIAL (thunk) = function;
1810 THUNK_DELTA (thunk) = delta;
1811 /* So that finish_file can write out any thunks that need to be: */
1812 pushdecl_top_level (thunk);
1818 emit_thunk (thunk_fndecl)
1825 struct args_size stack_args_size;
1826 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1827 int delta = THUNK_DELTA (thunk_fndecl);
1830 int current_call_is_indirect = 0; /* needed for HPPA FUNCTION_ARG */
1832 /* Used to remember which regs we need to emit a USE rtx for. */
1833 rtx need_use[FIRST_PSEUDO_REGISTER];
1834 int need_use_count = 0;
1836 /* rtx for the 'this' parameter. */
1837 rtx this_rtx = 0, this_reg_rtx = 0, fixed_this_rtx;
1839 char *(*save_decl_printable_name) () = decl_printable_name;
1840 /* Data on reg parms scanned so far. */
1841 CUMULATIVE_ARGS args_so_far;
1843 if (TREE_ASM_WRITTEN (thunk_fndecl))
1846 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1848 if (TREE_PUBLIC (function))
1850 TREE_PUBLIC (thunk_fndecl) = 1;
1851 if (DECL_EXTERNAL (function))
1853 DECL_EXTERNAL (thunk_fndecl) = 1;
1854 assemble_external (thunk_fndecl);
1859 decl_printable_name = thunk_printable_name;
1860 if (current_function_decl)
1862 current_function_decl = thunk_fndecl;
1863 init_function_start (thunk_fndecl, input_filename, lineno);
1865 expand_start_bindings (1);
1867 /* Start updating where the next arg would go. */
1868 INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (function), NULL_RTX);
1869 stack_args_size.constant = 0;
1870 stack_args_size.var = 0;
1871 /* SETUP for possible structure return address FIXME */
1873 /* Now look through all the parameters, make sure that we
1874 don't clobber any registers used for parameters.
1875 Also, pick up an rtx for the first "this" parameter. */
1876 for (argp = TYPE_ARG_TYPES (TREE_TYPE (function));
1878 argp = TREE_CHAIN (argp))
1881 tree passed_type = TREE_VALUE (argp);
1882 register rtx entry_parm;
1883 int named = 1; /* FIXME */
1884 struct args_size stack_offset;
1885 struct args_size arg_size;
1887 if (passed_type == void_type_node)
1890 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
1891 && contains_placeholder_p (TYPE_SIZE (passed_type)))
1892 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1893 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far,
1894 TYPE_MODE (passed_type),
1898 passed_type = build_pointer_type (passed_type);
1900 entry_parm = FUNCTION_ARG (args_so_far,
1901 TYPE_MODE (passed_type),
1904 if (entry_parm != 0)
1905 need_use[need_use_count++] = entry_parm;
1907 locate_and_pad_parm (TYPE_MODE (passed_type), passed_type,
1908 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1914 &stack_args_size, &stack_offset, &arg_size);
1916 /* REGNO (entry_parm);*/
1919 this_reg_rtx = entry_parm;
1922 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
1924 rtx internal_arg_pointer, stack_parm;
1926 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
1927 || ! (fixed_regs[ARG_POINTER_REGNUM]
1928 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
1929 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
1931 internal_arg_pointer = virtual_incoming_args_rtx;
1933 if (offset_rtx == const0_rtx)
1934 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1935 internal_arg_pointer);
1937 entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type),
1938 gen_rtx (PLUS, Pmode,
1939 internal_arg_pointer,
1943 this_rtx = entry_parm;
1946 FUNCTION_ARG_ADVANCE (args_so_far,
1947 TYPE_MODE (passed_type),
1952 fixed_this_rtx = plus_constant (this_rtx, delta);
1953 if (this_rtx != fixed_this_rtx)
1954 emit_move_insn (this_rtx, fixed_this_rtx);
1957 emit_insn (gen_rtx (USE, VOIDmode, this_reg_rtx));
1959 emit_indirect_jump (XEXP (DECL_RTL (function), 0));
1961 while (need_use_count > 0)
1962 emit_insn (gen_rtx (USE, VOIDmode, need_use[--need_use_count]));
1964 expand_end_bindings (NULL, 1, 0);
1967 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
1968 Note that that may have been done above, in save_for_inline_copying.
1969 The call to resume_temporary_allocation near the end of this function
1970 goes back to the usual state of affairs. */
1972 rtl_in_current_obstack ();
1974 insns = get_insns ();
1976 /* Copy any shared structure that should not be shared. */
1978 unshare_all_rtl (insns);
1980 /* Instantiate all virtual registers. */
1982 instantiate_virtual_regs (current_function_decl, get_insns ());
1984 /* We are no longer anticipating cse in this function, at least. */
1986 cse_not_expected = 1;
1988 /* Now we choose between stupid (pcc-like) register allocation
1989 (if we got the -noreg switch and not -opt)
1990 and smart register allocation. */
1992 if (optimize > 0) /* Stupid allocation probably won't work */
1993 obey_regdecls = 0; /* if optimizations being done. */
1997 regclass (insns, max_reg_num ());
2000 stupid_life_analysis (insns, max_reg_num (), NULL);
2001 failure = reload (insns, 0, NULL);
2005 /* Do control and data flow analysis,
2006 and write some of the results to dump file. */
2008 flow_analysis (insns, max_reg_num (), NULL);
2010 failure = global_alloc (NULL);
2013 reload_completed = 1;
2015 #ifdef LEAF_REGISTERS
2017 if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ())
2021 /* If a machine dependent reorganization is needed, call it. */
2022 #ifdef MACHINE_DEPENDENT_REORG
2023 MACHINE_DEPENDENT_REORG (insns);
2026 /* Now turn the rtl into assembler code. */
2029 char *fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2030 assemble_start_function (thunk_fndecl, fnname);
2031 final (insns, asm_out_file, optimize, 0);
2032 assemble_end_function (thunk_fndecl, fnname);
2035 exit_rest_of_compilation:
2037 reload_completed = 0;
2039 /* Cancel the effect of rtl_in_current_obstack. */
2041 resume_temporary_allocation ();
2043 decl_printable_name = save_decl_printable_name;
2044 current_function_decl = 0;
2047 /* Code for synthesizing methods which have default semantics defined. */
2049 /* For the anonymous union in TYPE, return the member that is at least as
2050 large as the rest of the members, so we can copy it. */
2052 largest_union_member (type)
2055 tree f, type_size = TYPE_SIZE (type);
2057 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
2058 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
2061 /* We should always find one. */
2062 my_friendly_abort (323);
2066 /* Generate code for default X(X&) constructor. */
2068 do_build_copy_constructor (fndecl)
2071 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2077 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2078 parm = TREE_CHAIN (parm);
2079 parm = convert_from_reference (parm);
2081 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2083 t = build (INIT_EXPR, void_type_node, C_C_D, parm);
2084 TREE_SIDE_EFFECTS (t) = 1;
2085 cplus_expand_expr_stmt (t);
2089 tree fields = TYPE_FIELDS (current_class_type);
2090 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2091 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2094 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2097 tree basetype = BINFO_TYPE (t);
2098 tree p = convert_to_reference
2099 (build_reference_type (basetype), parm,
2100 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2101 p = convert_from_reference (p);
2102 current_base_init_list = tree_cons (TYPE_NESTED_NAME (basetype),
2103 p, current_base_init_list);
2106 for (i = 0; i < n_bases; ++i)
2108 tree p, basetype = TREE_VEC_ELT (binfos, i);
2109 if (TREE_VIA_VIRTUAL (basetype))
2112 basetype = BINFO_TYPE (basetype);
2113 p = convert_to_reference
2114 (build_reference_type (basetype), parm,
2115 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2116 p = convert_from_reference (p);
2117 current_base_init_list = tree_cons (TYPE_NESTED_NAME (basetype),
2118 p, current_base_init_list);
2120 for (; fields; fields = TREE_CHAIN (fields))
2123 tree field = fields;
2125 if (TREE_CODE (field) != FIELD_DECL)
2127 if (DECL_NAME (field))
2129 if (VFIELD_NAME_P (DECL_NAME (field)))
2131 if (VBASE_NAME_P (DECL_NAME (field)))
2134 /* True for duplicate members. */
2135 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2138 else if ((t = TREE_TYPE (field)) != NULL_TREE
2139 && TREE_CODE (t) == UNION_TYPE
2140 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2141 && TYPE_FIELDS (t) != NULL_TREE)
2142 field = largest_union_member (t);
2146 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2147 init = build_tree_list (NULL_TREE, init);
2149 current_member_init_list
2150 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2152 current_member_init_list = nreverse (current_member_init_list);
2153 current_base_init_list = nreverse (current_base_init_list);
2161 do_build_assign_ref (fndecl)
2164 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2169 parm = convert_from_reference (parm);
2171 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2173 tree t = build (MODIFY_EXPR, void_type_node, C_C_D, parm);
2174 TREE_SIDE_EFFECTS (t) = 1;
2175 cplus_expand_expr_stmt (t);
2179 tree fields = TYPE_FIELDS (current_class_type);
2180 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2181 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2184 for (i = 0; i < n_bases; ++i)
2186 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2187 if (TYPE_HAS_ASSIGN_REF (basetype))
2189 tree p = convert_to_reference
2190 (build_reference_type (basetype), parm,
2191 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2192 p = convert_from_reference (p);
2193 p = build_member_call (TYPE_NESTED_NAME (basetype),
2194 ansi_opname [MODIFY_EXPR],
2195 build_tree_list (NULL_TREE, p));
2196 expand_expr_stmt (p);
2199 for (; fields; fields = TREE_CHAIN (fields))
2202 tree field = fields;
2204 if (TREE_CODE (field) != FIELD_DECL)
2206 if (DECL_NAME (field))
2208 if (VFIELD_NAME_P (DECL_NAME (field)))
2210 if (VBASE_NAME_P (DECL_NAME (field)))
2213 /* True for duplicate members. */
2214 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2217 else if ((t = TREE_TYPE (field)) != NULL_TREE
2218 && TREE_CODE (t) == UNION_TYPE
2219 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2220 && TYPE_FIELDS (t) != NULL_TREE)
2221 field = largest_union_member (t);
2225 comp = build (COMPONENT_REF, TREE_TYPE (field), C_C_D, field);
2226 init = build (COMPONENT_REF, TREE_TYPE (field), parm, field);
2228 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2231 c_expand_return (C_C_D);
2235 void push_cp_function_context ();
2236 void pop_cp_function_context ();
2239 synthesize_method (fndecl)
2242 int nested = (current_function_decl != NULL_TREE);
2243 tree context = decl_function_context (fndecl);
2244 char *f = input_filename;
2245 tree base = DECL_CLASS_CONTEXT (fndecl);
2248 push_cp_function_context (context);
2250 input_filename = DECL_SOURCE_FILE (fndecl);
2251 interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (base);
2252 interface_only = CLASSTYPE_INTERFACE_ONLY (base);
2253 start_function (NULL_TREE, fndecl, NULL_TREE, NULL_TREE, 1);
2254 store_parm_decls ();
2256 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2257 do_build_assign_ref (fndecl);
2258 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2262 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2263 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2264 arg_chain = TREE_CHAIN (arg_chain);
2265 if (arg_chain != void_list_node)
2266 do_build_copy_constructor (fndecl);
2267 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2271 finish_function (lineno, 0, nested);
2273 /* Do we really *want* to inline this function? */
2274 if (DECL_INLINE (fndecl))
2276 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
2277 will check our size. */
2278 DECL_INLINE (fndecl) = 0;
2279 if (function_cannot_inline_p (fndecl) == 0)
2280 DECL_INLINE (fndecl) = 1;
2284 extract_interface_info ();
2286 pop_cp_function_context (context);