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-97, 1998 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"
45 extern char *index ();
48 /* TREE_LIST of the current inline functions that need to be
50 struct pending_inline
*pending_inlines
;
54 #define obstack_chunk_alloc xmalloc
55 #define obstack_chunk_free free
57 /* Obstack where we build text strings for overloading, etc. */
58 static struct obstack scratch_obstack
;
59 static char *scratch_firstobj
;
61 static void icat
PROTO((HOST_WIDE_INT
));
62 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
63 static void flush_repeats
PROTO((tree
));
64 static void build_overload_identifier
PROTO((tree
));
65 static void build_overload_nested_name
PROTO((tree
));
66 static void build_overload_int
PROTO((tree
, int));
67 static void build_overload_identifier
PROTO((tree
));
68 static void build_qualified_name
PROTO((tree
));
69 static void build_overload_value
PROTO((tree
, tree
, int));
70 static char *thunk_printable_name
PROTO((tree
));
71 static void do_build_assign_ref
PROTO((tree
));
72 static void do_build_copy_constructor
PROTO((tree
));
73 static tree largest_union_member
PROTO((tree
));
74 static tree build_decl_overload_real
PROTO((tree
, tree
, tree
, tree
,
76 static void build_template_parm_names
PROTO((tree
, tree
));
77 static void build_underscore_int
PROTO((int));
79 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
80 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
81 # define OB_PUTC2(C1,C2) \
82 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
83 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
84 # define OB_PUTID(ID) \
85 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
86 IDENTIFIER_LENGTH (ID)))
87 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
88 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
89 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
94 gcc_obstack_init (&scratch_obstack
);
95 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
98 /* This must be large enough to hold any printed integer or floating-point
100 static char digit_buffer
[128];
102 /* Move inline function definitions out of structure so that they
103 can be processed normally. CNAME is the name of the class
104 we are working from, METHOD_LIST is the list of method lists
105 of the structure. We delete friend methods here, after
106 saving away their inline function definitions (if any). */
109 do_inline_function_hair (type
, friend_list
)
110 tree type
, friend_list
;
112 tree method
= TYPE_METHODS (type
);
114 if (method
&& TREE_CODE (method
) == TREE_VEC
)
116 if (TREE_VEC_ELT (method
, 1))
117 method
= TREE_VEC_ELT (method
, 1);
118 else if (TREE_VEC_ELT (method
, 0))
119 method
= TREE_VEC_ELT (method
, 0);
121 method
= TREE_VEC_ELT (method
, 2);
126 /* Do inline member functions. */
127 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
132 my_friendly_assert (info
->fndecl
== method
, 238);
133 args
= DECL_ARGUMENTS (method
);
136 DECL_CONTEXT (args
) = method
;
137 args
= TREE_CHAIN (args
);
140 /* Allow this decl to be seen in global scope. Don't do this for
141 local class methods, though. */
142 if (! current_function_decl
)
143 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method
)) = method
;
145 method
= TREE_CHAIN (method
);
149 tree fndecl
= TREE_VALUE (friend_list
);
150 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
155 my_friendly_assert (info
->fndecl
== fndecl
, 239);
156 args
= DECL_ARGUMENTS (fndecl
);
159 DECL_CONTEXT (args
) = fndecl
;
160 args
= TREE_CHAIN (args
);
163 /* Allow this decl to be seen in global scope */
164 if (! current_function_decl
)
165 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl
)) = fndecl
;
168 friend_list
= TREE_CHAIN (friend_list
);
172 /* Report an argument type mismatch between the best declared function
173 we could find and the current argument list that we have. */
176 report_type_mismatch (cp
, parmtypes
, name_kind
)
177 struct candidate
*cp
;
181 int i
= cp
->u
.bad_arg
;
188 my_friendly_assert (TREE_CODE (cp
->function
) == TEMPLATE_DECL
, 240);
189 cp_error ("type unification failed for function template `%#D'",
194 cp_error ("too few arguments for %s `%#D'", name_kind
, cp
->function
);
197 cp_error ("too many arguments for %s `%#D'", name_kind
, cp
->function
);
200 if (TREE_CODE (TREE_TYPE (cp
->function
)) != METHOD_TYPE
)
203 /* Happens when the implicit object parameter is rejected. */
204 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))),
206 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
207 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
208 cp_error ("call to non-volatile %s `%#D' with volatile object",
209 name_kind
, cp
->function
);
211 cp_error ("call to non-const %s `%#D' with const object",
212 name_kind
, cp
->function
);
216 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
221 ttf
= TREE_CHAIN (ttf
);
222 tta
= TREE_CHAIN (tta
);
226 OB_PUTS ("bad argument ");
227 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
228 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
230 OB_PUTCP (digit_buffer
);
232 OB_PUTS (" for function `");
233 OB_PUTCP (decl_as_string (cp
->function
, 1));
234 OB_PUTS ("' (type was ");
236 /* Reset `i' so that type printing routines do the right thing. */
239 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
240 if (code
== ERROR_MARK
)
241 OB_PUTS ("(failed type instantiation)");
244 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
245 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
248 else OB_PUTS ("void");
252 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
253 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
254 obstack_object_size (&scratch_obstack
));
255 error (tmp_firstobj
);
258 /* Here is where overload code starts. */
260 /* Array of types seen so far in top-level call to `build_overload_name'.
261 Allocated and deallocated by caller. */
262 static tree
*typevec
;
264 /* Number of types interned by `build_overload_name' so far. */
267 /* Number of occurrences of last type seen. */
270 /* Nonzero if we should not try folding parameter types. */
273 #define ALLOCATE_TYPEVEC(PARMTYPES) \
274 do { maxtype = 0, nrepeats = 0; \
275 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
277 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
278 do { tree t = (PARMTYPES); \
279 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
282 /* Code to concatenate an asciified integer to a string. */
292 unsigned HOST_WIDE_INT ui
;
294 /* Handle this case first, to go really quickly. For many common values,
295 the result of ui/10 below is 1. */
313 OB_PUTC ('0' + (ui
% 10));
318 HOST_WIDE_INT lo
, hi
;
320 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
329 uhi
= (lo
== 0 ? -hi
: -hi
-1);
333 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
338 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
341 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
344 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
348 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
363 while (typevec
[tindex
] != type
)
381 static int numeric_output_need_bar
;
384 build_overload_nested_name (decl
)
387 if (DECL_CONTEXT (decl
))
389 tree context
= DECL_CONTEXT (decl
);
390 /* For a template type parameter, we want to output an 'Xn'
391 rather than 'T' or some such. */
392 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
)
393 build_overload_name (context
, 0, 0);
396 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
397 context
= TYPE_NAME (context
);
398 build_overload_nested_name (context
);
402 if (TREE_CODE (decl
) == FUNCTION_DECL
)
404 tree name
= DECL_ASSEMBLER_NAME (decl
);
407 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
410 if (numeric_output_need_bar
)
412 icat (strlen (label
));
414 numeric_output_need_bar
= 1;
417 build_overload_identifier (decl
);
421 build_underscore_int (i
)
431 /* Encoding for an INTEGER_CST value. */
434 build_overload_int (value
, in_template
)
438 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
439 /* We don't ever want this output, but it's inconvenient not to
440 be able to build the string. This should cause assembler
441 errors we'll notice. */
444 sprintf (digit_buffer
, " *%d", n
++);
445 OB_PUTCP (digit_buffer
);
449 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
450 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
452 if (TREE_INT_CST_HIGH (value
)
453 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
455 /* need to print a DImode value in decimal */
456 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
459 /* else fall through to print in smaller mode */
461 /* Wordsize or smaller */
462 icat (TREE_INT_CST_LOW (value
));
466 build_overload_value (type
, value
, in_template
)
470 while (TREE_CODE (value
) == NON_LVALUE_EXPR
471 || TREE_CODE (value
) == NOP_EXPR
)
472 value
= TREE_OPERAND (value
, 0);
473 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
474 type
= TREE_TYPE (type
);
476 if (numeric_output_need_bar
)
479 numeric_output_need_bar
= 0;
482 if (TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
485 build_underscore_int (TEMPLATE_CONST_IDX (value
));
486 build_underscore_int (TEMPLATE_CONST_LEVEL (value
));
490 if (TREE_CODE (type
) == POINTER_TYPE
491 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
493 /* Handle a pointer to data member as a template instantiation
494 parameter, boy, what fun! */
495 type
= integer_type_node
;
496 if (TREE_CODE (value
) != INTEGER_CST
)
498 sorry ("unknown pointer to member constant");
503 if (TYPE_PTRMEMFUNC_P (type
))
504 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
506 switch (TREE_CODE (type
))
512 build_overload_int (value
, in_template
);
513 numeric_output_need_bar
= 1;
519 char *bufp
= digit_buffer
;
521 pedwarn ("ANSI C++ forbids floating-point template arguments");
523 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
524 val
= TREE_REAL_CST (value
);
525 if (REAL_VALUE_ISNAN (val
))
527 sprintf (bufp
, "NaN");
531 if (REAL_VALUE_NEGATIVE (val
))
533 val
= REAL_VALUE_NEGATE (val
);
536 if (REAL_VALUE_ISINF (val
))
538 sprintf (bufp
, "Infinity");
542 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
543 bufp
= (char *) index (bufp
, 'e');
545 strcat (digit_buffer
, "e0");
571 #ifdef NO_DOT_IN_LABEL
572 bufp
= (char *) index (bufp
, '.');
578 OB_PUTCP (digit_buffer
);
579 numeric_output_need_bar
= 1;
583 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
584 && TREE_CODE (value
) != ADDR_EXPR
)
586 if (TREE_CODE (value
) == CONSTRUCTOR
)
588 /* This is dangerous code, crack built up pointer to members. */
589 tree args
= CONSTRUCTOR_ELTS (value
);
590 tree a1
= TREE_VALUE (args
);
591 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
592 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
593 a3
= TREE_VALUE (a3
);
595 if (TREE_CODE (a1
) == INTEGER_CST
596 && TREE_CODE (a2
) == INTEGER_CST
)
598 build_overload_int (a1
, in_template
);
600 build_overload_int (a2
, in_template
);
602 if (TREE_CODE (a3
) == ADDR_EXPR
)
604 a3
= TREE_OPERAND (a3
, 0);
605 if (TREE_CODE (a3
) == FUNCTION_DECL
)
607 numeric_output_need_bar
= 0;
608 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
612 else if (TREE_CODE (a3
) == INTEGER_CST
)
615 build_overload_int (a3
, in_template
);
616 numeric_output_need_bar
= 1;
621 sorry ("template instantiation with pointer to method that is too complex");
624 if (TREE_CODE (value
) == INTEGER_CST
625 || TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
627 build_overload_int (value
, in_template
);
628 numeric_output_need_bar
= 1;
631 value
= TREE_OPERAND (value
, 0);
632 if (TREE_CODE (value
) == VAR_DECL
)
634 my_friendly_assert (DECL_NAME (value
) != 0, 245);
635 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
638 else if (TREE_CODE (value
) == FUNCTION_DECL
)
640 my_friendly_assert (DECL_NAME (value
) != 0, 246);
641 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
645 my_friendly_abort (71);
646 break; /* not really needed */
649 sorry ("conversion of %s as template parameter",
650 tree_code_name
[(int) TREE_CODE (type
)]);
651 my_friendly_abort (72);
656 /* Add encodings for the vector of template parameters in PARMLIST,
657 given the vector of arguments to be substituted in ARGLIST. */
660 build_template_parm_names (parmlist
, arglist
)
666 nparms
= TREE_VEC_LENGTH (parmlist
);
668 for (i
= 0; i
< nparms
; i
++)
670 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
671 tree arg
= TREE_VEC_ELT (arglist
, i
);
672 if (TREE_CODE (parm
) == TYPE_DECL
)
674 /* This parameter is a type. */
676 build_overload_name (arg
, 0, 0);
680 parm
= tsubst (parm
, arglist
,
681 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
682 /* It's a PARM_DECL. */
683 build_overload_name (TREE_TYPE (parm
), 0, 0);
684 build_overload_value (parm
, arg
, uses_template_parms (arglist
));
691 build_overload_identifier (name
)
694 if (TREE_CODE (name
) == TYPE_DECL
695 && IS_AGGR_TYPE (TREE_TYPE (name
))
696 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
697 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
))))
699 tree
template, parmlist
, arglist
, tname
;
700 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
701 arglist
= TREE_VALUE (template);
702 template = TREE_PURPOSE (template);
703 tname
= DECL_NAME (template);
704 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
706 icat (IDENTIFIER_LENGTH (tname
));
708 build_template_parm_names (parmlist
, arglist
);
712 if (TREE_CODE (name
) == TYPE_DECL
)
713 name
= DECL_NAME (name
);
714 if (numeric_output_need_bar
)
717 numeric_output_need_bar
= 0;
719 icat (IDENTIFIER_LENGTH (name
));
724 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
725 the mangling for it. Used by build_overload_name and build_static_name. */
728 build_qualified_name (decl
)
734 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
735 decl
= TYPE_NAME (decl
);
737 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
738 if (TREE_CODE (decl
) == TYPE_DECL
739 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
741 OB_PUTID (DECL_ASSEMBLER_NAME (decl
));
746 while (DECL_CONTEXT (context
))
749 context
= DECL_CONTEXT (context
);
750 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
751 context
= TYPE_NAME (context
);
762 numeric_output_need_bar
= 0;
764 build_overload_nested_name (decl
);
767 /* Given a list of parameters in PARMTYPES, create an unambiguous
768 overload string. Should distinguish any type that C (or C++) can
769 distinguish. I.e., pointers to functions are treated correctly.
771 Caller must deal with whether a final `e' goes on the end or not.
773 Any default conversions must take place before this function
776 BEGIN and END control initialization and finalization of the
777 obstack where we build the string. */
780 build_overload_name (parmtypes
, begin
, end
)
787 if (begin
) OB_INIT ();
788 numeric_output_need_bar
= 0;
790 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
792 parmtype
= parmtypes
;
798 parmtype
= TREE_VALUE (parmtypes
);
802 if (! nofold
&& ! just_one
)
804 /* Every argument gets counted. */
805 typevec
[maxtype
++] = parmtype
;
807 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
814 flush_repeats (typevec
[maxtype
-2]);
816 if (TREE_USED (parmtype
))
819 /* We can turn this on at some point when we want
820 improved symbol mangling. */
823 /* This is bug compatible with 2.7.x */
824 flush_repeats (parmtype
);
829 /* Only cache types which take more than one character. */
830 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
831 || (TREE_CODE (parmtype
) != INTEGER_TYPE
832 && TREE_CODE (parmtype
) != REAL_TYPE
))
833 TREE_USED (parmtype
) = 1;
836 if (TYPE_PTRMEMFUNC_P (parmtype
))
837 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
839 if (TREE_READONLY (parmtype
))
841 if (TREE_CODE (parmtype
) == INTEGER_TYPE
842 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
844 if (TYPE_VOLATILE (parmtype
))
847 switch (TREE_CODE (parmtype
))
851 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
853 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
861 #if PARM_CAN_BE_ARRAY_TYPE
866 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
867 error ("pointer or reference to array of unknown bound in parm type");
870 length
= array_type_nelts (parmtype
);
871 if (TREE_CODE (length
) == INTEGER_CST
)
872 icat (TREE_INT_CST_LOW (length
) + 1);
885 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
891 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
892 /* Otherwise have to implement reentrant typevecs,
893 unmark and remark types, etc. */
894 int old_nofold
= nofold
;
898 flush_repeats (typevec
[maxtype
-1]);
900 /* @@ It may be possible to pass a function type in
901 which is not preceded by a 'P'. */
902 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
905 if (firstarg
== NULL_TREE
)
907 else if (firstarg
== void_list_node
)
910 build_overload_name (firstarg
, 0, 0);
914 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
915 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
917 firstarg
= TREE_CHAIN (firstarg
);
919 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
925 /* For cfront 2.0 compatibility. */
928 if (firstarg
== NULL_TREE
)
930 else if (firstarg
== void_list_node
)
933 build_overload_name (firstarg
, 0, 0);
936 /* Separate args from return type. */
938 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
944 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
945 if (parmtype
== integer_type_node
946 || parmtype
== unsigned_type_node
)
948 else if (parmtype
== long_integer_type_node
949 || parmtype
== long_unsigned_type_node
)
951 else if (parmtype
== short_integer_type_node
952 || parmtype
== short_unsigned_type_node
)
954 else if (parmtype
== signed_char_type_node
)
959 else if (parmtype
== char_type_node
960 || parmtype
== unsigned_char_type_node
)
962 else if (parmtype
== wchar_type_node
)
964 else if (parmtype
== long_long_integer_type_node
965 || parmtype
== long_long_unsigned_type_node
)
968 /* it would seem there is no way to enter these in source code,
970 else if (parmtype
== long_long_long_integer_type_node
971 || parmtype
== long_long_long_unsigned_type_node
)
975 my_friendly_abort (73);
983 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
984 if (parmtype
== long_double_type_node
)
986 else if (parmtype
== double_type_node
)
988 else if (parmtype
== float_type_node
)
990 else my_friendly_abort (74);
995 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
1002 extern tree void_list_node
;
1004 /* See if anybody is wasting memory. */
1005 my_friendly_assert (parmtypes
== void_list_node
, 247);
1007 /* This is the end of a parameter list. */
1008 if (end
) OB_FINISH ();
1009 return (char *)obstack_base (&scratch_obstack
);
1014 case ERROR_MARK
: /* not right, but nothing is anyway */
1017 /* have to do these */
1021 /* Make this type signature look incompatible
1028 tree name
= TYPE_NAME (parmtype
);
1030 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
1032 build_overload_identifier (TYPE_NAME (parmtype
));
1035 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1037 build_qualified_name (name
);
1042 /* We can get here if __null is defined to have type ({unkown
1043 type}*), which it is if -ansi is not used. Treat this
1048 case TEMPLATE_TYPE_PARM
:
1050 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1051 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1055 /* When mangling the type of a function template whose
1056 declaration looks like:
1058 template <class T> void foo(typename T::U)
1060 we have to mangle these. */
1061 build_qualified_name (parmtype
);
1065 my_friendly_abort (75);
1069 if (just_one
) break;
1070 parmtypes
= TREE_CHAIN (parmtypes
);
1075 flush_repeats (typevec
[maxtype
-1]);
1077 /* To get here, parms must end with `...'. */
1081 if (end
) OB_FINISH ();
1082 return (char *)obstack_base (&scratch_obstack
);
1085 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1086 be either a class TYPE or a FUNCTION_DECL. */
1089 build_static_name (context
, name
)
1093 numeric_output_need_bar
= 0;
1096 build_qualified_name (context
);
1099 OB_PUTS ("__static_");
1100 build_qualified_name (context
);
1106 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1110 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1119 char *name
= IDENTIFIER_POINTER (dname
);
1121 /* member operators new and delete look like methods at this point. */
1122 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1123 && TREE_CHAIN (parms
) == void_list_node
)
1125 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1126 return get_identifier ("__builtin_delete");
1127 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1128 return get_identifier ("__builtin_vec_delete");
1129 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1130 return get_identifier ("__builtin_new");
1131 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1132 return get_identifier ("__builtin_vec_new");
1136 if (for_method
!= 2)
1138 /* Otherwise, we can divine that this is a constructor,
1139 and figure out its name without any extra encoding. */
1141 OB_PUTC2 ('_', '_');
1145 /* We can get away without doing this. */
1148 if (tparms
!= NULL_TREE
)
1151 tree this_type
= TREE_VALUE (parms
);
1153 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1154 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1155 TREE_CHAIN (parms
));
1157 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1158 TREE_CHAIN (parms
));
1168 build_template_parm_names (tparms
, targs
);
1172 if (parms
== NULL_TREE
)
1174 else if (parms
== void_list_node
)
1178 ALLOCATE_TYPEVEC (parms
);
1182 build_overload_name (TREE_VALUE (parms
), 0, 0);
1184 typevec
[maxtype
++] = TREE_VALUE (parms
);
1185 TREE_USED (TREE_VALUE (parms
)) = 1;
1187 if (TREE_CHAIN (parms
))
1188 build_overload_name (TREE_CHAIN (parms
), 0, 0);
1193 build_overload_name (parms
, 0, 0);
1194 DEALLOCATE_TYPEVEC (parms
);
1197 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1199 /* Add the return type. */
1201 build_overload_name (ret_type
, 0, 0);
1206 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1207 if (IDENTIFIER_OPNAME_P (dname
))
1208 IDENTIFIER_OPNAME_P (n
) = 1;
1213 /* Change the name of a function definition so that it may be
1214 overloaded. NAME is the name of the function to overload,
1215 PARMS is the parameter list (which determines what name the
1216 final function obtains).
1218 FOR_METHOD is 1 if this overload is being performed
1219 for a method, rather than a function type. It is 2 if
1220 this overload is being performed for a constructor. */
1223 build_decl_overload (dname
, parms
, for_method
)
1228 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1229 NULL_TREE
, for_method
);
1233 /* Like build_decl_overload, but for template functions. */
1236 build_template_decl_overload (dname
, parms
, ret_type
, tparms
, targs
,
1245 return build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1250 /* Build an overload name for the type expression TYPE. */
1253 build_typename_overload (type
)
1259 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1261 build_overload_name (type
, 0, 1);
1262 id
= get_identifier (obstack_base (&scratch_obstack
));
1263 IDENTIFIER_OPNAME_P (id
) = 1;
1265 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1267 TREE_TYPE (id
) = type
;
1272 build_overload_with_type (name
, type
)
1279 build_overload_name (type
, 0, 1);
1280 return get_identifier (obstack_base (&scratch_obstack
));
1284 get_id_2 (name
, name2
)
1292 return get_identifier (obstack_base (&scratch_obstack
));
1295 /* Given a tree_code CODE, and some arguments (at least one),
1296 attempt to use an overloaded operator on the arguments.
1298 For unary operators, only the first argument need be checked.
1299 For binary operators, both arguments may need to be checked.
1301 Member functions can convert class references to class pointers,
1302 for one-level deep indirection. More than that is not supported.
1303 Operators [](), ()(), and ->() must be member functions.
1305 We call function call building calls with LOOKUP_COMPLAIN if they
1306 are our only hope. This is true when we see a vanilla operator
1307 applied to something of aggregate type. If this fails, we are free
1308 to return `error_mark_node', because we will have reported the
1311 Operators NEW and DELETE overload in funny ways: operator new takes
1312 a single `size' parameter, and operator delete takes a pointer to the
1313 storage being deleted. When overloading these operators, success is
1314 assumed. If there is a failure, report an error message and return
1315 `error_mark_node'. */
1319 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1320 enum tree_code code
;
1322 tree xarg1
, xarg2
, arg3
;
1326 tree type1
, type2
, fnname
;
1327 tree fields1
= 0, parms
= 0;
1330 int binary_is_unary
;
1332 if (flag_ansi_overloading
)
1333 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1335 if (xarg1
== error_mark_node
)
1336 return error_mark_node
;
1338 if (code
== COND_EXPR
)
1340 if (xarg2
== error_mark_node
1341 || arg3
== error_mark_node
)
1342 return error_mark_node
;
1344 if (code
== COMPONENT_REF
)
1345 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1348 /* First, see if we can work with the first argument */
1349 type1
= TREE_TYPE (xarg1
);
1351 /* Some tree codes have length > 1, but we really only want to
1352 overload them if their first argument has a user defined type. */
1355 case PREINCREMENT_EXPR
:
1356 case PREDECREMENT_EXPR
:
1357 case POSTINCREMENT_EXPR
:
1358 case POSTDECREMENT_EXPR
:
1360 binary_is_unary
= 1;
1364 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1365 If they do not, return error_mark_node instead of NULL_TREE. */
1367 if (xarg2
== error_mark_node
)
1368 return error_mark_node
;
1370 rval
= error_mark_node
;
1371 binary_is_unary
= 0;
1378 tree args
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1379 fnname
= ansi_opname
[(int) code
];
1380 if (flags
& LOOKUP_GLOBAL
)
1381 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
);
1383 rval
= build_method_call
1384 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1386 fnname
, args
, NULL_TREE
, flags
);
1387 if (rval
== error_mark_node
)
1388 /* User might declare fancy operator new, but invoke it
1389 like standard one. */
1392 TREE_TYPE (rval
) = xarg1
;
1393 TREE_CALLS_NEW (rval
) = 1;
1398 case VEC_DELETE_EXPR
:
1401 fnname
= ansi_opname
[(int) code
];
1402 if (flags
& LOOKUP_GLOBAL
)
1403 return build_overload_call (fnname
,
1404 build_expr_list (NULL_TREE
, xarg1
),
1405 flags
& LOOKUP_COMPLAIN
);
1406 arg1
= TREE_TYPE (xarg1
);
1408 /* This handles the case where we're trying to delete
1413 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
1415 /* Strip off the pointer and the array. */
1416 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
1418 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
1419 arg1
= (TREE_TYPE (arg1
));
1421 arg1
= build_pointer_type (arg1
);
1424 rval
= build_method_call
1425 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
1428 fnname
, expr_tree_cons (NULL_TREE
, xarg1
,
1429 build_expr_list (NULL_TREE
, xarg2
)),
1432 /* This can happen when operator delete is protected. */
1433 my_friendly_assert (rval
!= error_mark_node
, 250);
1434 TREE_TYPE (rval
) = void_type_node
;
1441 binary_is_unary
= 0;
1442 try_second
= tree_code_length
[(int) code
] == 2;
1443 if (try_second
&& xarg2
== error_mark_node
)
1444 return error_mark_node
;
1448 if (try_second
&& xarg2
== error_mark_node
)
1449 return error_mark_node
;
1451 /* What ever it was, we do not know how to deal with it. */
1452 if (type1
== NULL_TREE
)
1455 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1456 type1
= TREE_TYPE (type1
);
1458 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1460 arg1
= convert_from_reference (xarg1
);
1461 type1
= TREE_TYPE (arg1
);
1468 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1470 /* Try to fail. First, fail if unary */
1473 /* Second, see if second argument is non-aggregate. */
1474 type2
= TREE_TYPE (xarg2
);
1475 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1476 type2
= TREE_TYPE (type2
);
1477 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1479 arg2
= convert_from_reference (xarg2
);
1480 type2
= TREE_TYPE (arg2
);
1487 if (!IS_AGGR_TYPE (type2
))
1494 /* First arg may succeed; see whether second should. */
1495 type2
= TREE_TYPE (xarg2
);
1496 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1497 type2
= TREE_TYPE (type2
);
1498 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1500 arg2
= convert_from_reference (xarg2
);
1501 type2
= TREE_TYPE (arg2
);
1508 if (! IS_AGGR_TYPE (type2
))
1512 if (type1
== unknown_type_node
1513 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1515 /* This will not be implemented in the foreseeable future. */
1519 if (code
== MODIFY_EXPR
)
1520 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1522 fnname
= ansi_opname
[(int) code
];
1524 global_fn
= lookup_name_nonclass (fnname
);
1526 /* This is the last point where we will accept failure. This
1527 may be too eager if we wish an overloaded operator not to match,
1528 but would rather a normal operator be called on a type-converted
1531 if (IS_AGGR_TYPE (type1
))
1533 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1534 /* ARM $13.4.7, prefix/postfix ++/--. */
1535 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1537 xarg2
= integer_zero_node
;
1538 binary_is_unary
= 0;
1543 int have_postfix
= 0;
1545 /* Look for an `operator++ (int)'. If they didn't have
1546 one, then we fall back to the old way of doing things. */
1547 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1549 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1550 if (TREE_CHAIN (t2
) != NULL_TREE
1551 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1560 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1562 /* There's probably a LOT of code in the world that
1563 relies upon this old behavior. */
1564 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1567 binary_is_unary
= 1;
1573 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1576 /* If RVAL winds up being `error_mark_node', we will return
1577 that... There is no way that normal semantics of these
1578 operators will succeed. */
1580 /* This argument may be an uncommitted OFFSET_REF. This is
1581 the case for example when dealing with static class members
1582 which are referenced from their class name rather than
1583 from a class instance. */
1584 if (TREE_CODE (xarg1
) == OFFSET_REF
1585 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1586 xarg1
= TREE_OPERAND (xarg1
, 1);
1587 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1588 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1589 xarg2
= TREE_OPERAND (xarg2
, 1);
1592 flags
|= LOOKUP_GLOBAL
;
1594 if (code
== CALL_EXPR
)
1596 /* This can only be a member function. */
1597 return build_method_call (xarg1
, fnname
, xarg2
,
1598 NULL_TREE
, LOOKUP_NORMAL
);
1600 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1603 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1605 else if (code
== COND_EXPR
)
1607 parms
= expr_tree_cons (NULL_TREE
, xarg2
, build_expr_list (NULL_TREE
, arg3
));
1608 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1610 else if (code
== METHOD_CALL_EXPR
)
1612 /* must be a member function. */
1613 parms
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1614 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1619 parms
= build_expr_list (NULL_TREE
, xarg2
);
1620 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1624 parms
= expr_tree_cons (NULL_TREE
, xarg1
,
1625 build_expr_list (NULL_TREE
, xarg2
));
1626 rval
= build_overload_call (fnname
, parms
, flags
);
1632 /* This function takes an identifier, ID, and attempts to figure out what
1633 it means. There are a number of possible scenarios, presented in increasing
1636 1) not in a class's scope
1637 2) in class's scope, member name of the class's method
1638 3) in class's scope, but not a member name of the class
1639 4) in class's scope, member name of a class's variable
1641 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1642 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1644 As a last ditch, try to look up the name as a label and return that
1647 Values which are declared as being of REFERENCE_TYPE are
1648 automatically dereferenced here (as a hack to make the
1649 compiler faster). */
1652 hack_identifier (value
, name
)
1657 if (value
== error_mark_node
)
1659 if (current_class_name
)
1661 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1662 if (fields
== error_mark_node
)
1663 return error_mark_node
;
1668 fndecl
= TREE_VALUE (fields
);
1669 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1670 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1672 warning ("methods cannot be converted to function pointers");
1677 error ("ambiguous request for method pointer `%s'",
1678 IDENTIFIER_POINTER (name
));
1679 return error_mark_node
;
1683 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1685 return IDENTIFIER_LABEL_VALUE (name
);
1687 return error_mark_node
;
1690 type
= TREE_TYPE (value
);
1691 if (TREE_CODE (value
) == FIELD_DECL
)
1693 if (current_class_ptr
== NULL_TREE
)
1695 error ("request for member `%s' in static member function",
1696 IDENTIFIER_POINTER (DECL_NAME (value
)));
1697 return error_mark_node
;
1699 TREE_USED (current_class_ptr
) = 1;
1701 /* Mark so that if we are in a constructor, and then find that
1702 this field was initialized by a base initializer,
1703 we can emit an error message. */
1704 TREE_USED (value
) = 1;
1705 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1707 else if (really_overloaded_fn (value
))
1710 tree t
= get_first_fn (value
);
1711 for (; t
; t
= DECL_CHAIN (t
))
1713 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1716 assemble_external (t
);
1721 else if (TREE_CODE (value
) == TREE_LIST
)
1723 /* Ambiguous reference to base members, possibly other cases?. */
1725 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1727 mark_used (TREE_VALUE (t
));
1734 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1736 tree context
= decl_function_context (value
);
1737 if (context
!= NULL_TREE
&& context
!= current_function_decl
1738 && ! TREE_STATIC (value
))
1740 cp_error ("use of %s from containing function",
1741 (TREE_CODE (value
) == VAR_DECL
1742 ? "`auto' variable" : "parameter"));
1743 cp_error_at (" `%#D' declared here", value
);
1744 value
= error_mark_node
;
1748 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1750 if (DECL_LANG_SPECIFIC (value
)
1751 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1754 register tree context
1755 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1756 ? DECL_CLASS_CONTEXT (value
)
1757 : DECL_CONTEXT (value
);
1759 get_base_distance (context
, current_class_type
, 0, &path
);
1762 access
= compute_access (path
, value
);
1763 if (access
!= access_public_node
)
1765 if (TREE_CODE (value
) == VAR_DECL
)
1766 error ("static member `%s' is %s",
1767 IDENTIFIER_POINTER (name
),
1768 TREE_PRIVATE (value
) ? "private"
1769 : "from a private base class");
1771 error ("enum `%s' is from private base class",
1772 IDENTIFIER_POINTER (name
));
1773 return error_mark_node
;
1778 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1782 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1783 IDENTIFIER_POINTER (name
));
1784 return error_mark_node
;
1790 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1791 value
= convert_from_reference (value
);
1797 thunk_printable_name (decl
)
1800 return "<thunk function>";
1804 make_thunk (function
, delta
)
1813 if (TREE_CODE (function
) != ADDR_EXPR
)
1815 func_decl
= TREE_OPERAND (function
, 0);
1816 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1818 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1819 buffer
= (char *)alloca (strlen (func_name
) + 32);
1821 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1823 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1824 thunk_id
= get_identifier (buffer
);
1825 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1826 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1828 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1829 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1831 if (thunk
== NULL_TREE
)
1833 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1834 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1835 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1836 comdat_linkage (thunk
);
1837 TREE_SET_CODE (thunk
, THUNK_DECL
);
1838 DECL_INITIAL (thunk
) = function
;
1839 THUNK_DELTA (thunk
) = delta
;
1840 DECL_EXTERNAL (thunk
) = 1;
1841 DECL_ARTIFICIAL (thunk
) = 1;
1842 /* So that finish_file can write out any thunks that need to be: */
1843 pushdecl_top_level (thunk
);
1848 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1851 emit_thunk (thunk_fndecl
)
1854 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1855 int delta
= THUNK_DELTA (thunk_fndecl
);
1857 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1860 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1862 TREE_ADDRESSABLE (function
) = 1;
1863 mark_used (function
);
1865 if (current_function_decl
)
1868 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1871 #ifdef ASM_OUTPUT_MI_THUNK
1873 current_function_decl
= thunk_fndecl
;
1874 /* Make sure we build up its RTL before we go onto the
1875 temporary obstack. */
1876 make_function_rtl (thunk_fndecl
);
1877 temporary_allocation ();
1878 DECL_RESULT (thunk_fndecl
)
1879 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1880 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1881 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1882 assemble_start_function (thunk_fndecl
, fnname
);
1883 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
1884 assemble_end_function (thunk_fndecl
, fnname
);
1885 permanent_allocation (1);
1886 current_function_decl
= 0;
1887 #else /* ASM_OUTPUT_MI_THUNK */
1888 /* If we don't have the necessary macro for efficient thunks, generate a
1889 thunk function that just makes a call to the real function.
1890 Unfortunately, this doesn't work for varargs. */
1894 if (varargs_function_p (function
))
1895 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1898 /* Set up clone argument trees for the thunk. */
1900 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
1902 tree x
= copy_node (a
);
1904 DECL_CONTEXT (x
) = thunk_fndecl
;
1908 DECL_ARGUMENTS (thunk_fndecl
) = a
;
1909 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
1910 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
1911 copy_lang_decl (thunk_fndecl
);
1912 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
1913 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
1915 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
1916 store_parm_decls ();
1917 current_function_is_thunk
= 1;
1919 /* Build up the call to the real function. */
1920 t
= build_int_2 (delta
, -1 * (delta
< 0));
1921 TREE_TYPE (t
) = signed_type (sizetype
);
1922 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
1923 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
1924 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
1925 t
= expr_tree_cons (NULL_TREE
, a
, t
);
1927 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
1928 c_expand_return (t
);
1930 finish_function (lineno
, 0, 0);
1932 /* Don't let the backend defer this function. */
1933 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
1935 output_inline_function (thunk_fndecl
);
1936 permanent_allocation (1);
1938 #endif /* ASM_OUTPUT_MI_THUNK */
1941 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
1944 /* Code for synthesizing methods which have default semantics defined. */
1946 /* For the anonymous union in TYPE, return the member that is at least as
1947 large as the rest of the members, so we can copy it. */
1950 largest_union_member (type
)
1953 tree f
, type_size
= TYPE_SIZE (type
);
1955 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
1956 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
1959 /* We should always find one. */
1960 my_friendly_abort (323);
1964 /* Generate code for default X(X&) constructor. */
1967 do_build_copy_constructor (fndecl
)
1970 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
1976 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1977 parm
= TREE_CHAIN (parm
);
1978 parm
= convert_from_reference (parm
);
1980 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
1982 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
1983 TREE_SIDE_EFFECTS (t
) = 1;
1984 cplus_expand_expr_stmt (t
);
1988 tree fields
= TYPE_FIELDS (current_class_type
);
1989 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
1990 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
1993 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
1996 tree basetype
= BINFO_TYPE (t
);
1997 tree p
= convert_to_reference
1998 (build_reference_type (basetype
), parm
,
1999 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2000 p
= convert_from_reference (p
);
2002 if (p
== error_mark_node
)
2003 cp_error ("in default copy constructor");
2005 current_base_init_list
= tree_cons (basetype
,
2006 p
, current_base_init_list
);
2009 for (i
= 0; i
< n_bases
; ++i
)
2011 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2012 if (TREE_VIA_VIRTUAL (basetype
))
2015 basetype
= BINFO_TYPE (basetype
);
2016 p
= convert_to_reference
2017 (build_reference_type (basetype
), parm
,
2018 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2020 if (p
== error_mark_node
)
2021 cp_error ("in default copy constructor");
2024 p
= convert_from_reference (p
);
2025 current_base_init_list
= tree_cons (basetype
,
2026 p
, current_base_init_list
);
2029 for (; fields
; fields
= TREE_CHAIN (fields
))
2032 tree field
= fields
;
2034 if (TREE_CODE (field
) != FIELD_DECL
)
2038 if (DECL_NAME (field
))
2040 if (VFIELD_NAME_P (DECL_NAME (field
)))
2042 if (VBASE_NAME_P (DECL_NAME (field
)))
2045 /* True for duplicate members. */
2046 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2049 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2050 && TREE_CODE (t
) == UNION_TYPE
2051 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2052 && TYPE_FIELDS (t
) != NULL_TREE
)
2056 init
= build (COMPONENT_REF
, t
, init
, field
);
2057 field
= largest_union_member (t
);
2059 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2060 && TREE_CODE (t
) == UNION_TYPE
2061 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2062 && TYPE_FIELDS (t
) != NULL_TREE
);
2067 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2068 init
= build_tree_list (NULL_TREE
, init
);
2070 current_member_init_list
2071 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2073 current_member_init_list
= nreverse (current_member_init_list
);
2074 current_base_init_list
= nreverse (current_base_init_list
);
2082 do_build_assign_ref (fndecl
)
2085 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2090 parm
= convert_from_reference (parm
);
2092 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2094 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2095 TREE_SIDE_EFFECTS (t
) = 1;
2096 cplus_expand_expr_stmt (t
);
2100 tree fields
= TYPE_FIELDS (current_class_type
);
2101 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2102 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2105 for (i
= 0; i
< n_bases
; ++i
)
2107 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2108 tree p
= convert_to_reference
2109 (build_reference_type (basetype
), parm
,
2110 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2111 p
= convert_from_reference (p
);
2112 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2113 build_expr_list (NULL_TREE
, p
));
2114 expand_expr_stmt (p
);
2116 for (; fields
; fields
= TREE_CHAIN (fields
))
2119 tree field
= fields
;
2121 if (TREE_CODE (field
) != FIELD_DECL
)
2124 if (TREE_READONLY (field
))
2126 if (DECL_NAME (field
))
2127 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2129 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2132 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2134 if (DECL_NAME (field
))
2135 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2137 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2141 comp
= current_class_ref
;
2144 if (DECL_NAME (field
))
2146 if (VFIELD_NAME_P (DECL_NAME (field
)))
2148 if (VBASE_NAME_P (DECL_NAME (field
)))
2151 /* True for duplicate members. */
2152 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2155 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2156 && TREE_CODE (t
) == UNION_TYPE
2157 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2158 && TYPE_FIELDS (t
) != NULL_TREE
)
2162 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2163 init
= build (COMPONENT_REF
, t
, init
, field
);
2164 field
= largest_union_member (t
);
2166 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2167 && TREE_CODE (t
) == UNION_TYPE
2168 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2169 && TYPE_FIELDS (t
) != NULL_TREE
);
2174 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2175 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2177 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2180 c_expand_return (current_class_ref
);
2185 synthesize_method (fndecl
)
2188 int nested
= (current_function_decl
!= NULL_TREE
);
2189 tree context
= hack_decl_function_context (fndecl
);
2192 import_export_decl (fndecl
);
2195 push_to_top_level ();
2197 push_cp_function_context (context
);
2199 interface_unknown
= 1;
2200 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2201 store_parm_decls ();
2203 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2204 do_build_assign_ref (fndecl
);
2205 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2209 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2210 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2211 arg_chain
= TREE_CHAIN (arg_chain
);
2212 if (arg_chain
!= void_list_node
)
2213 do_build_copy_constructor (fndecl
);
2214 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2218 finish_function (lineno
, 0, nested
);
2220 extract_interface_info ();
2222 pop_from_top_level ();
2224 pop_cp_function_context (context
);