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
));
75 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
76 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
77 # define OB_PUTC2(C1,C2) \
78 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
79 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
80 # define OB_PUTID(ID) \
81 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
82 IDENTIFIER_LENGTH (ID)))
83 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
84 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
85 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
90 gcc_obstack_init (&scratch_obstack
);
91 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
94 /* This must be large enough to hold any printed integer or floating-point
96 static char digit_buffer
[128];
98 /* Move inline function definitions out of structure so that they
99 can be processed normally. CNAME is the name of the class
100 we are working from, METHOD_LIST is the list of method lists
101 of the structure. We delete friend methods here, after
102 saving away their inline function definitions (if any). */
105 do_inline_function_hair (type
, friend_list
)
106 tree type
, friend_list
;
108 tree method
= TYPE_METHODS (type
);
110 if (method
&& TREE_CODE (method
) == TREE_VEC
)
112 if (TREE_VEC_ELT (method
, 1))
113 method
= TREE_VEC_ELT (method
, 1);
114 else if (TREE_VEC_ELT (method
, 0))
115 method
= TREE_VEC_ELT (method
, 0);
117 method
= TREE_VEC_ELT (method
, 2);
122 /* Do inline member functions. */
123 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
128 my_friendly_assert (info
->fndecl
== method
, 238);
129 args
= DECL_ARGUMENTS (method
);
132 DECL_CONTEXT (args
) = method
;
133 args
= TREE_CHAIN (args
);
136 /* Allow this decl to be seen in global scope. Don't do this for
137 local class methods, though. */
138 if (! current_function_decl
)
139 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method
)) = method
;
141 method
= TREE_CHAIN (method
);
145 tree fndecl
= TREE_VALUE (friend_list
);
146 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
151 my_friendly_assert (info
->fndecl
== fndecl
, 239);
152 args
= DECL_ARGUMENTS (fndecl
);
155 DECL_CONTEXT (args
) = fndecl
;
156 args
= TREE_CHAIN (args
);
159 /* Allow this decl to be seen in global scope */
160 if (! current_function_decl
)
161 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl
)) = fndecl
;
164 friend_list
= TREE_CHAIN (friend_list
);
168 /* Report an argument type mismatch between the best declared function
169 we could find and the current argument list that we have. */
172 report_type_mismatch (cp
, parmtypes
, name_kind
)
173 struct candidate
*cp
;
177 int i
= cp
->u
.bad_arg
;
184 my_friendly_assert (TREE_CODE (cp
->function
) == TEMPLATE_DECL
, 240);
185 cp_error ("type unification failed for function template `%#D'",
190 cp_error ("too few arguments for %s `%#D'", name_kind
, cp
->function
);
193 cp_error ("too many arguments for %s `%#D'", name_kind
, cp
->function
);
196 if (TREE_CODE (TREE_TYPE (cp
->function
)) != METHOD_TYPE
)
199 /* Happens when the implicit object parameter is rejected. */
200 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))),
202 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
203 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
204 cp_error ("call to non-volatile %s `%#D' with volatile object",
205 name_kind
, cp
->function
);
207 cp_error ("call to non-const %s `%#D' with const object",
208 name_kind
, cp
->function
);
212 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
217 ttf
= TREE_CHAIN (ttf
);
218 tta
= TREE_CHAIN (tta
);
222 OB_PUTS ("bad argument ");
223 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
224 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
226 OB_PUTCP (digit_buffer
);
228 OB_PUTS (" for function `");
229 OB_PUTCP (decl_as_string (cp
->function
, 1));
230 OB_PUTS ("' (type was ");
232 /* Reset `i' so that type printing routines do the right thing. */
235 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
236 if (code
== ERROR_MARK
)
237 OB_PUTS ("(failed type instantiation)");
240 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
241 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
244 else OB_PUTS ("void");
248 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
249 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
250 obstack_object_size (&scratch_obstack
));
251 error (tmp_firstobj
);
254 /* Here is where overload code starts. */
256 /* Array of types seen so far in top-level call to `build_overload_name'.
257 Allocated and deallocated by caller. */
258 static tree
*typevec
;
260 /* Number of types interned by `build_overload_name' so far. */
263 /* Number of occurrences of last type seen. */
266 /* Nonzero if we should not try folding parameter types. */
269 #define ALLOCATE_TYPEVEC(PARMTYPES) \
270 do { maxtype = 0, nrepeats = 0; \
271 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
273 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
274 do { tree t = (PARMTYPES); \
275 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
278 /* Code to concatenate an asciified integer to a string. */
288 unsigned HOST_WIDE_INT ui
;
290 /* Handle this case first, to go really quickly. For many common values,
291 the result of ui/10 below is 1. */
309 OB_PUTC ('0' + (ui
% 10));
314 HOST_WIDE_INT lo
, hi
;
316 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
325 uhi
= (lo
== 0 ? -hi
: -hi
-1);
329 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
334 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
337 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
340 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
344 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
359 while (typevec
[tindex
] != type
)
377 static int numeric_output_need_bar
;
380 build_overload_nested_name (decl
)
383 if (DECL_CONTEXT (decl
))
385 tree context
= DECL_CONTEXT (decl
);
386 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
387 context
= TYPE_NAME (context
);
388 build_overload_nested_name (context
);
391 if (TREE_CODE (decl
) == FUNCTION_DECL
)
393 tree name
= DECL_ASSEMBLER_NAME (decl
);
396 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
399 if (numeric_output_need_bar
)
401 icat (strlen (label
));
403 numeric_output_need_bar
= 1;
406 build_overload_identifier (decl
);
409 /* Encoding for an INTEGER_CST value. */
412 build_overload_int (value
, in_template
)
416 if (TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
419 if (TEMPLATE_CONST_IDX (value
) > 9)
421 icat (TEMPLATE_CONST_IDX (value
));
422 if (TEMPLATE_CONST_IDX (value
) > 9)
427 && TREE_CODE (value
) != INTEGER_CST
)
428 /* We don't ever want this output, but it's inconvenient not to
429 be able to build the string. This should cause assembler
430 errors we'll notice. */
433 sprintf (digit_buffer
, " *%d", n
++);
434 OB_PUTCP (digit_buffer
);
438 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
439 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
441 if (TREE_INT_CST_HIGH (value
)
442 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
444 /* need to print a DImode value in decimal */
445 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
448 /* else fall through to print in smaller mode */
450 /* Wordsize or smaller */
451 icat (TREE_INT_CST_LOW (value
));
455 build_overload_value (type
, value
, in_template
)
459 while (TREE_CODE (value
) == NON_LVALUE_EXPR
460 || TREE_CODE (value
) == NOP_EXPR
)
461 value
= TREE_OPERAND (value
, 0);
462 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
463 type
= TREE_TYPE (type
);
465 if (numeric_output_need_bar
)
468 numeric_output_need_bar
= 0;
471 if (TREE_CODE (type
) == POINTER_TYPE
472 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
474 /* Handle a pointer to data member as a template instantiation
475 parameter, boy, what fun! */
476 type
= integer_type_node
;
477 if (TREE_CODE (value
) != INTEGER_CST
)
479 sorry ("unknown pointer to member constant");
484 if (TYPE_PTRMEMFUNC_P (type
))
485 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
487 switch (TREE_CODE (type
))
493 build_overload_int (value
, in_template
);
494 numeric_output_need_bar
= 1;
500 char *bufp
= digit_buffer
;
502 pedwarn ("ANSI C++ forbids floating-point template arguments");
504 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
505 val
= TREE_REAL_CST (value
);
506 if (REAL_VALUE_ISNAN (val
))
508 sprintf (bufp
, "NaN");
512 if (REAL_VALUE_NEGATIVE (val
))
514 val
= REAL_VALUE_NEGATE (val
);
517 if (REAL_VALUE_ISINF (val
))
519 sprintf (bufp
, "Infinity");
523 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
524 bufp
= (char *) index (bufp
, 'e');
526 strcat (digit_buffer
, "e0");
552 #ifdef NO_DOT_IN_LABEL
553 bufp
= (char *) index (bufp
, '.');
559 OB_PUTCP (digit_buffer
);
560 numeric_output_need_bar
= 1;
564 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
565 && TREE_CODE (value
) != ADDR_EXPR
)
567 if (TREE_CODE (value
) == CONSTRUCTOR
)
569 /* This is dangerous code, crack built up pointer to members. */
570 tree args
= CONSTRUCTOR_ELTS (value
);
571 tree a1
= TREE_VALUE (args
);
572 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
573 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
574 a3
= TREE_VALUE (a3
);
576 if (TREE_CODE (a1
) == INTEGER_CST
577 && TREE_CODE (a2
) == INTEGER_CST
)
579 build_overload_int (a1
, in_template
);
581 build_overload_int (a2
, in_template
);
583 if (TREE_CODE (a3
) == ADDR_EXPR
)
585 a3
= TREE_OPERAND (a3
, 0);
586 if (TREE_CODE (a3
) == FUNCTION_DECL
)
588 numeric_output_need_bar
= 0;
589 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
593 else if (TREE_CODE (a3
) == INTEGER_CST
)
596 build_overload_int (a3
, in_template
);
597 numeric_output_need_bar
= 1;
602 sorry ("template instantiation with pointer to method that is too complex");
605 if (TREE_CODE (value
) == INTEGER_CST
606 || TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
608 build_overload_int (value
, in_template
);
609 numeric_output_need_bar
= 1;
612 value
= TREE_OPERAND (value
, 0);
613 if (TREE_CODE (value
) == VAR_DECL
)
615 my_friendly_assert (DECL_NAME (value
) != 0, 245);
616 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
619 else if (TREE_CODE (value
) == FUNCTION_DECL
)
621 my_friendly_assert (DECL_NAME (value
) != 0, 246);
622 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
626 my_friendly_abort (71);
627 break; /* not really needed */
630 sorry ("conversion of %s as template parameter",
631 tree_code_name
[(int) TREE_CODE (type
)]);
632 my_friendly_abort (72);
637 build_overload_identifier (name
)
640 if (TREE_CODE (name
) == TYPE_DECL
641 && IS_AGGR_TYPE (TREE_TYPE (name
))
642 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
643 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
))))
645 tree
template, parmlist
, arglist
, tname
;
647 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
648 arglist
= TREE_VALUE (template);
649 template = TREE_PURPOSE (template);
650 tname
= DECL_NAME (template);
651 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
652 nparms
= TREE_VEC_LENGTH (parmlist
);
654 icat (IDENTIFIER_LENGTH (tname
));
657 for (i
= 0; i
< nparms
; i
++)
659 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
660 tree arg
= TREE_VEC_ELT (arglist
, i
);
661 if (TREE_CODE (parm
) == TYPE_DECL
)
663 /* This parameter is a type. */
665 build_overload_name (arg
, 0, 0);
669 parm
= tsubst (parm
, arglist
,
670 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
671 /* It's a PARM_DECL. */
672 build_overload_name (TREE_TYPE (parm
), 0, 0);
673 build_overload_value (parm
, arg
, uses_template_parms (arglist
));
679 if (TREE_CODE (name
) == TYPE_DECL
)
680 name
= DECL_NAME (name
);
681 if (numeric_output_need_bar
)
684 numeric_output_need_bar
= 0;
686 icat (IDENTIFIER_LENGTH (name
));
691 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
692 the mangling for it. Used by build_overload_name and build_static_name. */
695 build_qualified_name (decl
)
701 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
702 decl
= TYPE_NAME (decl
);
704 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
705 if (TREE_CODE (decl
) == TYPE_DECL
706 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
708 OB_PUTID (DECL_ASSEMBLER_NAME (decl
));
713 while (DECL_CONTEXT (context
))
716 context
= DECL_CONTEXT (context
);
717 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
718 context
= TYPE_NAME (context
);
729 numeric_output_need_bar
= 0;
731 build_overload_nested_name (decl
);
734 /* Given a list of parameters in PARMTYPES, create an unambiguous
735 overload string. Should distinguish any type that C (or C++) can
736 distinguish. I.e., pointers to functions are treated correctly.
738 Caller must deal with whether a final `e' goes on the end or not.
740 Any default conversions must take place before this function
743 BEGIN and END control initialization and finalization of the
744 obstack where we build the string. */
747 build_overload_name (parmtypes
, begin
, end
)
754 if (begin
) OB_INIT ();
755 numeric_output_need_bar
= 0;
757 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
759 parmtype
= parmtypes
;
765 parmtype
= TREE_VALUE (parmtypes
);
769 if (! nofold
&& ! just_one
)
771 /* Every argument gets counted. */
772 typevec
[maxtype
++] = parmtype
;
774 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
781 flush_repeats (typevec
[maxtype
-2]);
783 if (TREE_USED (parmtype
))
786 /* We can turn this on at some point when we want
787 improved symbol mangling. */
790 /* This is bug compatible with 2.7.x */
791 flush_repeats (parmtype
);
796 /* Only cache types which take more than one character. */
797 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
798 || (TREE_CODE (parmtype
) != INTEGER_TYPE
799 && TREE_CODE (parmtype
) != REAL_TYPE
))
800 TREE_USED (parmtype
) = 1;
803 if (TYPE_PTRMEMFUNC_P (parmtype
))
804 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
806 if (TREE_READONLY (parmtype
))
808 if (TREE_CODE (parmtype
) == INTEGER_TYPE
809 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
811 if (TYPE_VOLATILE (parmtype
))
814 switch (TREE_CODE (parmtype
))
818 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
820 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
828 #if PARM_CAN_BE_ARRAY_TYPE
833 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
834 error ("pointer or reference to array of unknown bound in parm type");
837 length
= array_type_nelts (parmtype
);
838 if (TREE_CODE (length
) == INTEGER_CST
)
839 icat (TREE_INT_CST_LOW (length
) + 1);
852 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
858 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
859 /* Otherwise have to implement reentrant typevecs,
860 unmark and remark types, etc. */
861 int old_nofold
= nofold
;
865 flush_repeats (typevec
[maxtype
-1]);
867 /* @@ It may be possible to pass a function type in
868 which is not preceded by a 'P'. */
869 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
872 if (firstarg
== NULL_TREE
)
874 else if (firstarg
== void_list_node
)
877 build_overload_name (firstarg
, 0, 0);
881 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
882 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
884 firstarg
= TREE_CHAIN (firstarg
);
886 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
892 /* For cfront 2.0 compatibility. */
895 if (firstarg
== NULL_TREE
)
897 else if (firstarg
== void_list_node
)
900 build_overload_name (firstarg
, 0, 0);
903 /* Separate args from return type. */
905 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
911 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
912 if (parmtype
== integer_type_node
913 || parmtype
== unsigned_type_node
)
915 else if (parmtype
== long_integer_type_node
916 || parmtype
== long_unsigned_type_node
)
918 else if (parmtype
== short_integer_type_node
919 || parmtype
== short_unsigned_type_node
)
921 else if (parmtype
== signed_char_type_node
)
926 else if (parmtype
== char_type_node
927 || parmtype
== unsigned_char_type_node
)
929 else if (parmtype
== wchar_type_node
)
931 else if (parmtype
== long_long_integer_type_node
932 || parmtype
== long_long_unsigned_type_node
)
935 /* it would seem there is no way to enter these in source code,
937 else if (parmtype
== long_long_long_integer_type_node
938 || parmtype
== long_long_long_unsigned_type_node
)
942 my_friendly_abort (73);
950 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
951 if (parmtype
== long_double_type_node
)
953 else if (parmtype
== double_type_node
)
955 else if (parmtype
== float_type_node
)
957 else my_friendly_abort (74);
962 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
969 extern tree void_list_node
;
971 /* See if anybody is wasting memory. */
972 my_friendly_assert (parmtypes
== void_list_node
, 247);
974 /* This is the end of a parameter list. */
975 if (end
) OB_FINISH ();
976 return (char *)obstack_base (&scratch_obstack
);
981 case ERROR_MARK
: /* not right, but nothing is anyway */
984 /* have to do these */
988 /* Make this type signature look incompatible
995 tree name
= TYPE_NAME (parmtype
);
997 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
999 build_overload_identifier (TYPE_NAME (parmtype
));
1002 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1004 build_qualified_name (name
);
1009 /* This will take some work. */
1013 case TEMPLATE_TYPE_PARM
:
1015 if (TEMPLATE_TYPE_IDX (parmtype
) > 9)
1017 icat (TEMPLATE_TYPE_IDX (parmtype
));
1018 if (TEMPLATE_TYPE_IDX (parmtype
) > 9)
1023 /* We don't ever want this output, but it's inconvenient not to
1024 be able to build the string. This should cause assembler
1025 errors we'll notice. */
1028 sprintf (digit_buffer
, " *%d", n
++);
1029 OB_PUTCP (digit_buffer
);
1034 my_friendly_abort (75);
1038 if (just_one
) break;
1039 parmtypes
= TREE_CHAIN (parmtypes
);
1044 flush_repeats (typevec
[maxtype
-1]);
1046 /* To get here, parms must end with `...'. */
1050 if (end
) OB_FINISH ();
1051 return (char *)obstack_base (&scratch_obstack
);
1054 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1055 be either a class TYPE or a FUNCTION_DECL. */
1058 build_static_name (context
, name
)
1062 numeric_output_need_bar
= 0;
1065 build_qualified_name (context
);
1068 OB_PUTS ("__static_");
1069 build_qualified_name (context
);
1075 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1078 /* Change the name of a function definition so that it may be
1079 overloaded. NAME is the name of the function to overload,
1080 PARMS is the parameter list (which determines what name the
1081 final function obtains).
1083 FOR_METHOD is 1 if this overload is being performed
1084 for a method, rather than a function type. It is 2 if
1085 this overload is being performed for a constructor. */
1088 build_decl_overload (dname
, parms
, for_method
)
1093 char *name
= IDENTIFIER_POINTER (dname
);
1095 /* member operators new and delete look like methods at this point. */
1096 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
)
1098 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1099 return get_identifier ("__builtin_delete");
1100 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1101 return get_identifier ("__builtin_vec_delete");
1102 else if (TREE_CHAIN (parms
) == void_list_node
)
1104 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1105 return get_identifier ("__builtin_new");
1106 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1107 return get_identifier ("__builtin_vec_new");
1112 if (for_method
!= 2)
1114 /* Otherwise, we can divine that this is a constructor,
1115 and figure out its name without any extra encoding. */
1117 OB_PUTC2 ('_', '_');
1121 /* We can get away without doing this. */
1125 tree this_type
= TREE_VALUE (parms
);
1127 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1128 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1129 TREE_CHAIN (parms
));
1131 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1132 TREE_CHAIN (parms
));
1138 if (parms
== NULL_TREE
)
1139 OB_PUTC2 ('e', '\0');
1140 else if (parms
== void_list_node
)
1141 OB_PUTC2 ('v', '\0');
1144 ALLOCATE_TYPEVEC (parms
);
1148 build_overload_name (TREE_VALUE (parms
), 0, 0);
1150 typevec
[maxtype
++] = TREE_VALUE (parms
);
1151 TREE_USED (TREE_VALUE (parms
)) = 1;
1153 if (TREE_CHAIN (parms
))
1154 build_overload_name (TREE_CHAIN (parms
), 0, 1);
1156 OB_PUTC2 ('e', '\0');
1159 build_overload_name (parms
, 0, 1);
1160 DEALLOCATE_TYPEVEC (parms
);
1163 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1164 if (IDENTIFIER_OPNAME_P (dname
))
1165 IDENTIFIER_OPNAME_P (n
) = 1;
1170 /* Build an overload name for the type expression TYPE. */
1173 build_typename_overload (type
)
1179 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1181 build_overload_name (type
, 0, 1);
1182 id
= get_identifier (obstack_base (&scratch_obstack
));
1183 IDENTIFIER_OPNAME_P (id
) = 1;
1185 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1187 TREE_TYPE (id
) = type
;
1192 build_overload_with_type (name
, type
)
1199 build_overload_name (type
, 0, 1);
1200 return get_identifier (obstack_base (&scratch_obstack
));
1204 get_id_2 (name
, name2
)
1212 return get_identifier (obstack_base (&scratch_obstack
));
1215 /* Given a tree_code CODE, and some arguments (at least one),
1216 attempt to use an overloaded operator on the arguments.
1218 For unary operators, only the first argument need be checked.
1219 For binary operators, both arguments may need to be checked.
1221 Member functions can convert class references to class pointers,
1222 for one-level deep indirection. More than that is not supported.
1223 Operators [](), ()(), and ->() must be member functions.
1225 We call function call building calls with LOOKUP_COMPLAIN if they
1226 are our only hope. This is true when we see a vanilla operator
1227 applied to something of aggregate type. If this fails, we are free
1228 to return `error_mark_node', because we will have reported the
1231 Operators NEW and DELETE overload in funny ways: operator new takes
1232 a single `size' parameter, and operator delete takes a pointer to the
1233 storage being deleted. When overloading these operators, success is
1234 assumed. If there is a failure, report an error message and return
1235 `error_mark_node'. */
1239 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1240 enum tree_code code
;
1242 tree xarg1
, xarg2
, arg3
;
1246 tree type1
, type2
, fnname
;
1247 tree fields1
= 0, parms
= 0;
1250 int binary_is_unary
;
1252 if (flag_ansi_overloading
)
1253 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1255 if (xarg1
== error_mark_node
)
1256 return error_mark_node
;
1258 if (code
== COND_EXPR
)
1260 if (xarg2
== error_mark_node
1261 || arg3
== error_mark_node
)
1262 return error_mark_node
;
1264 if (code
== COMPONENT_REF
)
1265 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1268 /* First, see if we can work with the first argument */
1269 type1
= TREE_TYPE (xarg1
);
1271 /* Some tree codes have length > 1, but we really only want to
1272 overload them if their first argument has a user defined type. */
1275 case PREINCREMENT_EXPR
:
1276 case PREDECREMENT_EXPR
:
1277 case POSTINCREMENT_EXPR
:
1278 case POSTDECREMENT_EXPR
:
1280 binary_is_unary
= 1;
1284 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1285 If they do not, return error_mark_node instead of NULL_TREE. */
1287 if (xarg2
== error_mark_node
)
1288 return error_mark_node
;
1290 rval
= error_mark_node
;
1291 binary_is_unary
= 0;
1298 tree args
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1299 fnname
= ansi_opname
[(int) code
];
1300 if (flags
& LOOKUP_GLOBAL
)
1301 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
);
1303 rval
= build_method_call
1304 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1306 fnname
, args
, NULL_TREE
, flags
);
1307 if (rval
== error_mark_node
)
1308 /* User might declare fancy operator new, but invoke it
1309 like standard one. */
1312 TREE_TYPE (rval
) = xarg1
;
1313 TREE_CALLS_NEW (rval
) = 1;
1318 case VEC_DELETE_EXPR
:
1321 fnname
= ansi_opname
[(int) code
];
1322 if (flags
& LOOKUP_GLOBAL
)
1323 return build_overload_call (fnname
,
1324 build_tree_list (NULL_TREE
, xarg1
),
1325 flags
& LOOKUP_COMPLAIN
);
1326 arg1
= TREE_TYPE (xarg1
);
1328 /* This handles the case where we're trying to delete
1333 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
1335 /* Strip off the pointer and the array. */
1336 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
1338 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
1339 arg1
= (TREE_TYPE (arg1
));
1341 arg1
= build_pointer_type (arg1
);
1344 rval
= build_method_call
1345 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
1348 fnname
, tree_cons (NULL_TREE
, xarg1
,
1349 build_tree_list (NULL_TREE
, xarg2
)),
1352 /* This can happen when operator delete is protected. */
1353 my_friendly_assert (rval
!= error_mark_node
, 250);
1354 TREE_TYPE (rval
) = void_type_node
;
1361 binary_is_unary
= 0;
1362 try_second
= tree_code_length
[(int) code
] == 2;
1363 if (try_second
&& xarg2
== error_mark_node
)
1364 return error_mark_node
;
1368 if (try_second
&& xarg2
== error_mark_node
)
1369 return error_mark_node
;
1371 /* What ever it was, we do not know how to deal with it. */
1372 if (type1
== NULL_TREE
)
1375 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1376 type1
= TREE_TYPE (type1
);
1378 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1380 arg1
= convert_from_reference (xarg1
);
1381 type1
= TREE_TYPE (arg1
);
1388 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1390 /* Try to fail. First, fail if unary */
1393 /* Second, see if second argument is non-aggregate. */
1394 type2
= TREE_TYPE (xarg2
);
1395 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1396 type2
= TREE_TYPE (type2
);
1397 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1399 arg2
= convert_from_reference (xarg2
);
1400 type2
= TREE_TYPE (arg2
);
1407 if (!IS_AGGR_TYPE (type2
))
1414 /* First arg may succeed; see whether second should. */
1415 type2
= TREE_TYPE (xarg2
);
1416 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1417 type2
= TREE_TYPE (type2
);
1418 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1420 arg2
= convert_from_reference (xarg2
);
1421 type2
= TREE_TYPE (arg2
);
1428 if (! IS_AGGR_TYPE (type2
))
1432 if (type1
== unknown_type_node
1433 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1435 /* This will not be implemented in the foreseeable future. */
1439 if (code
== MODIFY_EXPR
)
1440 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1442 fnname
= ansi_opname
[(int) code
];
1444 global_fn
= lookup_name_nonclass (fnname
);
1446 /* This is the last point where we will accept failure. This
1447 may be too eager if we wish an overloaded operator not to match,
1448 but would rather a normal operator be called on a type-converted
1451 if (IS_AGGR_TYPE (type1
))
1453 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1454 /* ARM $13.4.7, prefix/postfix ++/--. */
1455 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1457 xarg2
= integer_zero_node
;
1458 binary_is_unary
= 0;
1463 int have_postfix
= 0;
1465 /* Look for an `operator++ (int)'. If they didn't have
1466 one, then we fall back to the old way of doing things. */
1467 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1469 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1470 if (TREE_CHAIN (t2
) != NULL_TREE
1471 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1480 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1482 /* There's probably a LOT of code in the world that
1483 relies upon this old behavior. */
1484 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1487 binary_is_unary
= 1;
1493 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1496 /* If RVAL winds up being `error_mark_node', we will return
1497 that... There is no way that normal semantics of these
1498 operators will succeed. */
1500 /* This argument may be an uncommitted OFFSET_REF. This is
1501 the case for example when dealing with static class members
1502 which are referenced from their class name rather than
1503 from a class instance. */
1504 if (TREE_CODE (xarg1
) == OFFSET_REF
1505 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1506 xarg1
= TREE_OPERAND (xarg1
, 1);
1507 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1508 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1509 xarg2
= TREE_OPERAND (xarg2
, 1);
1512 flags
|= LOOKUP_GLOBAL
;
1514 if (code
== CALL_EXPR
)
1516 /* This can only be a member function. */
1517 return build_method_call (xarg1
, fnname
, xarg2
,
1518 NULL_TREE
, LOOKUP_NORMAL
);
1520 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1523 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1525 else if (code
== COND_EXPR
)
1527 parms
= tree_cons (NULL_TREE
, xarg2
, build_tree_list (NULL_TREE
, arg3
));
1528 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1530 else if (code
== METHOD_CALL_EXPR
)
1532 /* must be a member function. */
1533 parms
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1534 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1539 parms
= build_tree_list (NULL_TREE
, xarg2
);
1540 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1544 parms
= tree_cons (NULL_TREE
, xarg1
,
1545 build_tree_list (NULL_TREE
, xarg2
));
1546 rval
= build_overload_call (fnname
, parms
, flags
);
1552 /* This function takes an identifier, ID, and attempts to figure out what
1553 it means. There are a number of possible scenarios, presented in increasing
1556 1) not in a class's scope
1557 2) in class's scope, member name of the class's method
1558 3) in class's scope, but not a member name of the class
1559 4) in class's scope, member name of a class's variable
1561 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1562 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1564 As a last ditch, try to look up the name as a label and return that
1567 Values which are declared as being of REFERENCE_TYPE are
1568 automatically dereferenced here (as a hack to make the
1569 compiler faster). */
1572 hack_identifier (value
, name
)
1577 if (value
== error_mark_node
)
1579 if (current_class_name
)
1581 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1582 if (fields
== error_mark_node
)
1583 return error_mark_node
;
1588 fndecl
= TREE_VALUE (fields
);
1589 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1590 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1592 warning ("methods cannot be converted to function pointers");
1597 error ("ambiguous request for method pointer `%s'",
1598 IDENTIFIER_POINTER (name
));
1599 return error_mark_node
;
1603 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1605 return IDENTIFIER_LABEL_VALUE (name
);
1607 return error_mark_node
;
1610 type
= TREE_TYPE (value
);
1611 if (TREE_CODE (value
) == FIELD_DECL
)
1613 if (current_class_ptr
== NULL_TREE
)
1615 error ("request for member `%s' in static member function",
1616 IDENTIFIER_POINTER (DECL_NAME (value
)));
1617 return error_mark_node
;
1619 TREE_USED (current_class_ptr
) = 1;
1621 /* Mark so that if we are in a constructor, and then find that
1622 this field was initialized by a base initializer,
1623 we can emit an error message. */
1624 TREE_USED (value
) = 1;
1625 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1627 else if (really_overloaded_fn (value
))
1630 tree t
= get_first_fn (value
);
1631 for (; t
; t
= DECL_CHAIN (t
))
1633 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1636 assemble_external (t
);
1641 else if (TREE_CODE (value
) == TREE_LIST
)
1643 /* Ambiguous reference to base members, possibly other cases?. */
1645 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1647 mark_used (TREE_VALUE (t
));
1654 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1656 tree context
= decl_function_context (value
);
1657 if (context
!= NULL_TREE
&& context
!= current_function_decl
1658 && ! TREE_STATIC (value
))
1660 cp_error ("use of %s from containing function",
1661 (TREE_CODE (value
) == VAR_DECL
1662 ? "`auto' variable" : "parameter"));
1663 cp_error_at (" `%#D' declared here", value
);
1664 value
= error_mark_node
;
1668 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1670 if (DECL_LANG_SPECIFIC (value
)
1671 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1674 register tree context
1675 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1676 ? DECL_CLASS_CONTEXT (value
)
1677 : DECL_CONTEXT (value
);
1679 get_base_distance (context
, current_class_type
, 0, &path
);
1682 access
= compute_access (path
, value
);
1683 if (access
!= access_public_node
)
1685 if (TREE_CODE (value
) == VAR_DECL
)
1686 error ("static member `%s' is %s",
1687 IDENTIFIER_POINTER (name
),
1688 TREE_PRIVATE (value
) ? "private"
1689 : "from a private base class");
1691 error ("enum `%s' is from private base class",
1692 IDENTIFIER_POINTER (name
));
1693 return error_mark_node
;
1698 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1702 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1703 IDENTIFIER_POINTER (name
));
1704 return error_mark_node
;
1710 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1711 value
= convert_from_reference (value
);
1717 thunk_printable_name (decl
)
1720 return "<thunk function>";
1724 make_thunk (function
, delta
)
1733 if (TREE_CODE (function
) != ADDR_EXPR
)
1735 func_decl
= TREE_OPERAND (function
, 0);
1736 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1738 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1740 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1742 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1743 thunk_id
= get_identifier (buffer
);
1744 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1745 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1747 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1748 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1750 if (thunk
== NULL_TREE
)
1752 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1753 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1754 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1755 comdat_linkage (thunk
);
1756 TREE_SET_CODE (thunk
, THUNK_DECL
);
1757 DECL_INITIAL (thunk
) = function
;
1758 THUNK_DELTA (thunk
) = delta
;
1759 DECL_EXTERNAL (thunk
) = 1;
1760 DECL_ARTIFICIAL (thunk
) = 1;
1761 /* So that finish_file can write out any thunks that need to be: */
1762 pushdecl_top_level (thunk
);
1767 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1770 emit_thunk (thunk_fndecl
)
1773 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1774 int delta
= THUNK_DELTA (thunk_fndecl
);
1776 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1779 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1781 TREE_ADDRESSABLE (function
) = 1;
1782 mark_used (function
);
1784 if (current_function_decl
)
1787 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1790 #ifdef ASM_OUTPUT_MI_THUNK
1792 current_function_decl
= thunk_fndecl
;
1793 /* Make sure we build up its RTL before we go onto the
1794 temporary obstack. */
1795 make_function_rtl (thunk_fndecl
);
1796 temporary_allocation ();
1797 DECL_RESULT (thunk_fndecl
)
1798 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1799 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1800 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1801 assemble_start_function (thunk_fndecl
, fnname
);
1802 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
1803 assemble_end_function (thunk_fndecl
, fnname
);
1804 permanent_allocation (1);
1805 current_function_decl
= 0;
1806 #else /* ASM_OUTPUT_MI_THUNK */
1807 /* If we don't have the necessary macro for efficient thunks, generate a
1808 thunk function that just makes a call to the real function.
1809 Unfortunately, this doesn't work for varargs. */
1813 if (varargs_function_p (function
))
1814 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1817 /* Set up clone argument trees for the thunk. */
1819 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
1821 tree x
= copy_node (a
);
1823 DECL_CONTEXT (x
) = thunk_fndecl
;
1827 DECL_ARGUMENTS (thunk_fndecl
) = a
;
1828 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
1829 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
1830 copy_lang_decl (thunk_fndecl
);
1831 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
1832 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
1834 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
1835 store_parm_decls ();
1836 current_function_is_thunk
= 1;
1838 /* Build up the call to the real function. */
1839 t
= build_int_2 (delta
, -1 * (delta
< 0));
1840 TREE_TYPE (t
) = signed_type (sizetype
);
1841 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
1842 t
= tree_cons (NULL_TREE
, t
, NULL_TREE
);
1843 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
1844 t
= tree_cons (NULL_TREE
, a
, t
);
1846 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
1847 c_expand_return (t
);
1849 finish_function (lineno
, 0, 0);
1850 #endif /* ASM_OUTPUT_MI_THUNK */
1853 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
1856 /* Code for synthesizing methods which have default semantics defined. */
1858 /* For the anonymous union in TYPE, return the member that is at least as
1859 large as the rest of the members, so we can copy it. */
1862 largest_union_member (type
)
1865 tree f
, type_size
= TYPE_SIZE (type
);
1867 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
1868 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
1871 /* We should always find one. */
1872 my_friendly_abort (323);
1876 /* Generate code for default X(X&) constructor. */
1879 do_build_copy_constructor (fndecl
)
1882 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
1888 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1889 parm
= TREE_CHAIN (parm
);
1890 parm
= convert_from_reference (parm
);
1892 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
1894 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
1895 TREE_SIDE_EFFECTS (t
) = 1;
1896 cplus_expand_expr_stmt (t
);
1900 tree fields
= TYPE_FIELDS (current_class_type
);
1901 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
1902 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
1905 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
1908 tree basetype
= BINFO_TYPE (t
);
1909 tree p
= convert_to_reference
1910 (build_reference_type (basetype
), parm
,
1911 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
1912 p
= convert_from_reference (p
);
1914 if (p
== error_mark_node
)
1915 cp_error ("in default copy constructor");
1917 current_base_init_list
= tree_cons (basetype
,
1918 p
, current_base_init_list
);
1921 for (i
= 0; i
< n_bases
; ++i
)
1923 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
1924 if (TREE_VIA_VIRTUAL (basetype
))
1927 basetype
= BINFO_TYPE (basetype
);
1928 p
= convert_to_reference
1929 (build_reference_type (basetype
), parm
,
1930 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
1932 if (p
== error_mark_node
)
1933 cp_error ("in default copy constructor");
1936 p
= convert_from_reference (p
);
1937 current_base_init_list
= tree_cons (basetype
,
1938 p
, current_base_init_list
);
1941 for (; fields
; fields
= TREE_CHAIN (fields
))
1944 tree field
= fields
;
1946 if (TREE_CODE (field
) != FIELD_DECL
)
1950 if (DECL_NAME (field
))
1952 if (VFIELD_NAME_P (DECL_NAME (field
)))
1954 if (VBASE_NAME_P (DECL_NAME (field
)))
1957 /* True for duplicate members. */
1958 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
1961 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
1962 && TREE_CODE (t
) == UNION_TYPE
1963 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
1964 && TYPE_FIELDS (t
) != NULL_TREE
)
1968 init
= build (COMPONENT_REF
, t
, init
, field
);
1969 field
= largest_union_member (t
);
1971 while ((t
= TREE_TYPE (field
)) != NULL_TREE
1972 && TREE_CODE (t
) == UNION_TYPE
1973 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
1974 && TYPE_FIELDS (t
) != NULL_TREE
);
1979 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
1980 init
= build_tree_list (NULL_TREE
, init
);
1982 current_member_init_list
1983 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
1985 current_member_init_list
= nreverse (current_member_init_list
);
1986 current_base_init_list
= nreverse (current_base_init_list
);
1994 do_build_assign_ref (fndecl
)
1997 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2002 parm
= convert_from_reference (parm
);
2004 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2006 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2007 TREE_SIDE_EFFECTS (t
) = 1;
2008 cplus_expand_expr_stmt (t
);
2012 tree fields
= TYPE_FIELDS (current_class_type
);
2013 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2014 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2017 for (i
= 0; i
< n_bases
; ++i
)
2019 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2020 tree p
= convert_to_reference
2021 (build_reference_type (basetype
), parm
,
2022 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2023 p
= convert_from_reference (p
);
2024 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2025 build_tree_list (NULL_TREE
, p
));
2026 expand_expr_stmt (p
);
2028 for (; fields
; fields
= TREE_CHAIN (fields
))
2031 tree field
= fields
;
2033 if (TREE_CODE (field
) != FIELD_DECL
)
2036 if (TREE_READONLY (field
))
2038 if (DECL_NAME (field
))
2039 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2041 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2044 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2046 if (DECL_NAME (field
))
2047 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2049 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2053 comp
= current_class_ref
;
2056 if (DECL_NAME (field
))
2058 if (VFIELD_NAME_P (DECL_NAME (field
)))
2060 if (VBASE_NAME_P (DECL_NAME (field
)))
2063 /* True for duplicate members. */
2064 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2067 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2068 && TREE_CODE (t
) == UNION_TYPE
2069 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2070 && TYPE_FIELDS (t
) != NULL_TREE
)
2074 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2075 init
= build (COMPONENT_REF
, t
, init
, field
);
2076 field
= largest_union_member (t
);
2078 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2079 && TREE_CODE (t
) == UNION_TYPE
2080 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2081 && TYPE_FIELDS (t
) != NULL_TREE
);
2086 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2087 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2089 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2092 c_expand_return (current_class_ref
);
2097 synthesize_method (fndecl
)
2100 int nested
= (current_function_decl
!= NULL_TREE
);
2101 tree context
= hack_decl_function_context (fndecl
);
2104 push_to_top_level ();
2106 push_cp_function_context (context
);
2108 interface_unknown
= 1;
2109 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2110 store_parm_decls ();
2112 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2113 do_build_assign_ref (fndecl
);
2114 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2118 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2119 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2120 arg_chain
= TREE_CHAIN (arg_chain
);
2121 if (arg_chain
!= void_list_node
)
2122 do_build_copy_constructor (fndecl
);
2123 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2127 finish_function (lineno
, 0, nested
);
2129 extract_interface_info ();
2131 pop_from_top_level ();
2133 pop_cp_function_context (context
);