1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 89, 92-96, 1997 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #ifndef PARM_CAN_BE_ARRAY_TYPE
29 #define PARM_CAN_BE_ARRAY_TYPE 1
32 /* Handle method declarations. */
43 #include "hard-reg-set.h"
54 #ifdef NEED_DECLARATION_INDEX
55 extern char *index ();
58 /* TREE_LIST of the current inline functions that need to be
60 struct pending_inline
*pending_inlines
;
64 #define obstack_chunk_alloc xmalloc
65 #define obstack_chunk_free free
67 /* Obstack where we build text strings for overloading, etc. */
68 static struct obstack scratch_obstack
;
69 static char *scratch_firstobj
;
71 static void icat
PROTO((HOST_WIDE_INT
));
72 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
73 static void flush_repeats
PROTO((tree
));
74 static void build_overload_identifier
PROTO((tree
));
75 static void build_overload_nested_name
PROTO((tree
));
76 static void build_overload_int
PROTO((tree
, int));
77 static void build_overload_identifier
PROTO((tree
));
78 static void build_qualified_name
PROTO((tree
));
79 static void build_overload_value
PROTO((tree
, tree
, int));
80 static void issue_nrepeats
PROTO((tree
));
81 static char *build_mangled_name
PROTO((tree
,int,int));
82 static void process_modifiers
PROTO((tree
));
83 static void process_overload_item
PROTO((tree
,int));
84 static char *thunk_printable_name
PROTO((tree
));
85 static void do_build_assign_ref
PROTO((tree
));
86 static void do_build_copy_constructor
PROTO((tree
));
87 static tree largest_union_member
PROTO((tree
));
88 static tree build_decl_overload_real
PROTO((tree
, tree
, tree
, tree
,
90 static void build_template_template_parm_names
PROTO((tree
));
91 static void build_template_parm_names
PROTO((tree
, tree
));
92 static void build_underscore_int
PROTO((int));
94 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
95 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
96 # define OB_PUTC2(C1,C2) \
97 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
98 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
99 # define OB_PUTID(ID) \
100 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
101 IDENTIFIER_LENGTH (ID)))
102 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
103 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
104 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
109 gcc_obstack_init (&scratch_obstack
);
110 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
113 /* This must be large enough to hold any printed integer or floating-point
115 static char digit_buffer
[128];
117 /* Move inline function definitions out of structure so that they
118 can be processed normally. CNAME is the name of the class
119 we are working from, METHOD_LIST is the list of method lists
120 of the structure. We delete friend methods here, after
121 saving away their inline function definitions (if any). */
124 do_inline_function_hair (type
, friend_list
)
125 tree type
, friend_list
;
127 tree method
= TYPE_METHODS (type
);
129 if (method
&& TREE_CODE (method
) == TREE_VEC
)
131 if (TREE_VEC_ELT (method
, 1))
132 method
= TREE_VEC_ELT (method
, 1);
133 else if (TREE_VEC_ELT (method
, 0))
134 method
= TREE_VEC_ELT (method
, 0);
136 method
= TREE_VEC_ELT (method
, 2);
141 /* Do inline member functions. */
142 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
147 my_friendly_assert (info
->fndecl
== method
, 238);
148 args
= DECL_ARGUMENTS (method
);
151 DECL_CONTEXT (args
) = method
;
152 args
= TREE_CHAIN (args
);
155 /* Allow this decl to be seen in global scope. Don't do this for
156 local class methods, though. */
157 if (! current_function_decl
)
158 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method
)) = method
;
160 method
= TREE_CHAIN (method
);
164 tree fndecl
= TREE_VALUE (friend_list
);
165 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
170 my_friendly_assert (info
->fndecl
== fndecl
, 239);
171 args
= DECL_ARGUMENTS (fndecl
);
174 DECL_CONTEXT (args
) = fndecl
;
175 args
= TREE_CHAIN (args
);
178 /* Allow this decl to be seen in global scope */
179 if (! current_function_decl
)
180 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl
)) = fndecl
;
183 friend_list
= TREE_CHAIN (friend_list
);
187 /* Report an argument type mismatch between the best declared function
188 we could find and the current argument list that we have. */
191 report_type_mismatch (cp
, parmtypes
, name_kind
)
192 struct candidate
*cp
;
196 int i
= cp
->u
.bad_arg
;
203 my_friendly_assert (TREE_CODE (cp
->function
) == TEMPLATE_DECL
, 240);
204 cp_error ("type unification failed for function template `%#D'",
209 cp_error ("too few arguments for %s `%#D'", name_kind
, cp
->function
);
212 cp_error ("too many arguments for %s `%#D'", name_kind
, cp
->function
);
215 if (TREE_CODE (TREE_TYPE (cp
->function
)) != METHOD_TYPE
)
218 /* Happens when the implicit object parameter is rejected. */
219 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))),
221 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
222 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
223 cp_error ("call to non-volatile %s `%#D' with volatile object",
224 name_kind
, cp
->function
);
226 cp_error ("call to non-const %s `%#D' with const object",
227 name_kind
, cp
->function
);
231 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
236 ttf
= TREE_CHAIN (ttf
);
237 tta
= TREE_CHAIN (tta
);
241 OB_PUTS ("bad argument ");
242 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
243 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
245 OB_PUTCP (digit_buffer
);
247 OB_PUTS (" for function `");
248 OB_PUTCP (decl_as_string (cp
->function
, 1));
249 OB_PUTS ("' (type was ");
251 /* Reset `i' so that type printing routines do the right thing. */
254 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
255 if (code
== ERROR_MARK
)
256 OB_PUTS ("(failed type instantiation)");
259 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
260 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
263 else OB_PUTS ("void");
267 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
268 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
269 obstack_object_size (&scratch_obstack
));
270 error (tmp_firstobj
);
273 /* Here is where overload code starts. */
275 /* type tables for K and B type compression */
276 static tree
*btypelist
= NULL
;
277 static tree
*ktypelist
= NULL
;
278 static tree lasttype
= NULL
;
279 static int maxbsize
= 0;
280 static int maxksize
= 0;
282 /* number of each type seen */
283 static int maxbtype
= 0;
284 static int maxktype
= 0;
286 /* Number of occurrences of last b type seen. */
287 static int nrepeats
= 0;
289 /* Array of types seen so far in top-level call to `build_mangled_name'.
290 Allocated and deallocated by caller. */
291 static tree
*typevec
= NULL
;
293 /* Number of types interned by `build_mangled_name' so far. */
294 static int maxtype
= 0;
296 /* Number of occurrences of last type seen. */
297 static int Nrepeats
= 0;
299 /* Nonzero if we should not try folding parameter types. */
302 /* This appears to be set to true if an underscore is required to be
303 comcatenated before another number can be outputed. */
304 static int numeric_output_need_bar
;
309 if (flag_do_squangling
)
318 btypelist
= (tree
*)xmalloc (sizeof (tree
) * maxbsize
);
319 ktypelist
= (tree
*)xmalloc (sizeof (tree
) * maxksize
);
326 if (flag_do_squangling
)
342 /* Code to concatenate an asciified integer to a string. */
348 unsigned HOST_WIDE_INT ui
;
350 /* Handle this case first, to go really quickly. For many common values,
351 the result of ui/10 below is 1. */
369 OB_PUTC ('0' + (ui
% 10));
374 HOST_WIDE_INT lo
, hi
;
376 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
385 uhi
= (lo
== 0 ? -hi
: -hi
-1);
389 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
394 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
397 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
400 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
404 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
415 while (typevec
[tindex
] != type
)
434 /* issue squangling type repeating */
436 issue_nrepeats (lasttype
)
441 switch (TREE_CODE (lasttype
))
447 process_overload_item (lasttype
, FALSE
);
460 /* Check to see if a tree node has been entered into the Kcode typelist */
461 /* if not, add it. Return -1 if it isn't found, otherwise return the index */
463 check_ktype (node
, add
)
468 tree localnode
= node
;
470 if (ktypelist
== NULL
)
473 if (TREE_CODE (node
) == TYPE_DECL
)
474 localnode
= TREE_TYPE (node
);
476 for (x
=0; x
< maxktype
; x
++)
478 if (localnode
== ktypelist
[x
])
481 /* Didn't find it, so add it here */
484 if (maxksize
<= maxktype
)
486 maxksize
= maxksize
* 3 / 2;
487 ktypelist
= (tree
*)xrealloc (sizeof (tree
) * maxksize
);
489 ktypelist
[maxktype
++] = localnode
;
500 kindex
= check_ktype (decl
, FALSE
);
513 build_overload_nested_name (decl
)
517 if (ktypelist
&& issue_ktype (decl
))
520 if (DECL_CONTEXT (decl
))
522 tree context
= DECL_CONTEXT (decl
);
524 /* try to issue a K type, and if we can't continue the normal path */
525 if (!(ktypelist
&& issue_ktype (context
)))
527 /* For a template type parameter, we want to output an 'Xn'
528 rather than 'T' or some such. */
529 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
530 || TREE_CODE (context
) == TEMPLATE_TEMPLATE_PARM
)
531 build_mangled_name (context
, 0, 0);
534 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
535 context
= TYPE_NAME (context
);
536 build_overload_nested_name (context
);
542 if (TREE_CODE (decl
) == FUNCTION_DECL
)
544 tree name
= DECL_ASSEMBLER_NAME (decl
);
547 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
550 if (numeric_output_need_bar
)
552 icat (strlen (label
));
554 numeric_output_need_bar
= 1;
557 build_overload_identifier (decl
);
561 build_underscore_int (i
)
571 /* Encoding for an INTEGER_CST value. */
574 build_overload_int (value
, in_template
)
578 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
579 /* We don't ever want this output, but it's inconvenient not to
580 be able to build the string. This should cause assembler
581 errors we'll notice. */
584 sprintf (digit_buffer
, " *%d", n
++);
585 OB_PUTCP (digit_buffer
);
589 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
590 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
592 if (TREE_INT_CST_HIGH (value
)
593 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
595 /* need to print a DImode value in decimal */
596 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
599 /* else fall through to print in smaller mode */
601 /* Wordsize or smaller */
602 icat (TREE_INT_CST_LOW (value
));
606 build_overload_value (type
, value
, in_template
)
610 while (TREE_CODE (value
) == NON_LVALUE_EXPR
611 || TREE_CODE (value
) == NOP_EXPR
)
612 value
= TREE_OPERAND (value
, 0);
613 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
614 type
= TREE_TYPE (type
);
616 if (numeric_output_need_bar
)
619 numeric_output_need_bar
= 0;
622 if (TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
625 build_underscore_int (TEMPLATE_CONST_IDX (value
));
626 build_underscore_int (TEMPLATE_CONST_LEVEL (value
));
630 if (TREE_CODE (type
) == POINTER_TYPE
631 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
633 /* Handle a pointer to data member as a template instantiation
634 parameter, boy, what fun! */
635 type
= integer_type_node
;
636 if (TREE_CODE (value
) != INTEGER_CST
)
638 sorry ("unknown pointer to member constant");
643 if (TYPE_PTRMEMFUNC_P (type
))
644 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
646 switch (TREE_CODE (type
))
652 build_overload_int (value
, in_template
);
653 numeric_output_need_bar
= 1;
659 char *bufp
= digit_buffer
;
661 pedwarn ("ANSI C++ forbids floating-point template arguments");
663 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
664 val
= TREE_REAL_CST (value
);
665 if (REAL_VALUE_ISNAN (val
))
667 sprintf (bufp
, "NaN");
671 if (REAL_VALUE_NEGATIVE (val
))
673 val
= REAL_VALUE_NEGATE (val
);
676 if (REAL_VALUE_ISINF (val
))
678 sprintf (bufp
, "Infinity");
682 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
683 bufp
= (char *) index (bufp
, 'e');
685 strcat (digit_buffer
, "e0");
711 #ifdef NO_DOT_IN_LABEL
712 bufp
= (char *) index (bufp
, '.');
718 OB_PUTCP (digit_buffer
);
719 numeric_output_need_bar
= 1;
723 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
724 && TREE_CODE (value
) != ADDR_EXPR
)
726 if (TREE_CODE (value
) == CONSTRUCTOR
)
728 /* This is dangerous code, crack built up pointer to members. */
729 tree args
= CONSTRUCTOR_ELTS (value
);
730 tree a1
= TREE_VALUE (args
);
731 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
732 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
733 a3
= TREE_VALUE (a3
);
735 if (TREE_CODE (a1
) == INTEGER_CST
736 && TREE_CODE (a2
) == INTEGER_CST
)
738 build_overload_int (a1
, in_template
);
740 build_overload_int (a2
, in_template
);
742 if (TREE_CODE (a3
) == ADDR_EXPR
)
744 a3
= TREE_OPERAND (a3
, 0);
745 if (TREE_CODE (a3
) == FUNCTION_DECL
)
747 numeric_output_need_bar
= 0;
748 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
752 else if (TREE_CODE (a3
) == INTEGER_CST
)
755 build_overload_int (a3
, in_template
);
756 numeric_output_need_bar
= 1;
761 sorry ("template instantiation with pointer to method that is too complex");
764 if (TREE_CODE (value
) == INTEGER_CST
765 || TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
767 build_overload_int (value
, in_template
);
768 numeric_output_need_bar
= 1;
771 value
= TREE_OPERAND (value
, 0);
772 if (TREE_CODE (value
) == VAR_DECL
)
774 my_friendly_assert (DECL_NAME (value
) != 0, 245);
775 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
778 else if (TREE_CODE (value
) == FUNCTION_DECL
)
780 my_friendly_assert (DECL_NAME (value
) != 0, 246);
781 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
784 else if (TREE_CODE (value
) == SCOPE_REF
)
787 numeric_output_need_bar
= 0;
788 build_mangled_name (TREE_OPERAND (value
, 0), 0, 0);
789 build_overload_identifier (TREE_OPERAND (value
, 1));
793 my_friendly_abort (71);
794 break; /* not really needed */
797 sorry ("conversion of %s as template parameter",
798 tree_code_name
[(int) TREE_CODE (type
)]);
799 my_friendly_abort (72);
804 /* Add encodings for the declaration of template template parameters.
805 PARMLIST must be a TREE_VEC */
808 build_template_template_parm_names (parmlist
)
813 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
814 nparms
= TREE_VEC_LENGTH (parmlist
);
816 for (i
= 0; i
< nparms
; i
++)
818 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
819 if (TREE_CODE (parm
) == TYPE_DECL
)
821 /* This parameter is a type. */
824 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
826 /* This parameter is a template. */
828 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
832 /* It's a PARM_DECL. */
833 build_mangled_name (TREE_TYPE (parm
), 0, 0);
839 /* Add encodings for the vector of template parameters in PARMLIST,
840 given the vector of arguments to be substituted in ARGLIST. */
843 build_template_parm_names (parmlist
, arglist
)
849 nparms
= TREE_VEC_LENGTH (parmlist
);
851 for (i
= 0; i
< nparms
; i
++)
853 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
854 tree arg
= TREE_VEC_ELT (arglist
, i
);
855 if (TREE_CODE (parm
) == TYPE_DECL
)
857 /* This parameter is a type. */
859 build_mangled_name (arg
, 0, 0);
861 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
863 /* This parameter is a template. */
864 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
865 /* Output parameter declaration, argument index and level */
866 build_mangled_name (arg
, 0, 0);
869 /* A TEMPLATE_DECL node, output the parameter declaration
873 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
874 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
875 OB_PUTID (DECL_NAME (arg
));
880 parm
= tsubst (parm
, arglist
,
881 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
882 /* It's a PARM_DECL. */
883 build_mangled_name (TREE_TYPE (parm
), 0, 0);
884 build_overload_value (parm
, arg
, uses_template_parms (arglist
));
891 build_overload_identifier (name
)
894 if (TREE_CODE (name
) == TYPE_DECL
895 && IS_AGGR_TYPE (TREE_TYPE (name
))
896 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
897 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
898 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
902 tree
template, parmlist
, arglist
, tname
;
903 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
904 arglist
= TREE_VALUE (template);
905 template = TREE_PURPOSE (template);
906 tname
= DECL_NAME (template);
907 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
909 icat (IDENTIFIER_LENGTH (tname
));
911 build_template_parm_names (parmlist
, arglist
);
915 if (TREE_CODE (name
) == TYPE_DECL
)
916 name
= DECL_NAME (name
);
917 if (numeric_output_need_bar
)
920 numeric_output_need_bar
= 0;
922 icat (IDENTIFIER_LENGTH (name
));
927 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
928 the mangling for it. Used by build_mangled_name and build_static_name. */
931 build_qualified_name (decl
)
937 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
938 decl
= TYPE_NAME (decl
);
940 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
941 if (TREE_CODE (decl
) == TYPE_DECL
942 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
) && !flag_do_squangling
)
944 OB_PUTID (DECL_ASSEMBLER_NAME (decl
));
949 /* if we can't find a Ktype, do it the hard way */
950 if (check_ktype (context
, FALSE
) == -1)
951 while (DECL_CONTEXT (context
))
954 context
= DECL_CONTEXT (context
);
955 if (check_ktype (context
, FALSE
) != -1) /* found it! */
957 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
958 context
= TYPE_NAME (context
);
970 numeric_output_need_bar
= 0;
972 build_overload_nested_name (decl
);
975 /* Given a list of parameters in PARMTYPES, create an unambiguous
976 overload string. Should distinguish any type that C (or C++) can
977 distinguish. I.e., pointers to functions are treated correctly.
979 Caller must deal with whether a final `e' goes on the end or not.
981 Any default conversions must take place before this function
984 BEGIN and END control initialization and finalization of the
985 obstack where we build the string. */
988 build_overload_name (parmtypes
, begin
, end
)
994 ret
= build_mangled_name (parmtypes
, begin
, end
);
1000 build_mangled_name (parmtypes
, begin
, end
)
1008 numeric_output_need_bar
= 0;
1010 if (TREE_CODE (parmtypes
) != TREE_LIST
) /* just one item */
1012 if (TYPE_PTRMEMFUNC_P (parmtypes
))
1013 parmtypes
= TYPE_PTRMEMFUNC_FN_TYPE (parmtypes
);
1014 process_modifiers (parmtypes
);
1015 process_overload_item (parmtypes
, FALSE
);
1018 for ( ; parmtypes
!=NULL
; parmtypes
= TREE_CHAIN (parmtypes
))
1020 parmtype
= TREE_VALUE (parmtypes
);
1021 if (flag_do_squangling
) /* squangling style repeats */
1023 if (parmtype
== lasttype
)
1031 issue_nrepeats (lasttype
);
1033 lasttype
= parmtype
;
1036 if (!nofold
&& typevec
)
1038 /* Every argument gets counted. */
1039 typevec
[maxtype
++] = parmtype
;
1041 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
1048 flush_repeats (typevec
[maxtype
-2]);
1050 if (TREE_USED (parmtype
))
1053 /* We can turn this on at some point when we want
1054 improved symbol mangling. */
1057 /* This is bug compatible with 2.7.x */
1058 flush_repeats (parmtype
);
1063 /* Only cache types which take more than one character. */
1064 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
1065 || (TREE_CODE (parmtype
) != INTEGER_TYPE
1066 && TREE_CODE (parmtype
) != REAL_TYPE
))
1067 TREE_USED (parmtype
) = 1;
1069 if (TYPE_PTRMEMFUNC_P (parmtype
))
1070 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
1071 process_modifiers (parmtype
);
1072 if (TREE_CODE(parmtype
)==VOID_TYPE
)
1075 extern tree void_list_node
;
1077 /* See if anybody is wasting memory. */
1078 my_friendly_assert (parmtypes
== void_list_node
, 247);
1080 /* This is the end of a parameter list. */
1083 return (char *)obstack_base (&scratch_obstack
);
1085 process_overload_item (parmtype
, TRUE
);
1087 if (flag_do_squangling
&& nrepeats
!= 0)
1088 issue_nrepeats (lasttype
);
1090 if (Nrepeats
&& typevec
)
1091 flush_repeats (typevec
[maxtype
-1]);
1093 /* To get here, parms must end with `...'. */
1098 return (char *)obstack_base (&scratch_obstack
);
1101 /* handles emitting modifiers such as Constant, read-only, and volatile */
1103 process_modifiers (parmtype
)
1108 if (TREE_READONLY (parmtype
))
1110 if (TREE_CODE (parmtype
) == INTEGER_TYPE
&&
1111 TYPE_MAIN_VARIANT (parmtype
) ==
1112 unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
1114 if (TYPE_VOLATILE (parmtype
))
1118 /* Check to see if a tree node has been entered into the Bcode typelist
1119 if not, add it. Otherwise emit the code and return TRUE */
1126 if (btypelist
== NULL
)
1129 switch (TREE_CODE (node
))
1135 return 0; /* don't compress single char basic types */
1138 node
= TYPE_MAIN_VARIANT (node
);
1139 for (x
= 0; x
< maxbtype
; x
++)
1141 if (node
== btypelist
[x
])
1150 /* didn't find it, so add it here */
1151 if (maxbsize
<= maxbtype
)
1153 maxbsize
= maxbsize
* 3 / 2;
1154 btypelist
= (tree
*)xrealloc (sizeof (tree
) * maxbsize
);
1156 btypelist
[maxbtype
++] = node
;
1160 /* handle emitting the correct code for various node types */
1162 process_overload_item (parmtype
, extra_Gcode
)
1167 /* These tree types are considered modifiers for B code squangling , */
1168 /* and therefore should not get entries in the Btypelist */
1169 /* they are, however, repeatable types */
1171 switch (TREE_CODE (parmtype
))
1173 case REFERENCE_TYPE
:
1178 #if PARM_CAN_BE_ARRAY_TYPE
1183 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
1184 error("pointer/reference to array of unknown bound in parm type");
1187 length
= array_type_nelts (parmtype
);
1188 if (TREE_CODE (length
) == INTEGER_CST
)
1189 icat (TREE_INT_CST_LOW (length
) + 1);
1202 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1207 /* check if type is already in the typelist. If not, add it now */
1209 if (flag_do_squangling
&& btypelist
!= NULL
) {
1210 if (check_btype (parmtype
)) /* emits the code if it finds it */
1214 switch (TREE_CODE (parmtype
))
1218 build_mangled_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
1220 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1226 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
1227 /* Otherwise have to implement reentrant typevecs,
1228 unmark and remark types, etc. */
1229 int old_nofold
= nofold
;
1230 if (!flag_do_squangling
) {
1233 flush_repeats (typevec
[maxtype
-1]);
1237 issue_nrepeats (lasttype
);
1239 /* @@ It may be possible to pass a function type in
1240 which is not preceded by a 'P'. */
1241 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
1244 if (firstarg
== NULL_TREE
)
1246 else if (firstarg
== void_list_node
)
1249 build_mangled_name (firstarg
, 0, 0);
1253 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
1254 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
1256 firstarg
= TREE_CHAIN (firstarg
);
1258 build_mangled_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
1264 /* For cfront 2.0 compatibility. */
1267 if (firstarg
== NULL_TREE
)
1269 else if (firstarg
== void_list_node
)
1272 build_mangled_name (firstarg
, 0, 0);
1275 /* Separate args from return type. */
1277 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1278 nofold
= old_nofold
;
1283 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1284 if (parmtype
== integer_type_node
1285 || parmtype
== unsigned_type_node
)
1287 else if (parmtype
== long_integer_type_node
1288 || parmtype
== long_unsigned_type_node
)
1290 else if (parmtype
== short_integer_type_node
1291 || parmtype
== short_unsigned_type_node
)
1293 else if (parmtype
== signed_char_type_node
)
1298 else if (parmtype
== char_type_node
1299 || parmtype
== unsigned_char_type_node
)
1301 else if (parmtype
== wchar_type_node
)
1303 else if (parmtype
== long_long_integer_type_node
1304 || parmtype
== long_long_unsigned_type_node
)
1307 /* it would seem there is no way to enter these in source code,
1309 else if (parmtype
== long_long_long_integer_type_node
1310 || parmtype
== long_long_long_unsigned_type_node
)
1314 my_friendly_abort (73);
1322 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1323 if (parmtype
== long_double_type_node
)
1325 else if (parmtype
== double_type_node
)
1327 else if (parmtype
== float_type_node
)
1329 else my_friendly_abort (74);
1334 build_mangled_name (TREE_TYPE (parmtype
), 0, 0);
1341 case ERROR_MARK
: /* not right, but nothing is anyway */
1344 /* have to do these */
1349 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1350 /* drop through into next case */
1354 tree name
= TYPE_NAME (parmtype
);
1356 if (TREE_CODE (name
) == IDENTIFIER_NODE
)
1358 build_overload_identifier (TYPE_NAME (parmtype
));
1361 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1363 build_qualified_name (name
);
1368 /* This will take some work. */
1372 case TEMPLATE_TEMPLATE_PARM
:
1373 /* Find and output the original template parameter
1375 if (CLASSTYPE_TEMPLATE_INFO (parmtype
))
1380 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1381 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1383 build_template_parm_names (
1384 DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype
)),
1385 CLASSTYPE_TI_ARGS (parmtype
));
1392 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1393 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1395 build_template_template_parm_names (
1396 DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1400 case TEMPLATE_TYPE_PARM
:
1402 build_underscore_int (TEMPLATE_TYPE_IDX (parmtype
));
1403 build_underscore_int (TEMPLATE_TYPE_LEVEL (parmtype
));
1407 /* When mangling the type of a function template whose
1408 declaration looks like:
1410 template <class T> void foo(typename T::U)
1412 we have to mangle these. */
1413 build_qualified_name (parmtype
);
1417 my_friendly_abort (75);
1422 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1423 be either a class TYPE or a FUNCTION_DECL. */
1426 build_static_name (context
, name
)
1430 numeric_output_need_bar
= 0;
1431 start_squangling ();
1434 build_qualified_name (context
);
1437 OB_PUTS ("__static_");
1438 build_qualified_name (context
);
1445 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1449 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1458 char *name
= IDENTIFIER_POINTER (dname
);
1460 /* member operators new and delete look like methods at this point. */
1461 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1462 && TREE_CHAIN (parms
) == void_list_node
)
1464 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1465 return get_identifier ("__builtin_delete");
1466 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1467 return get_identifier ("__builtin_vec_delete");
1468 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1469 return get_identifier ("__builtin_new");
1470 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1471 return get_identifier ("__builtin_vec_new");
1474 start_squangling ();
1476 if (for_method
!= 2)
1478 /* Otherwise, we can divine that this is a constructor,
1479 and figure out its name without any extra encoding. */
1481 OB_PUTC2 ('_', '_');
1485 /* We can get away without doing this. */
1488 if (tparms
!= NULL_TREE
)
1491 tree this_type
= TREE_VALUE (parms
);
1493 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1494 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1495 TREE_CHAIN (parms
));
1497 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1498 TREE_CHAIN (parms
));
1508 build_template_parm_names (tparms
, targs
);
1512 if (parms
== NULL_TREE
)
1514 else if (parms
== void_list_node
)
1518 if (!flag_do_squangling
) /* Allocate typevec array. */
1522 typevec
= (tree
*)alloca (list_length (parms
) * sizeof (tree
));
1527 build_mangled_name (TREE_VALUE (parms
), 0, 0);
1529 if (!flag_do_squangling
) {
1530 typevec
[maxtype
++] = TREE_VALUE (parms
);
1531 TREE_USED (TREE_VALUE (parms
)) = 1;
1534 if (TREE_CHAIN (parms
))
1535 build_mangled_name (TREE_CHAIN (parms
), 0, 0);
1540 build_mangled_name (parms
, 0, 0);
1542 if (!flag_do_squangling
) /* Deallocate typevec array */
1548 TREE_USED (TREE_VALUE (t
)) = 0;
1554 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1556 /* Add the return type. */
1558 build_mangled_name (ret_type
, 0, 0);
1564 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1565 if (IDENTIFIER_OPNAME_P (dname
))
1566 IDENTIFIER_OPNAME_P (n
) = 1;
1571 /* Change the name of a function definition so that it may be
1572 overloaded. NAME is the name of the function to overload,
1573 PARMS is the parameter list (which determines what name the
1574 final function obtains).
1576 FOR_METHOD is 1 if this overload is being performed
1577 for a method, rather than a function type. It is 2 if
1578 this overload is being performed for a constructor. */
1581 build_decl_overload (dname
, parms
, for_method
)
1586 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1587 NULL_TREE
, for_method
);
1591 /* Like build_decl_overload, but for template functions. */
1594 build_template_decl_overload (dname
, parms
, ret_type
, tparms
, targs
,
1603 return build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1608 /* Build an overload name for the type expression TYPE. */
1611 build_typename_overload (type
)
1617 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1619 start_squangling ();
1620 build_mangled_name (type
, 0, 1);
1621 id
= get_identifier (obstack_base (&scratch_obstack
));
1622 IDENTIFIER_OPNAME_P (id
) = 1;
1624 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1626 TREE_TYPE (id
) = type
;
1632 build_overload_with_type (name
, type
)
1639 start_squangling ();
1640 build_mangled_name (type
, 0, 1);
1642 return get_identifier (obstack_base (&scratch_obstack
));
1646 get_id_2 (name
, name2
)
1654 return get_identifier (obstack_base (&scratch_obstack
));
1657 /* Given a tree_code CODE, and some arguments (at least one),
1658 attempt to use an overloaded operator on the arguments.
1660 For unary operators, only the first argument need be checked.
1661 For binary operators, both arguments may need to be checked.
1663 Member functions can convert class references to class pointers,
1664 for one-level deep indirection. More than that is not supported.
1665 Operators [](), ()(), and ->() must be member functions.
1667 We call function call building calls with LOOKUP_COMPLAIN if they
1668 are our only hope. This is true when we see a vanilla operator
1669 applied to something of aggregate type. If this fails, we are free
1670 to return `error_mark_node', because we will have reported the
1673 Operators NEW and DELETE overload in funny ways: operator new takes
1674 a single `size' parameter, and operator delete takes a pointer to the
1675 storage being deleted. When overloading these operators, success is
1676 assumed. If there is a failure, report an error message and return
1677 `error_mark_node'. */
1681 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1682 enum tree_code code
;
1684 tree xarg1
, xarg2
, arg3
;
1688 tree type1
, type2
, fnname
;
1689 tree fields1
= 0, parms
= 0;
1692 int binary_is_unary
;
1694 if (flag_ansi_overloading
)
1695 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1697 if (xarg1
== error_mark_node
)
1698 return error_mark_node
;
1700 if (code
== COND_EXPR
)
1702 if (xarg2
== error_mark_node
1703 || arg3
== error_mark_node
)
1704 return error_mark_node
;
1706 if (code
== COMPONENT_REF
)
1707 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1710 /* First, see if we can work with the first argument */
1711 type1
= TREE_TYPE (xarg1
);
1713 /* Some tree codes have length > 1, but we really only want to
1714 overload them if their first argument has a user defined type. */
1717 case PREINCREMENT_EXPR
:
1718 case PREDECREMENT_EXPR
:
1719 case POSTINCREMENT_EXPR
:
1720 case POSTDECREMENT_EXPR
:
1722 binary_is_unary
= 1;
1726 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1727 If they do not, return error_mark_node instead of NULL_TREE. */
1729 if (xarg2
== error_mark_node
)
1730 return error_mark_node
;
1732 rval
= error_mark_node
;
1733 binary_is_unary
= 0;
1740 tree args
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1741 fnname
= ansi_opname
[(int) code
];
1742 if (flags
& LOOKUP_GLOBAL
)
1743 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
);
1745 rval
= build_method_call
1746 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1748 fnname
, args
, NULL_TREE
, flags
);
1749 if (rval
== error_mark_node
)
1750 /* User might declare fancy operator new, but invoke it
1751 like standard one. */
1754 TREE_TYPE (rval
) = xarg1
;
1759 case VEC_DELETE_EXPR
:
1762 fnname
= ansi_opname
[(int) code
];
1763 if (flags
& LOOKUP_GLOBAL
)
1764 return build_overload_call (fnname
,
1765 build_expr_list (NULL_TREE
, xarg1
),
1766 flags
& LOOKUP_COMPLAIN
);
1767 arg1
= TREE_TYPE (xarg1
);
1769 /* This handles the case where we're trying to delete
1774 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
1776 /* Strip off the pointer and the array. */
1777 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
1779 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
1780 arg1
= (TREE_TYPE (arg1
));
1782 arg1
= build_pointer_type (arg1
);
1785 rval
= build_method_call
1786 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
1789 fnname
, expr_tree_cons (NULL_TREE
, xarg1
,
1790 build_expr_list (NULL_TREE
, xarg2
)),
1793 /* This can happen when operator delete is protected. */
1794 my_friendly_assert (rval
!= error_mark_node
, 250);
1795 TREE_TYPE (rval
) = void_type_node
;
1802 binary_is_unary
= 0;
1803 try_second
= tree_code_length
[(int) code
] == 2;
1804 if (try_second
&& xarg2
== error_mark_node
)
1805 return error_mark_node
;
1809 if (try_second
&& xarg2
== error_mark_node
)
1810 return error_mark_node
;
1812 /* What ever it was, we do not know how to deal with it. */
1813 if (type1
== NULL_TREE
)
1816 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1817 type1
= TREE_TYPE (type1
);
1819 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1821 arg1
= convert_from_reference (xarg1
);
1822 type1
= TREE_TYPE (arg1
);
1829 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1831 /* Try to fail. First, fail if unary */
1834 /* Second, see if second argument is non-aggregate. */
1835 type2
= TREE_TYPE (xarg2
);
1836 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1837 type2
= TREE_TYPE (type2
);
1838 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1840 arg2
= convert_from_reference (xarg2
);
1841 type2
= TREE_TYPE (arg2
);
1848 if (!IS_AGGR_TYPE (type2
))
1855 /* First arg may succeed; see whether second should. */
1856 type2
= TREE_TYPE (xarg2
);
1857 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1858 type2
= TREE_TYPE (type2
);
1859 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1861 arg2
= convert_from_reference (xarg2
);
1862 type2
= TREE_TYPE (arg2
);
1869 if (! IS_AGGR_TYPE (type2
))
1873 if (type1
== unknown_type_node
1874 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1876 /* This will not be implemented in the foreseeable future. */
1880 if (code
== MODIFY_EXPR
)
1881 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1883 fnname
= ansi_opname
[(int) code
];
1885 global_fn
= lookup_name_nonclass (fnname
);
1887 /* This is the last point where we will accept failure. This
1888 may be too eager if we wish an overloaded operator not to match,
1889 but would rather a normal operator be called on a type-converted
1892 if (IS_AGGR_TYPE (type1
))
1894 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1895 /* ARM $13.4.7, prefix/postfix ++/--. */
1896 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1898 xarg2
= integer_zero_node
;
1899 binary_is_unary
= 0;
1904 int have_postfix
= 0;
1906 /* Look for an `operator++ (int)'. If they didn't have
1907 one, then we fall back to the old way of doing things. */
1908 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1910 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1911 if (TREE_CHAIN (t2
) != NULL_TREE
1912 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1921 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1923 /* There's probably a LOT of code in the world that
1924 relies upon this old behavior. */
1925 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1928 binary_is_unary
= 1;
1934 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1937 /* If RVAL winds up being `error_mark_node', we will return
1938 that... There is no way that normal semantics of these
1939 operators will succeed. */
1941 /* This argument may be an uncommitted OFFSET_REF. This is
1942 the case for example when dealing with static class members
1943 which are referenced from their class name rather than
1944 from a class instance. */
1945 if (TREE_CODE (xarg1
) == OFFSET_REF
1946 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1947 xarg1
= TREE_OPERAND (xarg1
, 1);
1948 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1949 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1950 xarg2
= TREE_OPERAND (xarg2
, 1);
1953 flags
|= LOOKUP_GLOBAL
;
1955 if (code
== CALL_EXPR
)
1957 /* This can only be a member function. */
1958 return build_method_call (xarg1
, fnname
, xarg2
,
1959 NULL_TREE
, LOOKUP_NORMAL
);
1961 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1964 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1966 else if (code
== COND_EXPR
)
1968 parms
= expr_tree_cons (NULL_TREE
, xarg2
, build_expr_list (NULL_TREE
, arg3
));
1969 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1971 else if (code
== METHOD_CALL_EXPR
)
1973 /* must be a member function. */
1974 parms
= expr_tree_cons (NULL_TREE
, xarg2
, arg3
);
1975 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1980 parms
= build_expr_list (NULL_TREE
, xarg2
);
1981 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1985 parms
= expr_tree_cons (NULL_TREE
, xarg1
,
1986 build_expr_list (NULL_TREE
, xarg2
));
1987 rval
= build_overload_call (fnname
, parms
, flags
);
1993 /* This function takes an identifier, ID, and attempts to figure out what
1994 it means. There are a number of possible scenarios, presented in increasing
1997 1) not in a class's scope
1998 2) in class's scope, member name of the class's method
1999 3) in class's scope, but not a member name of the class
2000 4) in class's scope, member name of a class's variable
2002 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
2003 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
2005 As a last ditch, try to look up the name as a label and return that
2008 Values which are declared as being of REFERENCE_TYPE are
2009 automatically dereferenced here (as a hack to make the
2010 compiler faster). */
2013 hack_identifier (value
, name
)
2018 if (value
== error_mark_node
)
2020 if (current_class_name
)
2022 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
2023 if (fields
== error_mark_node
)
2024 return error_mark_node
;
2029 fndecl
= TREE_VALUE (fields
);
2030 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
2031 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
2033 warning ("methods cannot be converted to function pointers");
2038 error ("ambiguous request for method pointer `%s'",
2039 IDENTIFIER_POINTER (name
));
2040 return error_mark_node
;
2044 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
2046 return IDENTIFIER_LABEL_VALUE (name
);
2048 return error_mark_node
;
2051 type
= TREE_TYPE (value
);
2052 if (TREE_CODE (value
) == FIELD_DECL
)
2054 if (current_class_ptr
== NULL_TREE
)
2056 error ("request for member `%s' in static member function",
2057 IDENTIFIER_POINTER (DECL_NAME (value
)));
2058 return error_mark_node
;
2060 TREE_USED (current_class_ptr
) = 1;
2062 /* Mark so that if we are in a constructor, and then find that
2063 this field was initialized by a base initializer,
2064 we can emit an error message. */
2065 TREE_USED (value
) = 1;
2066 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
2068 else if (really_overloaded_fn (value
))
2071 tree t
= get_first_fn (value
);
2072 for (; t
; t
= DECL_CHAIN (t
))
2074 if (TREE_CODE (t
) == TEMPLATE_DECL
)
2077 assemble_external (t
);
2082 else if (TREE_CODE (value
) == TREE_LIST
)
2084 /* Ambiguous reference to base members, possibly other cases?. */
2086 while (t
&& TREE_CODE (t
) == TREE_LIST
)
2088 mark_used (TREE_VALUE (t
));
2095 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
2097 tree context
= decl_function_context (value
);
2098 if (context
!= NULL_TREE
&& context
!= current_function_decl
2099 && ! TREE_STATIC (value
))
2101 cp_error ("use of %s from containing function",
2102 (TREE_CODE (value
) == VAR_DECL
2103 ? "`auto' variable" : "parameter"));
2104 cp_error_at (" `%#D' declared here", value
);
2105 value
= error_mark_node
;
2109 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
2111 if (DECL_LANG_SPECIFIC (value
)
2112 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
2115 register tree context
2116 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
2117 ? DECL_CLASS_CONTEXT (value
)
2118 : DECL_CONTEXT (value
);
2120 get_base_distance (context
, current_class_type
, 0, &path
);
2123 access
= compute_access (path
, value
);
2124 if (access
!= access_public_node
)
2126 if (TREE_CODE (value
) == VAR_DECL
)
2127 error ("static member `%s' is %s",
2128 IDENTIFIER_POINTER (name
),
2129 TREE_PRIVATE (value
) ? "private"
2130 : "from a private base class");
2132 error ("enum `%s' is from private base class",
2133 IDENTIFIER_POINTER (name
));
2134 return error_mark_node
;
2139 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
2143 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2144 IDENTIFIER_POINTER (name
));
2145 return error_mark_node
;
2151 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! processing_template_decl
)
2152 value
= convert_from_reference (value
);
2158 thunk_printable_name (decl
)
2161 return "<thunk function>";
2165 make_thunk (function
, delta
)
2174 if (TREE_CODE (function
) != ADDR_EXPR
)
2176 func_decl
= TREE_OPERAND (function
, 0);
2177 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
2179 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
2180 buffer
= (char *)alloca (strlen (func_name
) + 32);
2182 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
2184 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
2185 thunk_id
= get_identifier (buffer
);
2186 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
2187 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
2189 cp_error ("implementation-reserved name `%D' used", thunk_id
);
2190 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
2192 if (thunk
== NULL_TREE
)
2194 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
2195 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
2196 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
2197 comdat_linkage (thunk
);
2198 TREE_SET_CODE (thunk
, THUNK_DECL
);
2199 DECL_INITIAL (thunk
) = function
;
2200 THUNK_DELTA (thunk
) = delta
;
2201 DECL_EXTERNAL (thunk
) = 1;
2202 DECL_ARTIFICIAL (thunk
) = 1;
2203 /* So that finish_file can write out any thunks that need to be: */
2204 pushdecl_top_level (thunk
);
2209 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2212 emit_thunk (thunk_fndecl
)
2215 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
2216 int delta
= THUNK_DELTA (thunk_fndecl
);
2218 if (TREE_ASM_WRITTEN (thunk_fndecl
))
2221 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
2223 TREE_ADDRESSABLE (function
) = 1;
2224 mark_used (function
);
2226 if (current_function_decl
)
2229 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
2232 #ifdef ASM_OUTPUT_MI_THUNK
2234 current_function_decl
= thunk_fndecl
;
2235 /* Make sure we build up its RTL before we go onto the
2236 temporary obstack. */
2237 make_function_rtl (thunk_fndecl
);
2238 temporary_allocation ();
2239 DECL_RESULT (thunk_fndecl
)
2240 = build_decl (RESULT_DECL
, 0, integer_type_node
);
2241 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
2242 init_function_start (thunk_fndecl
, input_filename
, lineno
);
2243 assemble_start_function (thunk_fndecl
, fnname
);
2244 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
2245 assemble_end_function (thunk_fndecl
, fnname
);
2246 permanent_allocation (1);
2247 current_function_decl
= 0;
2248 #else /* ASM_OUTPUT_MI_THUNK */
2249 /* If we don't have the necessary macro for efficient thunks, generate a
2250 thunk function that just makes a call to the real function.
2251 Unfortunately, this doesn't work for varargs. */
2255 if (varargs_function_p (function
))
2256 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2259 /* Set up clone argument trees for the thunk. */
2261 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
2263 tree x
= copy_node (a
);
2265 DECL_CONTEXT (x
) = thunk_fndecl
;
2269 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2270 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2271 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2272 copy_lang_decl (thunk_fndecl
);
2273 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2274 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2276 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
2277 store_parm_decls ();
2278 current_function_is_thunk
= 1;
2280 /* Build up the call to the real function. */
2281 t
= build_int_2 (delta
, -1 * (delta
< 0));
2282 TREE_TYPE (t
) = signed_type (sizetype
);
2283 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2284 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
2285 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2286 t
= expr_tree_cons (NULL_TREE
, a
, t
);
2288 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2289 c_expand_return (t
);
2291 finish_function (lineno
, 0, 0);
2293 /* Don't let the backend defer this function. */
2294 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2296 output_inline_function (thunk_fndecl
);
2297 permanent_allocation (1);
2299 #endif /* ASM_OUTPUT_MI_THUNK */
2302 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2305 /* Code for synthesizing methods which have default semantics defined. */
2307 /* For the anonymous union in TYPE, return the member that is at least as
2308 large as the rest of the members, so we can copy it. */
2311 largest_union_member (type
)
2314 tree f
, type_size
= TYPE_SIZE (type
);
2316 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2317 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2320 /* We should always find one. */
2321 my_friendly_abort (323);
2325 /* Generate code for default X(X&) constructor. */
2328 do_build_copy_constructor (fndecl
)
2331 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2337 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2338 parm
= TREE_CHAIN (parm
);
2339 parm
= convert_from_reference (parm
);
2341 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2343 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2344 TREE_SIDE_EFFECTS (t
) = 1;
2345 cplus_expand_expr_stmt (t
);
2349 tree fields
= TYPE_FIELDS (current_class_type
);
2350 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2351 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2354 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2357 tree basetype
= BINFO_TYPE (t
);
2358 tree p
= convert_to_reference
2359 (build_reference_type (basetype
), parm
,
2360 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2361 p
= convert_from_reference (p
);
2363 if (p
== error_mark_node
)
2364 cp_error ("in default copy constructor");
2366 current_base_init_list
= tree_cons (basetype
,
2367 p
, current_base_init_list
);
2370 for (i
= 0; i
< n_bases
; ++i
)
2372 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2373 if (TREE_VIA_VIRTUAL (basetype
))
2376 basetype
= BINFO_TYPE (basetype
);
2377 p
= convert_to_reference
2378 (build_reference_type (basetype
), parm
,
2379 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2381 if (p
== error_mark_node
)
2382 cp_error ("in default copy constructor");
2385 p
= convert_from_reference (p
);
2386 current_base_init_list
= tree_cons (basetype
,
2387 p
, current_base_init_list
);
2390 for (; fields
; fields
= TREE_CHAIN (fields
))
2393 tree field
= fields
;
2395 if (TREE_CODE (field
) != FIELD_DECL
)
2399 if (DECL_NAME (field
))
2401 if (VFIELD_NAME_P (DECL_NAME (field
)))
2403 if (VBASE_NAME_P (DECL_NAME (field
)))
2406 /* True for duplicate members. */
2407 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2410 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2411 && TREE_CODE (t
) == UNION_TYPE
2412 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2413 && TYPE_FIELDS (t
) != NULL_TREE
)
2417 init
= build (COMPONENT_REF
, t
, init
, field
);
2418 field
= largest_union_member (t
);
2420 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2421 && TREE_CODE (t
) == UNION_TYPE
2422 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2423 && TYPE_FIELDS (t
) != NULL_TREE
);
2428 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2429 init
= build_tree_list (NULL_TREE
, init
);
2431 current_member_init_list
2432 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2434 current_member_init_list
= nreverse (current_member_init_list
);
2435 current_base_init_list
= nreverse (current_base_init_list
);
2443 do_build_assign_ref (fndecl
)
2446 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2451 parm
= convert_from_reference (parm
);
2453 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2455 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2456 TREE_SIDE_EFFECTS (t
) = 1;
2457 cplus_expand_expr_stmt (t
);
2461 tree fields
= TYPE_FIELDS (current_class_type
);
2462 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2463 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2466 for (i
= 0; i
< n_bases
; ++i
)
2468 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2469 tree p
= convert_to_reference
2470 (build_reference_type (basetype
), parm
,
2471 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2472 p
= convert_from_reference (p
);
2473 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2474 build_expr_list (NULL_TREE
, p
));
2475 expand_expr_stmt (p
);
2477 for (; fields
; fields
= TREE_CHAIN (fields
))
2480 tree field
= fields
;
2482 if (TREE_CODE (field
) != FIELD_DECL
)
2485 if (TREE_READONLY (field
))
2487 if (DECL_NAME (field
))
2488 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2490 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2493 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2495 if (DECL_NAME (field
))
2496 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2498 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2502 comp
= current_class_ref
;
2505 if (DECL_NAME (field
))
2507 if (VFIELD_NAME_P (DECL_NAME (field
)))
2509 if (VBASE_NAME_P (DECL_NAME (field
)))
2512 /* True for duplicate members. */
2513 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2516 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2517 && TREE_CODE (t
) == UNION_TYPE
2518 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2519 && TYPE_FIELDS (t
) != NULL_TREE
)
2523 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2524 init
= build (COMPONENT_REF
, t
, init
, field
);
2525 field
= largest_union_member (t
);
2527 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2528 && TREE_CODE (t
) == UNION_TYPE
2529 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2530 && TYPE_FIELDS (t
) != NULL_TREE
);
2535 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2536 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2538 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2541 c_expand_return (current_class_ref
);
2546 synthesize_method (fndecl
)
2549 int nested
= (current_function_decl
!= NULL_TREE
);
2550 tree context
= hack_decl_function_context (fndecl
);
2553 import_export_decl (fndecl
);
2556 push_to_top_level ();
2558 push_cp_function_context (context
);
2560 interface_unknown
= 1;
2561 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2562 store_parm_decls ();
2564 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2565 do_build_assign_ref (fndecl
);
2566 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2570 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2571 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2572 arg_chain
= TREE_CHAIN (arg_chain
);
2573 if (arg_chain
!= void_list_node
)
2574 do_build_copy_constructor (fndecl
);
2575 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2579 finish_function (lineno
, 0, nested
);
2581 extract_interface_info ();
2583 pop_from_top_level ();
2585 pop_cp_function_context (context
);