1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and varaible name overloading.
3 Copyright (C) 1987 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@mcc.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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Handle method declarations. */
27 #include "cplus-tree.h"
30 /* TREE_LIST of the current inline functions that need to be
32 struct pending_inline
*pending_inlines
;
34 # define MAX_INLINE_BUF_SIZE 8188
35 # define OB_INIT() (inline_bufp = inline_buffer)
36 # define OB_PUTC(C) (*inline_bufp++ = (C))
37 # define OB_PUTC2(C1,C2) (OB_PUTC (C1), OB_PUTC (C2))
38 # define OB_PUTS(S) (strcpy (inline_bufp, S), inline_bufp += sizeof (S) - 1)
39 # define OB_PUTCP(S) (strcpy (inline_bufp, S), inline_bufp += strlen (S))
40 # define OB_FINISH() (*inline_bufp++ = '\0')
42 /* Counter to help build parameter names in case they were omitted. */
43 static int dummy_name
;
44 static int in_parmlist
;
45 /* Just a pointer into INLINE_BUFFER. */
46 static char *inline_bufp
;
47 /* Also a pointer into INLINE_BUFFER. This points to a safe place to
48 cut back to if we assign it 0, in case of error. */
49 static char *inline_errp
;
50 static char *inline_buffer
;
51 static void dump_type (), dump_decl ();
52 static void dump_init (), dump_unary_op (), dump_binary_op ();
54 tree wrapper_name
, wrapper_pred_name
, anti_wrapper_name
;
56 #ifdef NO_AUTO_OVERLOAD
63 char buf
[sizeof (ANTI_WRAPPER_NAME_FORMAT
) + 8];
64 sprintf (buf
, WRAPPER_NAME_FORMAT
, "");
65 wrapper_name
= get_identifier (buf
);
66 sprintf (buf
, WRAPPER_PRED_NAME_FORMAT
, "");
67 wrapper_pred_name
= get_identifier (buf
);
68 sprintf (buf
, ANTI_WRAPPER_NAME_FORMAT
, "");
69 anti_wrapper_name
= get_identifier (buf
);
72 /* Return a pointer to the end of the new text in INLINE_BUFFER.
73 We cannot use `fatal' or `error' in here because that
74 might cause an infinite loop. */
81 if (s
>= inline_buffer
+ MAX_INLINE_BUF_SIZE
)
83 fprintf (stderr
, "recompile c++ with larger MAX_INLINE_BUF_SIZE (%d)", MAX_INLINE_BUF_SIZE
);
89 /* Check that we have not overflowed INLINE_BUFFER.
90 We cannot use `fatal' or `error' in here because that
91 might cause an infinite loop. */
96 if (s
>= inline_buffer
+ MAX_INLINE_BUF_SIZE
)
98 fprintf (stderr
, "recompile c++ with larger MAX_INLINE_BUF_SIZE (%d)", MAX_INLINE_BUF_SIZE
);
104 make_anon_parm_name ()
108 sprintf (buf
, ANON_PARMNAME_FORMAT
, dummy_name
++);
109 return get_identifier (buf
);
113 clear_anon_parm_name ()
115 /* recycle these names. */
120 dump_readonly_or_volatile (t
)
123 if (TREE_READONLY (t
))
125 if (TREE_VOLATILE (t
))
126 OB_PUTS ("volatile ");
130 dump_type_prefix (t
, p
)
135 int print_struct
= 1;
141 switch (TREE_CODE (t
))
144 sprintf (inline_bufp
, ANON_PARMNAME_FORMAT
, dummy_name
++);
148 OB_PUTS ("<unknown type>");
152 dump_type (TREE_VALUE (t
), &old_p
);
155 if (TREE_CHAIN (t
) != void_list_node
)
158 dump_type (TREE_CHAIN (t
), &old_p
);
161 else OB_PUTS ("...");
166 dump_type_prefix (TREE_TYPE (t
), p
);
172 if (TREE_READONLY (t
))
174 if (TREE_VOLATILE (t
))
175 OB_PUTS ("volatile ");
180 tree type
= TREE_TYPE (t
);
181 if (TREE_CODE (type
) == FUNCTION_TYPE
)
183 type
= TREE_TYPE (type
);
188 dump_type_prefix (type
, &old_p
);
191 dump_type (TYPE_OFFSET_BASETYPE (t
), &old_p
);
198 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
199 dump_readonly_or_volatile (t
);
205 tree type
= TREE_TYPE (t
);
209 dump_type_prefix (type
, &old_p
);
212 dump_type (TYPE_METHOD_BASETYPE (t
), &old_p
);
219 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
220 dump_readonly_or_volatile (t
);
225 dump_type_prefix (TREE_TYPE (t
), p
);
227 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
228 dump_readonly_or_volatile (t
);
232 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
233 dump_readonly_or_volatile (t
);
234 dump_type_prefix (TREE_TYPE (t
), p
);
240 dump_type_prefix (TREE_TYPE (t
), &old_p
);
247 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
248 dump_readonly_or_volatile (t
);
251 case IDENTIFIER_NODE
:
252 sprintf (inline_bufp
, "%s ", IDENTIFIER_POINTER (t
));
256 if (TREE_READONLY (t
))
258 if (TREE_VOLATILE (t
))
259 OB_PUTS ("volatile ");
260 if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
262 name
= TYPE_NAME (t
);
263 if (TREE_CODE (name
) == TYPE_DECL
)
264 name
= DECL_NAME (name
);
266 sprintf (inline_bufp
, "struct %s ", IDENTIFIER_POINTER (name
));
268 sprintf (inline_bufp
, "class %s ", IDENTIFIER_POINTER (name
));
272 if (TREE_READONLY (t
))
274 if (TREE_VOLATILE (t
))
275 OB_PUTS ("volatile ");
276 name
= TYPE_NAME (t
);
277 if (TREE_CODE (name
) == TYPE_DECL
)
278 name
= DECL_NAME (name
);
279 sprintf (inline_bufp
, "union %s ", IDENTIFIER_POINTER (name
));
283 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
284 dump_readonly_or_volatile (t
);
285 name
= TYPE_NAME (t
);
286 if (TREE_CODE (name
) == TYPE_DECL
)
287 name
= DECL_NAME (name
);
288 sprintf (inline_bufp
, "enum %s ", IDENTIFIER_POINTER (name
));
292 if (TREE_READONLY (t
))
294 if (TREE_VOLATILE (t
))
295 OB_PUTS ("volatile ");
296 sprintf (inline_bufp
, "%s ", IDENTIFIER_POINTER (DECL_NAME (t
)));
300 /* Normally, `unsigned' is part of the deal. Not so if it comes
301 with `const' or `volatile'. */
302 if (TREE_UNSIGNED (t
)
303 && (TREE_READONLY (t
) || TREE_VOLATILE (t
)))
304 OB_PUTS ("unsigned ");
308 if (TREE_READONLY (t
))
310 if (TREE_VOLATILE (t
))
311 OB_PUTS ("volatile ");
312 sprintf (inline_bufp
, "%s ", TYPE_NAME_STRING (t
));
318 inline_bufp
= new_text_len (inline_bufp
);
322 dump_type_suffix (t
, p
)
331 switch (TREE_CODE (t
))
334 sprintf (inline_bufp
, ANON_PARMNAME_FORMAT
, dummy_name
++);
341 dump_type_suffix (TREE_TYPE (t
), p
);
346 tree type
= TREE_TYPE (t
);
349 if (TREE_CODE (type
) == FUNCTION_TYPE
)
352 tree next_arg
= TREE_CHAIN (TYPE_ARG_TYPES (type
));
356 if (next_arg
!= void_list_node
)
359 dump_type (next_arg
, &old_p
);
363 else OB_PUTS ("...");
365 dump_type_suffix (TREE_TYPE (type
), p
);
377 next_arg
= TREE_CHAIN (TYPE_ARG_TYPES (t
));
381 if (next_arg
!= void_list_node
)
384 dump_type (next_arg
, &old_p
);
388 else OB_PUTS ("...");
390 dump_readonly_or_volatile (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))));
391 dump_type_suffix (TREE_TYPE (t
), p
);
396 dump_type_suffix (TREE_TYPE (t
), p
);
400 dump_type_suffix (TREE_TYPE (t
), p
);
406 if (TYPE_ARG_TYPES (t
) && TYPE_ARG_TYPES (t
) != void_list_node
)
409 dump_type (TYPE_ARG_TYPES (t
), &old_p
);
413 dump_type_suffix (TREE_TYPE (t
), p
);
416 case IDENTIFIER_NODE
:
429 inline_bufp
= new_text_len (inline_bufp
);
438 int print_struct
= 1;
443 switch (TREE_CODE (t
))
446 sprintf (inline_bufp
, ANON_PARMNAME_FORMAT
, dummy_name
++);
450 OB_PUTS ("<unknown type>");
454 dump_type (TREE_VALUE (t
), &old_p
);
457 if (TREE_CHAIN (t
) != void_list_node
)
460 dump_type (TREE_CHAIN (t
), &old_p
);
463 else OB_PUTS ("...");
467 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
468 dump_readonly_or_volatile (t
);
470 dump_type (TREE_TYPE (t
), p
);
479 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
480 dump_readonly_or_volatile (t
);
481 dump_type (TREE_TYPE (t
), p
);
486 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
487 dump_readonly_or_volatile (t
);
488 dump_type (TREE_TYPE (t
), p
);
495 dump_type_prefix (t
, p
);
496 dump_type_suffix (t
, p
);
499 case IDENTIFIER_NODE
:
500 sprintf (inline_bufp
, "%s ", IDENTIFIER_POINTER (t
));
505 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
506 dump_readonly_or_volatile (t
);
507 if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
510 if (TREE_CODE (t
) == TYPE_DECL
)
513 sprintf (inline_bufp
, "struct %s ", IDENTIFIER_POINTER (t
));
515 sprintf (inline_bufp
, "class %s ", IDENTIFIER_POINTER (t
));
521 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
522 dump_readonly_or_volatile (t
);
524 if (TREE_CODE (t
) == TYPE_DECL
)
526 sprintf (inline_bufp
, "union %s ", IDENTIFIER_POINTER (t
));
532 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
533 dump_readonly_or_volatile (t
);
535 if (TREE_CODE (t
) == TYPE_DECL
)
537 sprintf (inline_bufp
, "enum %s ", IDENTIFIER_POINTER (t
));
542 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
543 dump_readonly_or_volatile (t
);
544 sprintf (inline_bufp
, "%s ", IDENTIFIER_POINTER (DECL_NAME (t
)));
548 /* Normally, `unsigned' is part of the deal. Not so if it comes
549 with `const' or `volatile'. */
550 if (TREE_READONLY (t
) | TREE_VOLATILE (t
))
551 dump_readonly_or_volatile (t
);
552 if (TREE_UNSIGNED (t
)
553 && (TREE_READONLY (t
) | TREE_VOLATILE (t
)))
554 OB_PUTS ("unsigned ");
558 sprintf (inline_bufp
, "%s ", TYPE_NAME_STRING (t
));
564 inline_bufp
= new_text_len (inline_bufp
);
576 switch (TREE_CODE (t
))
579 strcpy (inline_bufp
, " /* decl error */ ");
583 dump_type_prefix (TREE_TYPE (t
), &p
);
585 dump_decl (DECL_NAME (t
));
588 sprintf (inline_bufp
, ANON_PARMNAME_FORMAT
, dummy_name
++);
591 dump_type_suffix (TREE_TYPE (t
), &p
);
595 dump_decl (TREE_OPERAND (t
, 0));
598 dump_decl (TREE_OPERAND (t
, 1));
600 t
= tree_last (TYPE_ARG_TYPES (TREE_TYPE (t
)));
601 if (!t
|| t
!= void_list_node
)
607 dump_decl (TREE_OPERAND (t
, 0));
609 dump_decl (TREE_OPERAND (t
, 1));
614 sprintf (inline_bufp
, "%s ", IDENTIFIER_POINTER (DECL_NAME (t
)));
621 case IDENTIFIER_NODE
:
622 if (OPERATOR_NAME_P (t
))
623 sprintf (inline_bufp
, "operator %s ", operator_name_string (t
));
624 else if (OPERATOR_TYPENAME_P (t
))
626 OB_PUTS ("operator ");
627 dump_type (TREE_TYPE (t
), &p
);
631 sprintf (inline_bufp
, "%s ", IDENTIFIER_POINTER (t
));
636 dump_decl (TREE_OPERAND (t
, 0));
640 sprintf (inline_bufp
, "%s :: ", IDENTIFIER_POINTER (TREE_OPERAND (t
, 0)));
641 inline_bufp
+= sizeof ("%s :: ") + IDENTIFIER_LENGTH (TREE_OPERAND (t
, 0));
642 dump_decl (TREE_OPERAND (t
, 1));
647 dump_decl (TREE_OPERAND (t
, 0));
652 dump_decl (TREE_OPERAND (t
, 0));
658 inline_bufp
= new_text_len (inline_bufp
);
667 dump_init (TREE_VALUE (l
));
680 switch (TREE_CODE (t
))
684 sprintf (inline_bufp
, " %s ", IDENTIFIER_POINTER (DECL_NAME (t
)));
689 tree name
= DECL_NAME (t
);
691 if (DESTRUCTOR_NAME_P (name
))
692 sprintf (inline_bufp
, " ~%s ",
693 IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t
)));
694 else if (OPERATOR_NAME_P (name
))
695 sprintf (inline_bufp
, "operator %s ", operator_name_string (name
));
696 else if (OPERATOR_TYPENAME_P (name
))
699 OB_PUTS ("operator ");
700 dump_type (TREE_TYPE (name
), &dummy
);
703 else if (WRAPPER_NAME_P (name
))
704 sprintf (inline_bufp
, " ()%s ",
705 IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t
)));
706 else if (WRAPPER_PRED_NAME_P (name
))
707 sprintf (inline_bufp
, " ()?%s ",
708 IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t
)));
709 else if (ANTI_WRAPPER_NAME_P (name
))
710 sprintf (inline_bufp
, " ~()%s ",
711 IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t
)));
713 else sprintf (inline_bufp
, " %s ",
714 IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t
)));
721 dump_type (TREE_TYPE (t
), &dummy
);
723 dump_init (DECL_INITIAL (t
));
728 sprintf (inline_bufp
, " %d ", TREE_INT_CST_LOW (t
));
732 sprintf (inline_bufp
, " %g ", TREE_REAL_CST (t
));
737 char *p
= TREE_STRING_POINTER (t
);
738 int len
= TREE_STRING_LENGTH (t
) - 1;
741 check_text_len (inline_bufp
+ len
+ 2);
743 for (i
= 0; i
< len
; i
++)
745 register char c
= p
[i
];
746 if (c
== '\"' || c
== '\\')
748 if (c
>= ' ' && c
< 0177)
752 sprintf (inline_bufp
, "\\%03o", c
);
753 inline_bufp
= new_text_len (inline_bufp
);
761 dump_binary_op (",", t
, 1);
766 dump_init (TREE_OPERAND (t
, 0));
768 dump_init (TREE_OPERAND (t
, 1));
770 dump_init (TREE_OPERAND (t
, 2));
775 if (TREE_HAS_CONSTRUCTOR (t
))
779 dump_type (TREE_TYPE (TREE_TYPE (t
)), &dummy
);
780 PARM_DECL_EXPR (t
) = 1;
784 sorry ("operand of SAVE_EXPR not understood");
786 inline_bufp
= inline_errp
+ 1;
791 strcpy (inline_bufp
, TYPE_NAME_STRING (TREE_TYPE (t
)));
792 inline_bufp
= new_text_len (inline_bufp
);
794 dump_init_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
800 dump_init (TREE_OPERAND (t
, 0));
801 dump_init_list (TREE_OPERAND (t
, 1));
819 case TRUTH_ANDIF_EXPR
:
820 case TRUTH_ORIF_EXPR
:
827 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
,
828 strlen (opname_tab
[(int) TREE_CODE (t
)]));
834 dump_binary_op ("/", t
, 1);
840 dump_binary_op ("%", t
, 1);
844 dump_binary_op (".", t
, 1);
848 dump_unary_op ("+", t
, 1);
852 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
853 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
854 dump_init (TREE_OPERAND (t
, 0));
856 dump_unary_op ("&", t
, 1);
860 dump_unary_op ("*", t
, 1);
866 case PREDECREMENT_EXPR
:
867 case PREINCREMENT_EXPR
:
868 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
,
869 strlen (opname_tab
[(int) TREE_CODE (t
)]));
872 case POSTDECREMENT_EXPR
:
873 case POSTINCREMENT_EXPR
:
875 dump_init (TREE_OPERAND (t
, 0));
876 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
883 dump_type (TREE_TYPE (t
), &dummy
);
885 dump_init (TREE_OPERAND (t
, 0));
891 dump_init_list (CONSTRUCTOR_ELTS (t
));
895 /* This list is incomplete, but should suffice for now.
896 It is very important that `sorry' does not call
897 `report_error_function'. That could cause an infinite loop. */
899 sorry ("that operation not supported for default parameters");
901 /* fall through to ERROR_MARK... */
904 inline_bufp
= inline_errp
+ 1;
907 inline_bufp
= new_text_len (inline_bufp
);
911 dump_binary_op (opstring
, t
, len
)
917 dump_init (TREE_OPERAND (t
, 0));
918 sprintf (inline_bufp
, " %s ", opstring
);
919 inline_bufp
+= len
+ 2;
920 dump_init (TREE_OPERAND (t
, 1));
922 check_text_len (inline_bufp
);
926 dump_unary_op (opstring
, t
, len
)
932 sprintf (inline_bufp
, " %s ", opstring
);
933 inline_bufp
+= len
+ 2;
934 dump_init (TREE_OPERAND (t
, 0));
936 check_text_len (inline_bufp
);
939 #ifdef DO_METHODS_THE_OLD_WAY
940 /* Process the currently pending inline function definitions.
942 (1) Creating a temporary file which contains return type,
943 delarator name, and argment names and types of the
944 function to be inlined.
945 (2) Reading that file into a buffer which can then be
946 made to look line another piece of inline code to
947 process, stuffing that on the top of the inline
948 stack, then letting the lexer and parser read from those
952 static struct pending_inline
*
953 stash_inline_prefix (cname
, field
)
957 struct pending_inline
*t
;
958 tree name
, fndecl
, fntype
;
960 inline_buffer
= (char *)alloca (MAX_INLINE_BUF_SIZE
+ 4);
963 name
= DECL_ORIGINAL_NAME (field
);
964 /* We still don't do friends right. */
966 fntype
= TREE_TYPE (fndecl
);
968 if (TREE_INLINE (fndecl
))
969 strcpy (inline_buffer
, "inline ");
971 strcpy (inline_buffer
, "static ");
972 inline_bufp
= inline_buffer
+ strlen (inline_buffer
);
973 if (! OPERATOR_TYPENAME_P (name
))
974 dump_type_prefix (TREE_TYPE (fntype
), &p
);
975 if (TREE_CODE (fntype
) == METHOD_TYPE
)
977 dump_type (cname
, &p
);
978 inline_bufp
[-1] = ':';
979 *inline_bufp
++ = ':';
980 if (DESTRUCTOR_NAME_P (DECL_NAME (fndecl
)))
983 else if (WRAPPER_NAME_P (DECL_NAME (fndecl
)))
985 else if (WRAPPER_PRED_NAME_P (DECL_NAME (fndecl
)))
987 else if (ANTI_WRAPPER_NAME_P (DECL_NAME (fndecl
)))
993 if (! DESTRUCTOR_NAME_P (DECL_NAME (fndecl
)))
995 tree parmlist
= DECL_ARGUMENTS (fndecl
);
996 tree typelist
= TYPE_ARG_TYPES (fntype
);
998 if (TREE_CODE (field
) == FIELD_DECL
)
1000 parmlist
= TREE_CHAIN (parmlist
);
1001 typelist
= TREE_CHAIN (typelist
);
1007 dump_decl (parmlist
);
1009 if (TREE_PURPOSE (typelist
))
1011 inline_errp
= inline_bufp
;
1013 dump_init (TREE_PURPOSE (typelist
));
1015 if (*inline_errp
== '\0')
1016 inline_bufp
= inline_errp
;
1019 if (TREE_CHAIN (parmlist
))
1021 parmlist
= TREE_CHAIN (parmlist
);
1022 typelist
= TREE_CHAIN (typelist
);
1025 if (!typelist
|| typelist
!= void_list_node
)
1030 if (! OPERATOR_TYPENAME_P (name
))
1031 dump_type_suffix (TREE_TYPE (fntype
), &p
);
1032 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1033 dump_readonly_or_volatile (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))));
1035 extern tree value_identifier
;
1037 if (DECL_RESULT (fndecl
) != value_identifier
)
1039 tree result
= DECL_RESULT (fndecl
);
1041 OB_PUTS ("return ");
1042 OB_PUTS (IDENTIFIER_POINTER (DECL_NAME (result
)));
1043 if (DECL_INITIAL (result
))
1046 dump_init (DECL_INITIAL (result
));
1052 check_text_len (inline_bufp
);
1054 t
= (struct pending_inline
*)xmalloc (sizeof (struct pending_inline
));
1055 t
->len
= inline_bufp
- inline_buffer
;
1056 t
->buf
= (char *)xmalloc (t
->len
);
1057 bcopy (inline_buffer
, t
->buf
, t
->len
);
1059 t
->filename
= input_filename
;
1065 #define OVERLOAD_MAX_LEN 1024
1067 /* Pretty printing for announce_function. If BUF is nonzero, then
1068 the text is written there. The buffer is assued to be of size
1069 OVERLOAD_MAX_LEN. CNAME is the name of the class that FNDECL
1070 belongs to, if we could not figure that out from FNDECL
1071 itself. FNDECL is the declaration of the function we
1072 are interested in seeing. PRINT_RET_TYPE_P is non-zero if
1073 we should print the type that this function returns. */
1075 fndecl_as_string (buf
, cname
, fndecl
, print_ret_type_p
)
1078 int print_ret_type_p
;
1080 tree name
= DECL_NAME (fndecl
);
1081 tree fntype
= TREE_TYPE (fndecl
);
1082 tree parmtypes
= TYPE_ARG_TYPES (fntype
);
1086 inline_buffer
= buf
;
1089 if (DECL_STATIC_FUNCTION_P (fndecl
))
1090 cname
= TYPE_NAME (DECL_STATIC_CONTEXT (fndecl
));
1091 else if (! cname
&& TREE_CODE (fntype
) == METHOD_TYPE
)
1092 cname
= TYPE_NAME (TYPE_METHOD_BASETYPE (fntype
));
1094 if (print_ret_type_p
&& ! OPERATOR_TYPENAME_P (name
))
1095 dump_type_prefix (TREE_TYPE (fntype
), &p
);
1096 if (DECL_STATIC_FUNCTION_P (fndecl
))
1097 OB_PUTS ("static ");
1101 dump_type (cname
, &p
);
1102 inline_bufp
[-1] = ':';
1103 *inline_bufp
++ = ':';
1104 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
1105 parmtypes
= TREE_CHAIN (parmtypes
);
1106 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
1107 parmtypes
= TREE_CHAIN (parmtypes
);
1110 if (DESTRUCTOR_NAME_P (name
))
1113 parmtypes
= TREE_CHAIN (parmtypes
);
1114 dump_decl (DECL_ORIGINAL_NAME (fndecl
));
1116 else if (OPERATOR_NAME_P (name
))
1118 sprintf (inline_bufp
, "operator %s ", operator_name_string (name
));
1119 inline_bufp
+= strlen (inline_bufp
);
1121 else if (OPERATOR_TYPENAME_P (name
))
1123 /* This cannot use the hack that the operator's return
1124 type is stashed off of its name because it may be
1125 used for error reporting. In the case of conflicting
1126 declarations, both will have the same name, yet
1127 the types will be different, hence the TREE_TYPE field
1128 of the first name will be clobbered by the second. */
1129 OB_PUTS ("operator ");
1130 dump_type (TREE_TYPE (TREE_TYPE (fndecl
)), &p
);
1132 else if (DECL_CONSTRUCTOR_P (fndecl
))
1135 if (TYPE_DYNAMIC (TREE_TYPE (TREE_TYPE (DECL_ORIGINAL_NAME (fndecl
)))))
1137 OB_PUTS ("dynamic ");
1138 parmtypes
= TREE_CHAIN (parmtypes
);
1141 dump_decl (DECL_ORIGINAL_NAME (fndecl
));
1142 /* Skip past "in_charge" identifier. */
1143 if (TYPE_USES_VIRTUAL_BASECLASSES (TREE_TYPE (cname
)))
1144 parmtypes
= TREE_CHAIN (parmtypes
);
1149 if (WRAPPER_NAME_P (name
))
1150 OB_PUTC2 ('(', ')');
1151 if (WRAPPER_PRED_NAME_P (name
))
1153 else if (ANTI_WRAPPER_NAME_P (name
))
1156 dump_decl (DECL_ORIGINAL_NAME (fndecl
));
1163 if (parmtypes
!= void_list_node
)
1165 while (parmtypes
&& parmtypes
!= void_list_node
)
1167 dump_type (TREE_VALUE (parmtypes
), &p
);
1168 while (inline_bufp
[-1] == ' ')
1170 if (TREE_PURPOSE (parmtypes
))
1172 inline_errp
= inline_bufp
;
1174 dump_init (TREE_PURPOSE (parmtypes
));
1177 OB_PUTC2 (',', ' ');
1178 parmtypes
= TREE_CHAIN (parmtypes
);
1184 inline_bufp
-= spaces
;
1190 if (print_ret_type_p
&& ! OPERATOR_TYPENAME_P (name
))
1191 dump_type_suffix (TREE_TYPE (fntype
), &p
);
1193 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1194 dump_readonly_or_volatile (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))));
1197 check_text_len (inline_bufp
);
1199 if (strlen (buf
) >= OVERLOAD_MAX_LEN
)
1201 fprintf (stderr
, "fndecl_as_string returns something too large");
1210 type_as_string (buf
, typ
)
1217 inline_buffer
= buf
;
1229 /* Move inline function defintions out of structure so that they
1230 can be processed normally. CNAME is the name of the class
1231 we are working from, METHOD_LIST is the list of method lists
1232 of the structure. We delete friend methods here, after
1233 saving away their inline function definitions (if any). */
1235 /* Subroutine of `do_inline_function_hair'. */
1237 prepare_inline (cname
, fndecl
)
1240 if (DECL_PENDING_INLINE_INFO (fndecl
))
1242 struct pending_inline
*t1
, *t2
;
1245 t2
= DECL_PENDING_INLINE_INFO (fndecl
);
1246 t2
->next
= pending_inlines
;
1247 t2
->fndecl
= fndecl
;
1248 args
= DECL_ARGUMENTS (fndecl
);
1251 DECL_CONTEXT (args
) = fndecl
;
1252 args
= TREE_CHAIN (args
);
1254 #ifdef DO_METHODS_THE_OLD_WAY
1255 t1
= stash_inline_prefix (cname
, methods
);
1260 pending_inlines
= t1
;
1262 /* Allow this decl to be seen in global scope */
1263 IDENTIFIER_GLOBAL_VALUE (DECL_NAME (fndecl
)) = fndecl
;
1268 do_inline_function_hair (type
, friend_list
)
1269 tree type
, friend_list
;
1271 tree cname
= DECL_NAME (TYPE_NAME (type
));
1272 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1273 if (method_vec
!= 0)
1275 tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1276 tree
*end
= TREE_VEC_END (method_vec
);
1277 while (methods
!= end
)
1279 /* Do inline member functions. */
1280 tree method
= *methods
;
1283 prepare_inline (cname
, method
);
1284 method
= TREE_CHAIN (method
);
1291 prepare_inline (NULL_TREE
, TREE_VALUE (friend_list
));
1292 friend_list
= TREE_CHAIN (friend_list
);
1296 /* Report a argument type mismatch between the best declared function
1297 we could find and the current argument list that we have. */
1299 report_type_mismatch (cp
, parmtypes
, name_kind
, err_name
)
1300 struct candidate
*cp
;
1302 char *name_kind
, *err_name
;
1304 char buf
[OVERLOAD_MAX_LEN
];
1305 int i
= cp
->u
.bad_arg
;
1310 if (TREE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes
))))
1311 error ("call to const %s `%s' with non-const object", name_kind
, err_name
);
1313 error ("call to non-const %s `%s' with const object", name_kind
, err_name
);
1318 error ("too few arguments for %s `%s'", name_kind
, err_name
);
1323 error ("too many arguments for %s `%s'", name_kind
, err_name
);
1328 if (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
1330 /* Happens when we have an ambiguous base class. */
1331 assert (get_base_type (DECL_CONTEXT (cp
->function
), TREE_TYPE (TREE_TYPE (TREE_VALUE (parmtypes
))), 1) == error_mark_node
);
1335 ttf
= TYPE_ARG_TYPES (TREE_TYPE (cp
->function
));
1340 ttf
= TREE_CHAIN (ttf
);
1341 tta
= TREE_CHAIN (tta
);
1343 fndecl_as_string (buf
, 0, cp
->function
, 0);
1344 inline_bufp
= inline_buffer
+ strlen (inline_buffer
) + 1;
1345 inline_buffer
= inline_bufp
;
1347 /* Reset `i' so that type printing routines do the right thing. */
1350 enum tree_code code
= TREE_CODE (TREE_TYPE (TREE_VALUE (tta
)));
1351 if (code
== ERROR_MARK
)
1352 OB_PUTS ("(failed type instatiation)");
1355 i
= (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
);
1356 dump_type (TREE_TYPE (TREE_VALUE (tta
)), &i
);
1359 else OB_PUTS ("void");
1362 sprintf (inline_bufp
, "bad argument %d for function `%s' (type was %s)",
1363 cp
->u
.bad_arg
- (TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
), buf
, inline_buffer
);
1364 strcpy (buf
, inline_bufp
);
1368 /* Here is where overload code starts. */
1370 #define OVERLOAD_MAX_LEN 1024
1372 /* Array of types seen so far in top-level call to `build_overload_name'.
1373 Allocated and deallocated by caller. */
1374 static tree
*typevec
;
1376 /* Number of types interned by `build_overload_name' so far. */
1379 /* Number of occurances of last type seen. */
1380 static int nrepeats
;
1382 /* Nonzero if we should not try folding parameter types. */
1385 #define ALLOCATE_TYPEVEC(PARMTYPES) \
1386 do { maxtype = 0, nrepeats = 0; \
1387 typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0)
1389 #define DEALLOCATE_TYPEVEC(PARMTYPES) \
1390 do { tree t = (PARMTYPES); \
1391 while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \
1394 /* Code to concatenate an asciified integer to a string,
1395 and return the end of the string. */
1410 s
= icat (s
, i
/ 10);
1411 *s
++ = '0' + (i
% 10);
1420 flush_repeats (s
, type
)
1427 while (typevec
[tindex
] != type
)
1433 s
= icat (s
, nrepeats
);
1440 rval
= icat (s
, tindex
);
1446 /* Given a list of parameters in PARMS, and a buffer in TEXT, of
1447 length LEN bytes, create an unambiguous overload string. Should
1448 distinguish any type that C (or C++) can distinguish. I.e.,
1449 pointers to functions are treated correctly.
1451 Caller must deal with whether a final `e' goes on the end or not.
1453 Any default conversions must take place before this function
1457 build_overload_name (parmtypes
, text
, text_end
)
1459 char *text
, *text_end
;
1465 if (just_one
= (TREE_CODE (parmtypes
) != TREE_LIST
))
1467 parmtype
= parmtypes
;
1473 if (text_end
- text
< 4)
1474 fatal ("Out of string space in build_overload_name!");
1475 parmtype
= TREE_VALUE (parmtypes
);
1482 /* Every argument gets counted. */
1483 typevec
[maxtype
++] = parmtype
;
1485 if (TREE_USED (parmtype
))
1487 if (! just_one
&& parmtype
== typevec
[maxtype
-2])
1492 textp
= flush_repeats (textp
, parmtype
);
1493 if (! just_one
&& TREE_CHAIN (parmtypes
)
1494 && parmtype
== TREE_VALUE (TREE_CHAIN (parmtypes
)))
1500 while (typevec
[tindex
] != parmtype
)
1503 textp
= icat (textp
, tindex
);
1511 textp
= flush_repeats (textp
, typevec
[maxtype
-2]);
1513 /* Only cache types which take more than one character. */
1514 && (parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
1515 || (TREE_CODE (parmtype
) != INTEGER_TYPE
1516 && TREE_CODE (parmtype
) != REAL_TYPE
)))
1517 TREE_USED (parmtype
) = 1;
1520 if (TREE_READONLY (parmtype
))
1522 if (TREE_CODE (parmtype
) == INTEGER_TYPE
&& TREE_UNSIGNED (parmtype
))
1524 if (TREE_VOLATILE (parmtype
))
1527 switch (TREE_CODE (parmtype
))
1531 textp
= build_overload_name (TYPE_OFFSET_BASETYPE (parmtype
), textp
, text_end
);
1533 textp
= build_overload_name (TREE_TYPE (parmtype
), textp
, text_end
);
1536 case REFERENCE_TYPE
:
1541 #ifdef PARM_CAN_BE_ARRAY_TYPE
1546 length
= array_type_nelts (parmtype
);
1547 if (TREE_CODE (length
) == INTEGER_CST
)
1548 textp
= icat (textp
, TREE_INT_CST_LOW (length
));
1560 textp
= build_overload_name (TREE_TYPE (parmtype
), textp
, text_end
);
1566 tree firstarg
= TYPE_ARG_TYPES (parmtype
);
1567 /* Otherwise have to implement reentrant typevecs,
1568 unmark and remark types, etc. */
1569 int old_nofold
= nofold
;
1573 textp
= flush_repeats (textp
, typevec
[maxtype
-1]);
1575 /* @@ It may be possible to pass a function type in
1576 which is not preceded by a 'P'. */
1577 if (TREE_CODE (parmtype
) == FUNCTION_TYPE
)
1580 if (firstarg
== NULL_TREE
)
1582 else if (firstarg
== void_list_node
)
1585 textp
= build_overload_name (firstarg
, textp
, text_end
);
1589 int constp
= TREE_READONLY (TREE_TYPE (TREE_VALUE (firstarg
)));
1590 int volatilep
= TREE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg
)));
1592 firstarg
= TREE_CHAIN (firstarg
);
1594 textp
= build_overload_name (TYPE_METHOD_BASETYPE (parmtype
), textp
, text_end
);
1600 /* For cfront 2.0 compatability. */
1603 if (firstarg
== NULL_TREE
)
1605 else if (firstarg
== void_list_node
)
1608 textp
= build_overload_name (firstarg
, textp
, text_end
);
1611 /* Separate args from return type. */
1613 textp
= build_overload_name (TREE_TYPE (parmtype
), textp
, text_end
);
1614 nofold
= old_nofold
;
1619 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1620 switch (TYPE_MODE (parmtype
))
1623 if (parmtype
== long_integer_type_node
1624 || parmtype
== long_unsigned_type_node
)
1630 if (parmtype
== long_integer_type_node
1631 || parmtype
== long_unsigned_type_node
)
1633 else if (parmtype
== integer_type_node
1634 || parmtype
== unsigned_type_node
)
1636 else if (parmtype
== short_integer_type_node
1637 || parmtype
== short_unsigned_type_node
)
1643 if (parmtype
== long_integer_type_node
1644 || parmtype
== long_unsigned_type_node
)
1646 else if (parmtype
== short_integer_type_node
1647 || parmtype
== short_unsigned_type_node
)
1653 if (parmtype
== integer_type_node
1654 || parmtype
== unsigned_type_node
)
1668 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1669 if (parmtype
== long_double_type_node
)
1671 else if (parmtype
== double_type_node
)
1673 else if (parmtype
== float_type_node
)
1682 extern tree void_list_node
;
1684 /* See if anybody is wasting memory. */
1685 assert (parmtypes
== void_list_node
);
1687 /* This is the end of a parameter list. */
1694 case ERROR_MARK
: /* not right, but nothing is anyway */
1697 /* have to do these */
1701 /* Make this type signature look incompatible
1708 tree name
= TYPE_NAME (parmtype
);
1709 if (TREE_CODE (name
) == TYPE_DECL
)
1710 name
= DECL_NAME (name
);
1711 assert (TREE_CODE (name
) == IDENTIFIER_NODE
);
1712 textp
= icat (textp
, IDENTIFIER_LENGTH (name
));
1713 strcpy (textp
, IDENTIFIER_POINTER (name
));
1714 textp
+= IDENTIFIER_LENGTH (name
);
1719 /* This will take some work. */
1728 if (just_one
) break;
1729 parmtypes
= TREE_CHAIN (parmtypes
);
1734 textp
= flush_repeats (textp
, typevec
[maxtype
-1]);
1736 /* To get here, parms must end with `...'. */
1744 /* Change the name of a function definition so that it may be
1745 overloaded. NAME is the name of the function to overload,
1746 PARMS is the parameter list (which determines what name the
1747 final function obtains).
1749 FOR_METHOD is 1 if this overload is being performed
1750 for a method, rather than a function type. It is 2 if
1751 this overload is being performed for a constructor. */
1753 build_decl_overload (name
, parms
, for_method
)
1759 char tname
[OVERLOAD_MAX_LEN
];
1761 if (for_method
== 2)
1762 /* We can divine that this is a constructor,
1763 and figure out its name without any extra encoding. */
1767 strcpy (tname
, name
);
1768 tmp
= strlen (tname
);
1775 /* We can get away without doing this. */
1778 parms
= temp_tree_cons (NULL_TREE
, TREE_TYPE (TREE_VALUE (parms
)), TREE_CHAIN (parms
));
1783 if (parms
== NULL_TREE
)
1784 tname
[tmp
++] = 'e', tname
[tmp
] = '\0';
1785 else if (parms
== void_list_node
)
1786 tname
[tmp
++] = 'v', tname
[tmp
] = '\0';
1789 ALLOCATE_TYPEVEC (parms
);
1793 tmp
= build_overload_name (TREE_VALUE (parms
), tname
+tmp
, &tname
[OVERLOAD_MAX_LEN
]) - tname
;
1796 typevec
[maxtype
++] = TREE_VALUE (parms
);
1797 TREE_USED (TREE_VALUE (parms
)) = 1;
1800 if (TREE_CHAIN (parms
))
1801 build_overload_name (TREE_CHAIN (parms
), tname
+tmp
, &tname
[OVERLOAD_MAX_LEN
]);
1809 build_overload_name (parms
, tname
+tmp
, &tname
[OVERLOAD_MAX_LEN
]);
1810 DEALLOCATE_TYPEVEC (parms
);
1812 return get_identifier (tname
);
1815 /* Build an overload name for the type expression TYPE. */
1817 build_typename_overload (type
)
1820 char tname
[OVERLOAD_MAX_LEN
];
1821 int i
= sizeof (OPERATOR_TYPENAME_FORMAT
) - 1;
1822 sprintf (tname
, OPERATOR_TYPENAME_FORMAT
);
1824 /* We can get away without doing this--it really gets
1825 overloaded later. */
1831 build_overload_name (type
, tname
+ i
, &tname
[OVERLOAD_MAX_LEN
]);
1832 return get_identifier (tname
);
1835 /* Top-level interface to explicit overload requests. Allow NAME
1836 to be overloaded. Error if NAME is already declared for the current
1837 scope. Warning if function is redundanly overloaded. */
1840 declare_overloaded (name
)
1843 #ifdef NO_AUTO_OVERLOAD
1844 if (is_overloaded (name
))
1845 warning ("function `%s' already declared overloaded",
1846 IDENTIFIER_POINTER (name
));
1847 else if (IDENTIFIER_GLOBAL_VALUE (name
))
1848 error ("overloading function `%s' that is already defined",
1849 IDENTIFIER_POINTER (name
));
1852 TREE_OVERLOADED (name
) = 1;
1853 IDENTIFIER_GLOBAL_VALUE (name
) = build_tree_list (name
, NULL_TREE
);
1854 TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name
)) = unknown_type_node
;
1857 if (current_lang_name
== lang_name_cplusplus
)
1860 warning ("functions are implicitly overloaded in C++");
1862 else if (current_lang_name
== lang_name_c
)
1863 error ("overloading function `%s' cannot be done in C language context");
1869 #ifdef NO_AUTO_OVERLOAD
1870 /* Check to see if NAME is overloaded. For first approximation,
1871 check to see if its TREE_OVERLOADED is set. This is used on
1872 IDENTIFIER nodes. */
1874 is_overloaded (name
)
1878 return (TREE_OVERLOADED (name
)
1879 && (! IDENTIFIER_CLASS_VALUE (name
) || current_class_type
== 0)
1880 && ! IDENTIFIER_LOCAL_VALUE (name
));
1884 /* Given a tree_code CODE, and some arguments (at least one),
1885 attempt to use an overloaded operator on the arguments.
1887 For unary operators, only the first argument need be checked.
1888 For binary operators, both arguments may need to be checked.
1890 Member functions can convert class references to class pointers,
1891 for one-level deep indirection. More than that is not supported.
1892 Operators [](), ()(), and ->() must be member functions.
1894 We call function call building calls with nonzero complain if
1895 they are our only hope. This is true when we see a vanilla operator
1896 applied to something of aggregate type. If this fails, we are free to
1897 return `error_mark_node', because we will have reported the error.
1899 Operators NEW and DELETE overload in funny ways: operator new takes
1900 a single `size' parameter, and operator delete takes a pointer to the
1901 storage being deleted. When overloading these operators, success is
1902 assumed. If there is a failure, report an error message and return
1903 `error_mark_node'. */
1907 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1908 enum tree_code code
;
1914 tree type1
, type2
, fnname
;
1915 tree fields1
= 0, parms
= 0;
1918 int binary_is_unary
;
1920 if (xarg1
== error_mark_node
)
1921 return error_mark_node
;
1923 if (code
== COND_EXPR
)
1925 if (TREE_CODE (xarg2
) == ERROR_MARK
1926 || TREE_CODE (arg3
) == ERROR_MARK
)
1927 return error_mark_node
;
1929 if (code
== COMPONENT_REF
)
1930 if (TREE_CODE (TREE_TYPE (xarg1
)) == POINTER_TYPE
)
1933 /* First, see if we can work with the first argument */
1934 type1
= TREE_TYPE (xarg1
);
1936 /* Some tree codes have length > 1, but we really only want to
1937 overload them if their first argument has a user defined type. */
1940 case PREINCREMENT_EXPR
:
1941 code
= POSTINCREMENT_EXPR
;
1942 binary_is_unary
= 1;
1946 case POSTDECREMENT_EXPR
:
1947 code
= PREDECREMENT_EXPR
;
1948 binary_is_unary
= 1;
1952 case PREDECREMENT_EXPR
:
1953 case POSTINCREMENT_EXPR
:
1955 binary_is_unary
= 1;
1959 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1960 If they do not, return error_mark_node instead of NULL_TREE. */
1962 if (xarg2
== error_mark_node
)
1963 return error_mark_node
;
1965 rval
= error_mark_node
;
1966 binary_is_unary
= 0;
1972 /* For operators `new' (`delete'), only check visibility
1973 if we are in a constructor (destructor), and we are
1974 allocating for that constructor's (destructor's) type. */
1976 fnname
= get_identifier (OPERATOR_NEW_FORMAT
);
1977 if (flags
& LOOKUP_GLOBAL
)
1978 return build_overload_call (fnname
, tree_cons (NULL_TREE
, xarg2
, arg3
),
1979 flags
& LOOKUP_COMPLAIN
, 0);
1981 if (current_function_decl
== NULL_TREE
1982 || !DECL_CONSTRUCTOR_P (current_function_decl
)
1983 || current_class_type
!= TYPE_MAIN_VARIANT (type1
))
1984 flags
= LOOKUP_COMPLAIN
;
1985 rval
= build_method_call (build1 (NOP_EXPR
, xarg1
, error_mark_node
),
1986 fnname
, tree_cons (NULL_TREE
, xarg2
, arg3
),
1988 if (rval
== error_mark_node
)
1989 /* User might declare fancy operator new, but invoke it
1990 like standard one. */
1993 TREE_TYPE (rval
) = xarg1
;
1994 TREE_CALLS_NEW (rval
) = 1;
2001 /* See comment above. */
2003 fnname
= get_identifier (OPERATOR_DELETE_FORMAT
);
2004 if (flags
& LOOKUP_GLOBAL
)
2005 return build_overload_call (fnname
, build_tree_list (NULL_TREE
, xarg1
),
2006 flags
& LOOKUP_COMPLAIN
, 0);
2008 if (current_function_decl
== NULL_TREE
2009 || !DESTRUCTOR_NAME_P (DECL_NAME (current_function_decl
))
2010 || current_class_type
!= TYPE_MAIN_VARIANT (type1
))
2011 flags
= LOOKUP_COMPLAIN
;
2012 rval
= build_method_call (build1 (NOP_EXPR
, TREE_TYPE (xarg1
), error_mark_node
),
2013 fnname
, build_tree_list (NULL_TREE
, xarg1
),
2015 /* This happens when the user mis-declares `operator delete'.
2016 Should now be impossible. */
2017 assert (rval
!= error_mark_node
);
2018 TREE_TYPE (rval
) = void_type_node
;
2024 binary_is_unary
= 0;
2025 try_second
= tree_code_length
[(int) code
] == 2;
2026 if (xarg2
== error_mark_node
)
2027 return error_mark_node
;
2031 if (try_second
&& xarg2
== error_mark_node
)
2032 return error_mark_node
;
2034 /* What ever it was, we do not know how to deal with it. */
2035 if (type1
== NULL_TREE
)
2038 if (TREE_CODE (type1
) == OFFSET_TYPE
)
2039 type1
= TREE_TYPE (type1
);
2041 if (TREE_CODE (type1
) == REFERENCE_TYPE
)
2043 arg1
= convert_from_reference (xarg1
);
2044 type1
= TREE_TYPE (arg1
);
2051 if (!IS_AGGR_TYPE (type1
))
2053 /* Try to fail. First, fail if unary */
2056 /* Second, see if second argument is non-aggregate. */
2057 type2
= TREE_TYPE (xarg2
);
2058 if (TREE_CODE (type2
) == OFFSET_TYPE
)
2059 type2
= TREE_TYPE (type2
);
2060 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
2062 arg2
= convert_from_reference (xarg2
);
2063 type2
= TREE_TYPE (arg2
);
2070 if (!IS_AGGR_TYPE (type2
))
2077 /* First arg may succeed; see whether second should. */
2078 type2
= TREE_TYPE (xarg2
);
2079 if (TREE_CODE (type2
) == OFFSET_TYPE
)
2080 type2
= TREE_TYPE (type2
);
2081 if (TREE_CODE (type2
) == REFERENCE_TYPE
)
2083 arg2
= convert_from_reference (xarg2
);
2084 type2
= TREE_TYPE (arg2
);
2091 if (! IS_AGGR_TYPE (type2
))
2095 if (type1
== unknown_type_node
2096 || (try_second
&& TREE_TYPE (xarg2
) == unknown_type_node
))
2098 /* This will not be implemented in the forseeable future. */
2102 if (code
== MODIFY_EXPR
)
2104 tree op_id
= build_opid (MODIFY_EXPR
, arg3
);
2105 fnname
= build_operator_fnname (&op_id
, 0, 2);
2109 tree op_id
= build_opid (0, code
);
2110 if (binary_is_unary
)
2111 fnname
= build_operator_fnname (&op_id
, 0, 1);
2113 fnname
= build_operator_fnname (&op_id
, 0,
2114 tree_code_length
[(int) code
]);
2117 global_fn
= IDENTIFIER_GLOBAL_VALUE (fnname
);
2119 /* This is the last point where we will accept failure. This
2120 may be too eager if we wish an overloaded operator not to match,
2121 but would rather a normal operator be called on a type-converted
2124 if (IS_AGGR_TYPE (type1
))
2125 fields1
= lookup_fnfields (CLASSTYPE_AS_LIST (type1
), fnname
, 0);
2127 if (fields1
== NULL_TREE
&& global_fn
== NULL_TREE
)
2130 /* If RVAL winds up being `error_mark_node', we will return
2131 that... There is no way that normal semantics of these
2132 operators will succeed. */
2134 /* This argument may be an uncommited OFFSET_REF. This is
2135 the case for example when dealing with static class members
2136 which are referenced from their class name rather than
2137 from a class instance. */
2138 if (TREE_CODE (xarg1
) == OFFSET_REF
2139 && TREE_CODE (TREE_OPERAND (xarg1
, 1)) == VAR_DECL
)
2140 xarg1
= TREE_OPERAND (xarg1
, 1);
2141 if (try_second
&& xarg2
&& TREE_CODE (xarg2
) == OFFSET_REF
2142 && TREE_CODE (TREE_OPERAND (xarg2
, 1)) == VAR_DECL
)
2143 xarg2
= TREE_OPERAND (xarg2
, 1);
2146 flags
|= LOOKUP_GLOBAL
;
2148 if (code
== CALL_EXPR
)
2150 /* This can only be a member function. */
2151 return build_method_call (xarg1
, fnname
, xarg2
,
2152 NULL_TREE
, LOOKUP_NORMAL
);
2154 else if (tree_code_length
[(int) code
] == 1 || binary_is_unary
)
2157 rval
= build_method_call (xarg1
, fnname
, NULL_TREE
, NULL_TREE
, flags
);
2159 else if (code
== COND_EXPR
)
2161 parms
= tree_cons (0, xarg2
, build_tree_list (0, arg3
));
2162 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
2164 else if (code
== METHOD_CALL_EXPR
)
2166 /* must be a member function. */
2167 parms
= tree_cons (NULL_TREE
, xarg2
, arg3
);
2168 return build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, LOOKUP_NORMAL
);
2172 parms
= build_tree_list (NULL_TREE
, xarg2
);
2173 rval
= build_method_call (xarg1
, fnname
, parms
, NULL_TREE
, flags
);
2177 parms
= tree_cons (NULL_TREE
, xarg1
,
2178 build_tree_list (NULL_TREE
, xarg2
));
2179 rval
= build_overload_call (fnname
, parms
, flags
& LOOKUP_COMPLAIN
, 0);
2182 /* If we did not win, do not lose yet, since type conversion may work. */
2183 if (TREE_CODE (rval
) == ERROR_MARK
)
2185 if (flags
& LOOKUP_COMPLAIN
)
2193 /* This function takes an identifier, ID, and attempts to figure out what
2194 it means. There are a number of possible scenarios, presented in increasing
2197 1) not in a class's scope
2198 2) in class's scope, member name of the class's method
2199 3) in class's scope, but not a member name of the class
2200 4) in class's scope, member name of a class's variable
2202 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
2203 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
2204 yychar is the pending input character (suitably encoded :-).
2206 As a last ditch, try to look up the name as a label and return that
2209 Values which are declared as being of REFERENCE_TYPE are
2210 automatically dereferenced here (as a hack to make the
2211 compiler faster). */
2214 hack_identifier (value
, name
, yychar
)
2219 if (TREE_CODE (value
) == ERROR_MARK
)
2221 if (current_class_name
)
2223 tree fields
= lookup_fnfields (CLASSTYPE_AS_LIST (current_class_type
), name
, 0);
2226 fields
= TREE_VALUE (fields
);
2227 assert (TREE_CODE (fields
) == FUNCTION_DECL
);
2228 if (TREE_CHAIN (fields
) == NULL_TREE
)
2230 warning ("methods cannot be converted to function pointers");
2235 error ("ambiguous request for method pointer `%s'",
2236 IDENTIFIER_POINTER (name
));
2237 return error_mark_node
;
2241 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
2243 return IDENTIFIER_LABEL_VALUE (name
);
2245 return error_mark_node
;
2248 type
= TREE_TYPE (value
);
2249 if (TREE_NONLOCAL (value
))
2251 if (TREE_CODE (value
) == FIELD_DECL
)
2253 if (current_class_decl
== NULL_TREE
)
2255 error ("request for member `%s' in static member function",
2256 IDENTIFIER_POINTER (DECL_NAME (value
)));
2257 return error_mark_node
;
2259 TREE_USED (current_class_decl
) = 1;
2261 if (! ((TYPE_LANG_SPECIFIC (type
)
2262 && TYPE_OVERLOADS_CALL_EXPR (type
))
2263 || (TREE_CODE (type
) == REFERENCE_TYPE
2264 && TYPE_LANG_SPECIFIC (TREE_TYPE (type
))
2265 && TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (type
))))
2266 && TREE_CODE (type
) != FUNCTION_TYPE
2267 && TREE_CODE (type
) != METHOD_TYPE
2268 && (TREE_CODE (type
) != POINTER_TYPE
2269 || (TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
2270 && TREE_CODE (TREE_TYPE (type
)) != METHOD_TYPE
)))
2272 error ("component `%s' is not a method",
2273 IDENTIFIER_POINTER (name
));
2274 return error_mark_node
;
2276 /* Mark so that if we are in a constructor, and then find that
2277 this field was initialized by a base initializer,
2278 we can emit an error message. */
2279 TREE_USED (value
) = 1;
2280 return build_component_ref (C_C_D
, name
, 0, 1);
2282 if (DECL_CONTEXT (value
) != current_class_type
2283 && (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == CONST_DECL
))
2286 enum visibility_type visibility
;
2288 get_base_distance (DECL_CONTEXT (value
), current_class_type
, 0, &path
);
2289 visibility
= compute_visibility (path
, value
);
2290 if (visibility
!= visibility_public
)
2292 if (TREE_CODE (value
) == VAR_DECL
)
2293 error ("static member `%s' is from private base class",
2294 IDENTIFIER_POINTER (name
));
2296 error ("enum `%s' is from private base class",
2297 IDENTIFIER_POINTER (name
));
2298 return error_mark_node
;
2301 else if (TREE_CODE (value
) == TREE_LIST
&& type
== 0)
2303 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2304 IDENTIFIER_POINTER (name
));
2305 return error_mark_node
;
2311 if (! TREE_USED (value
))
2313 if (TREE_EXTERNAL (value
))
2314 assemble_external (value
);
2315 TREE_USED (value
) = 1;
2317 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2319 assert (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
2320 || TREE_CODE (value
) == RESULT_DECL
);
2321 if (DECL_REFERENCE_SLOT (value
))
2322 return DECL_REFERENCE_SLOT (value
);
2331 if (op
== NULL_TREE
)
2332 return error_mark_node
;
2334 if (TREE_CODE (op
) != TYPE_EXPR
)
2335 return grokopexpr (&op
, NULL_TREE
, 0, 0, 0);
2340 /* NONWRAPPER is nonzero if this call is not to be wrapped.
2341 TYPE is the type that the wrapper belongs to (in case
2342 it should be non-virtual).
2343 DECL is the function will will be (not be) wrapped. */
2345 hack_wrapper (nonwrapper
, type
, decl
)
2349 if (type
== NULL_TREE
|| is_aggr_typedef (type
, 1))
2352 type
= TREE_TYPE (type
);
2357 return build_nt (WRAPPER_EXPR
, type
, decl
);
2359 return build_nt (ANTI_WRAPPER_EXPR
, type
, decl
);
2361 return build_nt (WRAPPER_EXPR
, type
,
2362 build_nt (COND_EXPR
, decl
, NULL_TREE
, NULL_TREE
));
2364 assert (0 <= nonwrapper
&& nonwrapper
<= 2);
2367 return error_mark_node
;
2370 /* Return an IDENTIFIER which can be used as a name for
2371 anonymous structs and unions. */
2378 sprintf (buf
, ANON_AGGRNAME_FORMAT
, cnt
++);
2379 return get_identifier (buf
);
2382 /* Given an object OF, and a type conversion operator COMPONENT
2383 build a call to the conversion operator, if a call is requested,
2384 or return the address (as a pointer to member function) if one is not.
2386 OF can be a TYPE_DECL or any kind of datum that would normally
2387 be passed to `build_component_ref'. It may also be NULL_TREE,
2388 in which case `current_class_type' and `current_class_decl'
2389 provide default values.
2391 BASETYPE_PATH, if non-null, is the path of basetypes
2392 to go through before we get the the instance of interest.
2394 PROTECT says whether we apply C++ scoping rules or not. */
2396 build_component_type_expr (of
, component
, basetype_path
, protect
)
2397 tree of
, component
, basetype_path
;
2400 tree cname
= NULL_TREE
;
2403 int flags
= protect
? LOOKUP_NORMAL
: LOOKUP_COMPLAIN
;
2405 assert (IS_AGGR_TYPE (TREE_TYPE (of
)));
2406 assert (TREE_CODE (component
) == TYPE_EXPR
);
2408 tmp
= TREE_OPERAND (component
, 0);
2413 switch (TREE_CODE (tmp
))
2417 TREE_OPERAND (last
, 0) = TREE_OPERAND (tmp
, 0);
2419 TREE_OPERAND (component
, 0) = TREE_OPERAND (tmp
, 0);
2420 if (TREE_OPERAND (tmp
, 0)
2421 && TREE_OPERAND (tmp
, 0) != void_list_node
)
2423 error ("operator <typename> requires empty parameter list");
2424 TREE_OPERAND (tmp
, 0) = NULL_TREE
;
2426 last
= groktypename (build_tree_list (TREE_TYPE (component
),
2427 TREE_OPERAND (component
, 0)));
2428 name
= build_typename_overload (last
);
2429 TREE_TYPE (name
) = last
;
2431 if (of
&& TREE_CODE (of
) != TYPE_DECL
)
2432 return build_method_call (of
, name
, NULL_TREE
, NULL_TREE
, flags
);
2437 if (current_class_decl
== NULL_TREE
)
2439 error ("object required for `operator <typename>' call");
2440 return error_mark_node
;
2443 this_this
= convert_pointer_to (TREE_TYPE (of
), current_class_decl
);
2444 return build_method_call (this_this
, name
, NULL_TREE
,
2445 NULL_TREE
, flags
| LOOKUP_NONVIRTUAL
);
2447 else if (current_class_decl
)
2448 return build_method_call (tmp
, name
, NULL_TREE
, NULL_TREE
, flags
);
2450 error ("object required for `operator <typename>' call");
2451 return error_mark_node
;
2459 assert (cname
== 0);
2460 cname
= TREE_OPERAND (tmp
, 0);
2461 tmp
= TREE_OPERAND (tmp
, 1);
2468 tmp
= TREE_OPERAND (tmp
, 0);
2471 last
= groktypename (build_tree_list (TREE_TYPE (component
), TREE_OPERAND (component
, 0)));
2472 name
= build_typename_overload (last
);
2473 TREE_TYPE (name
) = last
;
2474 if (of
&& TREE_CODE (of
) == TYPE_DECL
)
2476 if (cname
== NULL_TREE
)
2478 cname
= DECL_NAME (of
);
2481 else assert (cname
== DECL_NAME (of
));
2488 if (current_class_decl
== NULL_TREE
)
2490 error ("object required for `operator <typename>' call");
2491 return error_mark_node
;
2494 this_this
= convert_pointer_to (TREE_TYPE (of
), current_class_decl
);
2495 return build_component_ref (this_this
, name
, 0, protect
);
2498 return build_offset_ref (cname
, name
);
2499 else if (current_class_name
)
2500 return build_offset_ref (current_class_name
, name
);
2502 error ("object required for `operator <typename>' member reference");
2503 return error_mark_node
;