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"
45 /* TREE_LIST of the current inline functions that need to be
47 struct pending_inline *pending_inlines;
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
54 /* Obstack where we build text strings for overloading, etc. */
55 static struct obstack scratch_obstack;
56 static char *scratch_firstobj;
58 static void icat PROTO((HOST_WIDE_INT));
59 static void dicat PROTO((HOST_WIDE_INT, HOST_WIDE_INT));
60 static void flush_repeats PROTO((tree));
61 static void build_overload_identifier PROTO((tree));
62 static void build_overload_nested_name PROTO((tree));
63 static void build_overload_int PROTO((tree, int));
64 static void build_overload_identifier PROTO((tree));
65 static void build_qualified_name PROTO((tree));
66 static void build_overload_value PROTO((tree, tree, int));
67 static void issue_nrepeats PROTO((tree));
68 static char *build_mangled_name PROTO((tree,int,int));
69 static void process_modifiers PROTO((tree));
70 static void process_overload_item PROTO((tree,int));
71 static void do_build_assign_ref PROTO((tree));
72 static void do_build_copy_constructor PROTO((tree));
73 static tree largest_union_member PROTO((tree));
74 static tree build_decl_overload_real PROTO((tree, tree, tree, tree,
76 static void build_template_template_parm_names PROTO((tree));
77 static void build_template_parm_names PROTO((tree, tree));
78 static void build_underscore_int PROTO((int));
79 static void start_squangling PROTO((void));
80 static void end_squangling PROTO((void));
81 static int check_ktype PROTO((tree, int));
82 static int issue_ktype PROTO((tree));
83 static void build_overload_scope_ref PROTO((tree));
84 static void build_mangled_template_parm_index PROTO((char *, tree));
85 static int check_btype PROTO((tree));
87 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
88 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
89 # define OB_PUTC2(C1,C2) \
90 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
91 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
92 # define OB_PUTID(ID) \
93 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
94 IDENTIFIER_LENGTH (ID)))
95 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
96 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
97 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
102 gcc_obstack_init (&scratch_obstack);
103 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
106 /* This must be large enough to hold any printed integer or floating-point
108 static char digit_buffer[128];
110 /* Move inline function definitions out of structure so that they
111 can be processed normally. CNAME is the name of the class
112 we are working from, METHOD_LIST is the list of method lists
113 of the structure. We delete friend methods here, after
114 saving away their inline function definitions (if any). */
117 do_inline_function_hair (type, friend_list)
118 tree type, friend_list;
120 tree method = TYPE_METHODS (type);
122 if (method && TREE_CODE (method) == TREE_VEC)
124 if (TREE_VEC_ELT (method, 1))
125 method = TREE_VEC_ELT (method, 1);
126 else if (TREE_VEC_ELT (method, 0))
127 method = TREE_VEC_ELT (method, 0);
129 method = TREE_VEC_ELT (method, 2);
134 /* Do inline member functions. */
135 struct pending_inline *info = DECL_PENDING_INLINE_INFO (method);
140 my_friendly_assert (info->fndecl == method, 238);
141 args = DECL_ARGUMENTS (method);
144 DECL_CONTEXT (args) = method;
145 args = TREE_CHAIN (args);
148 method = TREE_CHAIN (method);
152 tree fndecl = TREE_VALUE (friend_list);
153 struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl);
158 my_friendly_assert (info->fndecl == fndecl, 239);
159 args = DECL_ARGUMENTS (fndecl);
162 DECL_CONTEXT (args) = fndecl;
163 args = TREE_CHAIN (args);
167 friend_list = TREE_CHAIN (friend_list);
171 /* Here is where overload code starts. */
173 /* type tables for K and B type compression */
174 static tree *btypelist = NULL;
175 static tree *ktypelist = NULL;
176 static tree lasttype = NULL;
177 static int maxbsize = 0;
178 static int maxksize = 0;
180 /* number of each type seen */
181 static int maxbtype = 0;
182 static int maxktype = 0;
184 /* Number of occurrences of last b type seen. */
185 static int nrepeats = 0;
187 /* Array of types seen so far in top-level call to `build_mangled_name'.
188 Allocated and deallocated by caller. */
189 static tree *typevec = NULL;
191 /* Number of types interned by `build_mangled_name' so far. */
192 static int maxtype = 0;
194 /* Number of occurrences of last type seen. */
195 static int Nrepeats = 0;
197 /* Nonzero if we should not try folding parameter types. */
200 /* This appears to be set to true if an underscore is required to be
201 comcatenated before another number can be outputed. */
202 static int numeric_output_need_bar;
207 if (flag_do_squangling)
216 btypelist = (tree *)xmalloc (sizeof (tree) * maxbsize);
217 ktypelist = (tree *)xmalloc (sizeof (tree) * maxksize);
224 if (flag_do_squangling)
240 /* Code to concatenate an asciified integer to a string. */
246 unsigned HOST_WIDE_INT ui;
248 /* Handle this case first, to go really quickly. For many common values,
249 the result of ui/10 below is 1. */
267 OB_PUTC ('0' + (ui % 10));
272 HOST_WIDE_INT lo, hi;
274 unsigned HOST_WIDE_INT ulo, uhi, qlo, qhi;
283 uhi = (lo == 0 ? -hi : -hi-1);
287 && ulo < ((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)))
292 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
295 qlo = uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) / 5);
298 ulo += uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) % 5)
302 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
313 while (typevec[tindex] != type)
332 /* issue squangling type repeating */
334 issue_nrepeats (lasttype)
339 switch (TREE_CODE (lasttype))
345 process_overload_item (lasttype, FALSE);
361 /* Check to see if a tree node has been entered into the Kcode typelist */
362 /* if not, add it. Return -1 if it isn't found, otherwise return the index */
364 check_ktype (node, add)
369 tree localnode = node;
371 if (ktypelist == NULL)
374 if (TREE_CODE (node) == TYPE_DECL)
375 localnode = TREE_TYPE (node);
377 for (x=0; x < maxktype; x++)
379 if (localnode == ktypelist[x])
382 /* Didn't find it, so add it here */
385 if (maxksize <= maxktype)
387 maxksize = maxksize* 3 / 2;
388 ktypelist = (tree *)xrealloc (ktypelist, sizeof (tree) * maxksize);
390 ktypelist[maxktype++] = localnode;
401 kindex = check_ktype (decl, FALSE);
414 build_overload_nested_name (decl)
418 if (ktypelist && issue_ktype (decl))
421 if (DECL_CONTEXT (decl))
423 tree context = DECL_CONTEXT (decl);
425 /* try to issue a K type, and if we can't continue the normal path */
426 if (!(ktypelist && issue_ktype (context)))
428 /* For a template type parameter, we want to output an 'Xn'
429 rather than 'T' or some such. */
430 if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
431 || TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
432 build_mangled_name (context, 0, 0);
435 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
436 context = TYPE_NAME (context);
437 build_overload_nested_name (context);
441 else if (decl == global_namespace)
443 else if (DECL_NAMESPACE (decl))
444 build_overload_nested_name (DECL_NAMESPACE (decl));
446 /* XXX the above does not work for non-namespaces */
447 if (current_namespace && TREE_CODE (decl) != NAMESPACE_DECL)
448 build_overload_nested_name (current_namespace);
450 if (TREE_CODE (decl) == FUNCTION_DECL)
452 tree name = DECL_ASSEMBLER_NAME (decl);
455 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), static_labelno);
458 if (numeric_output_need_bar)
460 icat (strlen (label));
462 numeric_output_need_bar = 1;
464 else if (TREE_CODE (decl) == NAMESPACE_DECL)
465 build_overload_identifier (DECL_NAME (decl));
467 build_overload_identifier (decl);
471 build_underscore_int (i)
482 build_overload_scope_ref (value)
486 numeric_output_need_bar = 0;
487 build_mangled_name (TREE_OPERAND (value, 0), 0, 0);
488 build_overload_identifier (TREE_OPERAND (value, 1));
491 /* Encoding for an INTEGER_CST value. */
494 build_overload_int (value, in_template)
498 if (in_template && TREE_CODE (value) != INTEGER_CST)
500 if (TREE_CODE (value) == SCOPE_REF)
502 build_overload_scope_ref (value);
507 numeric_output_need_bar = 0;
509 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value))))
512 int operands = tree_code_length[(int) TREE_CODE (value)];
516 id = ansi_opname [(int) TREE_CODE (value)];
517 my_friendly_assert (id != NULL_TREE, 0);
518 name = IDENTIFIER_POINTER (id);
519 my_friendly_assert (name[0] == '_' && name[1] == '_', 0);
521 for (i = 0; i < operands; ++i)
526 /* We just outputted either the `E' or the name of the
528 numeric_output_need_bar = 0;
531 /* Skip the leading underscores. */
534 operand = TREE_OPERAND (value, i);
535 tc = TREE_CODE (operand);
537 if (TREE_CODE_CLASS (tc) == 't')
538 /* We can get here with sizeof, e.g.:
540 template <class T> void f(A<sizeof(T)>); */
541 process_overload_item (operand, 0);
542 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc)))
543 build_overload_int (operand, in_template);
545 build_overload_value (TREE_TYPE (operand),
552 /* We don't ever want this output, but it's
553 inconvenient not to be able to build the string.
554 This should cause assembler errors we'll notice. */
557 sprintf (digit_buffer, " *%d", n++);
558 OB_PUTCP (digit_buffer);
562 numeric_output_need_bar = 0;
566 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
567 if (TYPE_PRECISION (TREE_TYPE (value)) == 2 * HOST_BITS_PER_WIDE_INT)
569 if (TREE_INT_CST_HIGH (value)
570 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
572 /* need to print a DImode value in decimal */
573 dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value));
574 numeric_output_need_bar = 1;
577 /* else fall through to print in smaller mode */
579 /* Wordsize or smaller */
580 icat (TREE_INT_CST_LOW (value));
581 numeric_output_need_bar = 1;
585 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
586 supplied in INDEX. */
589 build_mangled_template_parm_index (s, index)
594 build_underscore_int (TEMPLATE_PARM_IDX (index));
595 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
596 representation of the function from the point of view of its
598 build_underscore_int (TEMPLATE_PARM_LEVEL (index));
603 build_overload_value (type, value, in_template)
607 while (TREE_CODE (value) == NON_LVALUE_EXPR
608 || TREE_CODE (value) == NOP_EXPR)
609 value = TREE_OPERAND (value, 0);
611 if (TREE_CODE (type) == PARM_DECL)
612 type = TREE_TYPE (type);
614 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type)) == 't', 0);
616 if (numeric_output_need_bar)
619 numeric_output_need_bar = 0;
622 if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
624 build_mangled_template_parm_index ("Y", value);
628 if (TREE_CODE (type) == POINTER_TYPE
629 && TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE)
631 /* Handle a pointer to data member as a template instantiation
632 parameter, boy, what fun! */
633 type = integer_type_node;
634 if (TREE_CODE (value) != INTEGER_CST)
636 sorry ("unknown pointer to member constant");
641 if (TYPE_PTRMEMFUNC_P (type))
642 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
644 switch (TREE_CODE (type))
650 build_overload_int (value, in_template);
656 char *bufp = digit_buffer;
658 pedwarn ("ANSI C++ forbids floating-point template arguments");
660 my_friendly_assert (TREE_CODE (value) == REAL_CST, 244);
661 val = TREE_REAL_CST (value);
662 if (REAL_VALUE_ISNAN (val))
664 sprintf (bufp, "NaN");
668 if (REAL_VALUE_NEGATIVE (val))
670 val = REAL_VALUE_NEGATE (val);
673 if (REAL_VALUE_ISINF (val))
675 sprintf (bufp, "Infinity");
679 REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
680 bufp = (char *) index (bufp, 'e');
682 strcat (digit_buffer, "e0");
708 #ifdef NO_DOT_IN_LABEL
709 bufp = (char *) index (bufp, '.');
715 OB_PUTCP (digit_buffer);
716 numeric_output_need_bar = 1;
720 if (TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
721 && TREE_CODE (value) != ADDR_EXPR)
723 if (TREE_CODE (value) == CONSTRUCTOR)
725 /* This is dangerous code, crack built up pointer to members. */
726 tree args = CONSTRUCTOR_ELTS (value);
727 tree a1 = TREE_VALUE (args);
728 tree a2 = TREE_VALUE (TREE_CHAIN (args));
729 tree a3 = CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args))));
730 a3 = TREE_VALUE (a3);
732 if (TREE_CODE (a1) == INTEGER_CST
733 && TREE_CODE (a2) == INTEGER_CST)
735 build_overload_int (a1, in_template);
737 build_overload_int (a2, in_template);
739 if (TREE_CODE (a3) == ADDR_EXPR)
741 a3 = TREE_OPERAND (a3, 0);
742 if (TREE_CODE (a3) == FUNCTION_DECL)
744 numeric_output_need_bar = 0;
745 build_overload_identifier (DECL_ASSEMBLER_NAME (a3));
749 else if (TREE_CODE (a3) == INTEGER_CST)
752 build_overload_int (a3, in_template);
757 sorry ("template instantiation with pointer to method that is too complex");
760 if (TREE_CODE (value) == INTEGER_CST)
762 build_overload_int (value, in_template);
765 else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
767 build_mangled_template_parm_index ("", value);
768 numeric_output_need_bar = 1;
772 value = TREE_OPERAND (value, 0);
773 if (TREE_CODE (value) == VAR_DECL)
775 my_friendly_assert (DECL_NAME (value) != 0, 245);
776 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
779 else if (TREE_CODE (value) == FUNCTION_DECL)
781 my_friendly_assert (DECL_NAME (value) != 0, 246);
782 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
785 else if (TREE_CODE (value) == SCOPE_REF)
786 build_overload_scope_ref (value);
788 my_friendly_abort (71);
789 break; /* not really needed */
792 sorry ("conversion of %s as template parameter",
793 tree_code_name [(int) TREE_CODE (type)]);
794 my_friendly_abort (72);
799 /* Add encodings for the declaration of template template parameters.
800 PARMLIST must be a TREE_VEC */
803 build_template_template_parm_names (parmlist)
808 my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
809 nparms = TREE_VEC_LENGTH (parmlist);
811 for (i = 0; i < nparms; i++)
813 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
814 if (TREE_CODE (parm) == TYPE_DECL)
816 /* This parameter is a type. */
819 else if (TREE_CODE (parm) == TEMPLATE_DECL)
821 /* This parameter is a template. */
823 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
827 /* It's a PARM_DECL. */
828 build_mangled_name (TREE_TYPE (parm), 0, 0);
834 /* Add encodings for the vector of template parameters in PARMLIST,
835 given the vector of arguments to be substituted in ARGLIST. */
838 build_template_parm_names (parmlist, arglist)
844 nparms = TREE_VEC_LENGTH (parmlist);
846 for (i = 0; i < nparms; i++)
848 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
849 tree arg = TREE_VEC_ELT (arglist, i);
850 if (TREE_CODE (parm) == TYPE_DECL)
852 /* This parameter is a type. */
854 build_mangled_name (arg, 0, 0);
856 else if (TREE_CODE (parm) == TEMPLATE_DECL)
858 /* This parameter is a template. */
859 if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
860 /* Output parameter declaration, argument index and level */
861 build_mangled_name (arg, 0, 0);
864 /* A TEMPLATE_DECL node, output the parameter declaration
868 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
869 icat (IDENTIFIER_LENGTH (DECL_NAME (arg)));
870 OB_PUTID (DECL_NAME (arg));
875 parm = tsubst (parm, arglist, NULL_TREE);
876 /* It's a PARM_DECL. */
877 build_mangled_name (TREE_TYPE (parm), 0, 0);
878 build_overload_value (parm, arg, uses_template_parms (arglist));
885 build_overload_identifier (name)
888 if (TREE_CODE (name) == TYPE_DECL
889 && IS_AGGR_TYPE (TREE_TYPE (name))
890 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
891 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))
892 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
896 tree template, parmlist, arglist, tname;
897 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name));
898 arglist = TREE_VALUE (template);
899 template = TREE_PURPOSE (template);
900 tname = DECL_NAME (template);
901 parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
903 icat (IDENTIFIER_LENGTH (tname));
905 build_template_parm_names (parmlist, arglist);
909 if (TREE_CODE (name) == TYPE_DECL)
910 name = DECL_NAME (name);
911 if (numeric_output_need_bar)
914 numeric_output_need_bar = 0;
916 icat (IDENTIFIER_LENGTH (name));
921 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
922 the mangling for it. Used by build_mangled_name and build_static_name. */
925 build_qualified_name (decl)
931 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
932 decl = TYPE_NAME (decl);
934 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
935 if (TREE_CODE (decl) == TYPE_DECL
936 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling)
938 tree id = DECL_ASSEMBLER_NAME (decl);
940 if (isdigit (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1]))
941 numeric_output_need_bar = 1;
946 /* if we can't find a Ktype, do it the hard way */
947 if (check_ktype (context, FALSE) == -1)
949 /* count type scopes */
950 while (DECL_CONTEXT (context))
953 context = DECL_CONTEXT (context);
954 if (check_ktype (context, FALSE) != -1) /* found it! */
956 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
957 context = TYPE_NAME (context);
959 /* now count namespace scopes */
960 if (TREE_CODE (decl) == NAMESPACE_DECL)
962 i = 0; /* we have nothing done, yet: reset */
966 /* decl must be a type, which we have to scope with the
969 /* XXX MvL somehow, types have no lang_decl, so no namespace */
970 context = current_namespace;
974 while (context != global_namespace)
977 context = DECL_NAMESPACE (context);
983 build_underscore_int (i);
984 numeric_output_need_bar = 0;
986 build_overload_nested_name (decl);
989 /* Given a list of parameters in PARMTYPES, create an unambiguous
990 overload string. Should distinguish any type that C (or C++) can
991 distinguish. I.e., pointers to functions are treated correctly.
993 Caller must deal with whether a final `e' goes on the end or not.
995 Any default conversions must take place before this function
998 BEGIN and END control initialization and finalization of the
999 obstack where we build the string. */
1002 build_overload_name (parmtypes, begin, end)
1007 start_squangling ();
1008 ret = build_mangled_name (parmtypes, begin, end);
1014 build_mangled_name (parmtypes, begin, end)
1022 numeric_output_need_bar = 0;
1024 if (TREE_CODE (parmtypes) != TREE_LIST) /* just one item */
1026 if (TYPE_PTRMEMFUNC_P (parmtypes))
1027 parmtypes = TYPE_PTRMEMFUNC_FN_TYPE (parmtypes);
1028 process_modifiers (parmtypes);
1029 process_overload_item (parmtypes, FALSE);
1032 for ( ; parmtypes!=NULL; parmtypes = TREE_CHAIN (parmtypes))
1034 parmtype = TREE_VALUE (parmtypes);
1035 parmtype = build_type_variant (TYPE_MAIN_VARIANT (parmtype),
1036 TYPE_READONLY (parmtype), TYPE_VOLATILE (parmtype));
1037 if (flag_do_squangling) /* squangling style repeats */
1039 if (parmtype == lasttype)
1047 issue_nrepeats (lasttype);
1049 lasttype = parmtype;
1052 if (!nofold && typevec)
1054 /* Every argument gets counted. */
1055 typevec[maxtype++] = parmtype;
1057 if (TREE_USED (parmtype) && parmtype == typevec[maxtype-2]
1058 && ! is_java_type (parmtype))
1065 flush_repeats (typevec[maxtype-2]);
1067 if (TREE_USED (parmtype))
1070 /* We can turn this on at some point when we want
1071 improved symbol mangling. */
1074 /* This is bug compatible with 2.7.x */
1075 flush_repeats (parmtype);
1080 /* Only cache types which take more than one character. */
1081 if ((parmtype != TYPE_MAIN_VARIANT (parmtype)
1082 || (TREE_CODE (parmtype) != INTEGER_TYPE
1083 && TREE_CODE (parmtype) != REAL_TYPE))
1084 && ! is_java_type (parmtype))
1085 TREE_USED (parmtype) = 1;
1087 if (TYPE_PTRMEMFUNC_P (parmtype))
1088 parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype);
1089 process_modifiers (parmtype);
1090 if (TREE_CODE(parmtype)==VOID_TYPE)
1093 extern tree void_list_node;
1095 /* See if anybody is wasting memory. */
1096 my_friendly_assert (parmtypes == void_list_node, 247);
1098 /* This is the end of a parameter list. */
1101 return (char *)obstack_base (&scratch_obstack);
1103 process_overload_item (parmtype, TRUE);
1105 if (flag_do_squangling && nrepeats != 0)
1106 issue_nrepeats (lasttype);
1108 if (Nrepeats && typevec)
1109 flush_repeats (typevec[maxtype-1]);
1111 /* To get here, parms must end with `...'. */
1116 return (char *)obstack_base (&scratch_obstack);
1119 /* handles emitting modifiers such as Constant, read-only, and volatile */
1121 process_modifiers (parmtype)
1126 if (TREE_READONLY (parmtype))
1128 if (TREE_CODE (parmtype) == INTEGER_TYPE
1129 && (TYPE_MAIN_VARIANT (parmtype)
1130 == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
1131 && ! is_java_type (parmtype))
1135 if (TYPE_VOLATILE (parmtype))
1139 /* True iff TYPE was declared as a "Java" type (inside extern "Java"). */
1145 if (TYPE_NAME (type) != NULL_TREE)
1147 tree decl = TYPE_NAME (type);
1148 if (TREE_CODE (decl) == TYPE_DECL
1149 && DECL_LANG_SPECIFIC (decl) != NULL
1150 && DECL_LANGUAGE (decl) == lang_java)
1156 /* Check to see if a tree node has been entered into the Bcode typelist
1157 if not, add it. Otherwise emit the code and return TRUE */
1164 if (btypelist == NULL)
1167 switch (TREE_CODE (node))
1173 return 0; /* don't compress single char basic types */
1179 node = TYPE_MAIN_VARIANT (node);
1180 for (x = 0; x < maxbtype; x++)
1182 if (node == btypelist[x])
1191 /* didn't find it, so add it here */
1192 if (maxbsize <= maxbtype)
1194 maxbsize = maxbsize * 3 / 2;
1195 btypelist = (tree *)xrealloc (btypelist, sizeof (tree) * maxbsize);
1197 btypelist[maxbtype++] = node;
1201 /* handle emitting the correct code for various node types */
1203 process_overload_item (parmtype, extra_Gcode)
1208 /* These tree types are considered modifiers for B code squangling , */
1209 /* and therefore should not get entries in the Btypelist */
1210 /* they are, however, repeatable types */
1212 switch (TREE_CODE (parmtype))
1214 case REFERENCE_TYPE:
1219 #if PARM_CAN_BE_ARRAY_TYPE
1224 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
1225 error("pointer/reference to array of unknown bound in parm type");
1228 length = array_type_nelts (parmtype);
1229 if (TREE_CODE (length) == INTEGER_CST)
1230 icat (TREE_INT_CST_LOW (length) + 1);
1243 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1251 /* check if type is already in the typelist. If not, add it now */
1253 if (flag_do_squangling && btypelist != NULL) {
1254 if (check_btype (parmtype)) /* emits the code if it finds it */
1258 switch (TREE_CODE (parmtype))
1262 build_mangled_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0);
1264 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1270 tree firstarg = TYPE_ARG_TYPES (parmtype);
1271 /* Otherwise have to implement reentrant typevecs,
1272 unmark and remark types, etc. */
1273 int old_nofold = nofold;
1274 if (!flag_do_squangling) {
1277 flush_repeats (typevec[maxtype-1]);
1281 issue_nrepeats (lasttype);
1283 /* @@ It may be possible to pass a function type in
1284 which is not preceded by a 'P'. */
1285 if (TREE_CODE (parmtype) == FUNCTION_TYPE)
1288 if (firstarg == NULL_TREE)
1290 else if (firstarg == void_list_node)
1293 build_mangled_name (firstarg, 0, 0);
1297 int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
1298 int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
1300 firstarg = TREE_CHAIN (firstarg);
1302 build_mangled_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0);
1308 /* For cfront 2.0 compatibility. */
1311 if (firstarg == NULL_TREE)
1313 else if (firstarg == void_list_node)
1316 build_mangled_name (firstarg, 0, 0);
1319 /* Separate args from return type. */
1321 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1322 nofold = old_nofold;
1327 /* "Java" integer types should mangle the same on all platforms,
1328 and only depend on precision, not target 'int' size. */
1329 if (is_java_type (parmtype))
1331 if (TREE_UNSIGNED (parmtype))
1333 switch (TYPE_PRECISION (parmtype))
1335 case 8: OB_PUTC ('b'); return;
1336 case 16: OB_PUTC ('w'); return;
1341 switch (TYPE_PRECISION (parmtype))
1343 case 8: OB_PUTC ('c'); return;
1344 case 16: OB_PUTC ('s'); return;
1345 case 32: OB_PUTC ('i'); return;
1346 case 64: OB_PUTC ('x'); return;
1351 parmtype = TYPE_MAIN_VARIANT (parmtype);
1352 if (parmtype == integer_type_node
1353 || parmtype == unsigned_type_node)
1355 else if (parmtype == long_integer_type_node
1356 || parmtype == long_unsigned_type_node)
1358 else if (parmtype == short_integer_type_node
1359 || parmtype == short_unsigned_type_node)
1361 else if (parmtype == signed_char_type_node)
1366 else if (parmtype == char_type_node
1367 || parmtype == unsigned_char_type_node)
1369 else if (parmtype == wchar_type_node)
1371 else if (parmtype == long_long_integer_type_node
1372 || parmtype == long_long_unsigned_type_node)
1375 /* it would seem there is no way to enter these in source code,
1377 else if (parmtype == long_long_long_integer_type_node
1378 || parmtype == long_long_long_unsigned_type_node)
1382 my_friendly_abort (73);
1390 parmtype = TYPE_MAIN_VARIANT (parmtype);
1391 if (parmtype == long_double_type_node)
1393 else if (parmtype == double_type_node)
1395 else if (parmtype == float_type_node)
1397 else my_friendly_abort (74);
1402 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1409 case ERROR_MARK: /* not right, but nothing is anyway */
1412 /* have to do these */
1417 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1418 /* drop through into next case */
1422 tree name = TYPE_NAME (parmtype);
1424 if (TREE_CODE (name) == IDENTIFIER_NODE)
1426 build_overload_identifier (TYPE_NAME (parmtype));
1429 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
1431 build_qualified_name (name);
1436 /* This will take some work. */
1440 case TEMPLATE_TEMPLATE_PARM:
1441 /* Find and output the original template parameter
1443 if (CLASSTYPE_TEMPLATE_INFO (parmtype))
1445 build_mangled_template_parm_index ("tzX",
1446 TEMPLATE_TYPE_PARM_INDEX
1448 build_template_parm_names
1449 (DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype)),
1450 CLASSTYPE_TI_ARGS (parmtype));
1454 build_mangled_template_parm_index ("ZzX",
1455 TEMPLATE_TYPE_PARM_INDEX
1457 build_template_template_parm_names
1458 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
1462 case TEMPLATE_TYPE_PARM:
1463 build_mangled_template_parm_index ("X",
1464 TEMPLATE_TYPE_PARM_INDEX
1469 /* When mangling the type of a function template whose
1470 declaration looks like:
1472 template <class T> void foo(typename T::U)
1474 we have to mangle these. */
1475 build_qualified_name (parmtype);
1479 my_friendly_abort (75);
1484 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1485 be either a class TYPE or a FUNCTION_DECL. */
1488 build_static_name (context, name)
1492 numeric_output_need_bar = 0;
1493 start_squangling ();
1496 build_qualified_name (context);
1499 OB_PUTS ("__static_");
1500 build_qualified_name (context);
1507 return get_identifier ((char *)obstack_base (&scratch_obstack));
1511 build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1520 char *name = IDENTIFIER_POINTER (dname);
1522 /* member operators new and delete look like methods at this point. */
1523 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
1524 && TREE_CHAIN (parms) == void_list_node)
1526 if (dname == ansi_opname[(int) DELETE_EXPR])
1527 return get_identifier ("__builtin_delete");
1528 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1529 return get_identifier ("__builtin_vec_delete");
1530 if (dname == ansi_opname[(int) NEW_EXPR])
1531 return get_identifier ("__builtin_new");
1532 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1533 return get_identifier ("__builtin_vec_new");
1536 start_squangling ();
1538 if (for_method != 2)
1540 /* Otherwise, we can divine that this is a constructor,
1541 and figure out its name without any extra encoding. */
1543 OB_PUTC2 ('_', '_');
1547 /* We can get away without doing this. */
1550 if (tparms != NULL_TREE)
1553 tree this_type = TREE_VALUE (parms);
1555 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
1556 parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type),
1557 TREE_CHAIN (parms));
1559 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type),
1560 TREE_CHAIN (parms));
1565 /* XXX this works only if we call this in the same namespace
1566 as the declaration. Unfortunately, we don't have the _DECL,
1568 else if (current_namespace == global_namespace)
1573 build_template_parm_names (tparms, targs);
1577 /* qualify with namespace */
1578 if (!for_method && current_namespace != global_namespace)
1579 build_qualified_name (current_namespace);
1581 if (parms == NULL_TREE)
1583 else if (parms == void_list_node)
1587 if (!flag_do_squangling) /* Allocate typevec array. */
1591 typevec = (tree *)alloca (list_length (parms) * sizeof (tree));
1596 build_mangled_name (TREE_VALUE (parms), 0, 0);
1598 if (!flag_do_squangling) {
1599 typevec[maxtype++] = TREE_VALUE (parms);
1600 TREE_USED (TREE_VALUE (parms)) = 1;
1603 if (TREE_CHAIN (parms))
1604 build_mangled_name (TREE_CHAIN (parms), 0, 0);
1610 /* the namespace qualifier for a global function
1611 will count as type */
1612 if (current_namespace != global_namespace
1613 && !flag_do_squangling)
1614 typevec[maxtype++] = current_namespace;
1615 build_mangled_name (parms, 0, 0);
1618 if (!flag_do_squangling) /* Deallocate typevec array */
1624 TREE_USED (TREE_VALUE (t)) = 0;
1630 if (ret_type != NULL_TREE && for_method != 2)
1632 /* Add the return type. */
1634 build_mangled_name (ret_type, 0, 0);
1640 tree n = get_identifier (obstack_base (&scratch_obstack));
1641 if (IDENTIFIER_OPNAME_P (dname))
1642 IDENTIFIER_OPNAME_P (n) = 1;
1647 /* Change the name of a function definition so that it may be
1648 overloaded. NAME is the name of the function to overload,
1649 PARMS is the parameter list (which determines what name the
1650 final function obtains).
1652 FOR_METHOD is 1 if this overload is being performed
1653 for a method, rather than a function type. It is 2 if
1654 this overload is being performed for a constructor. */
1657 build_decl_overload (dname, parms, for_method)
1662 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1663 NULL_TREE, for_method);
1667 /* Like build_decl_overload, but for template functions. */
1670 build_template_decl_overload (dname, parms, ret_type, tparms, targs,
1679 return build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1684 /* Build an overload name for the type expression TYPE. */
1687 build_typename_overload (type)
1693 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1695 start_squangling ();
1696 build_mangled_name (type, 0, 1);
1697 id = get_identifier (obstack_base (&scratch_obstack));
1698 IDENTIFIER_OPNAME_P (id) = 1;
1700 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1702 TREE_TYPE (id) = type;
1708 build_overload_with_type (name, type)
1715 start_squangling ();
1716 build_mangled_name (type, 0, 1);
1718 return get_identifier (obstack_base (&scratch_obstack));
1722 get_id_2 (name, name2)
1730 return get_identifier (obstack_base (&scratch_obstack));
1733 /* Given a tree_code CODE, and some arguments (at least one),
1734 attempt to use an overloaded operator on the arguments.
1736 For unary operators, only the first argument need be checked.
1737 For binary operators, both arguments may need to be checked.
1739 Member functions can convert class references to class pointers,
1740 for one-level deep indirection. More than that is not supported.
1741 Operators [](), ()(), and ->() must be member functions.
1743 We call function call building calls with LOOKUP_COMPLAIN if they
1744 are our only hope. This is true when we see a vanilla operator
1745 applied to something of aggregate type. If this fails, we are free
1746 to return `error_mark_node', because we will have reported the
1749 Operators NEW and DELETE overload in funny ways: operator new takes
1750 a single `size' parameter, and operator delete takes a pointer to the
1751 storage being deleted. When overloading these operators, success is
1752 assumed. If there is a failure, report an error message and return
1753 `error_mark_node'. */
1757 build_opfncall (code, flags, xarg1, xarg2, arg3)
1758 enum tree_code code;
1760 tree xarg1, xarg2, arg3;
1762 return build_new_op (code, flags, xarg1, xarg2, arg3);
1765 /* This function takes an identifier, ID, and attempts to figure out what
1766 it means. There are a number of possible scenarios, presented in increasing
1769 1) not in a class's scope
1770 2) in class's scope, member name of the class's method
1771 3) in class's scope, but not a member name of the class
1772 4) in class's scope, member name of a class's variable
1774 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1775 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1777 As a last ditch, try to look up the name as a label and return that
1780 Values which are declared as being of REFERENCE_TYPE are
1781 automatically dereferenced here (as a hack to make the
1782 compiler faster). */
1785 hack_identifier (value, name)
1790 if (value == error_mark_node)
1792 if (current_class_name)
1794 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1795 if (fields == error_mark_node)
1796 return error_mark_node;
1801 fndecl = TREE_VALUE (fields);
1802 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1803 if (DECL_CHAIN (fndecl) == NULL_TREE)
1805 warning ("methods cannot be converted to function pointers");
1810 error ("ambiguous request for method pointer `%s'",
1811 IDENTIFIER_POINTER (name));
1812 return error_mark_node;
1816 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1818 return IDENTIFIER_LABEL_VALUE (name);
1820 return error_mark_node;
1823 type = TREE_TYPE (value);
1824 if (TREE_CODE (value) == FIELD_DECL)
1826 if (current_class_ptr == NULL_TREE)
1828 error ("request for member `%s' in static member function",
1829 IDENTIFIER_POINTER (DECL_NAME (value)));
1830 return error_mark_node;
1832 TREE_USED (current_class_ptr) = 1;
1834 /* Mark so that if we are in a constructor, and then find that
1835 this field was initialized by a base initializer,
1836 we can emit an error message. */
1837 TREE_USED (value) = 1;
1838 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
1840 else if (really_overloaded_fn (value))
1843 tree t = get_first_fn (value);
1844 for (; t; t = DECL_CHAIN (t))
1846 if (TREE_CODE (t) == TEMPLATE_DECL)
1849 assemble_external (t);
1854 else if (TREE_CODE (value) == TREE_LIST)
1856 /* Ambiguous reference to base members, possibly other cases?. */
1858 while (t && TREE_CODE (t) == TREE_LIST)
1860 mark_used (TREE_VALUE (t));
1867 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL)
1869 tree context = decl_function_context (value);
1870 if (context != NULL_TREE && context != current_function_decl
1871 && ! TREE_STATIC (value))
1873 cp_error ("use of %s from containing function",
1874 (TREE_CODE (value) == VAR_DECL
1875 ? "`auto' variable" : "parameter"));
1876 cp_error_at (" `%#D' declared here", value);
1877 value = error_mark_node;
1881 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1883 if (DECL_LANG_SPECIFIC (value)
1884 && DECL_CLASS_CONTEXT (value) != current_class_type)
1887 register tree context
1888 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1889 ? DECL_CLASS_CONTEXT (value)
1890 : DECL_CONTEXT (value);
1892 get_base_distance (context, current_class_type, 0, &path);
1895 access = compute_access (path, value);
1896 if (access != access_public_node)
1898 if (TREE_CODE (value) == VAR_DECL)
1899 error ("static member `%s' is %s",
1900 IDENTIFIER_POINTER (name),
1901 TREE_PRIVATE (value) ? "private"
1902 : "from a private base class");
1904 error ("enum `%s' is from private base class",
1905 IDENTIFIER_POINTER (name));
1906 return error_mark_node;
1911 else if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1915 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1916 IDENTIFIER_POINTER (name));
1917 return error_mark_node;
1923 if (TREE_CODE (type) == REFERENCE_TYPE && ! processing_template_decl)
1924 value = convert_from_reference (value);
1930 make_thunk (function, delta)
1939 if (TREE_CODE (function) != ADDR_EXPR)
1941 func_decl = TREE_OPERAND (function, 0);
1942 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1944 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1945 buffer = (char *)alloca (strlen (func_name) + 32);
1947 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1949 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1950 thunk_id = get_identifier (buffer);
1951 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1952 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1954 cp_error ("implementation-reserved name `%D' used", thunk_id);
1955 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1957 if (thunk == NULL_TREE)
1959 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
1960 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
1961 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
1962 comdat_linkage (thunk);
1963 TREE_SET_CODE (thunk, THUNK_DECL);
1964 DECL_INITIAL (thunk) = function;
1965 THUNK_DELTA (thunk) = delta;
1966 DECL_EXTERNAL (thunk) = 1;
1967 DECL_ARTIFICIAL (thunk) = 1;
1968 /* So that finish_file can write out any thunks that need to be: */
1969 pushdecl_top_level (thunk);
1974 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1977 emit_thunk (thunk_fndecl)
1980 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1981 int delta = THUNK_DELTA (thunk_fndecl);
1983 if (TREE_ASM_WRITTEN (thunk_fndecl))
1986 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1988 TREE_ADDRESSABLE (function) = 1;
1989 mark_used (function);
1991 if (current_function_decl)
1994 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
1997 #ifdef ASM_OUTPUT_MI_THUNK
1999 current_function_decl = thunk_fndecl;
2000 /* Make sure we build up its RTL before we go onto the
2001 temporary obstack. */
2002 make_function_rtl (thunk_fndecl);
2003 temporary_allocation ();
2004 DECL_RESULT (thunk_fndecl)
2005 = build_decl (RESULT_DECL, 0, integer_type_node);
2006 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2007 init_function_start (thunk_fndecl, input_filename, lineno);
2008 assemble_start_function (thunk_fndecl, fnname);
2009 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
2010 assemble_end_function (thunk_fndecl, fnname);
2011 permanent_allocation (1);
2012 current_function_decl = 0;
2013 #else /* ASM_OUTPUT_MI_THUNK */
2014 /* If we don't have the necessary macro for efficient thunks, generate a
2015 thunk function that just makes a call to the real function.
2016 Unfortunately, this doesn't work for varargs. */
2020 if (varargs_function_p (function))
2021 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2024 /* Set up clone argument trees for the thunk. */
2026 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
2028 tree x = copy_node (a);
2030 DECL_CONTEXT (x) = thunk_fndecl;
2034 DECL_ARGUMENTS (thunk_fndecl) = a;
2035 DECL_RESULT (thunk_fndecl) = NULL_TREE;
2036 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
2037 copy_lang_decl (thunk_fndecl);
2038 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
2039 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
2041 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, 1);
2042 store_parm_decls ();
2043 current_function_is_thunk = 1;
2045 /* Build up the call to the real function. */
2046 t = build_int_2 (delta, -1 * (delta < 0));
2047 TREE_TYPE (t) = signed_type (sizetype);
2048 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
2049 t = expr_tree_cons (NULL_TREE, t, NULL_TREE);
2050 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
2051 t = expr_tree_cons (NULL_TREE, a, t);
2053 t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t);
2054 c_expand_return (t);
2056 finish_function (lineno, 0, 0);
2058 /* Don't let the backend defer this function. */
2059 if (DECL_DEFER_OUTPUT (thunk_fndecl))
2061 output_inline_function (thunk_fndecl);
2062 permanent_allocation (1);
2064 #endif /* ASM_OUTPUT_MI_THUNK */
2067 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
2070 /* Code for synthesizing methods which have default semantics defined. */
2072 /* For the anonymous union in TYPE, return the member that is at least as
2073 large as the rest of the members, so we can copy it. */
2076 largest_union_member (type)
2079 tree f, type_size = TYPE_SIZE (type);
2081 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
2082 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
2085 /* We should always find one. */
2086 my_friendly_abort (323);
2090 /* Generate code for default X(X&) constructor. */
2093 do_build_copy_constructor (fndecl)
2096 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2102 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2103 parm = TREE_CHAIN (parm);
2104 parm = convert_from_reference (parm);
2106 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
2107 && is_empty_class (current_class_type))
2108 /* Don't copy the padding byte; it might not have been allocated
2109 if *this is a base subobject. */;
2110 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2112 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
2113 TREE_SIDE_EFFECTS (t) = 1;
2114 cplus_expand_expr_stmt (t);
2118 tree fields = TYPE_FIELDS (current_class_type);
2119 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2120 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2123 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2126 tree basetype = BINFO_TYPE (t);
2127 tree p = convert_to_reference
2128 (build_reference_type (basetype), parm,
2129 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2130 p = convert_from_reference (p);
2132 if (p == error_mark_node)
2133 cp_error ("in default copy constructor");
2135 current_base_init_list = tree_cons (basetype,
2136 p, current_base_init_list);
2139 for (i = 0; i < n_bases; ++i)
2141 tree p, basetype = TREE_VEC_ELT (binfos, i);
2142 if (TREE_VIA_VIRTUAL (basetype))
2145 basetype = BINFO_TYPE (basetype);
2146 p = convert_to_reference
2147 (build_reference_type (basetype), parm,
2148 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2150 if (p == error_mark_node)
2151 cp_error ("in default copy constructor");
2154 p = convert_from_reference (p);
2155 current_base_init_list = tree_cons (basetype,
2156 p, current_base_init_list);
2159 for (; fields; fields = TREE_CHAIN (fields))
2162 tree field = fields;
2164 if (TREE_CODE (field) != FIELD_DECL)
2168 if (DECL_NAME (field))
2170 if (VFIELD_NAME_P (DECL_NAME (field)))
2172 if (VBASE_NAME_P (DECL_NAME (field)))
2175 /* True for duplicate members. */
2176 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2179 else if ((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)
2186 init = build (COMPONENT_REF, t, init, field);
2187 field = largest_union_member (t);
2189 while ((t = TREE_TYPE (field)) != NULL_TREE
2190 && TREE_CODE (t) == UNION_TYPE
2191 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2192 && TYPE_FIELDS (t) != NULL_TREE);
2197 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2198 init = build_tree_list (NULL_TREE, init);
2200 current_member_init_list
2201 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2203 current_member_init_list = nreverse (current_member_init_list);
2204 current_base_init_list = nreverse (current_base_init_list);
2212 do_build_assign_ref (fndecl)
2215 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2220 parm = convert_from_reference (parm);
2222 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
2223 && is_empty_class (current_class_type))
2224 /* Don't copy the padding byte; it might not have been allocated
2225 if *this is a base subobject. */;
2226 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2228 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
2229 TREE_SIDE_EFFECTS (t) = 1;
2230 cplus_expand_expr_stmt (t);
2234 tree fields = TYPE_FIELDS (current_class_type);
2235 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2236 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2239 for (i = 0; i < n_bases; ++i)
2241 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2242 tree p = convert_to_reference
2243 (build_reference_type (basetype), parm,
2244 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2245 p = convert_from_reference (p);
2246 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2247 build_expr_list (NULL_TREE, p));
2248 expand_expr_stmt (p);
2250 for (; fields; fields = TREE_CHAIN (fields))
2253 tree field = fields;
2255 if (TREE_CODE (field) != FIELD_DECL)
2258 if (TREE_READONLY (field))
2260 if (DECL_NAME (field))
2261 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
2263 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
2266 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2268 if (DECL_NAME (field))
2269 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
2271 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
2275 comp = current_class_ref;
2278 if (DECL_NAME (field))
2280 if (VFIELD_NAME_P (DECL_NAME (field)))
2282 if (VBASE_NAME_P (DECL_NAME (field)))
2285 /* True for duplicate members. */
2286 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2289 else if ((t = TREE_TYPE (field)) != NULL_TREE
2290 && TREE_CODE (t) == UNION_TYPE
2291 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2292 && TYPE_FIELDS (t) != NULL_TREE)
2296 comp = build (COMPONENT_REF, t, comp, field);
2297 init = build (COMPONENT_REF, t, init, field);
2298 field = largest_union_member (t);
2300 while ((t = TREE_TYPE (field)) != NULL_TREE
2301 && TREE_CODE (t) == UNION_TYPE
2302 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2303 && TYPE_FIELDS (t) != NULL_TREE);
2308 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2309 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2311 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2314 c_expand_return (current_class_ref);
2319 synthesize_method (fndecl)
2322 int nested = (current_function_decl != NULL_TREE);
2323 tree context = hack_decl_function_context (fndecl);
2326 import_export_decl (fndecl);
2329 push_to_top_level ();
2331 push_cp_function_context (context);
2333 interface_unknown = 1;
2334 start_function (NULL_TREE, fndecl, NULL_TREE, 1);
2335 store_parm_decls ();
2337 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2338 do_build_assign_ref (fndecl);
2339 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2343 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2344 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2345 arg_chain = TREE_CHAIN (arg_chain);
2346 if (arg_chain != void_list_node)
2347 do_build_copy_constructor (fndecl);
2348 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2352 finish_function (lineno, 0, nested);
2354 extract_interface_info ();
2356 pop_from_top_level ();
2358 pop_cp_function_context (context);