1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 89, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #ifndef PARM_CAN_BE_ARRAY_TYPE
25 #define PARM_CAN_BE_ARRAY_TYPE 1
28 /* Handle method declarations. */
39 #include "hard-reg-set.h"
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
));
644 else if (TREE_CODE (value
) == SCOPE_REF
)
647 numeric_output_need_bar
= 0;
648 build_overload_name (TREE_OPERAND (value
, 0), 0, 0);
649 build_overload_identifier (TREE_OPERAND (value
, 1));
653 my_friendly_abort (71);
654 break; /* not really needed */
657 sorry ("conversion of %s as template parameter",
658 tree_code_name
[(int) TREE_CODE (type
)]);
659 my_friendly_abort (72);
664 /* Add encodings for the vector of template parameters in PARMLIST,
665 given the vector of arguments to be substituted in ARGLIST. */
668 build_template_parm_names (parmlist
, arglist
)
674 nparms
= TREE_VEC_LENGTH (parmlist
);
676 for (i
= 0; i
< nparms
; i
++)
678 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
679 tree arg
= TREE_VEC_ELT (arglist
, i
);
680 if (TREE_CODE (parm
) == TYPE_DECL
)
682 /* This parameter is a type. */
684 build_overload_name (arg
, 0, 0);
688 parm
= tsubst (parm
, arglist
,
689 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
690 /* It's a PARM_DECL. */
691 build_overload_name (TREE_TYPE (parm
), 0, 0);
692 build_overload_value (parm
, arg
, uses_template_parms (arglist
));
699 build_overload_identifier (name
)
702 if (TREE_CODE (name
) == TYPE_DECL
703 && IS_AGGR_TYPE (TREE_TYPE (name
))
704 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
705 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
))))
707 tree
template, parmlist
, arglist
, tname
;
708 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
709 arglist
= TREE_VALUE (template);
710 template = TREE_PURPOSE (template);
711 tname
= DECL_NAME (template);
712 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
714 icat (IDENTIFIER_LENGTH (tname
));
716 build_template_parm_names (parmlist
, arglist
);
720 if (TREE_CODE (name
) == TYPE_DECL
)
721 name
= DECL_NAME (name
);
722 if (numeric_output_need_bar
)
725 numeric_output_need_bar
= 0;
727 icat (IDENTIFIER_LENGTH (name
));
732 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
733 the mangling for it. Used by build_overload_name and build_static_name. */
736 build_qualified_name (decl
)
742 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
743 decl
= TYPE_NAME (decl
);
745 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
746 if (TREE_CODE (decl
) == TYPE_DECL
747 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
749 OB_PUTID (DECL_ASSEMBLER_NAME (decl
));
754 while (DECL_CONTEXT (context
))
757 context
= DECL_CONTEXT (context
);
758 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
759 context
= TYPE_NAME (context
);
770 numeric_output_need_bar
= 0;
772 build_overload_nested_name (decl
);
775 /* Given a list of parameters in PARMTYPES, create an unambiguous
776 overload string. Should distinguish any type that C (or C++) can
777 distinguish. I.e., pointers to functions are treated correctly.
779 Caller must deal with whether a final `e' goes on the end or not.
781 Any default conversions must take place before this function
784 BEGIN and END control initialization and finalization of the
785 obstack where we build the string. */
788 build_overload_name (parmtypes
, begin
, end
)
795 if (begin
) OB_INIT ();
796 numeric_output_need_bar
= 0;
798 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
800 parmtype
= parmtypes
;
806 parmtype
= TREE_VALUE (parmtypes
);
810 if (! nofold
&& ! just_one
)
812 /* Every argument gets counted. */
813 typevec
[maxtype
++] = parmtype
;
815 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
822 flush_repeats (typevec
[maxtype
-2]);
824 if (TREE_USED (parmtype
))
827 /* We can turn this on at some point when we want
828 improved symbol mangling. */
831 /* This is bug compatible with 2.7.x */
832 flush_repeats (parmtype
);
837 /* Only cache types which take more than one character. */
838 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
839 || (TREE_CODE (parmtype
) != INTEGER_TYPE
840 && TREE_CODE (parmtype
) != REAL_TYPE
))
841 TREE_USED (parmtype
) = 1;
844 if (TYPE_PTRMEMFUNC_P (parmtype
))
845 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
847 if (TREE_READONLY (parmtype
))
849 if (TREE_CODE (parmtype
) == INTEGER_TYPE
850 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
852 if (TYPE_VOLATILE (parmtype
))
855 switch (TREE_CODE (parmtype
))
859 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
861 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
869 #if PARM_CAN_BE_ARRAY_TYPE
874 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
875 error ("pointer or reference to array of unknown bound in parm type");
878 length
= array_type_nelts (parmtype
);
879 if (TREE_CODE (length
) == INTEGER_CST
)
880 icat (TREE_INT_CST_LOW (length
) + 1);
893 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
899 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
900 /* Otherwise have to implement reentrant typevecs,
901 unmark and remark types, etc. */
902 int old_nofold
= nofold
;
906 flush_repeats (typevec
[maxtype
-1]);
908 /* @@ It may be possible to pass a function type in
909 which is not preceded by a 'P'. */
910 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
913 if (firstarg
== NULL_TREE
)
915 else if (firstarg
== void_list_node
)
918 build_overload_name (firstarg
, 0, 0);
922 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
923 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
925 firstarg
= TREE_CHAIN (firstarg
);
927 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
933 /* For cfront 2.0 compatibility. */
936 if (firstarg
== NULL_TREE
)
938 else if (firstarg
== void_list_node
)
941 build_overload_name (firstarg
, 0, 0);
944 /* Separate args from return type. */
946 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
952 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
953 if (parmtype
== integer_type_node
954 || parmtype
== unsigned_type_node
)
956 else if (parmtype
== long_integer_type_node
957 || parmtype
== long_unsigned_type_node
)
959 else if (parmtype
== short_integer_type_node
960 || parmtype
== short_unsigned_type_node
)
962 else if (parmtype
== signed_char_type_node
)
967 else if (parmtype
== char_type_node
968 || parmtype
== unsigned_char_type_node
)
970 else if (parmtype
== wchar_type_node
)
972 else if (parmtype
== long_long_integer_type_node
973 || parmtype
== long_long_unsigned_type_node
)
976 /* it would seem there is no way to enter these in source code,
978 else if (parmtype
== long_long_long_integer_type_node
979 || parmtype
== long_long_long_unsigned_type_node
)
983 my_friendly_abort (73);
991 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
992 if (parmtype
== long_double_type_node
)
994 else if (parmtype
== double_type_node
)
996 else if (parmtype
== float_type_node
)
998 else my_friendly_abort (74);
1003 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
1010 extern tree void_list_node
;
1012 /* See if anybody is wasting memory. */
1013 my_friendly_assert (parmtypes
== void_list_node
, 247);
1015 /* This is the end of a parameter list. */
1016 if (end
) OB_FINISH ();
1017 return (char *)obstack_base (&scratch_obstack
);
1022 case ERROR_MARK
: /* not right, but nothing is anyway */
1025 /* have to do these */
1029 /* Make this type signature look incompatible
1036 tree name
= TYPE_NAME (parmtype
);
1038 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
1040 build_overload_identifier (TYPE_NAME (parmtype
));
1043 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1045 build_qualified_name (name
);
1050 /* This will take some work. */
1054 case TEMPLATE_TYPE_PARM
:
1056 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1057 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1061 /* When mangling the type of a function template whose
1062 declaration looks like:
1064 template <class T> void foo(typename T::U)
1066 we have to mangle these. */
1067 build_qualified_name (parmtype
);
1071 my_friendly_abort (75);
1075 if (just_one
) break;
1076 parmtypes
= TREE_CHAIN (parmtypes
);
1081 flush_repeats (typevec
[maxtype
-1]);
1083 /* To get here, parms must end with `...'. */
1087 if (end
) OB_FINISH ();
1088 return (char *)obstack_base (&scratch_obstack
);
1091 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1092 be either a class TYPE or a FUNCTION_DECL. */
1095 build_static_name (context
, name
)
1099 numeric_output_need_bar
= 0;
1102 build_qualified_name (context
);
1105 OB_PUTS ("__static_");
1106 build_qualified_name (context
);
1112 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1116 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1125 char *name
= IDENTIFIER_POINTER (dname
);
1127 /* member operators new and delete look like methods at this point. */
1128 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1129 && TREE_CHAIN (parms
) == void_list_node
)
1131 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1132 return get_identifier ("__builtin_delete");
1133 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1134 return get_identifier ("__builtin_vec_delete");
1135 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1136 return get_identifier ("__builtin_new");
1137 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1138 return get_identifier ("__builtin_vec_new");
1142 if (for_method
!= 2)
1144 /* Otherwise, we can divine that this is a constructor,
1145 and figure out its name without any extra encoding. */
1147 OB_PUTC2 ('_', '_');
1151 /* We can get away without doing this. */
1154 if (tparms
!= NULL_TREE
)
1157 tree this_type
= TREE_VALUE (parms
);
1159 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1160 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1161 TREE_CHAIN (parms
));
1163 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1164 TREE_CHAIN (parms
));
1174 build_template_parm_names (tparms
, targs
);
1178 if (parms
== NULL_TREE
)
1180 else if (parms
== void_list_node
)
1184 ALLOCATE_TYPEVEC (parms
);
1188 build_overload_name (TREE_VALUE (parms
), 0, 0);
1190 typevec
[maxtype
++] = TREE_VALUE (parms
);
1191 TREE_USED (TREE_VALUE (parms
)) = 1;
1193 if (TREE_CHAIN (parms
))
1194 build_overload_name (TREE_CHAIN (parms
), 0, 0);
1199 build_overload_name (parms
, 0, 0);
1200 DEALLOCATE_TYPEVEC (parms
);
1203 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1205 /* Add the return type. */
1207 build_overload_name (ret_type
, 0, 0);
1212 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1213 if (IDENTIFIER_OPNAME_P (dname
))
1214 IDENTIFIER_OPNAME_P (n
) = 1;
1219 /* Change the name of a function definition so that it may be
1220 overloaded. NAME is the name of the function to overload,
1221 PARMS is the parameter list (which determines what name the
1222 final function obtains).
1224 FOR_METHOD is 1 if this overload is being performed
1225 for a method, rather than a function type. It is 2 if
1226 this overload is being performed for a constructor. */
1229 build_decl_overload (dname
, parms
, for_method
)
1234 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1235 NULL_TREE
, for_method
);
1239 /* Like build_decl_overload, but for template functions. */
1242 build_template_decl_overload (dname
, parms
, ret_type
, tparms
, targs
,
1251 return build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1256 /* Build an overload name for the type expression TYPE. */
1259 build_typename_overload (type
)
1265 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1267 build_overload_name (type
, 0, 1);
1268 id
= get_identifier (obstack_base (&scratch_obstack
));
1269 IDENTIFIER_OPNAME_P (id
) = 1;
1271 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1273 TREE_TYPE (id
) = type
;
1278 build_overload_with_type (name
, type
)
1285 build_overload_name (type
, 0, 1);
1286 return get_identifier (obstack_base (&scratch_obstack
));
1290 get_id_2 (name
, name2
)
1298 return get_identifier (obstack_base (&scratch_obstack
));
1301 /* Given a tree_code CODE, and some arguments (at least one),
1302 attempt to use an overloaded operator on the arguments.
1304 For unary operators, only the first argument need be checked.
1305 For binary operators, both arguments may need to be checked.
1307 Member functions can convert class references to class pointers,
1308 for one-level deep indirection. More than that is not supported.
1309 Operators [](), ()(), and ->() must be member functions.
1311 We call function call building calls with LOOKUP_COMPLAIN if they
1312 are our only hope. This is true when we see a vanilla operator
1313 applied to something of aggregate type. If this fails, we are free
1314 to return `error_mark_node', because we will have reported the
1317 Operators NEW and DELETE overload in funny ways: operator new takes
1318 a single `size' parameter, and operator delete takes a pointer to the
1319 storage being deleted. When overloading these operators, success is
1320 assumed. If there is a failure, report an error message and return
1321 `error_mark_node'. */
1325 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1326 enum tree_code code
;
1328 tree xarg1
, xarg2
, arg3
;
1332 tree type1
, type2
, fnname
;
1333 tree fields1
= 0, parms
= 0;
1336 int binary_is_unary
;
1338 if (flag_ansi_overloading
)
1339 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1341 if (xarg1
== error_mark_node
)
1342 return error_mark_node
;
1344 if (code
== COND_EXPR
)
1346 if (xarg2
== error_mark_node
1347 || arg3
== error_mark_node
)
1348 return error_mark_node
;
1350 if (code
== COMPONENT_REF
)
1351 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1354 /* First, see if we can work with the first argument */
1355 type1
= TREE_TYPE (xarg1
);
1357 /* Some tree codes have length > 1, but we really only want to
1358 overload them if their first argument has a user defined type. */
1361 case PREINCREMENT_EXPR
:
1362 case PREDECREMENT_EXPR
:
1363 case POSTINCREMENT_EXPR
:
1364 case POSTDECREMENT_EXPR
:
1366 binary_is_unary
= 1;
1370 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1371 If they do not, return error_mark_node instead of NULL_TREE. */
1373 if (xarg2
== error_mark_node
)
1374 return error_mark_node
;
1376 rval
= error_mark_node
;
1377 binary_is_unary
= 0;
1384 tree args
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1385 fnname
= ansi_opname
[(int) code
];
1386 if (flags
& LOOKUP_GLOBAL
)
1387 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
);
1389 rval
= build_method_call
1390 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1392 fnname
, args
, NULL_TREE
, flags
);
1393 if (rval
== error_mark_node
)
1394 /* User might declare fancy operator new, but invoke it
1395 like standard one. */
1398 TREE_TYPE (rval
) = xarg1
;
1403 case VEC_DELETE_EXPR
:
1406 fnname
= ansi_opname
[(int) code
];
1407 if (flags
& LOOKUP_GLOBAL
)
1408 return build_overload_call (fnname
,
1409 build_expr_list (NULL_TREE
, xarg1
),
1410 flags
& LOOKUP_COMPLAIN
);
1411 arg1
= TREE_TYPE (xarg1
);
1413 /* This handles the case where we're trying to delete
1418 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
1420 /* Strip off the pointer and the array. */
1421 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
1423 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
1424 arg1
= (TREE_TYPE (arg1
));
1426 arg1
= build_pointer_type (arg1
);
1429 rval
= build_method_call
1430 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
1433 fnname
, expr_tree_cons (NULL_TREE
, xarg1
,
1434 build_expr_list (NULL_TREE
, xarg2
)),
1437 /* This can happen when operator delete is protected. */
1438 my_friendly_assert (rval
!= error_mark_node
, 250);
1439 TREE_TYPE (rval
) = void_type_node
;
1446 binary_is_unary
= 0;
1447 try_second
= tree_code_length
[(int) code
] == 2;
1448 if (try_second
&& xarg2
== error_mark_node
)
1449 return error_mark_node
;
1453 if (try_second
&& xarg2
== error_mark_node
)
1454 return error_mark_node
;
1456 /* What ever it was, we do not know how to deal with it. */
1457 if (type1
== NULL_TREE
)
1460 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1461 type1
= TREE_TYPE (type1
);
1463 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1465 arg1
= convert_from_reference (xarg1
);
1466 type1
= TREE_TYPE (arg1
);
1473 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1475 /* Try to fail. First, fail if unary */
1478 /* Second, see if second argument is non-aggregate. */
1479 type2
= TREE_TYPE (xarg2
);
1480 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1481 type2
= TREE_TYPE (type2
);
1482 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1484 arg2
= convert_from_reference (xarg2
);
1485 type2
= TREE_TYPE (arg2
);
1492 if (!IS_AGGR_TYPE (type2
))
1499 /* First arg may succeed; see whether second should. */
1500 type2
= TREE_TYPE (xarg2
);
1501 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1502 type2
= TREE_TYPE (type2
);
1503 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1505 arg2
= convert_from_reference (xarg2
);
1506 type2
= TREE_TYPE (arg2
);
1513 if (! IS_AGGR_TYPE (type2
))
1517 if (type1
== unknown_type_node
1518 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1520 /* This will not be implemented in the foreseeable future. */
1524 if (code
== MODIFY_EXPR
)
1525 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1527 fnname
= ansi_opname
[(int) code
];
1529 global_fn
= lookup_name_nonclass (fnname
);
1531 /* This is the last point where we will accept failure. This
1532 may be too eager if we wish an overloaded operator not to match,
1533 but would rather a normal operator be called on a type-converted
1536 if (IS_AGGR_TYPE (type1
))
1538 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1539 /* ARM $13.4.7, prefix/postfix ++/--. */
1540 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1542 xarg2
= integer_zero_node
;
1543 binary_is_unary
= 0;
1548 int have_postfix
= 0;
1550 /* Look for an `operator++ (int)'. If they didn't have
1551 one, then we fall back to the old way of doing things. */
1552 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1554 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1555 if (TREE_CHAIN (t2
) != NULL_TREE
1556 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1565 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1567 /* There's probably a LOT of code in the world that
1568 relies upon this old behavior. */
1569 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1572 binary_is_unary
= 1;
1578 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1581 /* If RVAL winds up being `error_mark_node', we will return
1582 that... There is no way that normal semantics of these
1583 operators will succeed. */
1585 /* This argument may be an uncommitted OFFSET_REF. This is
1586 the case for example when dealing with static class members
1587 which are referenced from their class name rather than
1588 from a class instance. */
1589 if (TREE_CODE (xarg1
) == OFFSET_REF
1590 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1591 xarg1
= TREE_OPERAND (xarg1
, 1);
1592 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1593 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1594 xarg2
= TREE_OPERAND (xarg2
, 1);
1597 flags
|= LOOKUP_GLOBAL
;
1599 if (code
== CALL_EXPR
)
1601 /* This can only be a member function. */
1602 return build_method_call (xarg1
, fnname
, xarg2
,
1603 NULL_TREE
, LOOKUP_NORMAL
);
1605 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1608 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1610 else if (code
== COND_EXPR
)
1612 parms
= expr_tree_cons (NULL_TREE
, xarg2
, build_expr_list (NULL_TREE
, arg3
));
1613 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1615 else if (code
== METHOD_CALL_EXPR
)
1617 /* must be a member function. */
1618 parms
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1619 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1624 parms
= build_expr_list (NULL_TREE
, xarg2
);
1625 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1629 parms
= expr_tree_cons (NULL_TREE
, xarg1
,
1630 build_expr_list (NULL_TREE
, xarg2
));
1631 rval
= build_overload_call (fnname
, parms
, flags
);
1637 /* This function takes an identifier, ID, and attempts to figure out what
1638 it means. There are a number of possible scenarios, presented in increasing
1641 1) not in a class's scope
1642 2) in class's scope, member name of the class's method
1643 3) in class's scope, but not a member name of the class
1644 4) in class's scope, member name of a class's variable
1646 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1647 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1649 As a last ditch, try to look up the name as a label and return that
1652 Values which are declared as being of REFERENCE_TYPE are
1653 automatically dereferenced here (as a hack to make the
1654 compiler faster). */
1657 hack_identifier (value
, name
)
1662 if (value
== error_mark_node
)
1664 if (current_class_name
)
1666 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1667 if (fields
== error_mark_node
)
1668 return error_mark_node
;
1673 fndecl
= TREE_VALUE (fields
);
1674 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1675 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1677 warning ("methods cannot be converted to function pointers");
1682 error ("ambiguous request for method pointer `%s'",
1683 IDENTIFIER_POINTER (name
));
1684 return error_mark_node
;
1688 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1690 return IDENTIFIER_LABEL_VALUE (name
);
1692 return error_mark_node
;
1695 type
= TREE_TYPE (value
);
1696 if (TREE_CODE (value
) == FIELD_DECL
)
1698 if (current_class_ptr
== NULL_TREE
)
1700 error ("request for member `%s' in static member function",
1701 IDENTIFIER_POINTER (DECL_NAME (value
)));
1702 return error_mark_node
;
1704 TREE_USED (current_class_ptr
) = 1;
1706 /* Mark so that if we are in a constructor, and then find that
1707 this field was initialized by a base initializer,
1708 we can emit an error message. */
1709 TREE_USED (value
) = 1;
1710 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1712 else if (really_overloaded_fn (value
))
1715 tree t
= get_first_fn (value
);
1716 for (; t
; t
= DECL_CHAIN (t
))
1718 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1721 assemble_external (t
);
1726 else if (TREE_CODE (value
) == TREE_LIST
)
1728 /* Ambiguous reference to base members, possibly other cases?. */
1730 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1732 mark_used (TREE_VALUE (t
));
1739 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1741 tree context
= decl_function_context (value
);
1742 if (context
!= NULL_TREE
&& context
!= current_function_decl
1743 && ! TREE_STATIC (value
))
1745 cp_error ("use of %s from containing function",
1746 (TREE_CODE (value
) == VAR_DECL
1747 ? "`auto' variable" : "parameter"));
1748 cp_error_at (" `%#D' declared here", value
);
1749 value
= error_mark_node
;
1753 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1755 if (DECL_LANG_SPECIFIC (value
)
1756 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1759 register tree context
1760 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1761 ? DECL_CLASS_CONTEXT (value
)
1762 : DECL_CONTEXT (value
);
1764 get_base_distance (context
, current_class_type
, 0, &path
);
1767 access
= compute_access (path
, value
);
1768 if (access
!= access_public_node
)
1770 if (TREE_CODE (value
) == VAR_DECL
)
1771 error ("static member `%s' is %s",
1772 IDENTIFIER_POINTER (name
),
1773 TREE_PRIVATE (value
) ? "private"
1774 : "from a private base class");
1776 error ("enum `%s' is from private base class",
1777 IDENTIFIER_POINTER (name
));
1778 return error_mark_node
;
1783 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1787 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1788 IDENTIFIER_POINTER (name
));
1789 return error_mark_node
;
1795 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1796 value
= convert_from_reference (value
);
1802 thunk_printable_name (decl
)
1805 return "<thunk function>";
1809 make_thunk (function
, delta
)
1818 if (TREE_CODE (function
) != ADDR_EXPR
)
1820 func_decl
= TREE_OPERAND (function
, 0);
1821 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1823 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1825 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1827 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1828 thunk_id
= get_identifier (buffer
);
1829 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1830 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1832 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1833 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1835 if (thunk
== NULL_TREE
)
1837 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1838 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1839 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1840 comdat_linkage (thunk
);
1841 TREE_SET_CODE (thunk
, THUNK_DECL
);
1842 DECL_INITIAL (thunk
) = function
;
1843 THUNK_DELTA (thunk
) = delta
;
1844 DECL_EXTERNAL (thunk
) = 1;
1845 DECL_ARTIFICIAL (thunk
) = 1;
1846 /* So that finish_file can write out any thunks that need to be: */
1847 pushdecl_top_level (thunk
);
1852 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1855 emit_thunk (thunk_fndecl
)
1858 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1859 int delta
= THUNK_DELTA (thunk_fndecl
);
1861 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1864 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1866 TREE_ADDRESSABLE (function
) = 1;
1867 mark_used (function
);
1869 if (current_function_decl
)
1872 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1875 #ifdef ASM_OUTPUT_MI_THUNK
1877 current_function_decl
= thunk_fndecl
;
1878 /* Make sure we build up its RTL before we go onto the
1879 temporary obstack. */
1880 make_function_rtl (thunk_fndecl
);
1881 temporary_allocation ();
1882 DECL_RESULT (thunk_fndecl
)
1883 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1884 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1885 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1886 assemble_start_function (thunk_fndecl
, fnname
);
1887 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
1888 assemble_end_function (thunk_fndecl
, fnname
);
1889 permanent_allocation (1);
1890 current_function_decl
= 0;
1891 #else /* ASM_OUTPUT_MI_THUNK */
1892 /* If we don't have the necessary macro for efficient thunks, generate a
1893 thunk function that just makes a call to the real function.
1894 Unfortunately, this doesn't work for varargs. */
1898 if (varargs_function_p (function
))
1899 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1902 /* Set up clone argument trees for the thunk. */
1904 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
1906 tree x
= copy_node (a
);
1908 DECL_CONTEXT (x
) = thunk_fndecl
;
1912 DECL_ARGUMENTS (thunk_fndecl
) = a
;
1913 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
1914 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
1915 copy_lang_decl (thunk_fndecl
);
1916 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
1917 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
1919 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
1920 store_parm_decls ();
1921 current_function_is_thunk
= 1;
1923 /* Build up the call to the real function. */
1924 t
= build_int_2 (delta
, -1 * (delta
< 0));
1925 TREE_TYPE (t
) = signed_type (sizetype
);
1926 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
1927 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
1928 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
1929 t
= expr_tree_cons (NULL_TREE
, a
, t
);
1931 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
1932 c_expand_return (t
);
1934 finish_function (lineno
, 0, 0);
1936 /* Don't let the backend defer this function. */
1937 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
1939 output_inline_function (thunk_fndecl
);
1940 permanent_allocation (1);
1942 #endif /* ASM_OUTPUT_MI_THUNK */
1945 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
1948 /* Code for synthesizing methods which have default semantics defined. */
1950 /* For the anonymous union in TYPE, return the member that is at least as
1951 large as the rest of the members, so we can copy it. */
1954 largest_union_member (type
)
1957 tree f
, type_size
= TYPE_SIZE (type
);
1959 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
1960 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
1963 /* We should always find one. */
1964 my_friendly_abort (323);
1968 /* Generate code for default X(X&) constructor. */
1971 do_build_copy_constructor (fndecl
)
1974 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
1980 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1981 parm
= TREE_CHAIN (parm
);
1982 parm
= convert_from_reference (parm
);
1984 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
1986 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
1987 TREE_SIDE_EFFECTS (t
) = 1;
1988 cplus_expand_expr_stmt (t
);
1992 tree fields
= TYPE_FIELDS (current_class_type
);
1993 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
1994 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
1997 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2000 tree basetype
= BINFO_TYPE (t
);
2001 tree p
= convert_to_reference
2002 (build_reference_type (basetype
), parm
,
2003 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2004 p
= convert_from_reference (p
);
2006 if (p
== error_mark_node
)
2007 cp_error ("in default copy constructor");
2009 current_base_init_list
= tree_cons (basetype
,
2010 p
, current_base_init_list
);
2013 for (i
= 0; i
< n_bases
; ++i
)
2015 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2016 if (TREE_VIA_VIRTUAL (basetype
))
2019 basetype
= BINFO_TYPE (basetype
);
2020 p
= convert_to_reference
2021 (build_reference_type (basetype
), parm
,
2022 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2024 if (p
== error_mark_node
)
2025 cp_error ("in default copy constructor");
2028 p
= convert_from_reference (p
);
2029 current_base_init_list
= tree_cons (basetype
,
2030 p
, current_base_init_list
);
2033 for (; fields
; fields
= TREE_CHAIN (fields
))
2036 tree field
= fields
;
2038 if (TREE_CODE (field
) != FIELD_DECL
)
2042 if (DECL_NAME (field
))
2044 if (VFIELD_NAME_P (DECL_NAME (field
)))
2046 if (VBASE_NAME_P (DECL_NAME (field
)))
2049 /* True for duplicate members. */
2050 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2053 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2054 && TREE_CODE (t
) == UNION_TYPE
2055 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2056 && TYPE_FIELDS (t
) != NULL_TREE
)
2060 init
= build (COMPONENT_REF
, t
, init
, field
);
2061 field
= largest_union_member (t
);
2063 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2064 && TREE_CODE (t
) == UNION_TYPE
2065 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2066 && TYPE_FIELDS (t
) != NULL_TREE
);
2071 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2072 init
= build_tree_list (NULL_TREE
, init
);
2074 current_member_init_list
2075 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2077 current_member_init_list
= nreverse (current_member_init_list
);
2078 current_base_init_list
= nreverse (current_base_init_list
);
2086 do_build_assign_ref (fndecl
)
2089 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2094 parm
= convert_from_reference (parm
);
2096 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2098 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2099 TREE_SIDE_EFFECTS (t
) = 1;
2100 cplus_expand_expr_stmt (t
);
2104 tree fields
= TYPE_FIELDS (current_class_type
);
2105 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2106 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2109 for (i
= 0; i
< n_bases
; ++i
)
2111 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2112 tree p
= convert_to_reference
2113 (build_reference_type (basetype
), parm
,
2114 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2115 p
= convert_from_reference (p
);
2116 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2117 build_expr_list (NULL_TREE
, p
));
2118 expand_expr_stmt (p
);
2120 for (; fields
; fields
= TREE_CHAIN (fields
))
2123 tree field
= fields
;
2125 if (TREE_CODE (field
) != FIELD_DECL
)
2128 if (TREE_READONLY (field
))
2130 if (DECL_NAME (field
))
2131 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2133 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2136 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2138 if (DECL_NAME (field
))
2139 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2141 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2145 comp
= current_class_ref
;
2148 if (DECL_NAME (field
))
2150 if (VFIELD_NAME_P (DECL_NAME (field
)))
2152 if (VBASE_NAME_P (DECL_NAME (field
)))
2155 /* True for duplicate members. */
2156 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2159 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2160 && TREE_CODE (t
) == UNION_TYPE
2161 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2162 && TYPE_FIELDS (t
) != NULL_TREE
)
2166 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2167 init
= build (COMPONENT_REF
, t
, init
, field
);
2168 field
= largest_union_member (t
);
2170 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2171 && TREE_CODE (t
) == UNION_TYPE
2172 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2173 && TYPE_FIELDS (t
) != NULL_TREE
);
2178 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2179 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2181 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2184 c_expand_return (current_class_ref
);
2189 synthesize_method (fndecl
)
2192 int nested
= (current_function_decl
!= NULL_TREE
);
2193 tree context
= hack_decl_function_context (fndecl
);
2196 import_export_decl (fndecl
);
2199 push_to_top_level ();
2201 push_cp_function_context (context
);
2203 interface_unknown
= 1;
2204 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2205 store_parm_decls ();
2207 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2208 do_build_assign_ref (fndecl
);
2209 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2213 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2214 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2215 arg_chain
= TREE_CHAIN (arg_chain
);
2216 if (arg_chain
!= void_list_node
)
2217 do_build_copy_constructor (fndecl
);
2218 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2222 finish_function (lineno
, 0, nested
);
2224 extract_interface_info ();
2226 pop_from_top_level ();
2228 pop_cp_function_context (context
);