1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 89, 92-97, 1998 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #ifndef PARM_CAN_BE_ARRAY_TYPE
29 #define PARM_CAN_BE_ARRAY_TYPE 1
32 /* Handle method declarations. */
41 #include "hard-reg-set.h"
44 /* TREE_LIST of the current inline functions that need to be
46 struct pending_inline
*pending_inlines
;
50 #define obstack_chunk_alloc xmalloc
51 #define obstack_chunk_free free
53 /* Obstack where we build text strings for overloading, etc. */
54 static struct obstack scratch_obstack
;
55 static char *scratch_firstobj
;
57 static void icat
PROTO((HOST_WIDE_INT
));
58 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
59 static void flush_repeats
PROTO((tree
));
60 static void build_overload_identifier
PROTO((tree
));
61 static void build_overload_nested_name
PROTO((tree
));
62 static void build_overload_int
PROTO((tree
, int));
63 static void build_overload_identifier
PROTO((tree
));
64 static void build_qualified_name
PROTO((tree
));
65 static void build_overload_value
PROTO((tree
, tree
, int));
66 static void issue_nrepeats
PROTO((tree
));
67 static char *build_mangled_name
PROTO((tree
,int,int));
68 static void process_modifiers
PROTO((tree
));
69 static void process_overload_item
PROTO((tree
,int));
70 static void do_build_assign_ref
PROTO((tree
));
71 static void do_build_copy_constructor
PROTO((tree
));
72 static tree largest_union_member
PROTO((tree
));
73 static tree build_decl_overload_real
PROTO((tree
, tree
, tree
, tree
,
75 static void build_template_template_parm_names
PROTO((tree
));
76 static void build_template_parm_names
PROTO((tree
, tree
));
77 static void build_underscore_int
PROTO((int));
79 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
80 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
81 # define OB_PUTC2(C1,C2) \
82 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
83 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
84 # define OB_PUTID(ID) \
85 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
86 IDENTIFIER_LENGTH (ID)))
87 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
88 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
89 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
94 gcc_obstack_init (&scratch_obstack
);
95 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
98 /* This must be large enough to hold any printed integer or floating-point
100 static char digit_buffer
[128];
102 /* Move inline function definitions out of structure so that they
103 can be processed normally. CNAME is the name of the class
104 we are working from, METHOD_LIST is the list of method lists
105 of the structure. We delete friend methods here, after
106 saving away their inline function definitions (if any). */
109 do_inline_function_hair (type
, friend_list
)
110 tree type
, friend_list
;
112 tree method
= TYPE_METHODS (type
);
114 if (method
&& TREE_CODE (method
) == TREE_VEC
)
116 if (TREE_VEC_ELT (method
, 1))
117 method
= TREE_VEC_ELT (method
, 1);
118 else if (TREE_VEC_ELT (method
, 0))
119 method
= TREE_VEC_ELT (method
, 0);
121 method
= TREE_VEC_ELT (method
, 2);
126 /* Do inline member functions. */
127 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
132 my_friendly_assert (info
->fndecl
== method
, 238);
133 args
= DECL_ARGUMENTS (method
);
136 DECL_CONTEXT (args
) = method
;
137 args
= TREE_CHAIN (args
);
140 method
= TREE_CHAIN (method
);
144 tree fndecl
= TREE_VALUE (friend_list
);
145 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
150 my_friendly_assert (info
->fndecl
== fndecl
, 239);
151 args
= DECL_ARGUMENTS (fndecl
);
154 DECL_CONTEXT (args
) = fndecl
;
155 args
= TREE_CHAIN (args
);
159 friend_list
= TREE_CHAIN (friend_list
);
163 /* Here is where overload code starts. */
165 /* type tables for K and B type compression */
166 static tree
*btypelist
= NULL
;
167 static tree
*ktypelist
= NULL
;
168 static tree lasttype
= NULL
;
169 static int maxbsize
= 0;
170 static int maxksize
= 0;
172 /* number of each type seen */
173 static int maxbtype
= 0;
174 static int maxktype
= 0;
176 /* Number of occurrences of last b type seen. */
177 static int nrepeats
= 0;
179 /* Array of types seen so far in top-level call to `build_mangled_name'.
180 Allocated and deallocated by caller. */
181 static tree
*typevec
= NULL
;
183 /* Number of types interned by `build_mangled_name' so far. */
184 static int maxtype
= 0;
186 /* Number of occurrences of last type seen. */
187 static int Nrepeats
= 0;
189 /* Nonzero if we should not try folding parameter types. */
192 /* This appears to be set to true if an underscore is required to be
193 comcatenated before another number can be outputed. */
194 static int numeric_output_need_bar
;
199 if (flag_do_squangling
)
208 btypelist
= (tree
*)xmalloc (sizeof (tree
) * maxbsize
);
209 ktypelist
= (tree
*)xmalloc (sizeof (tree
) * maxksize
);
216 if (flag_do_squangling
)
232 /* Code to concatenate an asciified integer to a string. */
238 unsigned HOST_WIDE_INT ui
;
240 /* Handle this case first, to go really quickly. For many common values,
241 the result of ui/10 below is 1. */
259 OB_PUTC ('0' + (ui
% 10));
264 HOST_WIDE_INT lo
, hi
;
266 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
275 uhi
= (lo
== 0 ? -hi
: -hi
-1);
279 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
284 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
287 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
290 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
294 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
305 while (typevec
[tindex
] != type
)
324 /* issue squangling type repeating */
326 issue_nrepeats (lasttype
)
331 switch (TREE_CODE (lasttype
))
337 process_overload_item (lasttype
, FALSE
);
353 /* Check to see if a tree node has been entered into the Kcode typelist */
354 /* if not, add it. Return -1 if it isn't found, otherwise return the index */
356 check_ktype (node
, add
)
361 tree localnode
= node
;
363 if (ktypelist
== NULL
)
366 if (TREE_CODE (node
) == TYPE_DECL
)
367 localnode
= TREE_TYPE (node
);
369 for (x
=0; x
< maxktype
; x
++)
371 if (localnode
== ktypelist
[x
])
374 /* Didn't find it, so add it here */
377 if (maxksize
<= maxktype
)
379 maxksize
= maxksize
* 3 / 2;
380 ktypelist
= (tree
*)xrealloc (ktypelist
, sizeof (tree
) * maxksize
);
382 ktypelist
[maxktype
++] = localnode
;
393 kindex
= check_ktype (decl
, FALSE
);
406 build_overload_nested_name (decl
)
410 if (ktypelist
&& issue_ktype (decl
))
413 if (DECL_CONTEXT (decl
))
415 tree context
= DECL_CONTEXT (decl
);
417 /* try to issue a K type, and if we can't continue the normal path */
418 if (!(ktypelist
&& issue_ktype (context
)))
420 /* For a template type parameter, we want to output an 'Xn'
421 rather than 'T' or some such. */
422 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
423 || TREE_CODE (context
) == TEMPLATE_TEMPLATE_PARM
)
424 build_mangled_name (context
, 0, 0);
427 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
428 context
= TYPE_NAME (context
);
429 build_overload_nested_name (context
);
433 else if (decl
== global_namespace
)
435 else if (DECL_NAMESPACE (decl
))
436 build_overload_nested_name (DECL_NAMESPACE (decl
));
438 /* XXX the above does not work for non-namespaces */
439 if (current_namespace
&& TREE_CODE (decl
) != NAMESPACE_DECL
)
440 build_overload_nested_name (current_namespace
);
442 if (TREE_CODE (decl
) == FUNCTION_DECL
)
444 tree name
= DECL_ASSEMBLER_NAME (decl
);
447 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
450 if (numeric_output_need_bar
)
452 icat (strlen (label
));
454 numeric_output_need_bar
= 1;
456 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
457 build_overload_identifier (DECL_NAME (decl
));
459 build_overload_identifier (decl
);
463 build_underscore_int (i
)
474 build_overload_scope_ref (value
)
478 numeric_output_need_bar
= 0;
479 build_mangled_name (TREE_OPERAND (value
, 0), 0, 0);
480 build_overload_identifier (TREE_OPERAND (value
, 1));
483 /* Encoding for an INTEGER_CST value. */
486 build_overload_int (value
, in_template
)
490 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
492 if (TREE_CODE (value
) == SCOPE_REF
)
494 build_overload_scope_ref (value
);
499 numeric_output_need_bar
= 0;
501 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value
))))
504 int operands
= tree_code_length
[(int) TREE_CODE (value
)];
508 id
= ansi_opname
[(int) TREE_CODE (value
)];
509 my_friendly_assert (id
!= NULL_TREE
, 0);
510 name
= IDENTIFIER_POINTER (id
);
511 my_friendly_assert (name
[0] == '_' && name
[1] == '_', 0);
513 for (i
= 0; i
< operands
; ++i
)
518 /* We just outputted either the `E' or the name of the
520 numeric_output_need_bar
= 0;
523 /* Skip the leading underscores. */
526 operand
= TREE_OPERAND (value
, i
);
527 tc
= TREE_CODE (operand
);
529 if (TREE_CODE_CLASS (tc
) == 't')
530 /* We can get here with sizeof, e.g.:
532 template <class T> void f(A<sizeof(T)>); */
533 process_overload_item (operand
, 0);
534 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc
)))
535 build_overload_int (operand
, in_template
);
537 build_overload_value (TREE_TYPE (operand
),
544 /* We don't ever want this output, but it's
545 inconvenient not to be able to build the string.
546 This should cause assembler errors we'll notice. */
549 sprintf (digit_buffer
, " *%d", n
++);
550 OB_PUTCP (digit_buffer
);
554 numeric_output_need_bar
= 0;
558 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
559 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
561 if (TREE_INT_CST_HIGH (value
)
562 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
564 /* need to print a DImode value in decimal */
565 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
566 numeric_output_need_bar
= 1;
569 /* else fall through to print in smaller mode */
571 /* Wordsize or smaller */
572 icat (TREE_INT_CST_LOW (value
));
573 numeric_output_need_bar
= 1;
577 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
578 supplied in INDEX. */
581 build_mangled_template_parm_index (s
, index
)
586 build_underscore_int (TEMPLATE_PARM_IDX (index
));
587 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
588 representation of the function from the point of view of its
590 build_underscore_int (TEMPLATE_PARM_LEVEL (index
));
595 build_overload_value (type
, value
, in_template
)
599 while (TREE_CODE (value
) == NON_LVALUE_EXPR
600 || TREE_CODE (value
) == NOP_EXPR
)
601 value
= TREE_OPERAND (value
, 0);
603 if (TREE_CODE (type
) == PARM_DECL
)
604 type
= TREE_TYPE (type
);
606 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type
)) == 't', 0);
608 if (numeric_output_need_bar
)
611 numeric_output_need_bar
= 0;
614 if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
616 build_mangled_template_parm_index ("Y", value
);
620 if (TREE_CODE (type
) == POINTER_TYPE
621 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
623 /* Handle a pointer to data member as a template instantiation
624 parameter, boy, what fun! */
625 type
= integer_type_node
;
626 if (TREE_CODE (value
) != INTEGER_CST
)
628 sorry ("unknown pointer to member constant");
633 if (TYPE_PTRMEMFUNC_P (type
))
634 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
636 switch (TREE_CODE (type
))
642 build_overload_int (value
, in_template
);
648 char *bufp
= digit_buffer
;
650 pedwarn ("ANSI C++ forbids floating-point template arguments");
652 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
653 val
= TREE_REAL_CST (value
);
654 if (REAL_VALUE_ISNAN (val
))
656 sprintf (bufp
, "NaN");
660 if (REAL_VALUE_NEGATIVE (val
))
662 val
= REAL_VALUE_NEGATE (val
);
665 if (REAL_VALUE_ISINF (val
))
667 sprintf (bufp
, "Infinity");
671 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
672 bufp
= (char *) index (bufp
, 'e');
674 strcat (digit_buffer
, "e0");
700 #ifdef NO_DOT_IN_LABEL
701 bufp
= (char *) index (bufp
, '.');
707 OB_PUTCP (digit_buffer
);
708 numeric_output_need_bar
= 1;
712 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
713 && TREE_CODE (value
) != ADDR_EXPR
)
715 if (TREE_CODE (value
) == CONSTRUCTOR
)
717 /* This is dangerous code, crack built up pointer to members. */
718 tree args
= CONSTRUCTOR_ELTS (value
);
719 tree a1
= TREE_VALUE (args
);
720 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
721 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
722 a3
= TREE_VALUE (a3
);
724 if (TREE_CODE (a1
) == INTEGER_CST
725 && TREE_CODE (a2
) == INTEGER_CST
)
727 build_overload_int (a1
, in_template
);
729 build_overload_int (a2
, in_template
);
731 if (TREE_CODE (a3
) == ADDR_EXPR
)
733 a3
= TREE_OPERAND (a3
, 0);
734 if (TREE_CODE (a3
) == FUNCTION_DECL
)
736 numeric_output_need_bar
= 0;
737 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
741 else if (TREE_CODE (a3
) == INTEGER_CST
)
744 build_overload_int (a3
, in_template
);
749 sorry ("template instantiation with pointer to method that is too complex");
752 if (TREE_CODE (value
) == INTEGER_CST
)
754 build_overload_int (value
, in_template
);
757 else if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
759 build_mangled_template_parm_index ("", value
);
760 numeric_output_need_bar
= 1;
764 value
= TREE_OPERAND (value
, 0);
765 if (TREE_CODE (value
) == VAR_DECL
)
767 my_friendly_assert (DECL_NAME (value
) != 0, 245);
768 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
771 else if (TREE_CODE (value
) == FUNCTION_DECL
)
773 my_friendly_assert (DECL_NAME (value
) != 0, 246);
774 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
777 else if (TREE_CODE (value
) == SCOPE_REF
)
778 build_overload_scope_ref (value
);
780 my_friendly_abort (71);
781 break; /* not really needed */
784 sorry ("conversion of %s as template parameter",
785 tree_code_name
[(int) TREE_CODE (type
)]);
786 my_friendly_abort (72);
791 /* Add encodings for the declaration of template template parameters.
792 PARMLIST must be a TREE_VEC */
795 build_template_template_parm_names (parmlist
)
800 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
801 nparms
= TREE_VEC_LENGTH (parmlist
);
803 for (i
= 0; i
< nparms
; i
++)
805 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
806 if (TREE_CODE (parm
) == TYPE_DECL
)
808 /* This parameter is a type. */
811 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
813 /* This parameter is a template. */
815 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
819 /* It's a PARM_DECL. */
820 build_mangled_name (TREE_TYPE (parm
), 0, 0);
826 /* Add encodings for the vector of template parameters in PARMLIST,
827 given the vector of arguments to be substituted in ARGLIST. */
830 build_template_parm_names (parmlist
, arglist
)
836 nparms
= TREE_VEC_LENGTH (parmlist
);
838 for (i
= 0; i
< nparms
; i
++)
840 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
841 tree arg
= TREE_VEC_ELT (arglist
, i
);
842 if (TREE_CODE (parm
) == TYPE_DECL
)
844 /* This parameter is a type. */
846 build_mangled_name (arg
, 0, 0);
848 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
850 /* This parameter is a template. */
851 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
852 /* Output parameter declaration, argument index and level */
853 build_mangled_name (arg
, 0, 0);
856 /* A TEMPLATE_DECL node, output the parameter declaration
860 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
861 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
862 OB_PUTID (DECL_NAME (arg
));
867 parm
= tsubst (parm
, arglist
, NULL_TREE
);
868 /* It's a PARM_DECL. */
869 build_mangled_name (TREE_TYPE (parm
), 0, 0);
870 build_overload_value (parm
, arg
, uses_template_parms (arglist
));
877 build_overload_identifier (name
)
880 if (TREE_CODE (name
) == TYPE_DECL
881 && IS_AGGR_TYPE (TREE_TYPE (name
))
882 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
883 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
884 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
888 tree
template, parmlist
, arglist
, tname
;
889 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
890 arglist
= TREE_VALUE (template);
891 template = TREE_PURPOSE (template);
892 tname
= DECL_NAME (template);
893 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
895 icat (IDENTIFIER_LENGTH (tname
));
897 build_template_parm_names (parmlist
, arglist
);
901 if (TREE_CODE (name
) == TYPE_DECL
)
902 name
= DECL_NAME (name
);
903 if (numeric_output_need_bar
)
906 numeric_output_need_bar
= 0;
908 icat (IDENTIFIER_LENGTH (name
));
913 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
914 the mangling for it. Used by build_mangled_name and build_static_name. */
917 build_qualified_name (decl
)
923 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
924 decl
= TYPE_NAME (decl
);
926 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
927 if (TREE_CODE (decl
) == TYPE_DECL
928 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
) && !flag_do_squangling
)
930 tree id
= DECL_ASSEMBLER_NAME (decl
);
932 if (isdigit (IDENTIFIER_POINTER (id
) [IDENTIFIER_LENGTH (id
) - 1]))
933 numeric_output_need_bar
= 1;
938 /* if we can't find a Ktype, do it the hard way */
939 if (check_ktype (context
, FALSE
) == -1)
941 /* count type scopes */
942 while (DECL_CONTEXT (context
))
945 context
= DECL_CONTEXT (context
);
946 if (check_ktype (context
, FALSE
) != -1) /* found it! */
948 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
949 context
= TYPE_NAME (context
);
951 /* now count namespace scopes */
952 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
954 i
= 0; /* we have nothing done, yet: reset */
958 /* decl must be a type, which we have to scope with the
961 /* XXX MvL somehow, types have no lang_decl, so no namespace */
962 context
= current_namespace
;
966 while (context
!= global_namespace
)
969 context
= DECL_NAMESPACE (context
);
975 build_underscore_int (i
);
976 numeric_output_need_bar
= 0;
978 build_overload_nested_name (decl
);
981 /* Given a list of parameters in PARMTYPES, create an unambiguous
982 overload string. Should distinguish any type that C (or C++) can
983 distinguish. I.e., pointers to functions are treated correctly.
985 Caller must deal with whether a final `e' goes on the end or not.
987 Any default conversions must take place before this function
990 BEGIN and END control initialization and finalization of the
991 obstack where we build the string. */
994 build_overload_name (parmtypes
, begin
, end
)
1000 ret
= build_mangled_name (parmtypes
, begin
, end
);
1006 build_mangled_name (parmtypes
, begin
, end
)
1014 numeric_output_need_bar
= 0;
1016 if (TREE_CODE (parmtypes
) != TREE_LIST
) /* just one item */
1018 if (TYPE_PTRMEMFUNC_P (parmtypes
))
1019 parmtypes
= TYPE_PTRMEMFUNC_FN_TYPE (parmtypes
);
1020 process_modifiers (parmtypes
);
1021 process_overload_item (parmtypes
, FALSE
);
1024 for ( ; parmtypes
!=NULL
; parmtypes
= TREE_CHAIN (parmtypes
))
1026 parmtype
= TREE_VALUE (parmtypes
);
1027 if (flag_do_squangling
) /* squangling style repeats */
1029 if (parmtype
== lasttype
)
1037 issue_nrepeats (lasttype
);
1039 lasttype
= parmtype
;
1042 if (!nofold
&& typevec
)
1044 /* Every argument gets counted. */
1045 typevec
[maxtype
++] = parmtype
;
1047 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2]
1048 && ! is_java_type (parmtype
))
1055 flush_repeats (typevec
[maxtype
-2]);
1057 if (TREE_USED (parmtype
))
1060 /* We can turn this on at some point when we want
1061 improved symbol mangling. */
1064 /* This is bug compatible with 2.7.x */
1065 flush_repeats (parmtype
);
1070 /* Only cache types which take more than one character. */
1071 if ((parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
1072 || (TREE_CODE (parmtype
) != INTEGER_TYPE
1073 && TREE_CODE (parmtype
) != REAL_TYPE
))
1074 && ! is_java_type (parmtype
))
1075 TREE_USED (parmtype
) = 1;
1077 if (TYPE_PTRMEMFUNC_P (parmtype
))
1078 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
1079 process_modifiers (parmtype
);
1080 if (TREE_CODE(parmtype
)==VOID_TYPE
)
1083 extern tree void_list_node
;
1085 /* See if anybody is wasting memory. */
1086 my_friendly_assert (parmtypes
== void_list_node
, 247);
1088 /* This is the end of a parameter list. */
1091 return (char *)obstack_base (&scratch_obstack
);
1093 process_overload_item (parmtype
, TRUE
);
1095 if (flag_do_squangling
&& nrepeats
!= 0)
1096 issue_nrepeats (lasttype
);
1098 if (Nrepeats
&& typevec
)
1099 flush_repeats (typevec
[maxtype
-1]);
1101 /* To get here, parms must end with `...'. */
1106 return (char *)obstack_base (&scratch_obstack
);
1109 /* handles emitting modifiers such as Constant, read-only, and volatile */
1111 process_modifiers (parmtype
)
1116 if (TREE_READONLY (parmtype
))
1118 if (TREE_CODE (parmtype
) == INTEGER_TYPE
1119 && (TYPE_MAIN_VARIANT (parmtype
)
1120 == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
1121 && ! is_java_type (parmtype
))
1125 if (TYPE_VOLATILE (parmtype
))
1129 /* True iff TYPE was declared as a "Java" type (inside extern "Java"). */
1135 if (TYPE_NAME (type
) != NULL_TREE
)
1137 tree decl
= TYPE_NAME (type
);
1138 if (TREE_CODE (decl
) == TYPE_DECL
1139 && DECL_LANG_SPECIFIC (decl
) != NULL
1140 && DECL_LANGUAGE (decl
) == lang_java
)
1146 /* Check to see if a tree node has been entered into the Bcode typelist
1147 if not, add it. Otherwise emit the code and return TRUE */
1154 if (btypelist
== NULL
)
1157 switch (TREE_CODE (node
))
1163 return 0; /* don't compress single char basic types */
1169 node
= TYPE_MAIN_VARIANT (node
);
1170 for (x
= 0; x
< maxbtype
; x
++)
1172 if (node
== btypelist
[x
])
1181 /* didn't find it, so add it here */
1182 if (maxbsize
<= maxbtype
)
1184 maxbsize
= maxbsize
* 3 / 2;
1185 btypelist
= (tree
*)xrealloc (btypelist
, sizeof (tree
) * maxbsize
);
1187 btypelist
[maxbtype
++] = node
;
1191 /* handle emitting the correct code for various node types */
1193 process_overload_item (parmtype
, extra_Gcode
)
1198 /* These tree types are considered modifiers for B code squangling , */
1199 /* and therefore should not get entries in the Btypelist */
1200 /* they are, however, repeatable types */
1202 switch (TREE_CODE (parmtype
))
1204 case REFERENCE_TYPE
:
1209 #if PARM_CAN_BE_ARRAY_TYPE
1214 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
1215 error("pointer/reference to array of unknown bound in parm type");
1218 length
= array_type_nelts (parmtype
);
1219 if (TREE_CODE (length
) == INTEGER_CST
)
1220 icat (TREE_INT_CST_LOW (length
) + 1);
1233 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1241 /* check if type is already in the typelist. If not, add it now */
1243 if (flag_do_squangling
&& btypelist
!= NULL
) {
1244 if (check_btype (parmtype
)) /* emits the code if it finds it */
1248 switch (TREE_CODE (parmtype
))
1252 build_mangled_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
1254 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1260 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
1261 /* Otherwise have to implement reentrant typevecs,
1262 unmark and remark types, etc. */
1263 int old_nofold
= nofold
;
1264 if (!flag_do_squangling
) {
1267 flush_repeats (typevec
[maxtype
-1]);
1271 issue_nrepeats (lasttype
);
1273 /* @@ It may be possible to pass a function type in
1274 which is not preceded by a 'P'. */
1275 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
1278 if (firstarg
== NULL_TREE
)
1280 else if (firstarg
== void_list_node
)
1283 build_mangled_name (firstarg
, 0, 0);
1287 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
1288 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
1290 firstarg
= TREE_CHAIN (firstarg
);
1292 build_mangled_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
1298 /* For cfront 2.0 compatibility. */
1301 if (firstarg
== NULL_TREE
)
1303 else if (firstarg
== void_list_node
)
1306 build_mangled_name (firstarg
, 0, 0);
1309 /* Separate args from return type. */
1311 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1312 nofold
= old_nofold
;
1317 /* "Java" integer types should mangle the same on all platforms,
1318 and only depend on precision, not target 'int' size. */
1319 if (is_java_type (parmtype
))
1321 if (TREE_UNSIGNED (parmtype
))
1323 switch (TYPE_PRECISION (parmtype
))
1325 case 8: OB_PUTC ('b'); return;
1326 case 16: OB_PUTC ('w'); return;
1331 switch (TYPE_PRECISION (parmtype
))
1333 case 8: OB_PUTC ('c'); return;
1334 case 16: OB_PUTC ('s'); return;
1335 case 32: OB_PUTC ('i'); return;
1336 case 64: OB_PUTC ('x'); return;
1341 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1342 if (parmtype
== integer_type_node
1343 || parmtype
== unsigned_type_node
)
1345 else if (parmtype
== long_integer_type_node
1346 || parmtype
== long_unsigned_type_node
)
1348 else if (parmtype
== short_integer_type_node
1349 || parmtype
== short_unsigned_type_node
)
1351 else if (parmtype
== signed_char_type_node
)
1356 else if (parmtype
== char_type_node
1357 || parmtype
== unsigned_char_type_node
)
1359 else if (parmtype
== wchar_type_node
)
1361 else if (parmtype
== long_long_integer_type_node
1362 || parmtype
== long_long_unsigned_type_node
)
1365 /* it would seem there is no way to enter these in source code,
1367 else if (parmtype
== long_long_long_integer_type_node
1368 || parmtype
== long_long_long_unsigned_type_node
)
1372 my_friendly_abort (73);
1380 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1381 if (parmtype
== long_double_type_node
)
1383 else if (parmtype
== double_type_node
)
1385 else if (parmtype
== float_type_node
)
1387 else my_friendly_abort (74);
1392 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1399 case ERROR_MARK
: /* not right, but nothing is anyway */
1402 /* have to do these */
1407 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1408 /* drop through into next case */
1412 tree name
= TYPE_NAME (parmtype
);
1414 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
1416 build_overload_identifier (TYPE_NAME (parmtype
));
1419 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1421 build_qualified_name (name
);
1426 /* This will take some work. */
1430 case TEMPLATE_TEMPLATE_PARM
:
1431 /* Find and output the original template parameter
1433 if (CLASSTYPE_TEMPLATE_INFO (parmtype
))
1435 build_mangled_template_parm_index ("tzX",
1436 TEMPLATE_TYPE_PARM_INDEX
1438 build_template_parm_names
1439 (DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype
)),
1440 CLASSTYPE_TI_ARGS (parmtype
));
1444 build_mangled_template_parm_index ("ZzX",
1445 TEMPLATE_TYPE_PARM_INDEX
1447 build_template_template_parm_names
1448 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1452 case TEMPLATE_TYPE_PARM
:
1453 build_mangled_template_parm_index ("X",
1454 TEMPLATE_TYPE_PARM_INDEX
1459 /* When mangling the type of a function template whose
1460 declaration looks like:
1462 template <class T> void foo(typename T::U)
1464 we have to mangle these. */
1465 build_qualified_name (parmtype
);
1469 my_friendly_abort (75);
1474 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1475 be either a class TYPE or a FUNCTION_DECL. */
1478 build_static_name (context
, name
)
1482 numeric_output_need_bar
= 0;
1483 start_squangling ();
1486 build_qualified_name (context
);
1489 OB_PUTS ("__static_");
1490 build_qualified_name (context
);
1497 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1501 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1510 char *name
= IDENTIFIER_POINTER (dname
);
1512 /* member operators new and delete look like methods at this point. */
1513 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1514 && TREE_CHAIN (parms
) == void_list_node
)
1516 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1517 return get_identifier ("__builtin_delete");
1518 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1519 return get_identifier ("__builtin_vec_delete");
1520 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1521 return get_identifier ("__builtin_new");
1522 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1523 return get_identifier ("__builtin_vec_new");
1526 start_squangling ();
1528 if (for_method
!= 2)
1530 /* Otherwise, we can divine that this is a constructor,
1531 and figure out its name without any extra encoding. */
1533 OB_PUTC2 ('_', '_');
1537 /* We can get away without doing this. */
1540 if (tparms
!= NULL_TREE
)
1543 tree this_type
= TREE_VALUE (parms
);
1545 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1546 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1547 TREE_CHAIN (parms
));
1549 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1550 TREE_CHAIN (parms
));
1555 /* XXX this works only if we call this in the same namespace
1556 as the declaration. Unfortunately, we don't have the _DECL,
1558 else if (current_namespace
== global_namespace
)
1563 build_template_parm_names (tparms
, targs
);
1567 /* qualify with namespace */
1568 if (!for_method
&& current_namespace
!= global_namespace
)
1569 build_qualified_name (current_namespace
);
1571 if (parms
== NULL_TREE
)
1573 else if (parms
== void_list_node
)
1577 if (!flag_do_squangling
) /* Allocate typevec array. */
1581 typevec
= (tree
*)alloca (list_length (parms
) * sizeof (tree
));
1586 build_mangled_name (TREE_VALUE (parms
), 0, 0);
1588 if (!flag_do_squangling
) {
1589 typevec
[maxtype
++] = TREE_VALUE (parms
);
1590 TREE_USED (TREE_VALUE (parms
)) = 1;
1593 if (TREE_CHAIN (parms
))
1594 build_mangled_name (TREE_CHAIN (parms
), 0, 0);
1600 /* the namespace qualifier for a global function
1601 will count as type */
1602 if (current_namespace
!= global_namespace
1603 && !flag_do_squangling
)
1604 typevec
[maxtype
++] = current_namespace
;
1605 build_mangled_name (parms
, 0, 0);
1608 if (!flag_do_squangling
) /* Deallocate typevec array */
1614 TREE_USED (TREE_VALUE (t
)) = 0;
1620 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1622 /* Add the return type. */
1624 build_mangled_name (ret_type
, 0, 0);
1630 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1631 if (IDENTIFIER_OPNAME_P (dname
))
1632 IDENTIFIER_OPNAME_P (n
) = 1;
1637 /* Change the name of a function definition so that it may be
1638 overloaded. NAME is the name of the function to overload,
1639 PARMS is the parameter list (which determines what name the
1640 final function obtains).
1642 FOR_METHOD is 1 if this overload is being performed
1643 for a method, rather than a function type. It is 2 if
1644 this overload is being performed for a constructor. */
1647 build_decl_overload (dname
, parms
, for_method
)
1652 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1653 NULL_TREE
, for_method
);
1657 /* Like build_decl_overload, but for template functions. */
1660 build_template_decl_overload (dname
, parms
, ret_type
, tparms
, targs
,
1669 return build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1674 /* Build an overload name for the type expression TYPE. */
1677 build_typename_overload (type
)
1683 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1685 start_squangling ();
1686 build_mangled_name (type
, 0, 1);
1687 id
= get_identifier (obstack_base (&scratch_obstack
));
1688 IDENTIFIER_OPNAME_P (id
) = 1;
1690 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1692 TREE_TYPE (id
) = type
;
1698 build_overload_with_type (name
, type
)
1705 start_squangling ();
1706 build_mangled_name (type
, 0, 1);
1708 return get_identifier (obstack_base (&scratch_obstack
));
1712 get_id_2 (name
, name2
)
1720 return get_identifier (obstack_base (&scratch_obstack
));
1723 /* Given a tree_code CODE, and some arguments (at least one),
1724 attempt to use an overloaded operator on the arguments.
1726 For unary operators, only the first argument need be checked.
1727 For binary operators, both arguments may need to be checked.
1729 Member functions can convert class references to class pointers,
1730 for one-level deep indirection. More than that is not supported.
1731 Operators [](), ()(), and ->() must be member functions.
1733 We call function call building calls with LOOKUP_COMPLAIN if they
1734 are our only hope. This is true when we see a vanilla operator
1735 applied to something of aggregate type. If this fails, we are free
1736 to return `error_mark_node', because we will have reported the
1739 Operators NEW and DELETE overload in funny ways: operator new takes
1740 a single `size' parameter, and operator delete takes a pointer to the
1741 storage being deleted. When overloading these operators, success is
1742 assumed. If there is a failure, report an error message and return
1743 `error_mark_node'. */
1747 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1748 enum tree_code code
;
1750 tree xarg1
, xarg2
, arg3
;
1752 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1755 /* This function takes an identifier, ID, and attempts to figure out what
1756 it means. There are a number of possible scenarios, presented in increasing
1759 1) not in a class's scope
1760 2) in class's scope, member name of the class's method
1761 3) in class's scope, but not a member name of the class
1762 4) in class's scope, member name of a class's variable
1764 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1765 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1767 As a last ditch, try to look up the name as a label and return that
1770 Values which are declared as being of REFERENCE_TYPE are
1771 automatically dereferenced here (as a hack to make the
1772 compiler faster). */
1775 hack_identifier (value
, name
)
1780 if (value
== error_mark_node
)
1782 if (current_class_name
)
1784 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1785 if (fields
== error_mark_node
)
1786 return error_mark_node
;
1791 fndecl
= TREE_VALUE (fields
);
1792 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1793 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1795 warning ("methods cannot be converted to function pointers");
1800 error ("ambiguous request for method pointer `%s'",
1801 IDENTIFIER_POINTER (name
));
1802 return error_mark_node
;
1806 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1808 return IDENTIFIER_LABEL_VALUE (name
);
1810 return error_mark_node
;
1813 type
= TREE_TYPE (value
);
1814 if (TREE_CODE (value
) == FIELD_DECL
)
1816 if (current_class_ptr
== NULL_TREE
)
1818 error ("request for member `%s' in static member function",
1819 IDENTIFIER_POINTER (DECL_NAME (value
)));
1820 return error_mark_node
;
1822 TREE_USED (current_class_ptr
) = 1;
1824 /* Mark so that if we are in a constructor, and then find that
1825 this field was initialized by a base initializer,
1826 we can emit an error message. */
1827 TREE_USED (value
) = 1;
1828 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1830 else if (really_overloaded_fn (value
))
1833 tree t
= get_first_fn (value
);
1834 for (; t
; t
= DECL_CHAIN (t
))
1836 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1839 assemble_external (t
);
1844 else if (TREE_CODE (value
) == TREE_LIST
)
1846 /* Ambiguous reference to base members, possibly other cases?. */
1848 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1850 mark_used (TREE_VALUE (t
));
1857 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1859 tree context
= decl_function_context (value
);
1860 if (context
!= NULL_TREE
&& context
!= current_function_decl
1861 && ! TREE_STATIC (value
))
1863 cp_error ("use of %s from containing function",
1864 (TREE_CODE (value
) == VAR_DECL
1865 ? "`auto' variable" : "parameter"));
1866 cp_error_at (" `%#D' declared here", value
);
1867 value
= error_mark_node
;
1871 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1873 if (DECL_LANG_SPECIFIC (value
)
1874 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1877 register tree context
1878 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1879 ? DECL_CLASS_CONTEXT (value
)
1880 : DECL_CONTEXT (value
);
1882 get_base_distance (context
, current_class_type
, 0, &path
);
1885 access
= compute_access (path
, value
);
1886 if (access
!= access_public_node
)
1888 if (TREE_CODE (value
) == VAR_DECL
)
1889 error ("static member `%s' is %s",
1890 IDENTIFIER_POINTER (name
),
1891 TREE_PRIVATE (value
) ? "private"
1892 : "from a private base class");
1894 error ("enum `%s' is from private base class",
1895 IDENTIFIER_POINTER (name
));
1896 return error_mark_node
;
1901 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1905 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1906 IDENTIFIER_POINTER (name
));
1907 return error_mark_node
;
1913 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1914 value
= convert_from_reference (value
);
1920 make_thunk (function
, delta
)
1929 if (TREE_CODE (function
) != ADDR_EXPR
)
1931 func_decl
= TREE_OPERAND (function
, 0);
1932 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1934 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1935 buffer
= (char *)alloca (strlen (func_name
) + 32);
1937 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1939 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1940 thunk_id
= get_identifier (buffer
);
1941 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1942 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1944 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1945 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1947 if (thunk
== NULL_TREE
)
1949 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1950 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1951 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1952 comdat_linkage (thunk
);
1953 TREE_SET_CODE (thunk
, THUNK_DECL
);
1954 DECL_INITIAL (thunk
) = function
;
1955 THUNK_DELTA (thunk
) = delta
;
1956 DECL_EXTERNAL (thunk
) = 1;
1957 DECL_ARTIFICIAL (thunk
) = 1;
1958 /* So that finish_file can write out any thunks that need to be: */
1959 pushdecl_top_level (thunk
);
1964 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1967 emit_thunk (thunk_fndecl
)
1970 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1971 int delta
= THUNK_DELTA (thunk_fndecl
);
1973 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1976 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1978 TREE_ADDRESSABLE (function
) = 1;
1979 mark_used (function
);
1981 if (current_function_decl
)
1984 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1987 #ifdef ASM_OUTPUT_MI_THUNK
1989 current_function_decl
= thunk_fndecl
;
1990 /* Make sure we build up its RTL before we go onto the
1991 temporary obstack. */
1992 make_function_rtl (thunk_fndecl
);
1993 temporary_allocation ();
1994 DECL_RESULT (thunk_fndecl
)
1995 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1996 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1997 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1998 assemble_start_function (thunk_fndecl
, fnname
);
1999 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
2000 assemble_end_function (thunk_fndecl
, fnname
);
2001 permanent_allocation (1);
2002 current_function_decl
= 0;
2003 #else /* ASM_OUTPUT_MI_THUNK */
2004 /* If we don't have the necessary macro for efficient thunks, generate a
2005 thunk function that just makes a call to the real function.
2006 Unfortunately, this doesn't work for varargs. */
2010 if (varargs_function_p (function
))
2011 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2014 /* Set up clone argument trees for the thunk. */
2016 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
2018 tree x
= copy_node (a
);
2020 DECL_CONTEXT (x
) = thunk_fndecl
;
2024 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2025 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2026 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2027 copy_lang_decl (thunk_fndecl
);
2028 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2029 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2031 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
2032 store_parm_decls ();
2033 current_function_is_thunk
= 1;
2035 /* Build up the call to the real function. */
2036 t
= build_int_2 (delta
, -1 * (delta
< 0));
2037 TREE_TYPE (t
) = signed_type (sizetype
);
2038 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2039 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
2040 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2041 t
= expr_tree_cons (NULL_TREE
, a
, t
);
2043 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2044 c_expand_return (t
);
2046 finish_function (lineno
, 0, 0);
2048 /* Don't let the backend defer this function. */
2049 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2051 output_inline_function (thunk_fndecl
);
2052 permanent_allocation (1);
2054 #endif /* ASM_OUTPUT_MI_THUNK */
2057 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2060 /* Code for synthesizing methods which have default semantics defined. */
2062 /* For the anonymous union in TYPE, return the member that is at least as
2063 large as the rest of the members, so we can copy it. */
2066 largest_union_member (type
)
2069 tree f
, type_size
= TYPE_SIZE (type
);
2071 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2072 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2075 /* We should always find one. */
2076 my_friendly_abort (323);
2080 /* Generate code for default X(X&) constructor. */
2083 do_build_copy_constructor (fndecl
)
2086 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2092 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2093 parm
= TREE_CHAIN (parm
);
2094 parm
= convert_from_reference (parm
);
2096 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
)
2097 && is_empty_class (current_class_type
))
2098 /* Don't copy the padding byte; it might not have been allocated
2099 if *this is a base subobject. */;
2100 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2102 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2103 TREE_SIDE_EFFECTS (t
) = 1;
2104 cplus_expand_expr_stmt (t
);
2108 tree fields
= TYPE_FIELDS (current_class_type
);
2109 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2110 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2113 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2116 tree basetype
= BINFO_TYPE (t
);
2117 tree p
= convert_to_reference
2118 (build_reference_type (basetype
), parm
,
2119 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2120 p
= convert_from_reference (p
);
2122 if (p
== error_mark_node
)
2123 cp_error ("in default copy constructor");
2125 current_base_init_list
= tree_cons (basetype
,
2126 p
, current_base_init_list
);
2129 for (i
= 0; i
< n_bases
; ++i
)
2131 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2132 if (TREE_VIA_VIRTUAL (basetype
))
2135 basetype
= BINFO_TYPE (basetype
);
2136 p
= convert_to_reference
2137 (build_reference_type (basetype
), parm
,
2138 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2140 if (p
== error_mark_node
)
2141 cp_error ("in default copy constructor");
2144 p
= convert_from_reference (p
);
2145 current_base_init_list
= tree_cons (basetype
,
2146 p
, current_base_init_list
);
2149 for (; fields
; fields
= TREE_CHAIN (fields
))
2152 tree field
= fields
;
2154 if (TREE_CODE (field
) != FIELD_DECL
)
2158 if (DECL_NAME (field
))
2160 if (VFIELD_NAME_P (DECL_NAME (field
)))
2162 if (VBASE_NAME_P (DECL_NAME (field
)))
2165 /* True for duplicate members. */
2166 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2169 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2170 && TREE_CODE (t
) == UNION_TYPE
2171 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2172 && TYPE_FIELDS (t
) != NULL_TREE
)
2176 init
= build (COMPONENT_REF
, t
, init
, field
);
2177 field
= largest_union_member (t
);
2179 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2180 && TREE_CODE (t
) == UNION_TYPE
2181 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2182 && TYPE_FIELDS (t
) != NULL_TREE
);
2187 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2188 init
= build_tree_list (NULL_TREE
, init
);
2190 current_member_init_list
2191 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2193 current_member_init_list
= nreverse (current_member_init_list
);
2194 current_base_init_list
= nreverse (current_base_init_list
);
2202 do_build_assign_ref (fndecl
)
2205 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2210 parm
= convert_from_reference (parm
);
2212 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
)
2213 && is_empty_class (current_class_type
))
2214 /* Don't copy the padding byte; it might not have been allocated
2215 if *this is a base subobject. */;
2216 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2218 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2219 TREE_SIDE_EFFECTS (t
) = 1;
2220 cplus_expand_expr_stmt (t
);
2224 tree fields
= TYPE_FIELDS (current_class_type
);
2225 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2226 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2229 for (i
= 0; i
< n_bases
; ++i
)
2231 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2232 tree p
= convert_to_reference
2233 (build_reference_type (basetype
), parm
,
2234 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2235 p
= convert_from_reference (p
);
2236 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2237 build_expr_list (NULL_TREE
, p
));
2238 expand_expr_stmt (p
);
2240 for (; fields
; fields
= TREE_CHAIN (fields
))
2243 tree field
= fields
;
2245 if (TREE_CODE (field
) != FIELD_DECL
)
2248 if (TREE_READONLY (field
))
2250 if (DECL_NAME (field
))
2251 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2253 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2256 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2258 if (DECL_NAME (field
))
2259 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2261 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2265 comp
= current_class_ref
;
2268 if (DECL_NAME (field
))
2270 if (VFIELD_NAME_P (DECL_NAME (field
)))
2272 if (VBASE_NAME_P (DECL_NAME (field
)))
2275 /* True for duplicate members. */
2276 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2279 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2280 && TREE_CODE (t
) == UNION_TYPE
2281 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2282 && TYPE_FIELDS (t
) != NULL_TREE
)
2286 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2287 init
= build (COMPONENT_REF
, t
, init
, field
);
2288 field
= largest_union_member (t
);
2290 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2291 && TREE_CODE (t
) == UNION_TYPE
2292 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2293 && TYPE_FIELDS (t
) != NULL_TREE
);
2298 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2299 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2301 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2304 c_expand_return (current_class_ref
);
2309 synthesize_method (fndecl
)
2312 int nested
= (current_function_decl
!= NULL_TREE
);
2313 tree context
= hack_decl_function_context (fndecl
);
2316 import_export_decl (fndecl
);
2319 push_to_top_level ();
2321 push_cp_function_context (context
);
2323 interface_unknown
= 1;
2324 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2325 store_parm_decls ();
2327 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2328 do_build_assign_ref (fndecl
);
2329 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2333 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2334 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2335 arg_chain
= TREE_CHAIN (arg_chain
);
2336 if (arg_chain
!= void_list_node
)
2337 do_build_copy_constructor (fndecl
);
2338 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2342 finish_function (lineno
, 0, nested
);
2344 extract_interface_info ();
2346 pop_from_top_level ();
2348 pop_cp_function_context (context
);