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-96, 1997 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_template_parm_names
PROTO((tree
));
77 static void build_template_parm_names
PROTO((tree
, tree
));
78 static void build_underscore_int
PROTO((int));
80 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
81 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
82 # define OB_PUTC2(C1,C2) \
83 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
84 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
85 # define OB_PUTID(ID) \
86 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
87 IDENTIFIER_LENGTH (ID)))
88 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
89 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
90 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
95 gcc_obstack_init (&scratch_obstack
);
96 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
99 /* This must be large enough to hold any printed integer or floating-point
101 static char digit_buffer
[128];
103 /* Move inline function definitions out of structure so that they
104 can be processed normally. CNAME is the name of the class
105 we are working from, METHOD_LIST is the list of method lists
106 of the structure. We delete friend methods here, after
107 saving away their inline function definitions (if any). */
110 do_inline_function_hair (type
, friend_list
)
111 tree type
, friend_list
;
113 tree method
= TYPE_METHODS (type
);
115 if (method
&& TREE_CODE (method
) == TREE_VEC
)
117 if (TREE_VEC_ELT (method
, 1))
118 method
= TREE_VEC_ELT (method
, 1);
119 else if (TREE_VEC_ELT (method
, 0))
120 method
= TREE_VEC_ELT (method
, 0);
122 method
= TREE_VEC_ELT (method
, 2);
127 /* Do inline member functions. */
128 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
133 my_friendly_assert (info
->fndecl
== method
, 238);
134 args
= DECL_ARGUMENTS (method
);
137 DECL_CONTEXT (args
) = method
;
138 args
= TREE_CHAIN (args
);
141 /* Allow this decl to be seen in global scope. Don't do this for
142 local class methods, though. */
143 if (! current_function_decl
)
144 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method
)) = method
;
146 method
= TREE_CHAIN (method
);
150 tree fndecl
= TREE_VALUE (friend_list
);
151 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
156 my_friendly_assert (info
->fndecl
== fndecl
, 239);
157 args
= DECL_ARGUMENTS (fndecl
);
160 DECL_CONTEXT (args
) = fndecl
;
161 args
= TREE_CHAIN (args
);
164 /* Allow this decl to be seen in global scope */
165 if (! current_function_decl
)
166 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl
)) = fndecl
;
169 friend_list
= TREE_CHAIN (friend_list
);
173 /* Report an argument type mismatch between the best declared function
174 we could find and the current argument list that we have. */
177 report_type_mismatch (cp
, parmtypes
, name_kind
)
178 struct candidate
*cp
;
182 int i
= cp
->u
.bad_arg
;
189 my_friendly_assert (TREE_CODE (cp
->function
) == TEMPLATE_DECL
, 240);
190 cp_error ("type unification failed for function template `%#D'",
195 cp_error ("too few arguments for %s `%#D'", name_kind
, cp
->function
);
198 cp_error ("too many arguments for %s `%#D'", name_kind
, cp
->function
);
201 if (TREE_CODE (TREE_TYPE (cp
->function
)) != METHOD_TYPE
)
204 /* Happens when the implicit object parameter is rejected. */
205 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))),
207 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
208 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
209 cp_error ("call to non-volatile %s `%#D' with volatile object",
210 name_kind
, cp
->function
);
212 cp_error ("call to non-const %s `%#D' with const object",
213 name_kind
, cp
->function
);
217 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
222 ttf
= TREE_CHAIN (ttf
);
223 tta
= TREE_CHAIN (tta
);
227 OB_PUTS ("bad argument ");
228 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
229 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
231 OB_PUTCP (digit_buffer
);
233 OB_PUTS (" for function `");
234 OB_PUTCP (decl_as_string (cp
->function
, 1));
235 OB_PUTS ("' (type was ");
237 /* Reset `i' so that type printing routines do the right thing. */
240 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
241 if (code
== ERROR_MARK
)
242 OB_PUTS ("(failed type instantiation)");
245 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
246 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
249 else OB_PUTS ("void");
253 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
254 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
255 obstack_object_size (&scratch_obstack
));
256 error (tmp_firstobj
);
259 /* Here is where overload code starts. */
261 /* Array of types seen so far in top-level call to `build_overload_name'.
262 Allocated and deallocated by caller. */
263 static tree
*typevec
;
265 /* Number of types interned by `build_overload_name' so far. */
268 /* Number of occurrences of last type seen. */
271 /* Nonzero if we should not try folding parameter types. */
274 #define ALLOCATE_TYPEVEC(PARMTYPES) \
275 do { maxtype = 0, nrepeats = 0; \
276 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
278 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
279 do { tree t = (PARMTYPES); \
280 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
283 /* Code to concatenate an asciified integer to a string. */
293 unsigned HOST_WIDE_INT ui
;
295 /* Handle this case first, to go really quickly. For many common values,
296 the result of ui/10 below is 1. */
314 OB_PUTC ('0' + (ui
% 10));
319 HOST_WIDE_INT lo
, hi
;
321 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
330 uhi
= (lo
== 0 ? -hi
: -hi
-1);
334 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
339 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
342 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
345 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
349 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
364 while (typevec
[tindex
] != type
)
382 static int numeric_output_need_bar
;
385 build_overload_nested_name (decl
)
388 if (DECL_CONTEXT (decl
))
390 tree context
= DECL_CONTEXT (decl
);
391 /* For a template type parameter, we want to output an 'Xn'
392 rather than 'T' or some such. For a template template
393 parameter, we also want an extra prefix 'z' and the
395 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
396 || TREE_CODE (context
) == TEMPLATE_TEMPLATE_PARM
)
397 build_overload_name (context
, 0, 0);
400 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
401 context
= TYPE_NAME (context
);
402 build_overload_nested_name (context
);
406 if (TREE_CODE (decl
) == FUNCTION_DECL
)
408 tree name
= DECL_ASSEMBLER_NAME (decl
);
411 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
414 if (numeric_output_need_bar
)
416 icat (strlen (label
));
418 numeric_output_need_bar
= 1;
421 build_overload_identifier (decl
);
425 build_underscore_int (i
)
435 /* Encoding for an INTEGER_CST value. */
438 build_overload_int (value
, in_template
)
442 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
443 /* We don't ever want this output, but it's inconvenient not to
444 be able to build the string. This should cause assembler
445 errors we'll notice. */
448 sprintf (digit_buffer
, " *%d", n
++);
449 OB_PUTCP (digit_buffer
);
453 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
454 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
456 if (TREE_INT_CST_HIGH (value
)
457 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
459 /* need to print a DImode value in decimal */
460 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
463 /* else fall through to print in smaller mode */
465 /* Wordsize or smaller */
466 icat (TREE_INT_CST_LOW (value
));
470 build_overload_value (type
, value
, in_template
)
474 while (TREE_CODE (value
) == NON_LVALUE_EXPR
475 || TREE_CODE (value
) == NOP_EXPR
)
476 value
= TREE_OPERAND (value
, 0);
477 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
478 type
= TREE_TYPE (type
);
480 if (numeric_output_need_bar
)
483 numeric_output_need_bar
= 0;
486 if (TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
489 build_underscore_int (TEMPLATE_CONST_IDX (value
));
490 build_underscore_int (TEMPLATE_CONST_LEVEL (value
));
494 if (TREE_CODE (type
) == POINTER_TYPE
495 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
497 /* Handle a pointer to data member as a template instantiation
498 parameter, boy, what fun! */
499 type
= integer_type_node
;
500 if (TREE_CODE (value
) != INTEGER_CST
)
502 sorry ("unknown pointer to member constant");
507 if (TYPE_PTRMEMFUNC_P (type
))
508 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
510 switch (TREE_CODE (type
))
516 build_overload_int (value
, in_template
);
517 numeric_output_need_bar
= 1;
523 char *bufp
= digit_buffer
;
525 pedwarn ("ANSI C++ forbids floating-point template arguments");
527 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
528 val
= TREE_REAL_CST (value
);
529 if (REAL_VALUE_ISNAN (val
))
531 sprintf (bufp
, "NaN");
535 if (REAL_VALUE_NEGATIVE (val
))
537 val
= REAL_VALUE_NEGATE (val
);
540 if (REAL_VALUE_ISINF (val
))
542 sprintf (bufp
, "Infinity");
546 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
547 bufp
= (char *) index (bufp
, 'e');
549 strcat (digit_buffer
, "e0");
575 #ifdef NO_DOT_IN_LABEL
576 bufp
= (char *) index (bufp
, '.');
582 OB_PUTCP (digit_buffer
);
583 numeric_output_need_bar
= 1;
587 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
588 && TREE_CODE (value
) != ADDR_EXPR
)
590 if (TREE_CODE (value
) == CONSTRUCTOR
)
592 /* This is dangerous code, crack built up pointer to members. */
593 tree args
= CONSTRUCTOR_ELTS (value
);
594 tree a1
= TREE_VALUE (args
);
595 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
596 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
597 a3
= TREE_VALUE (a3
);
599 if (TREE_CODE (a1
) == INTEGER_CST
600 && TREE_CODE (a2
) == INTEGER_CST
)
602 build_overload_int (a1
, in_template
);
604 build_overload_int (a2
, in_template
);
606 if (TREE_CODE (a3
) == ADDR_EXPR
)
608 a3
= TREE_OPERAND (a3
, 0);
609 if (TREE_CODE (a3
) == FUNCTION_DECL
)
611 numeric_output_need_bar
= 0;
612 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
616 else if (TREE_CODE (a3
) == INTEGER_CST
)
619 build_overload_int (a3
, in_template
);
620 numeric_output_need_bar
= 1;
625 sorry ("template instantiation with pointer to method that is too complex");
628 if (TREE_CODE (value
) == INTEGER_CST
629 || TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
631 build_overload_int (value
, in_template
);
632 numeric_output_need_bar
= 1;
635 value
= TREE_OPERAND (value
, 0);
636 if (TREE_CODE (value
) == VAR_DECL
)
638 my_friendly_assert (DECL_NAME (value
) != 0, 245);
639 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
642 else if (TREE_CODE (value
) == FUNCTION_DECL
)
644 my_friendly_assert (DECL_NAME (value
) != 0, 246);
645 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
648 else if (TREE_CODE (value
) == SCOPE_REF
)
651 numeric_output_need_bar
= 0;
652 build_overload_name (TREE_OPERAND (value
, 0), 0, 0);
653 build_overload_identifier (TREE_OPERAND (value
, 1));
657 my_friendly_abort (71);
658 break; /* not really needed */
661 sorry ("conversion of %s as template parameter",
662 tree_code_name
[(int) TREE_CODE (type
)]);
663 my_friendly_abort (72);
668 /* Add encodings for the declaration of template template parameters.
669 PARMLIST must be a TREE_VEC */
672 build_template_template_parm_names (parmlist
)
677 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
678 nparms
= TREE_VEC_LENGTH (parmlist
);
680 for (i
= 0; i
< nparms
; i
++)
682 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
683 if (TREE_CODE (parm
) == TYPE_DECL
)
685 /* This parameter is a type. */
688 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
690 /* This parameter is a template. */
692 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
696 /* It's a PARM_DECL. */
697 build_overload_name (TREE_TYPE (parm
), 0, 0);
703 /* Add encodings for the vector of template parameters in PARMLIST,
704 given the vector of arguments to be substituted in ARGLIST. */
707 build_template_parm_names (parmlist
, arglist
)
713 nparms
= TREE_VEC_LENGTH (parmlist
);
715 for (i
= 0; i
< nparms
; i
++)
717 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
718 tree arg
= TREE_VEC_ELT (arglist
, i
);
719 if (TREE_CODE (parm
) == TYPE_DECL
)
721 /* This parameter is a type. */
723 build_overload_name (arg
, 0, 0);
725 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
727 /* This parameter is a template. */
728 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
729 /* Output parameter declaration, argument index and level */
730 build_overload_name (arg
, 0, 0);
733 /* A TEMPLATE_DECL node, output the parameter declaration
737 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
738 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
739 OB_PUTID (DECL_NAME (arg
));
744 parm
= tsubst (parm
, arglist
,
745 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
746 /* It's a PARM_DECL. */
747 build_overload_name (TREE_TYPE (parm
), 0, 0);
748 build_overload_value (parm
, arg
, uses_template_parms (arglist
));
755 build_overload_identifier (name
)
758 if (TREE_CODE (name
) == TYPE_DECL
759 && IS_AGGR_TYPE (TREE_TYPE (name
))
760 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
761 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
762 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
766 tree
template, parmlist
, arglist
, tname
;
767 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
768 arglist
= TREE_VALUE (template);
769 template = TREE_PURPOSE (template);
770 tname
= DECL_NAME (template);
771 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
773 icat (IDENTIFIER_LENGTH (tname
));
775 build_template_parm_names (parmlist
, arglist
);
779 if (TREE_CODE (name
) == TYPE_DECL
)
780 name
= DECL_NAME (name
);
781 if (numeric_output_need_bar
)
784 numeric_output_need_bar
= 0;
786 icat (IDENTIFIER_LENGTH (name
));
791 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
792 the mangling for it. Used by build_overload_name and build_static_name. */
795 build_qualified_name (decl
)
801 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
802 decl
= TYPE_NAME (decl
);
804 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
805 if (TREE_CODE (decl
) == TYPE_DECL
806 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
808 OB_PUTID (DECL_ASSEMBLER_NAME (decl
));
813 while (DECL_CONTEXT (context
))
816 context
= DECL_CONTEXT (context
);
817 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
818 context
= TYPE_NAME (context
);
829 numeric_output_need_bar
= 0;
831 build_overload_nested_name (decl
);
834 /* Given a list of parameters in PARMTYPES, create an unambiguous
835 overload string. Should distinguish any type that C (or C++) can
836 distinguish. I.e., pointers to functions are treated correctly.
838 Caller must deal with whether a final `e' goes on the end or not.
840 Any default conversions must take place before this function
843 BEGIN and END control initialization and finalization of the
844 obstack where we build the string. */
847 build_overload_name (parmtypes
, begin
, end
)
854 if (begin
) OB_INIT ();
855 numeric_output_need_bar
= 0;
857 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
859 parmtype
= parmtypes
;
865 parmtype
= TREE_VALUE (parmtypes
);
869 if (! nofold
&& ! just_one
)
871 /* Every argument gets counted. */
872 typevec
[maxtype
++] = parmtype
;
874 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
881 flush_repeats (typevec
[maxtype
-2]);
883 if (TREE_USED (parmtype
))
886 /* We can turn this on at some point when we want
887 improved symbol mangling. */
890 /* This is bug compatible with 2.7.x */
891 flush_repeats (parmtype
);
896 /* Only cache types which take more than one character. */
897 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
898 || (TREE_CODE (parmtype
) != INTEGER_TYPE
899 && TREE_CODE (parmtype
) != REAL_TYPE
))
900 TREE_USED (parmtype
) = 1;
903 if (TYPE_PTRMEMFUNC_P (parmtype
))
904 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
906 if (TREE_READONLY (parmtype
))
908 if (TREE_CODE (parmtype
) == INTEGER_TYPE
909 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
911 if (TYPE_VOLATILE (parmtype
))
914 switch (TREE_CODE (parmtype
))
918 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
920 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
928 #if PARM_CAN_BE_ARRAY_TYPE
933 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
934 error ("pointer or reference to array of unknown bound in parm type");
937 length
= array_type_nelts (parmtype
);
938 if (TREE_CODE (length
) == INTEGER_CST
)
939 icat (TREE_INT_CST_LOW (length
) + 1);
952 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
958 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
959 /* Otherwise have to implement reentrant typevecs,
960 unmark and remark types, etc. */
961 int old_nofold
= nofold
;
965 flush_repeats (typevec
[maxtype
-1]);
967 /* @@ It may be possible to pass a function type in
968 which is not preceded by a 'P'. */
969 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
972 if (firstarg
== NULL_TREE
)
974 else if (firstarg
== void_list_node
)
977 build_overload_name (firstarg
, 0, 0);
981 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
982 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
984 firstarg
= TREE_CHAIN (firstarg
);
986 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
992 /* For cfront 2.0 compatibility. */
995 if (firstarg
== NULL_TREE
)
997 else if (firstarg
== void_list_node
)
1000 build_overload_name (firstarg
, 0, 0);
1003 /* Separate args from return type. */
1005 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
1006 nofold
= old_nofold
;
1011 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1012 if (parmtype
== integer_type_node
1013 || parmtype
== unsigned_type_node
)
1015 else if (parmtype
== long_integer_type_node
1016 || parmtype
== long_unsigned_type_node
)
1018 else if (parmtype
== short_integer_type_node
1019 || parmtype
== short_unsigned_type_node
)
1021 else if (parmtype
== signed_char_type_node
)
1026 else if (parmtype
== char_type_node
1027 || parmtype
== unsigned_char_type_node
)
1029 else if (parmtype
== wchar_type_node
)
1031 else if (parmtype
== long_long_integer_type_node
1032 || parmtype
== long_long_unsigned_type_node
)
1035 /* it would seem there is no way to enter these in source code,
1037 else if (parmtype
== long_long_long_integer_type_node
1038 || parmtype
== long_long_long_unsigned_type_node
)
1042 my_friendly_abort (73);
1050 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1051 if (parmtype
== long_double_type_node
)
1053 else if (parmtype
== double_type_node
)
1055 else if (parmtype
== float_type_node
)
1057 else my_friendly_abort (74);
1062 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
1069 extern tree void_list_node
;
1071 /* See if anybody is wasting memory. */
1072 my_friendly_assert (parmtypes
== void_list_node
, 247);
1074 /* This is the end of a parameter list. */
1075 if (end
) OB_FINISH ();
1076 return (char *)obstack_base (&scratch_obstack
);
1081 case ERROR_MARK
: /* not right, but nothing is anyway */
1084 /* have to do these */
1088 /* Make this type signature look incompatible
1095 tree name
= TYPE_NAME (parmtype
);
1097 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
1099 build_overload_identifier (TYPE_NAME (parmtype
));
1102 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1104 build_qualified_name (name
);
1109 /* We can get here if __null is defined to have type ({unkown
1110 type}*), which it is if -ansi is not used. Treat this
1115 case TEMPLATE_TEMPLATE_PARM
:
1116 /* Find and output the original template parameter
1118 if (CLASSTYPE_TEMPLATE_INFO (parmtype
))
1123 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1124 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1126 build_template_parm_names (
1127 DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype
)),
1128 CLASSTYPE_TI_ARGS (parmtype
));
1135 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1136 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1138 build_template_template_parm_names (
1139 DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1143 case TEMPLATE_TYPE_PARM
:
1145 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1146 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1150 /* When mangling the type of a function template whose
1151 declaration looks like:
1153 template <class T> void foo(typename T::U)
1155 we have to mangle these. */
1156 build_qualified_name (parmtype
);
1160 my_friendly_abort (75);
1164 if (just_one
) break;
1165 parmtypes
= TREE_CHAIN (parmtypes
);
1170 flush_repeats (typevec
[maxtype
-1]);
1172 /* To get here, parms must end with `...'. */
1176 if (end
) OB_FINISH ();
1177 return (char *)obstack_base (&scratch_obstack
);
1180 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1181 be either a class TYPE or a FUNCTION_DECL. */
1184 build_static_name (context
, name
)
1188 numeric_output_need_bar
= 0;
1191 build_qualified_name (context
);
1194 OB_PUTS ("__static_");
1195 build_qualified_name (context
);
1201 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1205 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1214 char *name
= IDENTIFIER_POINTER (dname
);
1216 /* member operators new and delete look like methods at this point. */
1217 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1218 && TREE_CHAIN (parms
) == void_list_node
)
1220 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1221 return get_identifier ("__builtin_delete");
1222 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1223 return get_identifier ("__builtin_vec_delete");
1224 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1225 return get_identifier ("__builtin_new");
1226 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1227 return get_identifier ("__builtin_vec_new");
1231 if (for_method
!= 2)
1233 /* Otherwise, we can divine that this is a constructor,
1234 and figure out its name without any extra encoding. */
1236 OB_PUTC2 ('_', '_');
1240 /* We can get away without doing this. */
1243 if (tparms
!= NULL_TREE
)
1246 tree this_type
= TREE_VALUE (parms
);
1248 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1249 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1250 TREE_CHAIN (parms
));
1252 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1253 TREE_CHAIN (parms
));
1263 build_template_parm_names (tparms
, targs
);
1267 if (parms
== NULL_TREE
)
1269 else if (parms
== void_list_node
)
1273 ALLOCATE_TYPEVEC (parms
);
1277 build_overload_name (TREE_VALUE (parms
), 0, 0);
1279 typevec
[maxtype
++] = TREE_VALUE (parms
);
1280 TREE_USED (TREE_VALUE (parms
)) = 1;
1282 if (TREE_CHAIN (parms
))
1283 build_overload_name (TREE_CHAIN (parms
), 0, 0);
1288 build_overload_name (parms
, 0, 0);
1289 DEALLOCATE_TYPEVEC (parms
);
1292 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1294 /* Add the return type. */
1296 build_overload_name (ret_type
, 0, 0);
1301 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1302 if (IDENTIFIER_OPNAME_P (dname
))
1303 IDENTIFIER_OPNAME_P (n
) = 1;
1308 /* Change the name of a function definition so that it may be
1309 overloaded. NAME is the name of the function to overload,
1310 PARMS is the parameter list (which determines what name the
1311 final function obtains).
1313 FOR_METHOD is 1 if this overload is being performed
1314 for a method, rather than a function type. It is 2 if
1315 this overload is being performed for a constructor. */
1318 build_decl_overload (dname
, parms
, for_method
)
1323 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1324 NULL_TREE
, for_method
);
1328 /* Like build_decl_overload, but for template functions. */
1331 build_template_decl_overload (dname
, parms
, ret_type
, tparms
, targs
,
1340 return build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1345 /* Build an overload name for the type expression TYPE. */
1348 build_typename_overload (type
)
1354 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1356 build_overload_name (type
, 0, 1);
1357 id
= get_identifier (obstack_base (&scratch_obstack
));
1358 IDENTIFIER_OPNAME_P (id
) = 1;
1360 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1362 TREE_TYPE (id
) = type
;
1367 build_overload_with_type (name
, type
)
1374 build_overload_name (type
, 0, 1);
1375 return get_identifier (obstack_base (&scratch_obstack
));
1379 get_id_2 (name
, name2
)
1387 return get_identifier (obstack_base (&scratch_obstack
));
1390 /* Given a tree_code CODE, and some arguments (at least one),
1391 attempt to use an overloaded operator on the arguments.
1393 For unary operators, only the first argument need be checked.
1394 For binary operators, both arguments may need to be checked.
1396 Member functions can convert class references to class pointers,
1397 for one-level deep indirection. More than that is not supported.
1398 Operators [](), ()(), and ->() must be member functions.
1400 We call function call building calls with LOOKUP_COMPLAIN if they
1401 are our only hope. This is true when we see a vanilla operator
1402 applied to something of aggregate type. If this fails, we are free
1403 to return `error_mark_node', because we will have reported the
1406 Operators NEW and DELETE overload in funny ways: operator new takes
1407 a single `size' parameter, and operator delete takes a pointer to the
1408 storage being deleted. When overloading these operators, success is
1409 assumed. If there is a failure, report an error message and return
1410 `error_mark_node'. */
1414 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1415 enum tree_code code
;
1417 tree xarg1
, xarg2
, arg3
;
1421 tree type1
, type2
, fnname
;
1422 tree fields1
= 0, parms
= 0;
1425 int binary_is_unary
;
1427 if (flag_ansi_overloading
)
1428 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1430 if (xarg1
== error_mark_node
)
1431 return error_mark_node
;
1433 if (code
== COND_EXPR
)
1435 if (xarg2
== error_mark_node
1436 || arg3
== error_mark_node
)
1437 return error_mark_node
;
1439 if (code
== COMPONENT_REF
)
1440 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1443 /* First, see if we can work with the first argument */
1444 type1
= TREE_TYPE (xarg1
);
1446 /* Some tree codes have length > 1, but we really only want to
1447 overload them if their first argument has a user defined type. */
1450 case PREINCREMENT_EXPR
:
1451 case PREDECREMENT_EXPR
:
1452 case POSTINCREMENT_EXPR
:
1453 case POSTDECREMENT_EXPR
:
1455 binary_is_unary
= 1;
1459 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1460 If they do not, return error_mark_node instead of NULL_TREE. */
1462 if (xarg2
== error_mark_node
)
1463 return error_mark_node
;
1465 rval
= error_mark_node
;
1466 binary_is_unary
= 0;
1473 tree args
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1474 fnname
= ansi_opname
[(int) code
];
1475 if (flags
& LOOKUP_GLOBAL
)
1476 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
);
1478 rval
= build_method_call
1479 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1481 fnname
, args
, NULL_TREE
, flags
);
1482 if (rval
== error_mark_node
)
1483 /* User might declare fancy operator new, but invoke it
1484 like standard one. */
1487 TREE_TYPE (rval
) = xarg1
;
1492 case VEC_DELETE_EXPR
:
1495 fnname
= ansi_opname
[(int) code
];
1496 if (flags
& LOOKUP_GLOBAL
)
1497 return build_overload_call (fnname
,
1498 build_expr_list (NULL_TREE
, xarg1
),
1499 flags
& LOOKUP_COMPLAIN
);
1500 arg1
= TREE_TYPE (xarg1
);
1502 /* This handles the case where we're trying to delete
1507 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
1509 /* Strip off the pointer and the array. */
1510 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
1512 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
1513 arg1
= (TREE_TYPE (arg1
));
1515 arg1
= build_pointer_type (arg1
);
1518 rval
= build_method_call
1519 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
1522 fnname
, expr_tree_cons (NULL_TREE
, xarg1
,
1523 build_expr_list (NULL_TREE
, xarg2
)),
1526 /* This can happen when operator delete is protected. */
1527 my_friendly_assert (rval
!= error_mark_node
, 250);
1528 TREE_TYPE (rval
) = void_type_node
;
1535 binary_is_unary
= 0;
1536 try_second
= tree_code_length
[(int) code
] == 2;
1537 if (try_second
&& xarg2
== error_mark_node
)
1538 return error_mark_node
;
1542 if (try_second
&& xarg2
== error_mark_node
)
1543 return error_mark_node
;
1545 /* What ever it was, we do not know how to deal with it. */
1546 if (type1
== NULL_TREE
)
1549 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1550 type1
= TREE_TYPE (type1
);
1552 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1554 arg1
= convert_from_reference (xarg1
);
1555 type1
= TREE_TYPE (arg1
);
1562 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1564 /* Try to fail. First, fail if unary */
1567 /* Second, see if second argument is non-aggregate. */
1568 type2
= TREE_TYPE (xarg2
);
1569 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1570 type2
= TREE_TYPE (type2
);
1571 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1573 arg2
= convert_from_reference (xarg2
);
1574 type2
= TREE_TYPE (arg2
);
1581 if (!IS_AGGR_TYPE (type2
))
1588 /* First arg may succeed; see whether second should. */
1589 type2
= TREE_TYPE (xarg2
);
1590 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1591 type2
= TREE_TYPE (type2
);
1592 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1594 arg2
= convert_from_reference (xarg2
);
1595 type2
= TREE_TYPE (arg2
);
1602 if (! IS_AGGR_TYPE (type2
))
1606 if (type1
== unknown_type_node
1607 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1609 /* This will not be implemented in the foreseeable future. */
1613 if (code
== MODIFY_EXPR
)
1614 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1616 fnname
= ansi_opname
[(int) code
];
1618 global_fn
= lookup_name_nonclass (fnname
);
1620 /* This is the last point where we will accept failure. This
1621 may be too eager if we wish an overloaded operator not to match,
1622 but would rather a normal operator be called on a type-converted
1625 if (IS_AGGR_TYPE (type1
))
1627 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1628 /* ARM $13.4.7, prefix/postfix ++/--. */
1629 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1631 xarg2
= integer_zero_node
;
1632 binary_is_unary
= 0;
1637 int have_postfix
= 0;
1639 /* Look for an `operator++ (int)'. If they didn't have
1640 one, then we fall back to the old way of doing things. */
1641 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1643 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1644 if (TREE_CHAIN (t2
) != NULL_TREE
1645 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1654 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1656 /* There's probably a LOT of code in the world that
1657 relies upon this old behavior. */
1658 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1661 binary_is_unary
= 1;
1667 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1670 /* If RVAL winds up being `error_mark_node', we will return
1671 that... There is no way that normal semantics of these
1672 operators will succeed. */
1674 /* This argument may be an uncommitted OFFSET_REF. This is
1675 the case for example when dealing with static class members
1676 which are referenced from their class name rather than
1677 from a class instance. */
1678 if (TREE_CODE (xarg1
) == OFFSET_REF
1679 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1680 xarg1
= TREE_OPERAND (xarg1
, 1);
1681 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1682 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1683 xarg2
= TREE_OPERAND (xarg2
, 1);
1686 flags
|= LOOKUP_GLOBAL
;
1688 if (code
== CALL_EXPR
)
1690 /* This can only be a member function. */
1691 return build_method_call (xarg1
, fnname
, xarg2
,
1692 NULL_TREE
, LOOKUP_NORMAL
);
1694 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1697 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1699 else if (code
== COND_EXPR
)
1701 parms
= expr_tree_cons (NULL_TREE
, xarg2
, build_expr_list (NULL_TREE
, arg3
));
1702 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1704 else if (code
== METHOD_CALL_EXPR
)
1706 /* must be a member function. */
1707 parms
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1708 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1713 parms
= build_expr_list (NULL_TREE
, xarg2
);
1714 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1718 parms
= expr_tree_cons (NULL_TREE
, xarg1
,
1719 build_expr_list (NULL_TREE
, xarg2
));
1720 rval
= build_overload_call (fnname
, parms
, flags
);
1726 /* This function takes an identifier, ID, and attempts to figure out what
1727 it means. There are a number of possible scenarios, presented in increasing
1730 1) not in a class's scope
1731 2) in class's scope, member name of the class's method
1732 3) in class's scope, but not a member name of the class
1733 4) in class's scope, member name of a class's variable
1735 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1736 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1738 As a last ditch, try to look up the name as a label and return that
1741 Values which are declared as being of REFERENCE_TYPE are
1742 automatically dereferenced here (as a hack to make the
1743 compiler faster). */
1746 hack_identifier (value
, name
)
1751 if (value
== error_mark_node
)
1753 if (current_class_name
)
1755 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1756 if (fields
== error_mark_node
)
1757 return error_mark_node
;
1762 fndecl
= TREE_VALUE (fields
);
1763 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1764 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1766 warning ("methods cannot be converted to function pointers");
1771 error ("ambiguous request for method pointer `%s'",
1772 IDENTIFIER_POINTER (name
));
1773 return error_mark_node
;
1777 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1779 return IDENTIFIER_LABEL_VALUE (name
);
1781 return error_mark_node
;
1784 type
= TREE_TYPE (value
);
1785 if (TREE_CODE (value
) == FIELD_DECL
)
1787 if (current_class_ptr
== NULL_TREE
)
1789 error ("request for member `%s' in static member function",
1790 IDENTIFIER_POINTER (DECL_NAME (value
)));
1791 return error_mark_node
;
1793 TREE_USED (current_class_ptr
) = 1;
1795 /* Mark so that if we are in a constructor, and then find that
1796 this field was initialized by a base initializer,
1797 we can emit an error message. */
1798 TREE_USED (value
) = 1;
1799 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1801 else if (really_overloaded_fn (value
))
1804 tree t
= get_first_fn (value
);
1805 for (; t
; t
= DECL_CHAIN (t
))
1807 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1810 assemble_external (t
);
1815 else if (TREE_CODE (value
) == TREE_LIST
)
1817 /* Ambiguous reference to base members, possibly other cases?. */
1819 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1821 mark_used (TREE_VALUE (t
));
1828 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1830 tree context
= decl_function_context (value
);
1831 if (context
!= NULL_TREE
&& context
!= current_function_decl
1832 && ! TREE_STATIC (value
))
1834 cp_error ("use of %s from containing function",
1835 (TREE_CODE (value
) == VAR_DECL
1836 ? "`auto' variable" : "parameter"));
1837 cp_error_at (" `%#D' declared here", value
);
1838 value
= error_mark_node
;
1842 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1844 if (DECL_LANG_SPECIFIC (value
)
1845 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1848 register tree context
1849 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1850 ? DECL_CLASS_CONTEXT (value
)
1851 : DECL_CONTEXT (value
);
1853 get_base_distance (context
, current_class_type
, 0, &path
);
1856 access
= compute_access (path
, value
);
1857 if (access
!= access_public_node
)
1859 if (TREE_CODE (value
) == VAR_DECL
)
1860 error ("static member `%s' is %s",
1861 IDENTIFIER_POINTER (name
),
1862 TREE_PRIVATE (value
) ? "private"
1863 : "from a private base class");
1865 error ("enum `%s' is from private base class",
1866 IDENTIFIER_POINTER (name
));
1867 return error_mark_node
;
1872 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1876 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1877 IDENTIFIER_POINTER (name
));
1878 return error_mark_node
;
1884 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1885 value
= convert_from_reference (value
);
1891 thunk_printable_name (decl
)
1894 return "<thunk function>";
1898 make_thunk (function
, delta
)
1907 if (TREE_CODE (function
) != ADDR_EXPR
)
1909 func_decl
= TREE_OPERAND (function
, 0);
1910 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1912 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1914 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1916 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1917 thunk_id
= get_identifier (buffer
);
1918 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1919 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1921 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1922 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1924 if (thunk
== NULL_TREE
)
1926 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1927 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1928 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1929 comdat_linkage (thunk
);
1930 TREE_SET_CODE (thunk
, THUNK_DECL
);
1931 DECL_INITIAL (thunk
) = function
;
1932 THUNK_DELTA (thunk
) = delta
;
1933 DECL_EXTERNAL (thunk
) = 1;
1934 DECL_ARTIFICIAL (thunk
) = 1;
1935 /* So that finish_file can write out any thunks that need to be: */
1936 pushdecl_top_level (thunk
);
1941 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1944 emit_thunk (thunk_fndecl
)
1947 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1948 int delta
= THUNK_DELTA (thunk_fndecl
);
1950 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1953 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1955 TREE_ADDRESSABLE (function
) = 1;
1956 mark_used (function
);
1958 if (current_function_decl
)
1961 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1964 #ifdef ASM_OUTPUT_MI_THUNK
1966 current_function_decl
= thunk_fndecl
;
1967 /* Make sure we build up its RTL before we go onto the
1968 temporary obstack. */
1969 make_function_rtl (thunk_fndecl
);
1970 temporary_allocation ();
1971 DECL_RESULT (thunk_fndecl
)
1972 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1973 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1974 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1975 assemble_start_function (thunk_fndecl
, fnname
);
1976 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
1977 assemble_end_function (thunk_fndecl
, fnname
);
1978 permanent_allocation (1);
1979 current_function_decl
= 0;
1980 #else /* ASM_OUTPUT_MI_THUNK */
1981 /* If we don't have the necessary macro for efficient thunks, generate a
1982 thunk function that just makes a call to the real function.
1983 Unfortunately, this doesn't work for varargs. */
1987 if (varargs_function_p (function
))
1988 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1991 /* Set up clone argument trees for the thunk. */
1993 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
1995 tree x
= copy_node (a
);
1997 DECL_CONTEXT (x
) = thunk_fndecl
;
2001 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2002 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2003 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2004 copy_lang_decl (thunk_fndecl
);
2005 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2006 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2008 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
2009 store_parm_decls ();
2010 current_function_is_thunk
= 1;
2012 /* Build up the call to the real function. */
2013 t
= build_int_2 (delta
, -1 * (delta
< 0));
2014 TREE_TYPE (t
) = signed_type (sizetype
);
2015 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2016 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
2017 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2018 t
= expr_tree_cons (NULL_TREE
, a
, t
);
2020 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2021 c_expand_return (t
);
2023 finish_function (lineno
, 0, 0);
2025 /* Don't let the backend defer this function. */
2026 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2028 output_inline_function (thunk_fndecl
);
2029 permanent_allocation (1);
2031 #endif /* ASM_OUTPUT_MI_THUNK */
2034 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2037 /* Code for synthesizing methods which have default semantics defined. */
2039 /* For the anonymous union in TYPE, return the member that is at least as
2040 large as the rest of the members, so we can copy it. */
2043 largest_union_member (type
)
2046 tree f
, type_size
= TYPE_SIZE (type
);
2048 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2049 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2052 /* We should always find one. */
2053 my_friendly_abort (323);
2057 /* Generate code for default X(X&) constructor. */
2060 do_build_copy_constructor (fndecl
)
2063 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2069 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2070 parm
= TREE_CHAIN (parm
);
2071 parm
= convert_from_reference (parm
);
2073 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2075 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2076 TREE_SIDE_EFFECTS (t
) = 1;
2077 cplus_expand_expr_stmt (t
);
2081 tree fields
= TYPE_FIELDS (current_class_type
);
2082 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2083 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2086 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2089 tree basetype
= BINFO_TYPE (t
);
2090 tree p
= convert_to_reference
2091 (build_reference_type (basetype
), parm
,
2092 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2093 p
= convert_from_reference (p
);
2095 if (p
== error_mark_node
)
2096 cp_error ("in default copy constructor");
2098 current_base_init_list
= tree_cons (basetype
,
2099 p
, current_base_init_list
);
2102 for (i
= 0; i
< n_bases
; ++i
)
2104 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2105 if (TREE_VIA_VIRTUAL (basetype
))
2108 basetype
= BINFO_TYPE (basetype
);
2109 p
= convert_to_reference
2110 (build_reference_type (basetype
), parm
,
2111 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2113 if (p
== error_mark_node
)
2114 cp_error ("in default copy constructor");
2117 p
= convert_from_reference (p
);
2118 current_base_init_list
= tree_cons (basetype
,
2119 p
, current_base_init_list
);
2122 for (; fields
; fields
= TREE_CHAIN (fields
))
2125 tree field
= fields
;
2127 if (TREE_CODE (field
) != FIELD_DECL
)
2131 if (DECL_NAME (field
))
2133 if (VFIELD_NAME_P (DECL_NAME (field
)))
2135 if (VBASE_NAME_P (DECL_NAME (field
)))
2138 /* True for duplicate members. */
2139 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2142 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2143 && TREE_CODE (t
) == UNION_TYPE
2144 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2145 && TYPE_FIELDS (t
) != NULL_TREE
)
2149 init
= build (COMPONENT_REF
, t
, init
, field
);
2150 field
= largest_union_member (t
);
2152 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2153 && TREE_CODE (t
) == UNION_TYPE
2154 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2155 && TYPE_FIELDS (t
) != NULL_TREE
);
2160 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2161 init
= build_tree_list (NULL_TREE
, init
);
2163 current_member_init_list
2164 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2166 current_member_init_list
= nreverse (current_member_init_list
);
2167 current_base_init_list
= nreverse (current_base_init_list
);
2175 do_build_assign_ref (fndecl
)
2178 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2183 parm
= convert_from_reference (parm
);
2185 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2187 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2188 TREE_SIDE_EFFECTS (t
) = 1;
2189 cplus_expand_expr_stmt (t
);
2193 tree fields
= TYPE_FIELDS (current_class_type
);
2194 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2195 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2198 for (i
= 0; i
< n_bases
; ++i
)
2200 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2201 tree p
= convert_to_reference
2202 (build_reference_type (basetype
), parm
,
2203 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2204 p
= convert_from_reference (p
);
2205 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2206 build_expr_list (NULL_TREE
, p
));
2207 expand_expr_stmt (p
);
2209 for (; fields
; fields
= TREE_CHAIN (fields
))
2212 tree field
= fields
;
2214 if (TREE_CODE (field
) != FIELD_DECL
)
2217 if (TREE_READONLY (field
))
2219 if (DECL_NAME (field
))
2220 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2222 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2225 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2227 if (DECL_NAME (field
))
2228 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2230 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2234 comp
= current_class_ref
;
2237 if (DECL_NAME (field
))
2239 if (VFIELD_NAME_P (DECL_NAME (field
)))
2241 if (VBASE_NAME_P (DECL_NAME (field
)))
2244 /* True for duplicate members. */
2245 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2248 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2249 && TREE_CODE (t
) == UNION_TYPE
2250 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2251 && TYPE_FIELDS (t
) != NULL_TREE
)
2255 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2256 init
= build (COMPONENT_REF
, t
, init
, field
);
2257 field
= largest_union_member (t
);
2259 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2260 && TREE_CODE (t
) == UNION_TYPE
2261 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2262 && TYPE_FIELDS (t
) != NULL_TREE
);
2267 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2268 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2270 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2273 c_expand_return (current_class_ref
);
2278 synthesize_method (fndecl
)
2281 int nested
= (current_function_decl
!= NULL_TREE
);
2282 tree context
= hack_decl_function_context (fndecl
);
2285 import_export_decl (fndecl
);
2288 push_to_top_level ();
2290 push_cp_function_context (context
);
2292 interface_unknown
= 1;
2293 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2294 store_parm_decls ();
2296 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2297 do_build_assign_ref (fndecl
);
2298 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2302 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2303 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2304 arg_chain
= TREE_CHAIN (arg_chain
);
2305 if (arg_chain
!= void_list_node
)
2306 do_build_copy_constructor (fndecl
);
2307 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2311 finish_function (lineno
, 0, nested
);
2313 extract_interface_info ();
2315 pop_from_top_level ();
2317 pop_cp_function_context (context
);