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 (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])
1054 flush_repeats (typevec
[maxtype
-2]);
1056 if (TREE_USED (parmtype
))
1059 /* We can turn this on at some point when we want
1060 improved symbol mangling. */
1063 /* This is bug compatible with 2.7.x */
1064 flush_repeats (parmtype
);
1069 /* Only cache types which take more than one character. */
1070 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
1071 || (TREE_CODE (parmtype
) != INTEGER_TYPE
1072 && TREE_CODE (parmtype
) != REAL_TYPE
))
1073 TREE_USED (parmtype
) = 1;
1075 if (TYPE_PTRMEMFUNC_P (parmtype
))
1076 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
1077 process_modifiers (parmtype
);
1078 if (TREE_CODE(parmtype
)==VOID_TYPE
)
1081 extern tree void_list_node
;
1083 /* See if anybody is wasting memory. */
1084 my_friendly_assert (parmtypes
== void_list_node
, 247);
1086 /* This is the end of a parameter list. */
1089 return (char *)obstack_base (&scratch_obstack
);
1091 process_overload_item (parmtype
, TRUE
);
1093 if (flag_do_squangling
&& nrepeats
!= 0)
1094 issue_nrepeats (lasttype
);
1096 if (Nrepeats
&& typevec
)
1097 flush_repeats (typevec
[maxtype
-1]);
1099 /* To get here, parms must end with `...'. */
1104 return (char *)obstack_base (&scratch_obstack
);
1107 /* handles emitting modifiers such as Constant, read-only, and volatile */
1109 process_modifiers (parmtype
)
1114 if (TREE_READONLY (parmtype
))
1116 if (TREE_CODE (parmtype
) == INTEGER_TYPE
&&
1117 TYPE_MAIN_VARIANT (parmtype
) ==
1118 unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
1120 if (TYPE_VOLATILE (parmtype
))
1124 /* Check to see if a tree node has been entered into the Bcode typelist
1125 if not, add it. Otherwise emit the code and return TRUE */
1132 if (btypelist
== NULL
)
1135 switch (TREE_CODE (node
))
1141 return 0; /* don't compress single char basic types */
1147 node
= TYPE_MAIN_VARIANT (node
);
1148 for (x
= 0; x
< maxbtype
; x
++)
1150 if (node
== btypelist
[x
])
1159 /* didn't find it, so add it here */
1160 if (maxbsize
<= maxbtype
)
1162 maxbsize
= maxbsize
* 3 / 2;
1163 btypelist
= (tree
*)xrealloc (sizeof (tree
) * maxbsize
);
1165 btypelist
[maxbtype
++] = node
;
1169 /* handle emitting the correct code for various node types */
1171 process_overload_item (parmtype
, extra_Gcode
)
1176 /* These tree types are considered modifiers for B code squangling , */
1177 /* and therefore should not get entries in the Btypelist */
1178 /* they are, however, repeatable types */
1180 switch (TREE_CODE (parmtype
))
1182 case REFERENCE_TYPE
:
1187 #if PARM_CAN_BE_ARRAY_TYPE
1192 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
1193 error("pointer/reference to array of unknown bound in parm type");
1196 length
= array_type_nelts (parmtype
);
1197 if (TREE_CODE (length
) == INTEGER_CST
)
1198 icat (TREE_INT_CST_LOW (length
) + 1);
1211 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1219 /* check if type is already in the typelist. If not, add it now */
1221 if (flag_do_squangling
&& btypelist
!= NULL
) {
1222 if (check_btype (parmtype
)) /* emits the code if it finds it */
1226 switch (TREE_CODE (parmtype
))
1230 build_mangled_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
1232 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1238 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
1239 /* Otherwise have to implement reentrant typevecs,
1240 unmark and remark types, etc. */
1241 int old_nofold
= nofold
;
1242 if (!flag_do_squangling
) {
1245 flush_repeats (typevec
[maxtype
-1]);
1249 issue_nrepeats (lasttype
);
1251 /* @@ It may be possible to pass a function type in
1252 which is not preceded by a 'P'. */
1253 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
1256 if (firstarg
== NULL_TREE
)
1258 else if (firstarg
== void_list_node
)
1261 build_mangled_name (firstarg
, 0, 0);
1265 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
1266 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
1268 firstarg
= TREE_CHAIN (firstarg
);
1270 build_mangled_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
1276 /* For cfront 2.0 compatibility. */
1279 if (firstarg
== NULL_TREE
)
1281 else if (firstarg
== void_list_node
)
1284 build_mangled_name (firstarg
, 0, 0);
1287 /* Separate args from return type. */
1289 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1290 nofold
= old_nofold
;
1295 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1296 if (parmtype
== integer_type_node
1297 || parmtype
== unsigned_type_node
)
1299 else if (parmtype
== long_integer_type_node
1300 || parmtype
== long_unsigned_type_node
)
1302 else if (parmtype
== short_integer_type_node
1303 || parmtype
== short_unsigned_type_node
)
1305 else if (parmtype
== signed_char_type_node
)
1310 else if (parmtype
== char_type_node
1311 || parmtype
== unsigned_char_type_node
)
1313 else if (parmtype
== wchar_type_node
)
1315 else if (parmtype
== long_long_integer_type_node
1316 || parmtype
== long_long_unsigned_type_node
)
1319 /* it would seem there is no way to enter these in source code,
1321 else if (parmtype
== long_long_long_integer_type_node
1322 || parmtype
== long_long_long_unsigned_type_node
)
1326 my_friendly_abort (73);
1334 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1335 if (parmtype
== long_double_type_node
)
1337 else if (parmtype
== double_type_node
)
1339 else if (parmtype
== float_type_node
)
1341 else my_friendly_abort (74);
1346 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1353 case ERROR_MARK
: /* not right, but nothing is anyway */
1356 /* have to do these */
1361 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1362 /* drop through into next case */
1366 tree name
= TYPE_NAME (parmtype
);
1368 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
1370 build_overload_identifier (TYPE_NAME (parmtype
));
1373 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1375 build_qualified_name (name
);
1380 /* This will take some work. */
1384 case TEMPLATE_TEMPLATE_PARM
:
1385 /* Find and output the original template parameter
1387 if (CLASSTYPE_TEMPLATE_INFO (parmtype
))
1389 build_mangled_template_parm_index ("tzX",
1390 TEMPLATE_TYPE_PARM_INDEX
1392 build_template_parm_names
1393 (DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype
)),
1394 CLASSTYPE_TI_ARGS (parmtype
));
1398 build_mangled_template_parm_index ("ZzX",
1399 TEMPLATE_TYPE_PARM_INDEX
1401 build_template_template_parm_names
1402 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1406 case TEMPLATE_TYPE_PARM
:
1407 build_mangled_template_parm_index ("X",
1408 TEMPLATE_TYPE_PARM_INDEX
1413 /* When mangling the type of a function template whose
1414 declaration looks like:
1416 template <class T> void foo(typename T::U)
1418 we have to mangle these. */
1419 build_qualified_name (parmtype
);
1423 my_friendly_abort (75);
1428 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1429 be either a class TYPE or a FUNCTION_DECL. */
1432 build_static_name (context
, name
)
1436 numeric_output_need_bar
= 0;
1437 start_squangling ();
1440 build_qualified_name (context
);
1443 OB_PUTS ("__static_");
1444 build_qualified_name (context
);
1451 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1455 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1464 char *name
= IDENTIFIER_POINTER (dname
);
1466 /* member operators new and delete look like methods at this point. */
1467 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1468 && TREE_CHAIN (parms
) == void_list_node
)
1470 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1471 return get_identifier ("__builtin_delete");
1472 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1473 return get_identifier ("__builtin_vec_delete");
1474 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1475 return get_identifier ("__builtin_new");
1476 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1477 return get_identifier ("__builtin_vec_new");
1480 start_squangling ();
1482 if (for_method
!= 2)
1484 /* Otherwise, we can divine that this is a constructor,
1485 and figure out its name without any extra encoding. */
1487 OB_PUTC2 ('_', '_');
1491 /* We can get away without doing this. */
1494 if (tparms
!= NULL_TREE
)
1497 tree this_type
= TREE_VALUE (parms
);
1499 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1500 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1501 TREE_CHAIN (parms
));
1503 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1504 TREE_CHAIN (parms
));
1509 /* XXX this works only if we call this in the same namespace
1510 as the declaration. Unfortunately, we don't have the _DECL,
1512 else if (current_namespace
== global_namespace
)
1517 build_template_parm_names (tparms
, targs
);
1521 /* qualify with namespace */
1522 if (!for_method
&& current_namespace
!= global_namespace
)
1523 build_qualified_name (current_namespace
);
1525 if (parms
== NULL_TREE
)
1527 else if (parms
== void_list_node
)
1531 if (!flag_do_squangling
) /* Allocate typevec array. */
1535 typevec
= (tree
*)alloca (list_length (parms
) * sizeof (tree
));
1540 build_mangled_name (TREE_VALUE (parms
), 0, 0);
1542 if (!flag_do_squangling
) {
1543 typevec
[maxtype
++] = TREE_VALUE (parms
);
1544 TREE_USED (TREE_VALUE (parms
)) = 1;
1547 if (TREE_CHAIN (parms
))
1548 build_mangled_name (TREE_CHAIN (parms
), 0, 0);
1554 /* the namespace qualifier for a global function
1555 will count as type */
1556 if (current_namespace
!= global_namespace
1557 && !flag_do_squangling
)
1558 typevec
[maxtype
++] = current_namespace
;
1559 build_mangled_name (parms
, 0, 0);
1562 if (!flag_do_squangling
) /* Deallocate typevec array */
1568 TREE_USED (TREE_VALUE (t
)) = 0;
1574 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1576 /* Add the return type. */
1578 build_mangled_name (ret_type
, 0, 0);
1584 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1585 if (IDENTIFIER_OPNAME_P (dname
))
1586 IDENTIFIER_OPNAME_P (n
) = 1;
1591 /* Change the name of a function definition so that it may be
1592 overloaded. NAME is the name of the function to overload,
1593 PARMS is the parameter list (which determines what name the
1594 final function obtains).
1596 FOR_METHOD is 1 if this overload is being performed
1597 for a method, rather than a function type. It is 2 if
1598 this overload is being performed for a constructor. */
1601 build_decl_overload (dname
, parms
, for_method
)
1606 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1607 NULL_TREE
, for_method
);
1611 /* Like build_decl_overload, but for template functions. */
1614 build_template_decl_overload (dname
, parms
, ret_type
, tparms
, targs
,
1623 return build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1628 /* Build an overload name for the type expression TYPE. */
1631 build_typename_overload (type
)
1637 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1639 start_squangling ();
1640 build_mangled_name (type
, 0, 1);
1641 id
= get_identifier (obstack_base (&scratch_obstack
));
1642 IDENTIFIER_OPNAME_P (id
) = 1;
1644 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1646 TREE_TYPE (id
) = type
;
1652 build_overload_with_type (name
, type
)
1659 start_squangling ();
1660 build_mangled_name (type
, 0, 1);
1662 return get_identifier (obstack_base (&scratch_obstack
));
1666 get_id_2 (name
, name2
)
1674 return get_identifier (obstack_base (&scratch_obstack
));
1677 /* Given a tree_code CODE, and some arguments (at least one),
1678 attempt to use an overloaded operator on the arguments.
1680 For unary operators, only the first argument need be checked.
1681 For binary operators, both arguments may need to be checked.
1683 Member functions can convert class references to class pointers,
1684 for one-level deep indirection. More than that is not supported.
1685 Operators [](), ()(), and ->() must be member functions.
1687 We call function call building calls with LOOKUP_COMPLAIN if they
1688 are our only hope. This is true when we see a vanilla operator
1689 applied to something of aggregate type. If this fails, we are free
1690 to return `error_mark_node', because we will have reported the
1693 Operators NEW and DELETE overload in funny ways: operator new takes
1694 a single `size' parameter, and operator delete takes a pointer to the
1695 storage being deleted. When overloading these operators, success is
1696 assumed. If there is a failure, report an error message and return
1697 `error_mark_node'. */
1701 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1702 enum tree_code code
;
1704 tree xarg1
, xarg2
, arg3
;
1706 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1709 /* This function takes an identifier, ID, and attempts to figure out what
1710 it means. There are a number of possible scenarios, presented in increasing
1713 1) not in a class's scope
1714 2) in class's scope, member name of the class's method
1715 3) in class's scope, but not a member name of the class
1716 4) in class's scope, member name of a class's variable
1718 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1719 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1721 As a last ditch, try to look up the name as a label and return that
1724 Values which are declared as being of REFERENCE_TYPE are
1725 automatically dereferenced here (as a hack to make the
1726 compiler faster). */
1729 hack_identifier (value
, name
)
1734 if (value
== error_mark_node
)
1736 if (current_class_name
)
1738 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1739 if (fields
== error_mark_node
)
1740 return error_mark_node
;
1745 fndecl
= TREE_VALUE (fields
);
1746 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1747 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1749 warning ("methods cannot be converted to function pointers");
1754 error ("ambiguous request for method pointer `%s'",
1755 IDENTIFIER_POINTER (name
));
1756 return error_mark_node
;
1760 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1762 return IDENTIFIER_LABEL_VALUE (name
);
1764 return error_mark_node
;
1767 type
= TREE_TYPE (value
);
1768 if (TREE_CODE (value
) == FIELD_DECL
)
1770 if (current_class_ptr
== NULL_TREE
)
1772 error ("request for member `%s' in static member function",
1773 IDENTIFIER_POINTER (DECL_NAME (value
)));
1774 return error_mark_node
;
1776 TREE_USED (current_class_ptr
) = 1;
1778 /* Mark so that if we are in a constructor, and then find that
1779 this field was initialized by a base initializer,
1780 we can emit an error message. */
1781 TREE_USED (value
) = 1;
1782 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1784 else if (really_overloaded_fn (value
))
1787 tree t
= get_first_fn (value
);
1788 for (; t
; t
= DECL_CHAIN (t
))
1790 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1793 assemble_external (t
);
1798 else if (TREE_CODE (value
) == TREE_LIST
)
1800 /* Ambiguous reference to base members, possibly other cases?. */
1802 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1804 mark_used (TREE_VALUE (t
));
1811 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1813 tree context
= decl_function_context (value
);
1814 if (context
!= NULL_TREE
&& context
!= current_function_decl
1815 && ! TREE_STATIC (value
))
1817 cp_error ("use of %s from containing function",
1818 (TREE_CODE (value
) == VAR_DECL
1819 ? "`auto' variable" : "parameter"));
1820 cp_error_at (" `%#D' declared here", value
);
1821 value
= error_mark_node
;
1825 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1827 if (DECL_LANG_SPECIFIC (value
)
1828 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1831 register tree context
1832 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1833 ? DECL_CLASS_CONTEXT (value
)
1834 : DECL_CONTEXT (value
);
1836 get_base_distance (context
, current_class_type
, 0, &path
);
1839 access
= compute_access (path
, value
);
1840 if (access
!= access_public_node
)
1842 if (TREE_CODE (value
) == VAR_DECL
)
1843 error ("static member `%s' is %s",
1844 IDENTIFIER_POINTER (name
),
1845 TREE_PRIVATE (value
) ? "private"
1846 : "from a private base class");
1848 error ("enum `%s' is from private base class",
1849 IDENTIFIER_POINTER (name
));
1850 return error_mark_node
;
1855 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1859 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1860 IDENTIFIER_POINTER (name
));
1861 return error_mark_node
;
1867 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
1868 value
= convert_from_reference (value
);
1874 make_thunk (function
, delta
)
1883 if (TREE_CODE (function
) != ADDR_EXPR
)
1885 func_decl
= TREE_OPERAND (function
, 0);
1886 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1888 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1889 buffer
= (char *)alloca (strlen (func_name
) + 32);
1891 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1893 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1894 thunk_id
= get_identifier (buffer
);
1895 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1896 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1898 cp_error ("implementation-reserved name `%D' used", thunk_id
);
1899 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1901 if (thunk
== NULL_TREE
)
1903 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1904 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
1905 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
1906 comdat_linkage (thunk
);
1907 TREE_SET_CODE (thunk
, THUNK_DECL
);
1908 DECL_INITIAL (thunk
) = function
;
1909 THUNK_DELTA (thunk
) = delta
;
1910 DECL_EXTERNAL (thunk
) = 1;
1911 DECL_ARTIFICIAL (thunk
) = 1;
1912 /* So that finish_file can write out any thunks that need to be: */
1913 pushdecl_top_level (thunk
);
1918 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1921 emit_thunk (thunk_fndecl
)
1924 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1925 int delta
= THUNK_DELTA (thunk_fndecl
);
1927 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1930 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1932 TREE_ADDRESSABLE (function
) = 1;
1933 mark_used (function
);
1935 if (current_function_decl
)
1938 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
1941 #ifdef ASM_OUTPUT_MI_THUNK
1943 current_function_decl
= thunk_fndecl
;
1944 /* Make sure we build up its RTL before we go onto the
1945 temporary obstack. */
1946 make_function_rtl (thunk_fndecl
);
1947 temporary_allocation ();
1948 DECL_RESULT (thunk_fndecl
)
1949 = build_decl (RESULT_DECL
, 0, integer_type_node
);
1950 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
1951 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1952 assemble_start_function (thunk_fndecl
, fnname
);
1953 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
1954 assemble_end_function (thunk_fndecl
, fnname
);
1955 permanent_allocation (1);
1956 current_function_decl
= 0;
1957 #else /* ASM_OUTPUT_MI_THUNK */
1958 /* If we don't have the necessary macro for efficient thunks, generate a
1959 thunk function that just makes a call to the real function.
1960 Unfortunately, this doesn't work for varargs. */
1964 if (varargs_function_p (function
))
1965 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1968 /* Set up clone argument trees for the thunk. */
1970 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
1972 tree x
= copy_node (a
);
1974 DECL_CONTEXT (x
) = thunk_fndecl
;
1978 DECL_ARGUMENTS (thunk_fndecl
) = a
;
1979 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
1980 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
1981 copy_lang_decl (thunk_fndecl
);
1982 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
1983 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
1985 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
1986 store_parm_decls ();
1987 current_function_is_thunk
= 1;
1989 /* Build up the call to the real function. */
1990 t
= build_int_2 (delta
, -1 * (delta
< 0));
1991 TREE_TYPE (t
) = signed_type (sizetype
);
1992 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
1993 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
1994 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
1995 t
= expr_tree_cons (NULL_TREE
, a
, t
);
1997 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
1998 c_expand_return (t
);
2000 finish_function (lineno
, 0, 0);
2002 /* Don't let the backend defer this function. */
2003 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2005 output_inline_function (thunk_fndecl
);
2006 permanent_allocation (1);
2008 #endif /* ASM_OUTPUT_MI_THUNK */
2011 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2014 /* Code for synthesizing methods which have default semantics defined. */
2016 /* For the anonymous union in TYPE, return the member that is at least as
2017 large as the rest of the members, so we can copy it. */
2020 largest_union_member (type
)
2023 tree f
, type_size
= TYPE_SIZE (type
);
2025 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2026 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2029 /* We should always find one. */
2030 my_friendly_abort (323);
2034 /* Generate code for default X(X&) constructor. */
2037 do_build_copy_constructor (fndecl
)
2040 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2046 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2047 parm
= TREE_CHAIN (parm
);
2048 parm
= convert_from_reference (parm
);
2050 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2052 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2053 TREE_SIDE_EFFECTS (t
) = 1;
2054 cplus_expand_expr_stmt (t
);
2058 tree fields
= TYPE_FIELDS (current_class_type
);
2059 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2060 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2063 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2066 tree basetype
= BINFO_TYPE (t
);
2067 tree p
= convert_to_reference
2068 (build_reference_type (basetype
), parm
,
2069 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2070 p
= convert_from_reference (p
);
2072 if (p
== error_mark_node
)
2073 cp_error ("in default copy constructor");
2075 current_base_init_list
= tree_cons (basetype
,
2076 p
, current_base_init_list
);
2079 for (i
= 0; i
< n_bases
; ++i
)
2081 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2082 if (TREE_VIA_VIRTUAL (basetype
))
2085 basetype
= BINFO_TYPE (basetype
);
2086 p
= convert_to_reference
2087 (build_reference_type (basetype
), parm
,
2088 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2090 if (p
== error_mark_node
)
2091 cp_error ("in default copy constructor");
2094 p
= convert_from_reference (p
);
2095 current_base_init_list
= tree_cons (basetype
,
2096 p
, current_base_init_list
);
2099 for (; fields
; fields
= TREE_CHAIN (fields
))
2102 tree field
= fields
;
2104 if (TREE_CODE (field
) != FIELD_DECL
)
2108 if (DECL_NAME (field
))
2110 if (VFIELD_NAME_P (DECL_NAME (field
)))
2112 if (VBASE_NAME_P (DECL_NAME (field
)))
2115 /* True for duplicate members. */
2116 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2119 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2120 && TREE_CODE (t
) == UNION_TYPE
2121 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2122 && TYPE_FIELDS (t
) != NULL_TREE
)
2126 init
= build (COMPONENT_REF
, t
, init
, field
);
2127 field
= largest_union_member (t
);
2129 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2130 && TREE_CODE (t
) == UNION_TYPE
2131 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2132 && TYPE_FIELDS (t
) != NULL_TREE
);
2137 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2138 init
= build_tree_list (NULL_TREE
, init
);
2140 current_member_init_list
2141 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2143 current_member_init_list
= nreverse (current_member_init_list
);
2144 current_base_init_list
= nreverse (current_base_init_list
);
2152 do_build_assign_ref (fndecl
)
2155 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2160 parm
= convert_from_reference (parm
);
2162 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2164 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2165 TREE_SIDE_EFFECTS (t
) = 1;
2166 cplus_expand_expr_stmt (t
);
2170 tree fields
= TYPE_FIELDS (current_class_type
);
2171 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2172 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2175 for (i
= 0; i
< n_bases
; ++i
)
2177 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2178 tree p
= convert_to_reference
2179 (build_reference_type (basetype
), parm
,
2180 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2181 p
= convert_from_reference (p
);
2182 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2183 build_expr_list (NULL_TREE
, p
));
2184 expand_expr_stmt (p
);
2186 for (; fields
; fields
= TREE_CHAIN (fields
))
2189 tree field
= fields
;
2191 if (TREE_CODE (field
) != FIELD_DECL
)
2194 if (TREE_READONLY (field
))
2196 if (DECL_NAME (field
))
2197 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2199 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2202 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2204 if (DECL_NAME (field
))
2205 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2207 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2211 comp
= current_class_ref
;
2214 if (DECL_NAME (field
))
2216 if (VFIELD_NAME_P (DECL_NAME (field
)))
2218 if (VBASE_NAME_P (DECL_NAME (field
)))
2221 /* True for duplicate members. */
2222 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2225 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2226 && TREE_CODE (t
) == UNION_TYPE
2227 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2228 && TYPE_FIELDS (t
) != NULL_TREE
)
2232 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2233 init
= build (COMPONENT_REF
, t
, init
, field
);
2234 field
= largest_union_member (t
);
2236 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2237 && TREE_CODE (t
) == UNION_TYPE
2238 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2239 && TYPE_FIELDS (t
) != NULL_TREE
);
2244 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2245 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2247 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2250 c_expand_return (current_class_ref
);
2255 synthesize_method (fndecl
)
2258 int nested
= (current_function_decl
!= NULL_TREE
);
2259 tree context
= hack_decl_function_context (fndecl
);
2262 import_export_decl (fndecl
);
2265 push_to_top_level ();
2267 push_cp_function_context (context
);
2269 interface_unknown
= 1;
2270 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2271 store_parm_decls ();
2273 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2274 do_build_assign_ref (fndecl
);
2275 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2279 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2280 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2281 arg_chain
= TREE_CHAIN (arg_chain
);
2282 if (arg_chain
!= void_list_node
)
2283 do_build_copy_constructor (fndecl
);
2284 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2288 finish_function (lineno
, 0, nested
);
2290 extract_interface_info ();
2292 pop_from_top_level ();
2294 pop_cp_function_context (context
);