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 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
182 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
183 cp_error ("call to non-volatile %s `%#D' with volatile object",
184 name_kind
, cp
->function
);
186 cp_error ("call to non-const %s `%#D' with const object",
187 name_kind
, cp
->function
);
191 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
196 ttf
= TREE_CHAIN (ttf
);
197 tta
= TREE_CHAIN (tta
);
201 OB_PUTS ("bad argument ");
202 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
203 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
205 OB_PUTCP (digit_buffer
);
207 OB_PUTS (" for function `");
208 OB_PUTCP (decl_as_string (cp
->function
, 1));
209 OB_PUTS ("' (type was ");
211 /* Reset `i' so that type printing routines do the right thing. */
214 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
215 if (code
== ERROR_MARK
)
216 OB_PUTS ("(failed type instantiation)");
219 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
220 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
223 else OB_PUTS ("void");
227 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
228 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
229 obstack_object_size (&scratch_obstack
));
230 error (tmp_firstobj
);
233 /* Here is where overload code starts. */
235 /* Array of types seen so far in top-level call to `build_overload_name'.
236 Allocated and deallocated by caller. */
237 static tree
*typevec
;
239 /* Number of types interned by `build_overload_name' so far. */
242 /* Number of occurrences of last type seen. */
245 /* Nonzero if we should not try folding parameter types. */
248 #define ALLOCATE_TYPEVEC(PARMTYPES) \
249 do { maxtype = 0, nrepeats = 0; \
250 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
252 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
253 do { tree t = (PARMTYPES); \
254 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
257 /* Code to concatenate an asciified integer to a string. */
266 /* Handle this case first, to go really quickly. For many common values,
267 the result of i/10 below is 1. */
284 OB_PUTC ('0' + (i
% 10));
298 while (typevec
[tindex
] != type
)
316 static int numeric_output_need_bar
;
317 static void build_overload_identifier ();
320 build_overload_nested_name (decl
)
323 if (DECL_CONTEXT (decl
))
325 tree context
= DECL_CONTEXT (decl
);
326 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
327 context
= TYPE_MAIN_DECL (context
);
328 build_overload_nested_name (context
);
331 if (TREE_CODE (decl
) == FUNCTION_DECL
)
333 tree name
= DECL_ASSEMBLER_NAME (decl
);
335 extern int var_labelno
;
337 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), var_labelno
);
340 if (numeric_output_need_bar
)
343 numeric_output_need_bar
= 0;
345 icat (strlen (label
));
350 tree name
= DECL_NAME (decl
);
351 build_overload_identifier (name
);
355 /* Encoding for an INTEGER_CST value. */
357 build_overload_int (value
)
360 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
361 if (TYPE_PRECISION (value
) == 2 * HOST_BITS_PER_WIDE_INT
)
363 if (tree_int_cst_lt (value
, integer_zero_node
))
366 value
= build_int_2 (~ TREE_INT_CST_LOW (value
),
367 - TREE_INT_CST_HIGH (value
));
369 if (TREE_INT_CST_HIGH (value
)
370 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
372 /* need to print a DImode value in decimal */
373 sorry ("conversion of long long as PT parameter");
375 /* else fall through to print in smaller mode */
377 /* Wordsize or smaller */
378 icat (TREE_INT_CST_LOW (value
));
382 build_overload_value (type
, value
)
385 while (TREE_CODE (value
) == NON_LVALUE_EXPR
386 || TREE_CODE (value
) == NOP_EXPR
)
387 value
= TREE_OPERAND (value
, 0);
388 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
389 type
= TREE_TYPE (type
);
391 if (numeric_output_need_bar
)
394 numeric_output_need_bar
= 0;
397 if (TREE_CODE (type
) == POINTER_TYPE
398 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
400 /* Handle a pointer to data member as a template instantiation
401 parameter, boy, what fun! */
402 type
= integer_type_node
;
403 if (TREE_CODE (value
) != INTEGER_CST
)
405 sorry ("unknown pointer to member constant");
410 if (TYPE_PTRMEMFUNC_P (type
))
411 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
413 switch (TREE_CODE (type
))
419 build_overload_int (value
);
420 numeric_output_need_bar
= 1;
423 #ifndef REAL_IS_NOT_DOUBLE
427 char *bufp
= digit_buffer
;
428 extern char *index ();
430 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
431 val
= TREE_REAL_CST (value
);
437 sprintf (bufp
, "%e", val
);
438 bufp
= (char *) index (bufp
, 'e');
440 strcat (digit_buffer
, "e0");
466 OB_PUTCP (digit_buffer
);
467 numeric_output_need_bar
= 1;
472 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
473 && TREE_CODE (value
) != ADDR_EXPR
)
475 if (TREE_CODE (value
) == CONSTRUCTOR
)
477 /* This is dangerous code, crack built up pointer to members. */
478 tree args
= CONSTRUCTOR_ELTS (value
);
479 tree a1
= TREE_VALUE (args
);
480 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
481 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
482 a3
= TREE_VALUE (a3
);
484 if (TREE_CODE (a1
) == INTEGER_CST
485 && TREE_CODE (a2
) == INTEGER_CST
)
487 build_overload_int (a1
);
489 build_overload_int (a2
);
491 if (TREE_CODE (a3
) == ADDR_EXPR
)
493 a3
= TREE_OPERAND (a3
, 0);
494 if (TREE_CODE (a3
) == FUNCTION_DECL
)
496 numeric_output_need_bar
= 0;
497 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
501 else if (TREE_CODE (a3
) == INTEGER_CST
)
504 build_overload_int (a3
);
505 numeric_output_need_bar
= 1;
510 sorry ("template instantiation with pointer to method that is too complex");
513 if (TREE_CODE (value
) == INTEGER_CST
)
515 build_overload_int (value
);
516 numeric_output_need_bar
= 1;
519 value
= TREE_OPERAND (value
, 0);
520 if (TREE_CODE (value
) == VAR_DECL
)
522 my_friendly_assert (DECL_NAME (value
) != 0, 245);
523 build_overload_identifier (DECL_NAME (value
));
526 else if (TREE_CODE (value
) == FUNCTION_DECL
)
528 my_friendly_assert (DECL_NAME (value
) != 0, 246);
529 build_overload_identifier (DECL_NAME (value
));
533 my_friendly_abort (71);
534 break; /* not really needed */
537 sorry ("conversion of %s as template parameter",
538 tree_code_name
[(int) TREE_CODE (type
)]);
539 my_friendly_abort (72);
544 build_overload_identifier (name
)
547 if (IDENTIFIER_TEMPLATE (name
))
549 tree
template, parmlist
, arglist
, tname
;
551 template = IDENTIFIER_TEMPLATE (name
);
552 arglist
= TREE_VALUE (template);
553 template = TREE_PURPOSE (template);
554 tname
= DECL_NAME (template);
555 parmlist
= DECL_ARGUMENTS (template);
556 nparms
= TREE_VEC_LENGTH (parmlist
);
558 icat (IDENTIFIER_LENGTH (tname
));
561 for (i
= 0; i
< nparms
; i
++)
563 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
564 tree arg
= TREE_VEC_ELT (arglist
, i
);
565 if (TREE_CODE (parm
) == TYPE_DECL
)
567 /* This parameter is a type. */
569 build_overload_name (arg
, 0, 0);
573 parm
= tsubst (parm
, &TREE_VEC_ELT (arglist
, 0),
574 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
575 /* It's a PARM_DECL. */
576 build_overload_name (TREE_TYPE (parm
), 0, 0);
577 build_overload_value (parm
, arg
);
583 if (numeric_output_need_bar
)
586 numeric_output_need_bar
= 0;
588 icat (IDENTIFIER_LENGTH (name
));
593 /* Given a list of parameters in PARMTYPES, create an unambiguous
594 overload string. Should distinguish any type that C (or C++) can
595 distinguish. I.e., pointers to functions are treated correctly.
597 Caller must deal with whether a final `e' goes on the end or not.
599 Any default conversions must take place before this function
602 BEGIN and END control initialization and finalization of the
603 obstack where we build the string. */
606 build_overload_name (parmtypes
, begin
, end
)
613 if (begin
) OB_INIT ();
614 numeric_output_need_bar
= 0;
616 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
618 parmtype
= parmtypes
;
624 parmtype
= TREE_VALUE (parmtypes
);
628 if (! nofold
&& ! just_one
)
630 /* Every argument gets counted. */
631 typevec
[maxtype
++] = parmtype
;
633 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
640 flush_repeats (typevec
[maxtype
-2]);
642 if (TREE_USED (parmtype
))
644 flush_repeats (parmtype
);
648 /* Only cache types which take more than one character. */
649 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
650 || (TREE_CODE (parmtype
) != INTEGER_TYPE
651 && TREE_CODE (parmtype
) != REAL_TYPE
))
652 TREE_USED (parmtype
) = 1;
655 if (TYPE_PTRMEMFUNC_P (parmtype
))
656 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
658 if (TREE_READONLY (parmtype
))
660 if (TREE_CODE (parmtype
) == INTEGER_TYPE
661 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
663 if (TYPE_VOLATILE (parmtype
))
666 switch (TREE_CODE (parmtype
))
670 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
672 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
680 #if PARM_CAN_BE_ARRAY_TYPE
685 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
686 error ("pointer or reference to array of unknown bound in parm type");
689 length
= array_type_nelts (parmtype
);
690 if (TREE_CODE (length
) == INTEGER_CST
)
691 icat (TREE_INT_CST_LOW (length
) + 1);
704 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
710 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
711 /* Otherwise have to implement reentrant typevecs,
712 unmark and remark types, etc. */
713 int old_nofold
= nofold
;
717 flush_repeats (typevec
[maxtype
-1]);
719 /* @@ It may be possible to pass a function type in
720 which is not preceded by a 'P'. */
721 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
724 if (firstarg
== NULL_TREE
)
726 else if (firstarg
== void_list_node
)
729 build_overload_name (firstarg
, 0, 0);
733 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
734 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
736 firstarg
= TREE_CHAIN (firstarg
);
738 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
744 /* For cfront 2.0 compatibility. */
747 if (firstarg
== NULL_TREE
)
749 else if (firstarg
== void_list_node
)
752 build_overload_name (firstarg
, 0, 0);
755 /* Separate args from return type. */
757 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
763 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
764 if (parmtype
== integer_type_node
765 || parmtype
== unsigned_type_node
)
767 else if (parmtype
== long_integer_type_node
768 || parmtype
== long_unsigned_type_node
)
770 else if (parmtype
== short_integer_type_node
771 || parmtype
== short_unsigned_type_node
)
773 else if (parmtype
== signed_char_type_node
)
778 else if (parmtype
== char_type_node
779 || parmtype
== unsigned_char_type_node
)
781 else if (parmtype
== wchar_type_node
)
783 else if (parmtype
== long_long_integer_type_node
784 || parmtype
== long_long_unsigned_type_node
)
787 /* it would seem there is no way to enter these in source code,
789 else if (parmtype
== long_long_long_integer_type_node
790 || parmtype
== long_long_long_unsigned_type_node
)
794 my_friendly_abort (73);
802 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
803 if (parmtype
== long_double_type_node
)
805 else if (parmtype
== double_type_node
)
807 else if (parmtype
== float_type_node
)
809 else my_friendly_abort (74);
816 extern tree void_list_node
;
818 /* See if anybody is wasting memory. */
819 my_friendly_assert (parmtypes
== void_list_node
, 247);
821 /* This is the end of a parameter list. */
822 if (end
) OB_FINISH ();
823 return (char *)obstack_base (&scratch_obstack
);
828 case ERROR_MARK
: /* not right, but nothing is anyway */
831 /* have to do these */
835 /* Make this type signature look incompatible
842 tree name
= TYPE_NAME (parmtype
);
845 if (TREE_CODE (name
) == TYPE_DECL
)
849 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
850 if (DECL_ASSEMBLER_NAME (context
) != DECL_NAME (context
))
852 OB_PUTID (DECL_ASSEMBLER_NAME (context
));
855 while (DECL_CONTEXT (context
))
858 context
= DECL_CONTEXT (context
);
859 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
860 context
= TYPE_NAME (context
);
862 name
= DECL_NAME (name
);
864 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 248);
873 numeric_output_need_bar
= 0;
874 build_overload_nested_name (TYPE_MAIN_DECL (parmtype
));
877 build_overload_identifier (name
);
882 /* This will take some work. */
886 case TEMPLATE_TYPE_PARM
:
887 case TEMPLATE_CONST_PARM
:
888 case UNINSTANTIATED_P_TYPE
:
889 /* We don't ever want this output, but it's inconvenient not to
890 be able to build the string. This should cause assembler
891 errors we'll notice. */
894 sprintf (digit_buffer
, " *%d", n
++);
895 OB_PUTCP (digit_buffer
);
900 my_friendly_abort (75);
905 parmtypes
= TREE_CHAIN (parmtypes
);
910 flush_repeats (typevec
[maxtype
-1]);
912 /* To get here, parms must end with `...'. */
916 if (end
) OB_FINISH ();
917 return (char *)obstack_base (&scratch_obstack
);
921 build_static_name (basetype
, name
)
924 char *basename
= build_overload_name (basetype
, 1, 1);
925 char *buf
= (char *) alloca (IDENTIFIER_LENGTH (name
)
926 + sizeof (STATIC_NAME_FORMAT
)
927 + strlen (basename
));
928 sprintf (buf
, STATIC_NAME_FORMAT
, basename
, IDENTIFIER_POINTER (name
));
929 return get_identifier (buf
);
932 /* Change the name of a function definition so that it may be
933 overloaded. NAME is the name of the function to overload,
934 PARMS is the parameter list (which determines what name the
935 final function obtains).
937 FOR_METHOD is 1 if this overload is being performed
938 for a method, rather than a function type. It is 2 if
939 this overload is being performed for a constructor. */
941 build_decl_overload (dname
, parms
, for_method
)
946 char *name
= IDENTIFIER_POINTER (dname
);
948 /* member operators new and delete look like methods at this point. */
949 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
)
951 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
952 return get_identifier ("__builtin_delete");
953 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
954 return get_identifier ("__builtin_vec_delete");
955 else if (TREE_CHAIN (parms
) == void_list_node
)
957 if (dname
== ansi_opname
[(int) NEW_EXPR
])
958 return get_identifier ("__builtin_new");
959 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
960 return get_identifier ("__builtin_vec_new");
967 /* Otherwise, we can divine that this is a constructor,
968 and figure out its name without any extra encoding. */
974 /* We can get away without doing this. */
978 tree this_type
= TREE_VALUE (parms
);
980 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
981 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
984 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
991 if (parms
== NULL_TREE
)
992 OB_PUTC2 ('e', '\0');
993 else if (parms
== void_list_node
)
994 OB_PUTC2 ('v', '\0');
997 ALLOCATE_TYPEVEC (parms
);
1001 build_overload_name (TREE_VALUE (parms
), 0, 0);
1003 typevec
[maxtype
++] = TREE_VALUE (parms
);
1004 TREE_USED (TREE_VALUE (parms
)) = 1;
1006 if (TREE_CHAIN (parms
))
1007 build_overload_name (TREE_CHAIN (parms
), 0, 1);
1009 OB_PUTC2 ('e', '\0');
1012 build_overload_name (parms
, 0, 1);
1013 DEALLOCATE_TYPEVEC (parms
);
1016 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1017 if (IDENTIFIER_OPNAME_P (dname
))
1018 IDENTIFIER_OPNAME_P (n
) = 1;
1023 /* Build an overload name for the type expression TYPE. */
1025 build_typename_overload (type
)
1031 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1033 build_overload_name (type
, 0, 1);
1034 id
= get_identifier (obstack_base (&scratch_obstack
));
1035 IDENTIFIER_OPNAME_P (id
) = 1;
1037 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_NAME (type
);
1039 TREE_TYPE (id
) = type
;
1043 #ifndef NO_DOLLAR_IN_LABEL
1044 #define T_DESC_FORMAT "TD$"
1045 #define I_DESC_FORMAT "ID$"
1046 #define M_DESC_FORMAT "MD$"
1048 #if !defined(NO_DOT_IN_LABEL)
1049 #define T_DESC_FORMAT "TD."
1050 #define I_DESC_FORMAT "ID."
1051 #define M_DESC_FORMAT "MD."
1053 #define T_DESC_FORMAT "__t_desc_"
1054 #define I_DESC_FORMAT "__i_desc_"
1055 #define M_DESC_FORMAT "__m_desc_"
1059 /* Build an overload name for the type expression TYPE. */
1061 build_t_desc_overload (type
)
1065 OB_PUTS (T_DESC_FORMAT
);
1069 /* Use a different format if the type isn't defined yet. */
1070 if (TYPE_SIZE (type
) == NULL_TREE
)
1075 for (p
= tname
; *p
; p
++)
1081 /* If there's no change, we have an inappropriate T_DESC_FORMAT. */
1082 my_friendly_assert (changed
!= 0, 249);
1086 build_overload_name (type
, 0, 1);
1087 return get_identifier (obstack_base (&scratch_obstack
));
1090 /* Top-level interface to explicit overload requests. Allow NAME
1091 to be overloaded. Error if NAME is already declared for the current
1092 scope. Warning if function is redundantly overloaded. */
1095 declare_overloaded (name
)
1098 #ifdef NO_AUTO_OVERLOAD
1099 if (is_overloaded (name
))
1100 warning ("function `%s' already declared overloaded",
1101 IDENTIFIER_POINTER (name
));
1102 else if (IDENTIFIER_GLOBAL_VALUE (name
))
1103 error ("overloading function `%s' that is already defined",
1104 IDENTIFIER_POINTER (name
));
1107 TREE_OVERLOADED (name
) = 1;
1108 IDENTIFIER_GLOBAL_VALUE (name
) = build_tree_list (name
, NULL_TREE
);
1109 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name
)) = unknown_type_node
;
1112 if (current_lang_name
== lang_name_cplusplus
)
1115 warning ("functions are implicitly overloaded in C++");
1117 else if (current_lang_name
== lang_name_c
)
1118 error ("overloading function `%s' cannot be done in C language context");
1120 my_friendly_abort (76);
1124 #ifdef NO_AUTO_OVERLOAD
1125 /* Check to see if NAME is overloaded. For first approximation,
1126 check to see if its TREE_OVERLOADED is set. This is used on
1127 IDENTIFIER nodes. */
1129 is_overloaded (name
)
1133 return (TREE_OVERLOADED (name
)
1134 && (! IDENTIFIER_CLASS_VALUE (name
) || current_class_type
== 0)
1135 && ! IDENTIFIER_LOCAL_VALUE (name
));
1139 /* Given a tree_code CODE, and some arguments (at least one),
1140 attempt to use an overloaded operator on the arguments.
1142 For unary operators, only the first argument need be checked.
1143 For binary operators, both arguments may need to be checked.
1145 Member functions can convert class references to class pointers,
1146 for one-level deep indirection. More than that is not supported.
1147 Operators [](), ()(), and ->() must be member functions.
1149 We call function call building calls with LOOKUP_COMPLAIN if they
1150 are our only hope. This is true when we see a vanilla operator
1151 applied to something of aggregate type. If this fails, we are free
1152 to return `error_mark_node', because we will have reported the
1155 Operators NEW and DELETE overload in funny ways: operator new takes
1156 a single `size' parameter, and operator delete takes a pointer to the
1157 storage being deleted. When overloading these operators, success is
1158 assumed. If there is a failure, report an error message and return
1159 `error_mark_node'. */
1163 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1164 enum tree_code code
;
1166 tree xarg1
, xarg2
, arg3
;
1170 tree type1
, type2
, fnname
;
1171 tree fields1
= 0, parms
= 0;
1174 int binary_is_unary
;
1176 if (xarg1
== error_mark_node
)
1177 return error_mark_node
;
1179 if (code
== COND_EXPR
)
1181 if (TREE_CODE (xarg2
) == ERROR_MARK
1182 || TREE_CODE (arg3
) == ERROR_MARK
)
1183 return error_mark_node
;
1185 if (code
== COMPONENT_REF
)
1186 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1189 /* First, see if we can work with the first argument */
1190 type1
= TREE_TYPE (xarg1
);
1192 /* Some tree codes have length > 1, but we really only want to
1193 overload them if their first argument has a user defined type. */
1196 case PREINCREMENT_EXPR
:
1197 case PREDECREMENT_EXPR
:
1198 case POSTINCREMENT_EXPR
:
1199 case POSTDECREMENT_EXPR
:
1201 binary_is_unary
= 1;
1205 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1206 If they do not, return error_mark_node instead of NULL_TREE. */
1208 if (xarg2
== error_mark_node
)
1209 return error_mark_node
;
1211 rval
= error_mark_node
;
1212 binary_is_unary
= 0;
1219 tree args
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1220 fnname
= ansi_opname
[(int) code
];
1221 if (flags
& LOOKUP_GLOBAL
)
1222 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
,
1223 (struct candidate
*)0);
1225 rval
= build_method_call
1226 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1228 fnname
, args
, NULL_TREE
, flags
);
1229 if (rval
== error_mark_node
)
1230 /* User might declare fancy operator new, but invoke it
1231 like standard one. */
1234 TREE_TYPE (rval
) = xarg1
;
1235 TREE_CALLS_NEW (rval
) = 1;
1240 case VEC_DELETE_EXPR
:
1243 fnname
= ansi_opname
[(int) code
];
1244 if (flags
& LOOKUP_GLOBAL
)
1245 return build_overload_call (fnname
,
1246 build_tree_list (NULL_TREE
, xarg1
),
1247 flags
& LOOKUP_COMPLAIN
,
1248 (struct candidate
*)0);
1250 rval
= build_method_call
1251 (build_indirect_ref (build1 (NOP_EXPR
, TREE_TYPE (xarg1
),
1254 fnname
, tree_cons (NULL_TREE
, xarg1
,
1255 build_tree_list (NULL_TREE
, xarg2
)),
1258 /* This can happen when operator delete is protected. */
1259 my_friendly_assert (rval
!= error_mark_node
, 250);
1260 TREE_TYPE (rval
) = void_type_node
;
1267 binary_is_unary
= 0;
1268 try_second
= tree_code_length
[(int) code
] == 2;
1269 if (try_second
&& xarg2
== error_mark_node
)
1270 return error_mark_node
;
1274 if (try_second
&& xarg2
== error_mark_node
)
1275 return error_mark_node
;
1277 /* What ever it was, we do not know how to deal with it. */
1278 if (type1
== NULL_TREE
)
1281 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1282 type1
= TREE_TYPE (type1
);
1284 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1286 arg1
= convert_from_reference (xarg1
);
1287 type1
= TREE_TYPE (arg1
);
1294 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1296 /* Try to fail. First, fail if unary */
1299 /* Second, see if second argument is non-aggregate. */
1300 type2
= TREE_TYPE (xarg2
);
1301 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1302 type2
= TREE_TYPE (type2
);
1303 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1305 arg2
= convert_from_reference (xarg2
);
1306 type2
= TREE_TYPE (arg2
);
1313 if (!IS_AGGR_TYPE (type2
))
1320 /* First arg may succeed; see whether second should. */
1321 type2
= TREE_TYPE (xarg2
);
1322 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1323 type2
= TREE_TYPE (type2
);
1324 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1326 arg2
= convert_from_reference (xarg2
);
1327 type2
= TREE_TYPE (arg2
);
1334 if (! IS_AGGR_TYPE (type2
))
1338 if (type1
== unknown_type_node
1339 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1341 /* This will not be implemented in the foreseeable future. */
1345 if (code
== MODIFY_EXPR
)
1346 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1348 fnname
= ansi_opname
[(int) code
];
1350 global_fn
= lookup_name_nonclass (fnname
);
1352 /* This is the last point where we will accept failure. This
1353 may be too eager if we wish an overloaded operator not to match,
1354 but would rather a normal operator be called on a type-converted
1357 if (IS_AGGR_TYPE (type1
))
1359 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1360 /* ARM $13.4.7, prefix/postfix ++/--. */
1361 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1363 xarg2
= integer_zero_node
;
1364 binary_is_unary
= 0;
1369 int have_postfix
= 0;
1371 /* Look for an `operator++ (int)'. If they didn't have
1372 one, then we fall back to the old way of doing things. */
1373 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1375 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1376 if (TREE_CHAIN (t2
) != NULL_TREE
1377 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1386 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1388 /* There's probably a LOT of code in the world that
1389 relies upon this old behavior. */
1390 if (! flag_traditional
)
1391 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1394 binary_is_unary
= 1;
1400 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1403 /* If RVAL winds up being `error_mark_node', we will return
1404 that... There is no way that normal semantics of these
1405 operators will succeed. */
1407 /* This argument may be an uncommitted OFFSET_REF. This is
1408 the case for example when dealing with static class members
1409 which are referenced from their class name rather than
1410 from a class instance. */
1411 if (TREE_CODE (xarg1
) == OFFSET_REF
1412 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1413 xarg1
= TREE_OPERAND (xarg1
, 1);
1414 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1415 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1416 xarg2
= TREE_OPERAND (xarg2
, 1);
1419 flags
|= LOOKUP_GLOBAL
;
1421 if (code
== CALL_EXPR
)
1423 /* This can only be a member function. */
1424 return build_method_call (xarg1
, fnname
, xarg2
,
1425 NULL_TREE
, LOOKUP_NORMAL
);
1427 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1430 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1432 else if (code
== COND_EXPR
)
1434 parms
= tree_cons (0, xarg2
, build_tree_list (NULL_TREE
, arg3
));
1435 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1437 else if (code
== METHOD_CALL_EXPR
)
1439 /* must be a member function. */
1440 parms
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1441 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1446 parms
= build_tree_list (NULL_TREE
, xarg2
);
1447 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1451 parms
= tree_cons (NULL_TREE
, xarg1
,
1452 build_tree_list (NULL_TREE
, xarg2
));
1453 rval
= build_overload_call (fnname
, parms
, flags
,
1454 (struct candidate
*)0);
1460 /* This function takes an identifier, ID, and attempts to figure out what
1461 it means. There are a number of possible scenarios, presented in increasing
1464 1) not in a class's scope
1465 2) in class's scope, member name of the class's method
1466 3) in class's scope, but not a member name of the class
1467 4) in class's scope, member name of a class's variable
1469 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1470 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1471 yychar is the pending input character (suitably encoded :-).
1473 As a last ditch, try to look up the name as a label and return that
1476 Values which are declared as being of REFERENCE_TYPE are
1477 automatically dereferenced here (as a hack to make the
1478 compiler faster). */
1481 hack_identifier (value
, name
, yychar
)
1487 if (TREE_CODE (value
) == ERROR_MARK
)
1489 if (current_class_name
)
1491 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1492 if (fields
== error_mark_node
)
1493 return error_mark_node
;
1498 fndecl
= TREE_VALUE (fields
);
1499 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1500 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1502 warning ("methods cannot be converted to function pointers");
1507 error ("ambiguous request for method pointer `%s'",
1508 IDENTIFIER_POINTER (name
));
1509 return error_mark_node
;
1513 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1515 return IDENTIFIER_LABEL_VALUE (name
);
1517 return error_mark_node
;
1520 type
= TREE_TYPE (value
);
1521 if (TREE_CODE (value
) == FIELD_DECL
)
1523 if (current_class_decl
== NULL_TREE
)
1525 error ("request for member `%s' in static member function",
1526 IDENTIFIER_POINTER (DECL_NAME (value
)));
1527 return error_mark_node
;
1529 TREE_USED (current_class_decl
) = 1;
1531 /* Mark so that if we are in a constructor, and then find that
1532 this field was initialized by a base initializer,
1533 we can emit an error message. */
1534 TREE_USED (value
) = 1;
1535 return build_component_ref (C_C_D
, name
, 0, 1);
1538 if (really_overloaded_fn (value
))
1541 tree t
= get_first_fn (value
);
1542 for (; t
; t
= DECL_CHAIN (t
))
1544 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1547 assemble_external (t
);
1552 else if (TREE_CODE (value
) == TREE_LIST
)
1554 /* Ambiguous reference to base members, possibly other cases?. */
1556 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1558 mark_used (TREE_VALUE (t
));
1565 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1567 if (DECL_LANG_SPECIFIC (value
)
1568 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1571 register tree context
1572 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1573 ? DECL_CLASS_CONTEXT (value
)
1574 : DECL_CONTEXT (value
);
1576 get_base_distance (context
, current_class_type
, 0, &path
);
1579 access
= compute_access (path
, value
);
1580 if (access
!= access_public_node
)
1582 if (TREE_CODE (value
) == VAR_DECL
)
1583 error ("static member `%s' is %s",
1584 IDENTIFIER_POINTER (name
),
1585 TREE_PRIVATE (value
) ? "private" :
1586 "from a private base class");
1588 error ("enum `%s' is from private base class",
1589 IDENTIFIER_POINTER (name
));
1590 return error_mark_node
;
1596 if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1600 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1601 IDENTIFIER_POINTER (name
));
1602 return error_mark_node
;
1608 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1610 my_friendly_assert (TREE_CODE (value
) == VAR_DECL
1611 || TREE_CODE (value
) == PARM_DECL
1612 || TREE_CODE (value
) == RESULT_DECL
, 252);
1613 return convert_from_reference (value
);
1620 /* Given an object OF, and a type conversion operator COMPONENT
1621 build a call to the conversion operator, if a call is requested,
1622 or return the address (as a pointer to member function) if one is not.
1624 OF can be a TYPE_DECL or any kind of datum that would normally
1625 be passed to `build_component_ref'. It may also be NULL_TREE,
1626 in which case `current_class_type' and `current_class_decl'
1627 provide default values.
1629 BASETYPE_PATH, if non-null, is the path of basetypes
1630 to go through before we get the the instance of interest.
1632 PROTECT says whether we apply C++ scoping rules or not. */
1634 build_component_type_expr (of
, component
, basetype_path
, protect
)
1635 tree of
, component
, basetype_path
;
1638 tree cname
= NULL_TREE
;
1641 int flags
= protect
? LOOKUP_NORMAL
: LOOKUP_COMPLAIN
;
1644 my_friendly_assert (IS_AGGR_TYPE (TREE_TYPE (of
)), 253);
1645 my_friendly_assert (TREE_CODE (component
) == TYPE_EXPR
, 254);
1647 tmp
= TREE_OPERAND (component
, 0);
1652 switch (TREE_CODE (tmp
))
1656 TREE_OPERAND (last
, 0) = TREE_OPERAND (tmp
, 0);
1658 TREE_OPERAND (component
, 0) = TREE_OPERAND (tmp
, 0);
1660 last
= groktypename (build_tree_list (TREE_TYPE (component
),
1661 TREE_OPERAND (component
, 0)));
1662 name
= build_typename_overload (last
);
1663 TREE_TYPE (name
) = last
;
1665 if (TREE_OPERAND (tmp
, 0)
1666 && TREE_OPERAND (tmp
, 0) != void_list_node
)
1668 cp_error ("`operator %T' requires empty parameter list", last
);
1669 TREE_OPERAND (tmp
, 0) = NULL_TREE
;
1672 if (of
&& TREE_CODE (of
) != TYPE_DECL
)
1673 return build_method_call (of
, name
, NULL_TREE
, NULL_TREE
, flags
);
1678 if (current_class_decl
== NULL_TREE
)
1680 cp_error ("object required for `operator %T' call",
1682 return error_mark_node
;
1685 this_this
= convert_pointer_to (TREE_TYPE (of
),
1686 current_class_decl
);
1687 this_this
= build_indirect_ref (this_this
, NULL_PTR
);
1688 return build_method_call (this_this
, name
, NULL_TREE
,
1689 NULL_TREE
, flags
| LOOKUP_NONVIRTUAL
);
1691 else if (current_class_decl
)
1692 return build_method_call (tmp
, name
, NULL_TREE
, NULL_TREE
, flags
);
1694 cp_error ("object required for `operator %T' call",
1696 return error_mark_node
;
1704 my_friendly_assert (cname
== 0, 255);
1705 cname
= TREE_OPERAND (tmp
, 0);
1706 tmp
= TREE_OPERAND (tmp
, 1);
1710 my_friendly_abort (77);
1713 tmp
= TREE_OPERAND (tmp
, 0);
1716 last
= groktypename (build_tree_list (TREE_TYPE (component
), TREE_OPERAND (component
, 0)));
1717 name
= build_typename_overload (last
);
1718 TREE_TYPE (name
) = last
;
1719 if (of
&& TREE_CODE (of
) == TYPE_DECL
)
1721 if (cname
== NULL_TREE
)
1723 cname
= DECL_NAME (of
);
1726 else my_friendly_assert (cname
== DECL_NAME (of
), 256);
1733 if (current_class_decl
== NULL_TREE
)
1735 cp_error ("object required for `operator %T' call",
1737 return error_mark_node
;
1740 this_this
= convert_pointer_to (TREE_TYPE (of
), current_class_decl
);
1741 return build_component_ref (this_this
, name
, 0, protect
);
1744 return build_offset_ref (cname
, name
);
1745 else if (current_class_name
)
1746 return build_offset_ref (current_class_name
, name
);
1748 cp_error ("object required for `operator %T' member reference",
1750 return error_mark_node
;
1755 thunk_printable_name (decl
)
1758 return "<thunk function>";
1762 make_thunk (function
, delta
)
1767 tree thunk_fndecl
, thunk_id
;
1770 static int thunk_number
= 0;
1772 if (TREE_CODE (function
) != ADDR_EXPR
)
1774 func_decl
= TREE_OPERAND (function
, 0);
1775 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1777 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1779 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1781 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1782 thunk_id
= get_identifier (buffer
);
1783 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1784 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1786 error_with_decl ("implementation-reserved name `%s' used");
1787 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1789 if (thunk
== NULL_TREE
)
1791 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1793 = build_decl (RESULT_DECL
, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type
)));
1794 TREE_READONLY (thunk
) = TYPE_READONLY (TREE_TYPE (vtable_entry_type
));
1795 TREE_THIS_VOLATILE (thunk
) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type
));
1796 make_function_rtl (thunk
);
1797 TREE_SET_CODE (thunk
, THUNK_DECL
);
1798 DECL_INITIAL (thunk
) = function
;
1799 THUNK_DELTA (thunk
) = delta
;
1800 DECL_EXTERNAL (thunk
) = 1;
1801 TREE_PUBLIC (thunk
) = 1;
1802 /* So that finish_file can write out any thunks that need to be: */
1803 pushdecl_top_level (thunk
);
1809 emit_thunk (thunk_fndecl
)
1816 struct args_size stack_args_size
;
1817 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1818 int delta
= THUNK_DELTA (thunk_fndecl
);
1821 int current_call_is_indirect
= 0; /* needed for HPPA FUNCTION_ARG */
1823 /* Used to remember which regs we need to emit a USE rtx for. */
1824 rtx need_use
[FIRST_PSEUDO_REGISTER
];
1825 int need_use_count
= 0;
1827 /* rtx for the 'this' parameter. */
1828 rtx this_rtx
= 0, this_reg_rtx
= 0, fixed_this_rtx
;
1830 char *(*save_decl_printable_name
) () = decl_printable_name
;
1831 /* Data on reg parms scanned so far. */
1832 CUMULATIVE_ARGS args_so_far
;
1834 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1837 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1839 if (! TREE_PUBLIC (function
))
1840 TREE_PUBLIC (thunk_fndecl
) = 0;
1841 if (DECL_EXTERNAL (function
))
1843 DECL_EXTERNAL (thunk_fndecl
) = 0;
1845 decl_printable_name
= thunk_printable_name
;
1846 if (current_function_decl
)
1848 current_function_decl
= thunk_fndecl
;
1849 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1851 expand_start_bindings (1);
1853 /* Start updating where the next arg would go. */
1854 INIT_CUMULATIVE_ARGS (args_so_far
, TREE_TYPE (function
), NULL_RTX
);
1855 stack_args_size
.constant
= 0;
1856 stack_args_size
.var
= 0;
1857 /* SETUP for possible structure return address FIXME */
1859 /* Now look through all the parameters, make sure that we
1860 don't clobber any registers used for parameters.
1861 Also, pick up an rtx for the first "this" parameter. */
1862 for (argp
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1864 argp
= TREE_CHAIN (argp
))
1867 tree passed_type
= TREE_VALUE (argp
);
1868 register rtx entry_parm
;
1869 int named
= 1; /* FIXME */
1870 struct args_size stack_offset
;
1871 struct args_size arg_size
;
1873 if (passed_type
== void_type_node
)
1876 if ((TREE_CODE (TYPE_SIZE (passed_type
)) != INTEGER_CST
1877 && contains_placeholder_p (TYPE_SIZE (passed_type
)))
1878 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1879 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far
,
1880 TYPE_MODE (passed_type
),
1884 passed_type
= build_pointer_type (passed_type
);
1886 entry_parm
= FUNCTION_ARG (args_so_far
,
1887 TYPE_MODE (passed_type
),
1890 if (entry_parm
!= 0)
1891 need_use
[need_use_count
++] = entry_parm
;
1893 locate_and_pad_parm (TYPE_MODE (passed_type
), passed_type
,
1894 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1900 &stack_args_size
, &stack_offset
, &arg_size
);
1902 /* REGNO (entry_parm);*/
1905 this_reg_rtx
= entry_parm
;
1908 rtx offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
1910 rtx internal_arg_pointer
, stack_parm
;
1912 if ((ARG_POINTER_REGNUM
== STACK_POINTER_REGNUM
1913 || ! (fixed_regs
[ARG_POINTER_REGNUM
]
1914 || ARG_POINTER_REGNUM
== FRAME_POINTER_REGNUM
)))
1915 internal_arg_pointer
= copy_to_reg (virtual_incoming_args_rtx
);
1917 internal_arg_pointer
= virtual_incoming_args_rtx
;
1919 if (offset_rtx
== const0_rtx
)
1920 entry_parm
= gen_rtx (MEM
, TYPE_MODE (passed_type
),
1921 internal_arg_pointer
);
1923 entry_parm
= gen_rtx (MEM
, TYPE_MODE (passed_type
),
1924 gen_rtx (PLUS
, Pmode
,
1925 internal_arg_pointer
,
1929 this_rtx
= entry_parm
;
1932 FUNCTION_ARG_ADVANCE (args_so_far
,
1933 TYPE_MODE (passed_type
),
1938 fixed_this_rtx
= plus_constant (this_rtx
, delta
);
1939 if (this_rtx
!= fixed_this_rtx
)
1940 emit_move_insn (this_rtx
, fixed_this_rtx
);
1943 emit_insn (gen_rtx (USE
, VOIDmode
, this_reg_rtx
));
1945 emit_indirect_jump (XEXP (DECL_RTL (function
), 0));
1947 while (need_use_count
> 0)
1948 emit_insn (gen_rtx (USE
, VOIDmode
, need_use
[--need_use_count
]));
1950 expand_end_bindings (NULL
, 1, 0);
1953 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
1954 Note that that may have been done above, in save_for_inline_copying.
1955 The call to resume_temporary_allocation near the end of this function
1956 goes back to the usual state of affairs. */
1958 rtl_in_current_obstack ();
1960 insns
= get_insns ();
1962 /* Copy any shared structure that should not be shared. */
1964 unshare_all_rtl (insns
);
1966 /* Instantiate all virtual registers. */
1968 instantiate_virtual_regs (current_function_decl
, get_insns ());
1970 /* We are no longer anticipating cse in this function, at least. */
1972 cse_not_expected
= 1;
1974 /* Now we choose between stupid (pcc-like) register allocation
1975 (if we got the -noreg switch and not -opt)
1976 and smart register allocation. */
1978 if (optimize
> 0) /* Stupid allocation probably won't work */
1979 obey_regdecls
= 0; /* if optimizations being done. */
1983 regclass (insns
, max_reg_num ());
1986 stupid_life_analysis (insns
, max_reg_num (), NULL
);
1987 failure
= reload (insns
, 0, NULL
);
1991 /* Do control and data flow analysis,
1992 and write some of the results to dump file. */
1994 flow_analysis (insns
, max_reg_num (), NULL
);
1996 failure
= global_alloc (NULL
);
1999 reload_completed
= 1;
2001 #ifdef LEAF_REGISTERS
2003 if (optimize
> 0 && only_leaf_regs_used () && leaf_function_p ())
2007 /* If a machine dependent reorganization is needed, call it. */
2008 #ifdef MACHINE_DEPENDENT_REORG
2009 MACHINE_DEPENDENT_REORG (insns
);
2012 /* Now turn the rtl into assembler code. */
2015 char *fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
2016 assemble_start_function (thunk_fndecl
, fnname
);
2017 final (insns
, asm_out_file
, optimize
, 0);
2018 assemble_end_function (thunk_fndecl
, fnname
);
2021 exit_rest_of_compilation
:
2023 reload_completed
= 0;
2025 /* Cancel the effect of rtl_in_current_obstack. */
2027 resume_temporary_allocation ();
2029 decl_printable_name
= save_decl_printable_name
;
2030 current_function_decl
= 0;
2033 /* Code for synthesizing methods which have default semantics defined. */
2035 /* For the anonymous union in TYPE, return the member that is at least as
2036 large as the rest of the members, so we can copy it. */
2038 largest_union_member (type
)
2041 tree f
, type_size
= TYPE_SIZE (type
);
2043 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2044 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2047 /* We should always find one. */
2048 my_friendly_abort (323);
2052 /* Generate code for default X(X&) constructor. */
2054 do_build_copy_constructor (fndecl
)
2057 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2063 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2064 parm
= TREE_CHAIN (parm
);
2065 parm
= convert_from_reference (parm
);
2067 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2069 t
= build (INIT_EXPR
, void_type_node
, C_C_D
, parm
);
2070 TREE_SIDE_EFFECTS (t
) = 1;
2071 cplus_expand_expr_stmt (t
);
2075 tree fields
= TYPE_FIELDS (current_class_type
);
2076 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2077 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2080 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2083 tree basetype
= BINFO_TYPE (t
);
2084 tree p
= convert_to_reference
2085 (build_reference_type (basetype
), parm
,
2086 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2087 p
= convert_from_reference (p
);
2088 current_base_init_list
= tree_cons (basetype
,
2089 p
, current_base_init_list
);
2092 for (i
= 0; i
< n_bases
; ++i
)
2094 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2095 if (TREE_VIA_VIRTUAL (basetype
))
2098 basetype
= BINFO_TYPE (basetype
);
2099 p
= convert_to_reference
2100 (build_reference_type (basetype
), parm
,
2101 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2102 p
= convert_from_reference (p
);
2103 current_base_init_list
= tree_cons (basetype
,
2104 p
, current_base_init_list
);
2106 for (; fields
; fields
= TREE_CHAIN (fields
))
2109 tree field
= fields
;
2111 if (TREE_CODE (field
) != FIELD_DECL
)
2113 if (DECL_NAME (field
))
2115 if (VFIELD_NAME_P (DECL_NAME (field
)))
2117 if (VBASE_NAME_P (DECL_NAME (field
)))
2120 /* True for duplicate members. */
2121 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2124 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2125 && TREE_CODE (t
) == UNION_TYPE
2126 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2127 && TYPE_FIELDS (t
) != NULL_TREE
)
2128 field
= largest_union_member (t
);
2132 init
= build (COMPONENT_REF
, TREE_TYPE (field
), parm
, field
);
2133 init
= build_tree_list (NULL_TREE
, init
);
2135 current_member_init_list
2136 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2138 current_member_init_list
= nreverse (current_member_init_list
);
2139 current_base_init_list
= nreverse (current_base_init_list
);
2147 do_build_assign_ref (fndecl
)
2150 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2155 parm
= convert_from_reference (parm
);
2157 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2159 tree t
= build (MODIFY_EXPR
, void_type_node
, C_C_D
, parm
);
2160 TREE_SIDE_EFFECTS (t
) = 1;
2161 cplus_expand_expr_stmt (t
);
2165 tree fields
= TYPE_FIELDS (current_class_type
);
2166 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2167 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2170 for (i
= 0; i
< n_bases
; ++i
)
2172 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2173 if (TYPE_HAS_ASSIGN_REF (basetype
))
2175 tree p
= convert_to_reference
2176 (build_reference_type (basetype
), parm
,
2177 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2178 p
= convert_from_reference (p
);
2179 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2180 build_tree_list (NULL_TREE
, p
));
2181 expand_expr_stmt (p
);
2184 for (; fields
; fields
= TREE_CHAIN (fields
))
2187 tree field
= fields
;
2189 if (TREE_CODE (field
) != FIELD_DECL
)
2191 if (DECL_NAME (field
))
2193 if (VFIELD_NAME_P (DECL_NAME (field
)))
2195 if (VBASE_NAME_P (DECL_NAME (field
)))
2198 /* True for duplicate members. */
2199 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2202 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2203 && TREE_CODE (t
) == UNION_TYPE
2204 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2205 && TYPE_FIELDS (t
) != NULL_TREE
)
2206 field
= largest_union_member (t
);
2210 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), C_C_D
, field
);
2211 init
= build (COMPONENT_REF
, TREE_TYPE (field
), parm
, field
);
2213 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2216 c_expand_return (C_C_D
);
2220 void push_cp_function_context ();
2221 void pop_cp_function_context ();
2224 synthesize_method (fndecl
)
2227 int nested
= (current_function_decl
!= NULL_TREE
);
2228 tree context
= decl_function_context (fndecl
);
2229 char *f
= input_filename
;
2230 tree base
= DECL_CLASS_CONTEXT (fndecl
);
2233 push_cp_function_context (context
);
2235 input_filename
= DECL_SOURCE_FILE (fndecl
);
2236 interface_unknown
= CLASSTYPE_INTERFACE_UNKNOWN (base
);
2237 interface_only
= CLASSTYPE_INTERFACE_ONLY (base
);
2238 start_function (NULL_TREE
, fndecl
, NULL_TREE
, NULL_TREE
, 1);
2239 store_parm_decls ();
2241 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2242 do_build_assign_ref (fndecl
);
2243 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2247 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2248 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2249 arg_chain
= TREE_CHAIN (arg_chain
);
2250 if (arg_chain
!= void_list_node
)
2251 do_build_copy_constructor (fndecl
);
2252 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2256 finish_function (lineno
, 0, nested
);
2258 /* Do we really *want* to inline this function? */
2259 if (DECL_INLINE (fndecl
))
2261 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
2262 will check our size. */
2263 DECL_INLINE (fndecl
) = 0;
2264 if (function_cannot_inline_p (fndecl
) == 0)
2265 DECL_INLINE (fndecl
) = 1;
2269 extract_interface_info ();
2271 pop_cp_function_context (context
);