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, 93, 94, 1995 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #ifndef PARM_CAN_BE_ARRAY_TYPE
25 #define PARM_CAN_BE_ARRAY_TYPE 1
28 /* Handle method declarations. */
39 #include "hard-reg-set.h"
42 /* TREE_LIST of the current inline functions that need to be
44 struct pending_inline
*pending_inlines
;
46 #define obstack_chunk_alloc xmalloc
47 #define obstack_chunk_free free
49 /* Obstack where we build text strings for overloading, etc. */
50 static struct obstack scratch_obstack
;
51 static char *scratch_firstobj
;
53 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
54 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
55 # define OB_PUTC2(C1,C2) \
56 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
57 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
58 # define OB_PUTID(ID) \
59 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
60 IDENTIFIER_LENGTH (ID)))
61 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
62 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
63 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
65 #ifdef NO_AUTO_OVERLOAD
72 gcc_obstack_init (&scratch_obstack
);
73 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
76 /* This must be large enough to hold any printed integer or floating-point
78 static char digit_buffer
[128];
80 /* Move inline function definitions out of structure so that they
81 can be processed normally. CNAME is the name of the class
82 we are working from, METHOD_LIST is the list of method lists
83 of the structure. We delete friend methods here, after
84 saving away their inline function definitions (if any). */
87 do_inline_function_hair (type
, friend_list
)
88 tree type
, friend_list
;
90 tree method
= TYPE_METHODS (type
);
92 if (method
&& TREE_CODE (method
) == TREE_VEC
)
94 if (TREE_VEC_ELT (method
, 0))
95 method
= TREE_VEC_ELT (method
, 0);
97 method
= TREE_VEC_ELT (method
, 1);
102 /* Do inline member functions. */
103 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
108 my_friendly_assert (info
->fndecl
== method
, 238);
109 args
= DECL_ARGUMENTS (method
);
112 DECL_CONTEXT (args
) = method
;
113 args
= TREE_CHAIN (args
);
116 /* Allow this decl to be seen in global scope. Don't do this for
117 local class methods, though. */
118 if (! current_function_decl
)
119 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method
)) = method
;
121 method
= TREE_CHAIN (method
);
125 tree fndecl
= TREE_VALUE (friend_list
);
126 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
131 my_friendly_assert (info
->fndecl
== fndecl
, 239);
132 args
= DECL_ARGUMENTS (fndecl
);
135 DECL_CONTEXT (args
) = fndecl
;
136 args
= TREE_CHAIN (args
);
139 /* Allow this decl to be seen in global scope */
140 if (! current_function_decl
)
141 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl
)) = fndecl
;
144 friend_list
= TREE_CHAIN (friend_list
);
148 /* Report an argument type mismatch between the best declared function
149 we could find and the current argument list that we have. */
151 report_type_mismatch (cp
, parmtypes
, name_kind
)
152 struct candidate
*cp
;
156 int i
= cp
->u
.bad_arg
;
163 my_friendly_assert (TREE_CODE (cp
->function
) == TEMPLATE_DECL
, 240);
164 cp_error ("type unification failed for function template `%#D'",
169 cp_error ("too few arguments for %s `%#D'", name_kind
, cp
->function
);
172 cp_error ("too many arguments for %s `%#D'", name_kind
, cp
->function
);
175 if (TREE_CODE (TREE_TYPE (cp
->function
)) != METHOD_TYPE
)
178 /* Happens when the implicit object parameter is rejected. */
179 my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))),
181 if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))))
182 && ! TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (cp
->function
))))))
183 cp_error ("call to non-volatile %s `%#D' with volatile object",
184 name_kind
, cp
->function
);
186 cp_error ("call to non-const %s `%#D' with const object",
187 name_kind
, cp
->function
);
191 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
196 ttf
= TREE_CHAIN (ttf
);
197 tta
= TREE_CHAIN (tta
);
201 OB_PUTS ("bad argument ");
202 sprintf (digit_buffer
, "%d", cp
->u
.bad_arg
203 - (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
205 OB_PUTCP (digit_buffer
);
207 OB_PUTS (" for function `");
208 OB_PUTCP (decl_as_string (cp
->function
, 1));
209 OB_PUTS ("' (type was ");
211 /* Reset `i' so that type printing routines do the right thing. */
214 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
215 if (code
== ERROR_MARK
)
216 OB_PUTS ("(failed type instantiation)");
219 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
220 OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta
)), 1));
223 else OB_PUTS ("void");
227 tmp_firstobj
= (char *)alloca (obstack_object_size (&scratch_obstack
));
228 bcopy (obstack_base (&scratch_obstack
), tmp_firstobj
,
229 obstack_object_size (&scratch_obstack
));
230 error (tmp_firstobj
);
233 /* Here is where overload code starts. */
235 /* Array of types seen so far in top-level call to `build_overload_name'.
236 Allocated and deallocated by caller. */
237 static tree
*typevec
;
239 /* Number of types interned by `build_overload_name' so far. */
242 /* Number of occurrences of last type seen. */
245 /* Nonzero if we should not try folding parameter types. */
248 #define ALLOCATE_TYPEVEC(PARMTYPES) \
249 do { maxtype = 0, nrepeats = 0; \
250 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
252 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
253 do { tree t = (PARMTYPES); \
254 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
257 /* Code to concatenate an asciified integer to a string. */
266 /* Handle this case first, to go really quickly. For many common values,
267 the result of i/10 below is 1. */
284 OB_PUTC ('0' + (i
% 10));
298 while (typevec
[tindex
] != type
)
316 static int numeric_output_need_bar
;
317 static void build_overload_identifier ();
320 build_overload_nested_name (decl
)
323 if (DECL_CONTEXT (decl
))
325 tree context
= DECL_CONTEXT (decl
);
326 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
327 context
= TYPE_MAIN_DECL (context
);
328 build_overload_nested_name (context
);
331 if (TREE_CODE (decl
) == FUNCTION_DECL
)
333 tree name
= DECL_ASSEMBLER_NAME (decl
);
335 extern int var_labelno
;
337 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), var_labelno
);
340 if (numeric_output_need_bar
)
343 numeric_output_need_bar
= 0;
345 icat (strlen (label
));
349 build_overload_identifier (decl
);
352 /* Encoding for an INTEGER_CST value. */
354 build_overload_int (value
)
357 if (TREE_CODE (value
) == TEMPLATE_CONST_PARM
)
360 if (TEMPLATE_CONST_IDX (value
) > 9)
362 icat (TEMPLATE_CONST_IDX (value
));
363 if (TEMPLATE_CONST_IDX (value
) > 9)
367 else if (current_template_parms
368 && TREE_CODE (value
) != INTEGER_CST
)
369 /* We don't ever want this output, but it's inconvenient not to
370 be able to build the string. This should cause assembler
371 errors we'll notice. */
374 sprintf (digit_buffer
, " *%d", n
++);
375 OB_PUTCP (digit_buffer
);
379 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
380 if (TYPE_PRECISION (value
) == 2 * HOST_BITS_PER_WIDE_INT
)
382 if (tree_int_cst_lt (value
, integer_zero_node
))
385 value
= build_int_2 (~ TREE_INT_CST_LOW (value
),
386 - TREE_INT_CST_HIGH (value
));
388 if (TREE_INT_CST_HIGH (value
)
389 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
391 /* need to print a DImode value in decimal */
392 sorry ("conversion of long long as PT parameter");
394 /* else fall through to print in smaller mode */
396 /* Wordsize or smaller */
397 icat (TREE_INT_CST_LOW (value
));
401 build_overload_value (type
, value
)
404 while (TREE_CODE (value
) == NON_LVALUE_EXPR
405 || TREE_CODE (value
) == NOP_EXPR
)
406 value
= TREE_OPERAND (value
, 0);
407 my_friendly_assert (TREE_CODE (type
) == PARM_DECL
, 242);
408 type
= TREE_TYPE (type
);
410 if (numeric_output_need_bar
)
413 numeric_output_need_bar
= 0;
416 if (TREE_CODE (type
) == POINTER_TYPE
417 && TREE_CODE (TREE_TYPE (type
)) == OFFSET_TYPE
)
419 /* Handle a pointer to data member as a template instantiation
420 parameter, boy, what fun! */
421 type
= integer_type_node
;
422 if (TREE_CODE (value
) != INTEGER_CST
)
424 sorry ("unknown pointer to member constant");
429 if (TYPE_PTRMEMFUNC_P (type
))
430 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
432 switch (TREE_CODE (type
))
438 build_overload_int (value
);
439 numeric_output_need_bar
= 1;
442 #ifndef REAL_IS_NOT_DOUBLE
446 char *bufp
= digit_buffer
;
447 extern char *index ();
449 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
450 val
= TREE_REAL_CST (value
);
456 sprintf (bufp
, "%e", val
);
457 bufp
= (char *) index (bufp
, 'e');
459 strcat (digit_buffer
, "e0");
485 OB_PUTCP (digit_buffer
);
486 numeric_output_need_bar
= 1;
491 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
492 && TREE_CODE (value
) != ADDR_EXPR
)
494 if (TREE_CODE (value
) == CONSTRUCTOR
)
496 /* This is dangerous code, crack built up pointer to members. */
497 tree args
= CONSTRUCTOR_ELTS (value
);
498 tree a1
= TREE_VALUE (args
);
499 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
500 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
501 a3
= TREE_VALUE (a3
);
503 if (TREE_CODE (a1
) == INTEGER_CST
504 && TREE_CODE (a2
) == INTEGER_CST
)
506 build_overload_int (a1
);
508 build_overload_int (a2
);
510 if (TREE_CODE (a3
) == ADDR_EXPR
)
512 a3
= TREE_OPERAND (a3
, 0);
513 if (TREE_CODE (a3
) == FUNCTION_DECL
)
515 numeric_output_need_bar
= 0;
516 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
520 else if (TREE_CODE (a3
) == INTEGER_CST
)
523 build_overload_int (a3
);
524 numeric_output_need_bar
= 1;
529 sorry ("template instantiation with pointer to method that is too complex");
532 if (TREE_CODE (value
) == INTEGER_CST
)
534 build_overload_int (value
);
535 numeric_output_need_bar
= 1;
538 value
= TREE_OPERAND (value
, 0);
539 if (TREE_CODE (value
) == VAR_DECL
)
541 my_friendly_assert (DECL_NAME (value
) != 0, 245);
542 build_overload_identifier (DECL_NAME (value
));
545 else if (TREE_CODE (value
) == FUNCTION_DECL
)
547 my_friendly_assert (DECL_NAME (value
) != 0, 246);
548 build_overload_identifier (DECL_NAME (value
));
552 my_friendly_abort (71);
553 break; /* not really needed */
556 sorry ("conversion of %s as template parameter",
557 tree_code_name
[(int) TREE_CODE (type
)]);
558 my_friendly_abort (72);
563 build_overload_identifier (name
)
566 if (TREE_CODE (name
) == TYPE_DECL
567 && IS_AGGR_TYPE (TREE_TYPE (name
))
568 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
569 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
))))
571 tree
template, parmlist
, arglist
, tname
;
573 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
));
574 arglist
= TREE_VALUE (template);
575 template = TREE_PURPOSE (template);
576 tname
= DECL_NAME (template);
577 parmlist
= DECL_ARGUMENTS (template);
578 nparms
= TREE_VEC_LENGTH (parmlist
);
580 icat (IDENTIFIER_LENGTH (tname
));
583 for (i
= 0; i
< nparms
; i
++)
585 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
586 tree arg
= TREE_VEC_ELT (arglist
, i
);
587 if (TREE_CODE (parm
) == TYPE_DECL
)
589 /* This parameter is a type. */
591 build_overload_name (arg
, 0, 0);
595 parm
= tsubst (parm
, &TREE_VEC_ELT (arglist
, 0),
596 TREE_VEC_LENGTH (arglist
), NULL_TREE
);
597 /* It's a PARM_DECL. */
598 build_overload_name (TREE_TYPE (parm
), 0, 0);
599 build_overload_value (parm
, arg
);
605 if (TREE_CODE (name
) == TYPE_DECL
)
606 name
= DECL_NAME (name
);
607 if (numeric_output_need_bar
)
610 numeric_output_need_bar
= 0;
612 icat (IDENTIFIER_LENGTH (name
));
617 /* Given a list of parameters in PARMTYPES, create an unambiguous
618 overload string. Should distinguish any type that C (or C++) can
619 distinguish. I.e., pointers to functions are treated correctly.
621 Caller must deal with whether a final `e' goes on the end or not.
623 Any default conversions must take place before this function
626 BEGIN and END control initialization and finalization of the
627 obstack where we build the string. */
630 build_overload_name (parmtypes
, begin
, end
)
637 if (begin
) OB_INIT ();
638 numeric_output_need_bar
= 0;
640 if ((just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
)))
642 parmtype
= parmtypes
;
648 parmtype
= TREE_VALUE (parmtypes
);
652 if (! nofold
&& ! just_one
)
654 /* Every argument gets counted. */
655 typevec
[maxtype
++] = parmtype
;
657 if (TREE_USED (parmtype
) && parmtype
== typevec
[maxtype
-2])
664 flush_repeats (typevec
[maxtype
-2]);
666 if (TREE_USED (parmtype
))
668 flush_repeats (parmtype
);
672 /* Only cache types which take more than one character. */
673 if (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
674 || (TREE_CODE (parmtype
) != INTEGER_TYPE
675 && TREE_CODE (parmtype
) != REAL_TYPE
))
676 TREE_USED (parmtype
) = 1;
679 if (TYPE_PTRMEMFUNC_P (parmtype
))
680 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
682 if (TREE_READONLY (parmtype
))
684 if (TREE_CODE (parmtype
) == INTEGER_TYPE
685 && TYPE_MAIN_VARIANT (parmtype
) == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
687 if (TYPE_VOLATILE (parmtype
))
690 switch (TREE_CODE (parmtype
))
694 build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), 0, 0);
696 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
704 #if PARM_CAN_BE_ARRAY_TYPE
709 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
710 error ("pointer or reference to array of unknown bound in parm type");
713 length
= array_type_nelts (parmtype
);
714 if (TREE_CODE (length
) == INTEGER_CST
)
715 icat (TREE_INT_CST_LOW (length
) + 1);
728 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
734 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
735 /* Otherwise have to implement reentrant typevecs,
736 unmark and remark types, etc. */
737 int old_nofold
= nofold
;
741 flush_repeats (typevec
[maxtype
-1]);
743 /* @@ It may be possible to pass a function type in
744 which is not preceded by a 'P'. */
745 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
748 if (firstarg
== NULL_TREE
)
750 else if (firstarg
== void_list_node
)
753 build_overload_name (firstarg
, 0, 0);
757 int constp
= TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
758 int volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
760 firstarg
= TREE_CHAIN (firstarg
);
762 build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), 0, 0);
768 /* For cfront 2.0 compatibility. */
771 if (firstarg
== NULL_TREE
)
773 else if (firstarg
== void_list_node
)
776 build_overload_name (firstarg
, 0, 0);
779 /* Separate args from return type. */
781 build_overload_name (TREE_TYPE (parmtype
), 0, 0);
787 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
788 if (parmtype
== integer_type_node
789 || parmtype
== unsigned_type_node
)
791 else if (parmtype
== long_integer_type_node
792 || parmtype
== long_unsigned_type_node
)
794 else if (parmtype
== short_integer_type_node
795 || parmtype
== short_unsigned_type_node
)
797 else if (parmtype
== signed_char_type_node
)
802 else if (parmtype
== char_type_node
803 || parmtype
== unsigned_char_type_node
)
805 else if (parmtype
== wchar_type_node
)
807 else if (parmtype
== long_long_integer_type_node
808 || parmtype
== long_long_unsigned_type_node
)
811 /* it would seem there is no way to enter these in source code,
813 else if (parmtype
== long_long_long_integer_type_node
814 || parmtype
== long_long_long_unsigned_type_node
)
818 my_friendly_abort (73);
826 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
827 if (parmtype
== long_double_type_node
)
829 else if (parmtype
== double_type_node
)
831 else if (parmtype
== float_type_node
)
833 else my_friendly_abort (74);
840 extern tree void_list_node
;
842 /* See if anybody is wasting memory. */
843 my_friendly_assert (parmtypes
== void_list_node
, 247);
845 /* This is the end of a parameter list. */
846 if (end
) OB_FINISH ();
847 return (char *)obstack_base (&scratch_obstack
);
852 case ERROR_MARK
: /* not right, but nothing is anyway */
855 /* have to do these */
859 /* Make this type signature look incompatible
866 tree name
= TYPE_NAME (parmtype
);
869 if (TREE_CODE (name
) == TYPE_DECL
)
873 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
874 if (DECL_ASSEMBLER_NAME (context
) != DECL_NAME (context
))
876 OB_PUTID (DECL_ASSEMBLER_NAME (context
));
879 while (DECL_CONTEXT (context
))
882 context
= DECL_CONTEXT (context
);
883 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
884 context
= TYPE_NAME (context
);
886 name
= DECL_NAME (name
);
888 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 248);
897 numeric_output_need_bar
= 0;
898 build_overload_nested_name (TYPE_MAIN_DECL (parmtype
));
901 build_overload_identifier (TYPE_MAIN_DECL (parmtype
));
906 /* This will take some work. */
910 case TEMPLATE_TYPE_PARM
:
912 if (TEMPLATE_TYPE_IDX (parmtype
) > 9)
914 icat (TEMPLATE_TYPE_IDX (parmtype
));
915 if (TEMPLATE_TYPE_IDX (parmtype
) > 9)
920 /* We don't ever want this output, but it's inconvenient not to
921 be able to build the string. This should cause assembler
922 errors we'll notice. */
925 sprintf (digit_buffer
, " *%d", n
++);
926 OB_PUTCP (digit_buffer
);
931 my_friendly_abort (75);
936 parmtypes
= TREE_CHAIN (parmtypes
);
941 flush_repeats (typevec
[maxtype
-1]);
943 /* To get here, parms must end with `...'. */
947 if (end
) OB_FINISH ();
948 return (char *)obstack_base (&scratch_obstack
);
952 build_static_name (basetype
, name
)
955 char *basename
= build_overload_name (basetype
, 1, 1);
956 char *buf
= (char *) alloca (IDENTIFIER_LENGTH (name
)
957 + sizeof (STATIC_NAME_FORMAT
)
958 + strlen (basename
));
959 sprintf (buf
, STATIC_NAME_FORMAT
, basename
, IDENTIFIER_POINTER (name
));
960 return get_identifier (buf
);
963 /* Change the name of a function definition so that it may be
964 overloaded. NAME is the name of the function to overload,
965 PARMS is the parameter list (which determines what name the
966 final function obtains).
968 FOR_METHOD is 1 if this overload is being performed
969 for a method, rather than a function type. It is 2 if
970 this overload is being performed for a constructor. */
972 build_decl_overload (dname
, parms
, for_method
)
977 char *name
= IDENTIFIER_POINTER (dname
);
979 /* member operators new and delete look like methods at this point. */
980 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
)
982 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
983 return get_identifier ("__builtin_delete");
984 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
985 return get_identifier ("__builtin_vec_delete");
986 else if (TREE_CHAIN (parms
) == void_list_node
)
988 if (dname
== ansi_opname
[(int) NEW_EXPR
])
989 return get_identifier ("__builtin_new");
990 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
991 return get_identifier ("__builtin_vec_new");
998 /* Otherwise, we can divine that this is a constructor,
999 and figure out its name without any extra encoding. */
1001 OB_PUTC2 ('_', '_');
1005 /* We can get away without doing this. */
1009 tree this_type
= TREE_VALUE (parms
);
1011 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1012 parms
= temp_tree_cons (NULL_TREE
, SIGNATURE_TYPE (this_type
),
1013 TREE_CHAIN (parms
));
1015 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (this_type
),
1016 TREE_CHAIN (parms
));
1022 if (parms
== NULL_TREE
)
1023 OB_PUTC2 ('e', '\0');
1024 else if (parms
== void_list_node
)
1025 OB_PUTC2 ('v', '\0');
1028 ALLOCATE_TYPEVEC (parms
);
1032 build_overload_name (TREE_VALUE (parms
), 0, 0);
1034 typevec
[maxtype
++] = TREE_VALUE (parms
);
1035 TREE_USED (TREE_VALUE (parms
)) = 1;
1037 if (TREE_CHAIN (parms
))
1038 build_overload_name (TREE_CHAIN (parms
), 0, 1);
1040 OB_PUTC2 ('e', '\0');
1043 build_overload_name (parms
, 0, 1);
1044 DEALLOCATE_TYPEVEC (parms
);
1047 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1048 if (IDENTIFIER_OPNAME_P (dname
))
1049 IDENTIFIER_OPNAME_P (n
) = 1;
1054 /* Build an overload name for the type expression TYPE. */
1056 build_typename_overload (type
)
1062 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1064 build_overload_name (type
, 0, 1);
1065 id
= get_identifier (obstack_base (&scratch_obstack
));
1066 IDENTIFIER_OPNAME_P (id
) = 1;
1068 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_NAME (type
);
1070 TREE_TYPE (id
) = type
;
1074 #ifndef NO_DOLLAR_IN_LABEL
1075 #define T_DESC_FORMAT "TD$"
1076 #define I_DESC_FORMAT "ID$"
1077 #define M_DESC_FORMAT "MD$"
1079 #if !defined(NO_DOT_IN_LABEL)
1080 #define T_DESC_FORMAT "TD."
1081 #define I_DESC_FORMAT "ID."
1082 #define M_DESC_FORMAT "MD."
1084 #define T_DESC_FORMAT "__t_desc_"
1085 #define I_DESC_FORMAT "__i_desc_"
1086 #define M_DESC_FORMAT "__m_desc_"
1090 /* Build an overload name for the type expression TYPE. */
1092 build_t_desc_overload (type
)
1096 OB_PUTS (T_DESC_FORMAT
);
1100 /* Use a different format if the type isn't defined yet. */
1101 if (TYPE_SIZE (type
) == NULL_TREE
)
1106 for (p
= tname
; *p
; p
++)
1112 /* If there's no change, we have an inappropriate T_DESC_FORMAT. */
1113 my_friendly_assert (changed
!= 0, 249);
1117 build_overload_name (type
, 0, 1);
1118 return get_identifier (obstack_base (&scratch_obstack
));
1121 /* Top-level interface to explicit overload requests. Allow NAME
1122 to be overloaded. Error if NAME is already declared for the current
1123 scope. Warning if function is redundantly overloaded. */
1126 declare_overloaded (name
)
1129 #ifdef NO_AUTO_OVERLOAD
1130 if (is_overloaded (name
))
1131 warning ("function `%s' already declared overloaded",
1132 IDENTIFIER_POINTER (name
));
1133 else if (IDENTIFIER_GLOBAL_VALUE (name
))
1134 error ("overloading function `%s' that is already defined",
1135 IDENTIFIER_POINTER (name
));
1138 TREE_OVERLOADED (name
) = 1;
1139 IDENTIFIER_GLOBAL_VALUE (name
) = build_tree_list (name
, NULL_TREE
);
1140 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name
)) = unknown_type_node
;
1143 if (current_lang_name
== lang_name_cplusplus
)
1146 warning ("functions are implicitly overloaded in C++");
1148 else if (current_lang_name
== lang_name_c
)
1149 error ("overloading function `%s' cannot be done in C language context");
1151 my_friendly_abort (76);
1155 #ifdef NO_AUTO_OVERLOAD
1156 /* Check to see if NAME is overloaded. For first approximation,
1157 check to see if its TREE_OVERLOADED is set. This is used on
1158 IDENTIFIER nodes. */
1160 is_overloaded (name
)
1164 return (TREE_OVERLOADED (name
)
1165 && (! IDENTIFIER_CLASS_VALUE (name
) || current_class_type
== 0)
1166 && ! IDENTIFIER_LOCAL_VALUE (name
));
1170 /* Given a tree_code CODE, and some arguments (at least one),
1171 attempt to use an overloaded operator on the arguments.
1173 For unary operators, only the first argument need be checked.
1174 For binary operators, both arguments may need to be checked.
1176 Member functions can convert class references to class pointers,
1177 for one-level deep indirection. More than that is not supported.
1178 Operators [](), ()(), and ->() must be member functions.
1180 We call function call building calls with LOOKUP_COMPLAIN if they
1181 are our only hope. This is true when we see a vanilla operator
1182 applied to something of aggregate type. If this fails, we are free
1183 to return `error_mark_node', because we will have reported the
1186 Operators NEW and DELETE overload in funny ways: operator new takes
1187 a single `size' parameter, and operator delete takes a pointer to the
1188 storage being deleted. When overloading these operators, success is
1189 assumed. If there is a failure, report an error message and return
1190 `error_mark_node'. */
1194 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1195 enum tree_code code
;
1197 tree xarg1
, xarg2
, arg3
;
1201 tree type1
, type2
, fnname
;
1202 tree fields1
= 0, parms
= 0;
1205 int binary_is_unary
;
1207 if (xarg1
== error_mark_node
)
1208 return error_mark_node
;
1210 if (code
== COND_EXPR
)
1212 if (TREE_CODE (xarg2
) == ERROR_MARK
1213 || TREE_CODE (arg3
) == ERROR_MARK
)
1214 return error_mark_node
;
1216 if (code
== COMPONENT_REF
)
1217 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1220 /* First, see if we can work with the first argument */
1221 type1
= TREE_TYPE (xarg1
);
1223 /* Some tree codes have length > 1, but we really only want to
1224 overload them if their first argument has a user defined type. */
1227 case PREINCREMENT_EXPR
:
1228 case PREDECREMENT_EXPR
:
1229 case POSTINCREMENT_EXPR
:
1230 case POSTDECREMENT_EXPR
:
1232 binary_is_unary
= 1;
1236 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1237 If they do not, return error_mark_node instead of NULL_TREE. */
1239 if (xarg2
== error_mark_node
)
1240 return error_mark_node
;
1242 rval
= error_mark_node
;
1243 binary_is_unary
= 0;
1250 tree args
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1251 fnname
= ansi_opname
[(int) code
];
1252 if (flags
& LOOKUP_GLOBAL
)
1253 return build_overload_call (fnname
, args
, flags
& LOOKUP_COMPLAIN
,
1254 (struct candidate
*)0);
1256 rval
= build_method_call
1257 (build_indirect_ref (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1259 fnname
, args
, NULL_TREE
, flags
);
1260 if (rval
== error_mark_node
)
1261 /* User might declare fancy operator new, but invoke it
1262 like standard one. */
1265 TREE_TYPE (rval
) = xarg1
;
1266 TREE_CALLS_NEW (rval
) = 1;
1271 case VEC_DELETE_EXPR
:
1274 fnname
= ansi_opname
[(int) code
];
1275 if (flags
& LOOKUP_GLOBAL
)
1276 return build_overload_call (fnname
,
1277 build_tree_list (NULL_TREE
, xarg1
),
1278 flags
& LOOKUP_COMPLAIN
,
1279 (struct candidate
*)0);
1281 rval
= build_method_call
1282 (build_indirect_ref (build1 (NOP_EXPR
, TREE_TYPE (xarg1
),
1285 fnname
, tree_cons (NULL_TREE
, xarg1
,
1286 build_tree_list (NULL_TREE
, xarg2
)),
1289 /* This can happen when operator delete is protected. */
1290 my_friendly_assert (rval
!= error_mark_node
, 250);
1291 TREE_TYPE (rval
) = void_type_node
;
1298 binary_is_unary
= 0;
1299 try_second
= tree_code_length
[(int) code
] == 2;
1300 if (try_second
&& xarg2
== error_mark_node
)
1301 return error_mark_node
;
1305 if (try_second
&& xarg2
== error_mark_node
)
1306 return error_mark_node
;
1308 /* What ever it was, we do not know how to deal with it. */
1309 if (type1
== NULL_TREE
)
1312 if (TREE_CODE (type1
) == OFFSET_TYPE
)
1313 type1
= TREE_TYPE (type1
);
1315 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
1317 arg1
= convert_from_reference (xarg1
);
1318 type1
= TREE_TYPE (arg1
);
1325 if (!IS_AGGR_TYPE (type1
) || TYPE_PTRMEMFUNC_P (type1
))
1327 /* Try to fail. First, fail if unary */
1330 /* Second, see if second argument is non-aggregate. */
1331 type2
= TREE_TYPE (xarg2
);
1332 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1333 type2
= TREE_TYPE (type2
);
1334 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1336 arg2
= convert_from_reference (xarg2
);
1337 type2
= TREE_TYPE (arg2
);
1344 if (!IS_AGGR_TYPE (type2
))
1351 /* First arg may succeed; see whether second should. */
1352 type2
= TREE_TYPE (xarg2
);
1353 if (TREE_CODE (type2
) == OFFSET_TYPE
)
1354 type2
= TREE_TYPE (type2
);
1355 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
1357 arg2
= convert_from_reference (xarg2
);
1358 type2
= TREE_TYPE (arg2
);
1365 if (! IS_AGGR_TYPE (type2
))
1369 if (type1
== unknown_type_node
1370 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
1372 /* This will not be implemented in the foreseeable future. */
1376 if (code
== MODIFY_EXPR
)
1377 fnname
= ansi_assopname
[(int) TREE_CODE (arg3
)];
1379 fnname
= ansi_opname
[(int) code
];
1381 global_fn
= lookup_name_nonclass (fnname
);
1383 /* This is the last point where we will accept failure. This
1384 may be too eager if we wish an overloaded operator not to match,
1385 but would rather a normal operator be called on a type-converted
1388 if (IS_AGGR_TYPE (type1
))
1390 fields1
= lookup_fnfields (TYPE_BINFO (type1
), fnname
, 0);
1391 /* ARM $13.4.7, prefix/postfix ++/--. */
1392 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
1394 xarg2
= integer_zero_node
;
1395 binary_is_unary
= 0;
1400 int have_postfix
= 0;
1402 /* Look for an `operator++ (int)'. If they didn't have
1403 one, then we fall back to the old way of doing things. */
1404 for (t
= TREE_VALUE (fields1
); t
; t
= DECL_CHAIN (t
))
1406 t2
= TYPE_ARG_TYPES (TREE_TYPE (t
));
1407 if (TREE_CHAIN (t2
) != NULL_TREE
1408 && TREE_VALUE (TREE_CHAIN (t2
)) == integer_type_node
)
1417 char *op
= POSTINCREMENT_EXPR
? "++" : "--";
1419 /* There's probably a LOT of code in the world that
1420 relies upon this old behavior. */
1421 if (! flag_traditional
)
1422 pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead",
1425 binary_is_unary
= 1;
1431 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
1434 /* If RVAL winds up being `error_mark_node', we will return
1435 that... There is no way that normal semantics of these
1436 operators will succeed. */
1438 /* This argument may be an uncommitted OFFSET_REF. This is
1439 the case for example when dealing with static class members
1440 which are referenced from their class name rather than
1441 from a class instance. */
1442 if (TREE_CODE (xarg1
) == OFFSET_REF
1443 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
1444 xarg1
= TREE_OPERAND (xarg1
, 1);
1445 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
1446 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
1447 xarg2
= TREE_OPERAND (xarg2
, 1);
1450 flags
|= LOOKUP_GLOBAL
;
1452 if (code
== CALL_EXPR
)
1454 /* This can only be a member function. */
1455 return build_method_call (xarg1
, fnname
, xarg2
,
1456 NULL_TREE
, LOOKUP_NORMAL
);
1458 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
1461 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
1463 else if (code
== COND_EXPR
)
1465 parms
= tree_cons (0, xarg2
, build_tree_list (NULL_TREE
, arg3
));
1466 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1468 else if (code
== METHOD_CALL_EXPR
)
1470 /* must be a member function. */
1471 parms
= tree_cons (NULL_TREE
, xarg2
, arg3
);
1472 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
,
1477 parms
= build_tree_list (NULL_TREE
, xarg2
);
1478 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
1482 parms
= tree_cons (NULL_TREE
, xarg1
,
1483 build_tree_list (NULL_TREE
, xarg2
));
1484 rval
= build_overload_call (fnname
, parms
, flags
,
1485 (struct candidate
*)0);
1491 /* This function takes an identifier, ID, and attempts to figure out what
1492 it means. There are a number of possible scenarios, presented in increasing
1495 1) not in a class's scope
1496 2) in class's scope, member name of the class's method
1497 3) in class's scope, but not a member name of the class
1498 4) in class's scope, member name of a class's variable
1500 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1501 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1503 As a last ditch, try to look up the name as a label and return that
1506 Values which are declared as being of REFERENCE_TYPE are
1507 automatically dereferenced here (as a hack to make the
1508 compiler faster). */
1511 hack_identifier (value
, name
)
1516 if (TREE_CODE (value
) == ERROR_MARK
)
1518 if (current_class_name
)
1520 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1521 if (fields
== error_mark_node
)
1522 return error_mark_node
;
1527 fndecl
= TREE_VALUE (fields
);
1528 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1529 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1531 warning ("methods cannot be converted to function pointers");
1536 error ("ambiguous request for method pointer `%s'",
1537 IDENTIFIER_POINTER (name
));
1538 return error_mark_node
;
1542 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1544 return IDENTIFIER_LABEL_VALUE (name
);
1546 return error_mark_node
;
1549 type
= TREE_TYPE (value
);
1550 if (TREE_CODE (value
) == FIELD_DECL
)
1552 if (current_class_decl
== NULL_TREE
)
1554 error ("request for member `%s' in static member function",
1555 IDENTIFIER_POINTER (DECL_NAME (value
)));
1556 return error_mark_node
;
1558 TREE_USED (current_class_decl
) = 1;
1560 /* Mark so that if we are in a constructor, and then find that
1561 this field was initialized by a base initializer,
1562 we can emit an error message. */
1563 TREE_USED (value
) = 1;
1564 return build_component_ref (C_C_D
, name
, 0, 1);
1567 if (really_overloaded_fn (value
))
1570 tree t
= get_first_fn (value
);
1571 for (; t
; t
= DECL_CHAIN (t
))
1573 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1576 assemble_external (t
);
1581 else if (TREE_CODE (value
) == TREE_LIST
)
1583 /* Ambiguous reference to base members, possibly other cases?. */
1585 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1587 mark_used (TREE_VALUE (t
));
1595 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
))
1597 tree context
= decl_function_context (value
);
1598 if (context
!= NULL_TREE
&& context
!= current_function_decl
1599 && ! TREE_STATIC (value
))
1601 cp_pedwarn ("use of %s from containing function",
1602 (TREE_CODE (value
) == VAR_DECL
1603 ? "`auto' variable" : "parameter"));
1604 cp_pedwarn_at (" `%#D' declared here", value
);
1608 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1610 if (DECL_LANG_SPECIFIC (value
)
1611 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1614 register tree context
1615 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1616 ? DECL_CLASS_CONTEXT (value
)
1617 : DECL_CONTEXT (value
);
1619 get_base_distance (context
, current_class_type
, 0, &path
);
1622 access
= compute_access (path
, value
);
1623 if (access
!= access_public_node
)
1625 if (TREE_CODE (value
) == VAR_DECL
)
1626 error ("static member `%s' is %s",
1627 IDENTIFIER_POINTER (name
),
1628 TREE_PRIVATE (value
) ? "private" :
1629 "from a private base class");
1631 error ("enum `%s' is from private base class",
1632 IDENTIFIER_POINTER (name
));
1633 return error_mark_node
;
1639 if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1643 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1644 IDENTIFIER_POINTER (name
));
1645 return error_mark_node
;
1651 if (TREE_CODE (type
) == REFERENCE_TYPE
&& ! current_template_parms
)
1653 my_friendly_assert (TREE_CODE (value
) == VAR_DECL
1654 || TREE_CODE (value
) == PARM_DECL
1655 || TREE_CODE (value
) == RESULT_DECL
, 252);
1656 return convert_from_reference (value
);
1663 /* Given an object OF, and a type conversion operator COMPONENT
1664 build a call to the conversion operator, if a call is requested,
1665 or return the address (as a pointer to member function) if one is not.
1667 OF can be a TYPE_DECL or any kind of datum that would normally
1668 be passed to `build_component_ref'. It may also be NULL_TREE,
1669 in which case `current_class_type' and `current_class_decl'
1670 provide default values.
1672 BASETYPE_PATH, if non-null, is the path of basetypes
1673 to go through before we get the the instance of interest.
1675 PROTECT says whether we apply C++ scoping rules or not. */
1677 build_component_type_expr (of
, component
, basetype_path
, protect
)
1678 tree of
, component
, basetype_path
;
1681 tree cname
= NULL_TREE
;
1684 int flags
= protect
? LOOKUP_NORMAL
: LOOKUP_COMPLAIN
;
1687 my_friendly_assert (IS_AGGR_TYPE (TREE_TYPE (of
)), 253);
1688 my_friendly_assert (TREE_CODE (component
) == TYPE_EXPR
, 254);
1690 tmp
= TREE_OPERAND (component
, 0);
1695 switch (TREE_CODE (tmp
))
1699 TREE_OPERAND (last
, 0) = TREE_OPERAND (tmp
, 0);
1701 TREE_OPERAND (component
, 0) = TREE_OPERAND (tmp
, 0);
1703 last
= groktypename (build_tree_list (TREE_TYPE (component
),
1704 TREE_OPERAND (component
, 0)));
1705 name
= build_typename_overload (last
);
1706 TREE_TYPE (name
) = last
;
1708 if (TREE_OPERAND (tmp
, 0)
1709 && TREE_OPERAND (tmp
, 0) != void_list_node
)
1711 cp_error ("`operator %T' requires empty parameter list", last
);
1712 TREE_OPERAND (tmp
, 0) = NULL_TREE
;
1715 if (of
&& TREE_CODE (of
) != TYPE_DECL
)
1716 return build_method_call (of
, name
, NULL_TREE
, NULL_TREE
, flags
);
1721 if (current_class_decl
== NULL_TREE
)
1723 cp_error ("object required for `operator %T' call",
1725 return error_mark_node
;
1728 this_this
= convert_pointer_to (TREE_TYPE (of
),
1729 current_class_decl
);
1730 this_this
= build_indirect_ref (this_this
, NULL_PTR
);
1731 return build_method_call (this_this
, name
, NULL_TREE
,
1732 NULL_TREE
, flags
| LOOKUP_NONVIRTUAL
);
1734 else if (current_class_decl
)
1735 return build_method_call (tmp
, name
, NULL_TREE
, NULL_TREE
, flags
);
1737 cp_error ("object required for `operator %T' call",
1739 return error_mark_node
;
1747 my_friendly_assert (cname
== 0, 255);
1748 cname
= TREE_OPERAND (tmp
, 0);
1749 tmp
= TREE_OPERAND (tmp
, 1);
1753 my_friendly_abort (77);
1756 tmp
= TREE_OPERAND (tmp
, 0);
1759 last
= groktypename (build_tree_list (TREE_TYPE (component
), TREE_OPERAND (component
, 0)));
1760 name
= build_typename_overload (last
);
1761 TREE_TYPE (name
) = last
;
1762 if (of
&& TREE_CODE (of
) == TYPE_DECL
)
1764 if (cname
== NULL_TREE
)
1766 cname
= DECL_NAME (of
);
1769 else my_friendly_assert (cname
== DECL_NAME (of
), 256);
1776 if (current_class_decl
== NULL_TREE
)
1778 cp_error ("object required for `operator %T' call",
1780 return error_mark_node
;
1783 this_this
= convert_pointer_to (TREE_TYPE (of
), current_class_decl
);
1784 return build_component_ref (this_this
, name
, 0, protect
);
1787 return build_offset_ref (cname
, name
);
1788 else if (current_class_name
)
1789 return build_offset_ref (current_class_name
, name
);
1791 cp_error ("object required for `operator %T' member reference",
1793 return error_mark_node
;
1798 thunk_printable_name (decl
)
1801 return "<thunk function>";
1805 make_thunk (function
, delta
)
1810 tree thunk_fndecl
, thunk_id
;
1813 static int thunk_number
= 0;
1815 if (TREE_CODE (function
) != ADDR_EXPR
)
1817 func_decl
= TREE_OPERAND (function
, 0);
1818 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
1820 func_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl
));
1822 sprintf (buffer
, "__thunk_%d_%s", -delta
, func_name
);
1824 sprintf (buffer
, "__thunk_n%d_%s", delta
, func_name
);
1825 thunk_id
= get_identifier (buffer
);
1826 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
1827 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
1829 error_with_decl ("implementation-reserved name `%s' used");
1830 IDENTIFIER_GLOBAL_VALUE (thunk_id
) = thunk
= NULL_TREE
;
1832 if (thunk
== NULL_TREE
)
1834 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
1836 = build_decl (RESULT_DECL
, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type
)));
1837 TREE_READONLY (thunk
) = TYPE_READONLY (TREE_TYPE (vtable_entry_type
));
1838 TREE_THIS_VOLATILE (thunk
) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type
));
1839 make_function_rtl (thunk
);
1840 TREE_SET_CODE (thunk
, THUNK_DECL
);
1841 DECL_INITIAL (thunk
) = function
;
1842 THUNK_DELTA (thunk
) = delta
;
1843 DECL_EXTERNAL (thunk
) = 1;
1844 TREE_PUBLIC (thunk
) = 1;
1845 /* So that finish_file can write out any thunks that need to be: */
1846 pushdecl_top_level (thunk
);
1852 emit_thunk (thunk_fndecl
)
1859 struct args_size stack_args_size
;
1860 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
1861 int delta
= THUNK_DELTA (thunk_fndecl
);
1864 int current_call_is_indirect
= 0; /* needed for HPPA FUNCTION_ARG */
1866 /* Used to remember which regs we need to emit a USE rtx for. */
1867 rtx need_use
[FIRST_PSEUDO_REGISTER
];
1868 int need_use_count
= 0;
1870 /* rtx for the 'this' parameter. */
1871 rtx this_rtx
= 0, this_reg_rtx
= 0, fixed_this_rtx
;
1873 char *(*save_decl_printable_name
) () = decl_printable_name
;
1874 /* Data on reg parms scanned so far. */
1875 CUMULATIVE_ARGS args_so_far
;
1877 if (TREE_ASM_WRITTEN (thunk_fndecl
))
1880 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1882 if (! TREE_PUBLIC (function
))
1883 TREE_PUBLIC (thunk_fndecl
) = 0;
1884 if (DECL_EXTERNAL (function
))
1886 DECL_EXTERNAL (thunk_fndecl
) = 0;
1888 decl_printable_name
= thunk_printable_name
;
1889 if (current_function_decl
)
1891 current_function_decl
= thunk_fndecl
;
1892 init_function_start (thunk_fndecl
, input_filename
, lineno
);
1894 expand_start_bindings (1);
1896 /* Start updating where the next arg would go. */
1897 INIT_CUMULATIVE_ARGS (args_so_far
, TREE_TYPE (function
), NULL_RTX
);
1898 stack_args_size
.constant
= 0;
1899 stack_args_size
.var
= 0;
1900 /* SETUP for possible structure return address FIXME */
1902 /* Now look through all the parameters, make sure that we
1903 don't clobber any registers used for parameters.
1904 Also, pick up an rtx for the first "this" parameter. */
1905 for (argp
= TYPE_ARG_TYPES (TREE_TYPE (function
));
1907 argp
= TREE_CHAIN (argp
))
1910 tree passed_type
= TREE_VALUE (argp
);
1911 register rtx entry_parm
;
1912 int named
= 1; /* FIXME */
1913 struct args_size stack_offset
;
1914 struct args_size arg_size
;
1916 if (passed_type
== void_type_node
)
1919 if ((TREE_CODE (TYPE_SIZE (passed_type
)) != INTEGER_CST
1920 && contains_placeholder_p (TYPE_SIZE (passed_type
)))
1921 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
1922 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far
,
1923 TYPE_MODE (passed_type
),
1927 passed_type
= build_pointer_type (passed_type
);
1929 entry_parm
= FUNCTION_ARG (args_so_far
,
1930 TYPE_MODE (passed_type
),
1933 if (entry_parm
!= 0)
1934 need_use
[need_use_count
++] = entry_parm
;
1936 locate_and_pad_parm (TYPE_MODE (passed_type
), passed_type
,
1937 #ifdef STACK_PARMS_IN_REG_PARM_AREA
1943 &stack_args_size
, &stack_offset
, &arg_size
);
1945 /* REGNO (entry_parm);*/
1948 this_reg_rtx
= entry_parm
;
1951 rtx offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
1953 rtx internal_arg_pointer
, stack_parm
;
1955 if ((ARG_POINTER_REGNUM
== STACK_POINTER_REGNUM
1956 || ! (fixed_regs
[ARG_POINTER_REGNUM
]
1957 || ARG_POINTER_REGNUM
== FRAME_POINTER_REGNUM
)))
1958 internal_arg_pointer
= copy_to_reg (virtual_incoming_args_rtx
);
1960 internal_arg_pointer
= virtual_incoming_args_rtx
;
1962 if (offset_rtx
== const0_rtx
)
1963 entry_parm
= gen_rtx (MEM
, TYPE_MODE (passed_type
),
1964 internal_arg_pointer
);
1966 entry_parm
= gen_rtx (MEM
, TYPE_MODE (passed_type
),
1967 gen_rtx (PLUS
, Pmode
,
1968 internal_arg_pointer
,
1972 this_rtx
= entry_parm
;
1975 FUNCTION_ARG_ADVANCE (args_so_far
,
1976 TYPE_MODE (passed_type
),
1981 fixed_this_rtx
= plus_constant (this_rtx
, delta
);
1982 if (this_rtx
!= fixed_this_rtx
)
1983 emit_move_insn (this_rtx
, fixed_this_rtx
);
1986 emit_insn (gen_rtx (USE
, VOIDmode
, this_reg_rtx
));
1988 emit_indirect_jump (XEXP (DECL_RTL (function
), 0));
1990 while (need_use_count
> 0)
1991 emit_insn (gen_rtx (USE
, VOIDmode
, need_use
[--need_use_count
]));
1993 expand_end_bindings (NULL
, 1, 0);
1996 /* From now on, allocate rtl in current_obstack, not in saveable_obstack.
1997 Note that that may have been done above, in save_for_inline_copying.
1998 The call to resume_temporary_allocation near the end of this function
1999 goes back to the usual state of affairs. */
2001 rtl_in_current_obstack ();
2003 insns
= get_insns ();
2005 /* Copy any shared structure that should not be shared. */
2007 unshare_all_rtl (insns
);
2009 /* Instantiate all virtual registers. */
2011 instantiate_virtual_regs (current_function_decl
, get_insns ());
2013 /* We are no longer anticipating cse in this function, at least. */
2015 cse_not_expected
= 1;
2017 /* Now we choose between stupid (pcc-like) register allocation
2018 (if we got the -noreg switch and not -opt)
2019 and smart register allocation. */
2021 if (optimize
> 0) /* Stupid allocation probably won't work */
2022 obey_regdecls
= 0; /* if optimizations being done. */
2026 regclass (insns
, max_reg_num ());
2029 stupid_life_analysis (insns
, max_reg_num (), NULL
);
2030 failure
= reload (insns
, 0, NULL
);
2034 /* Do control and data flow analysis,
2035 and write some of the results to dump file. */
2037 flow_analysis (insns
, max_reg_num (), NULL
);
2039 failure
= global_alloc (NULL
);
2042 reload_completed
= 1;
2044 #ifdef LEAF_REGISTERS
2046 if (optimize
> 0 && only_leaf_regs_used () && leaf_function_p ())
2050 /* If a machine dependent reorganization is needed, call it. */
2051 #ifdef MACHINE_DEPENDENT_REORG
2052 MACHINE_DEPENDENT_REORG (insns
);
2055 /* Now turn the rtl into assembler code. */
2058 char *fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
2059 assemble_start_function (thunk_fndecl
, fnname
);
2060 final (insns
, asm_out_file
, optimize
, 0);
2061 assemble_end_function (thunk_fndecl
, fnname
);
2064 exit_rest_of_compilation
:
2066 reload_completed
= 0;
2068 /* Cancel the effect of rtl_in_current_obstack. */
2070 resume_temporary_allocation ();
2072 decl_printable_name
= save_decl_printable_name
;
2073 current_function_decl
= 0;
2076 /* Code for synthesizing methods which have default semantics defined. */
2078 /* For the anonymous union in TYPE, return the member that is at least as
2079 large as the rest of the members, so we can copy it. */
2081 largest_union_member (type
)
2084 tree f
, type_size
= TYPE_SIZE (type
);
2086 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2087 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2090 /* We should always find one. */
2091 my_friendly_abort (323);
2095 /* Generate code for default X(X&) constructor. */
2097 do_build_copy_constructor (fndecl
)
2100 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2106 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2107 parm
= TREE_CHAIN (parm
);
2108 parm
= convert_from_reference (parm
);
2110 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2112 t
= build (INIT_EXPR
, void_type_node
, C_C_D
, 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
);
2131 current_base_init_list
= tree_cons (basetype
,
2132 p
, current_base_init_list
);
2135 for (i
= 0; i
< n_bases
; ++i
)
2137 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2138 if (TREE_VIA_VIRTUAL (basetype
))
2141 basetype
= BINFO_TYPE (basetype
);
2142 p
= convert_to_reference
2143 (build_reference_type (basetype
), parm
,
2144 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2145 p
= convert_from_reference (p
);
2146 current_base_init_list
= tree_cons (basetype
,
2147 p
, current_base_init_list
);
2149 for (; fields
; fields
= TREE_CHAIN (fields
))
2152 tree field
= fields
;
2154 if (TREE_CODE (field
) != FIELD_DECL
)
2156 if (DECL_NAME (field
))
2158 if (VFIELD_NAME_P (DECL_NAME (field
)))
2160 if (VBASE_NAME_P (DECL_NAME (field
)))
2163 /* True for duplicate members. */
2164 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2167 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2168 && TREE_CODE (t
) == UNION_TYPE
2169 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2170 && TYPE_FIELDS (t
) != NULL_TREE
)
2171 field
= largest_union_member (t
);
2175 init
= build (COMPONENT_REF
, TREE_TYPE (field
), parm
, field
);
2176 init
= build_tree_list (NULL_TREE
, init
);
2178 current_member_init_list
2179 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2181 current_member_init_list
= nreverse (current_member_init_list
);
2182 current_base_init_list
= nreverse (current_base_init_list
);
2190 do_build_assign_ref (fndecl
)
2193 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2198 parm
= convert_from_reference (parm
);
2200 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2202 tree t
= build (MODIFY_EXPR
, void_type_node
, C_C_D
, parm
);
2203 TREE_SIDE_EFFECTS (t
) = 1;
2204 cplus_expand_expr_stmt (t
);
2208 tree fields
= TYPE_FIELDS (current_class_type
);
2209 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2210 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2213 for (i
= 0; i
< n_bases
; ++i
)
2215 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2216 if (TYPE_HAS_ASSIGN_REF (basetype
))
2218 tree p
= convert_to_reference
2219 (build_reference_type (basetype
), parm
,
2220 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2221 p
= convert_from_reference (p
);
2222 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2223 build_tree_list (NULL_TREE
, p
));
2224 expand_expr_stmt (p
);
2227 for (; fields
; fields
= TREE_CHAIN (fields
))
2230 tree field
= fields
;
2232 if (TREE_CODE (field
) != FIELD_DECL
)
2234 if (DECL_NAME (field
))
2236 if (VFIELD_NAME_P (DECL_NAME (field
)))
2238 if (VBASE_NAME_P (DECL_NAME (field
)))
2241 /* True for duplicate members. */
2242 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2245 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2246 && TREE_CODE (t
) == UNION_TYPE
2247 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
))
2248 && TYPE_FIELDS (t
) != NULL_TREE
)
2249 field
= largest_union_member (t
);
2253 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), C_C_D
, field
);
2254 init
= build (COMPONENT_REF
, TREE_TYPE (field
), parm
, field
);
2256 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2259 c_expand_return (C_C_D
);
2264 synthesize_method (fndecl
)
2267 int nested
= (current_function_decl
!= NULL_TREE
);
2268 tree context
= decl_function_context (fndecl
);
2269 char *f
= input_filename
;
2270 tree base
= DECL_CLASS_CONTEXT (fndecl
);
2273 push_cp_function_context (context
);
2275 input_filename
= DECL_SOURCE_FILE (fndecl
);
2276 interface_unknown
= CLASSTYPE_INTERFACE_UNKNOWN (base
);
2277 interface_only
= CLASSTYPE_INTERFACE_ONLY (base
);
2278 start_function (NULL_TREE
, fndecl
, NULL_TREE
, NULL_TREE
, 1);
2279 store_parm_decls ();
2281 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2282 do_build_assign_ref (fndecl
);
2283 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2287 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2288 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2289 arg_chain
= TREE_CHAIN (arg_chain
);
2290 if (arg_chain
!= void_list_node
)
2291 do_build_copy_constructor (fndecl
);
2292 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2296 finish_function (lineno
, 0, nested
);
2298 /* Do we really *want* to inline this function? */
2299 if (DECL_INLINE (fndecl
))
2301 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
2302 will check our size. */
2303 DECL_INLINE (fndecl
) = 0;
2304 if (function_cannot_inline_p (fndecl
) == 0)
2305 DECL_INLINE (fndecl
) = 1;
2309 extract_interface_info ();
2311 pop_cp_function_context (context
);