No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / usr.bin / g++ / cc1plus / cplus-method.c
blob70b19410cec81856e3a9c7e9394bc4717685b44a
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)
11 any later version.
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. */
24 #include <stdio.h>
25 #include "config.h"
26 #include "tree.h"
27 #include "cplus-tree.h"
28 #include "assert.h"
30 /* TREE_LIST of the current inline functions that need to be
31 processed. */
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
57 int is_overloaded ();
58 #endif
60 void
61 init_method ()
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. */
75 static char *
76 new_text_len (s)
77 char *s;
79 while (*s++) ;
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);
84 abort ();
86 return s - 1;
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. */
92 static void
93 check_text_len (s)
94 char *s;
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);
99 abort ();
103 tree
104 make_anon_parm_name ()
106 char buf[32];
108 sprintf (buf, ANON_PARMNAME_FORMAT, dummy_name++);
109 return get_identifier (buf);
112 void
113 clear_anon_parm_name ()
115 /* recycle these names. */
116 dummy_name = 0;
119 static void
120 dump_readonly_or_volatile (t)
121 tree t;
123 if (TREE_READONLY (t))
124 OB_PUTS ("const ");
125 if (TREE_VOLATILE (t))
126 OB_PUTS ("volatile ");
129 static void
130 dump_type_prefix (t, p)
131 tree t;
132 int *p;
134 int old_p = 0;
135 int print_struct = 1;
136 tree name;
138 if (t == NULL_TREE)
139 return;
141 switch (TREE_CODE (t))
143 case ERROR_MARK:
144 sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
145 break;
147 case UNKNOWN_TYPE:
148 OB_PUTS ("<unknown type>");
149 return;
151 case TREE_LIST:
152 dump_type (TREE_VALUE (t), &old_p);
153 if (TREE_CHAIN (t))
155 if (TREE_CHAIN (t) != void_list_node)
157 OB_PUTC (',');
158 dump_type (TREE_CHAIN (t), &old_p);
161 else OB_PUTS ("...");
162 return;
164 case POINTER_TYPE:
165 *p += 1;
166 dump_type_prefix (TREE_TYPE (t), p);
167 while (*p)
169 OB_PUTC ('*');
170 *p -= 1;
172 if (TREE_READONLY (t))
173 OB_PUTS ("const ");
174 if (TREE_VOLATILE (t))
175 OB_PUTS ("volatile ");
176 return;
178 case OFFSET_TYPE:
180 tree type = TREE_TYPE (t);
181 if (TREE_CODE (type) == FUNCTION_TYPE)
183 type = TREE_TYPE (type);
184 if (in_parmlist)
185 OB_PUTS ("auto ");
188 dump_type_prefix (type, &old_p);
190 OB_PUTC ('(');
191 dump_type (TYPE_OFFSET_BASETYPE (t), &old_p);
192 OB_PUTC2 (':', ':');
193 while (*p)
195 OB_PUTC ('*');
196 *p -= 1;
198 if (TREE_READONLY (t) | TREE_VOLATILE (t))
199 dump_readonly_or_volatile (t);
200 return;
203 case METHOD_TYPE:
205 tree type = TREE_TYPE (t);
206 if (in_parmlist)
207 OB_PUTS ("auto ");
209 dump_type_prefix (type, &old_p);
211 OB_PUTC ('(');
212 dump_type (TYPE_METHOD_BASETYPE (t), &old_p);
213 OB_PUTC2 (':', ':');
214 while (*p)
216 OB_PUTC ('*');
217 *p -= 1;
219 if (TREE_READONLY (t) | TREE_VOLATILE (t))
220 dump_readonly_or_volatile (t);
221 return;
224 case REFERENCE_TYPE:
225 dump_type_prefix (TREE_TYPE (t), p);
226 OB_PUTC ('&');
227 if (TREE_READONLY (t) | TREE_VOLATILE (t))
228 dump_readonly_or_volatile (t);
229 return;
231 case ARRAY_TYPE:
232 if (TREE_READONLY (t) | TREE_VOLATILE (t))
233 dump_readonly_or_volatile (t);
234 dump_type_prefix (TREE_TYPE (t), p);
235 return;
237 case FUNCTION_TYPE:
238 if (in_parmlist)
239 OB_PUTS ("auto ");
240 dump_type_prefix (TREE_TYPE (t), &old_p);
241 OB_PUTC ('(');
242 while (*p)
244 OB_PUTC ('*');
245 *p -= 1;
247 if (TREE_READONLY (t) | TREE_VOLATILE (t))
248 dump_readonly_or_volatile (t);
249 return;
251 case IDENTIFIER_NODE:
252 sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (t));
253 break;
255 case RECORD_TYPE:
256 if (TREE_READONLY (t))
257 OB_PUTS ("const ");
258 if (TREE_VOLATILE (t))
259 OB_PUTS ("volatile ");
260 if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
261 print_struct = 0;
262 name = TYPE_NAME (t);
263 if (TREE_CODE (name) == TYPE_DECL)
264 name = DECL_NAME (name);
265 if (print_struct)
266 sprintf (inline_bufp, "struct %s ", IDENTIFIER_POINTER (name));
267 else
268 sprintf (inline_bufp, "class %s ", IDENTIFIER_POINTER (name));
269 break;
271 case UNION_TYPE:
272 if (TREE_READONLY (t))
273 OB_PUTS ("const ");
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));
280 break;
282 case ENUMERAL_TYPE:
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));
289 break;
291 case TYPE_DECL:
292 if (TREE_READONLY (t))
293 OB_PUTS ("const ");
294 if (TREE_VOLATILE (t))
295 OB_PUTS ("volatile ");
296 sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (DECL_NAME (t)));
297 break;
299 case INTEGER_TYPE:
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 ");
305 /* fall through. */
306 case REAL_TYPE:
307 case VOID_TYPE:
308 if (TREE_READONLY (t))
309 OB_PUTS ("const ");
310 if (TREE_VOLATILE (t))
311 OB_PUTS ("volatile ");
312 sprintf (inline_bufp, "%s ", TYPE_NAME_STRING (t));
313 break;
315 default:
316 abort ();
318 inline_bufp = new_text_len (inline_bufp);
321 static void
322 dump_type_suffix (t, p)
323 tree t;
324 int *p;
326 int old_p = 0;
328 if (t == NULL_TREE)
329 return;
331 switch (TREE_CODE (t))
333 case ERROR_MARK:
334 sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
335 break;
337 case UNKNOWN_TYPE:
338 return;
340 case POINTER_TYPE:
341 dump_type_suffix (TREE_TYPE (t), p);
342 return;
344 case OFFSET_TYPE:
346 tree type = TREE_TYPE (t);
348 OB_PUTC (')');
349 if (TREE_CODE (type) == FUNCTION_TYPE)
351 #if 0
352 tree next_arg = TREE_CHAIN (TYPE_ARG_TYPES (type));
353 OB_PUTC ('(');
354 if (next_arg)
356 if (next_arg != void_list_node)
358 in_parmlist++;
359 dump_type (next_arg, &old_p);
360 in_parmlist--;
363 else OB_PUTS ("...");
364 OB_PUTC (')');
365 dump_type_suffix (TREE_TYPE (type), p);
366 #else
367 abort ();
368 #endif
370 return;
373 case METHOD_TYPE:
375 tree next_arg;
376 OB_PUTC (')');
377 next_arg = TREE_CHAIN (TYPE_ARG_TYPES (t));
378 OB_PUTC ('(');
379 if (next_arg)
381 if (next_arg != void_list_node)
383 in_parmlist++;
384 dump_type (next_arg, &old_p);
385 in_parmlist--;
388 else OB_PUTS ("...");
389 OB_PUTC (')');
390 dump_readonly_or_volatile (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
391 dump_type_suffix (TREE_TYPE (t), p);
392 return;
395 case REFERENCE_TYPE:
396 dump_type_suffix (TREE_TYPE (t), p);
397 return;
399 case ARRAY_TYPE:
400 dump_type_suffix (TREE_TYPE (t), p);
401 OB_PUTC2 ('[', ']');
402 return;
404 case FUNCTION_TYPE:
405 OB_PUTC2 (')', '(');
406 if (TYPE_ARG_TYPES (t) && TYPE_ARG_TYPES (t) != void_list_node)
408 in_parmlist++;
409 dump_type (TYPE_ARG_TYPES (t), &old_p);
410 in_parmlist--;
412 OB_PUTC (')');
413 dump_type_suffix (TREE_TYPE (t), p);
414 return;
416 case IDENTIFIER_NODE:
417 case RECORD_TYPE:
418 case UNION_TYPE:
419 case ENUMERAL_TYPE:
420 case TYPE_DECL:
421 case INTEGER_TYPE:
422 case REAL_TYPE:
423 case VOID_TYPE:
424 return;
426 default:
427 abort ();
429 inline_bufp = new_text_len (inline_bufp);
432 static void
433 dump_type (t, p)
434 tree t;
435 int *p;
437 int old_p = 0;
438 int print_struct = 1;
440 if (t == NULL_TREE)
441 return;
443 switch (TREE_CODE (t))
445 case ERROR_MARK:
446 sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
447 break;
449 case UNKNOWN_TYPE:
450 OB_PUTS ("<unknown type>");
451 return;
453 case TREE_LIST:
454 dump_type (TREE_VALUE (t), &old_p);
455 if (TREE_CHAIN (t))
457 if (TREE_CHAIN (t) != void_list_node)
459 OB_PUTC (',');
460 dump_type (TREE_CHAIN (t), &old_p);
463 else OB_PUTS ("...");
464 return;
466 case POINTER_TYPE:
467 if (TREE_READONLY (t) | TREE_VOLATILE (t))
468 dump_readonly_or_volatile (t);
469 *p += 1;
470 dump_type (TREE_TYPE (t), p);
471 while (*p)
473 OB_PUTC ('*');
474 *p -= 1;
476 return;
478 case REFERENCE_TYPE:
479 if (TREE_READONLY (t) | TREE_VOLATILE (t))
480 dump_readonly_or_volatile (t);
481 dump_type (TREE_TYPE (t), p);
482 OB_PUTC ('&');
483 return;
485 case ARRAY_TYPE:
486 if (TREE_READONLY (t) | TREE_VOLATILE (t))
487 dump_readonly_or_volatile (t);
488 dump_type (TREE_TYPE (t), p);
489 OB_PUTC2 ('[', ']');
490 return;
492 case OFFSET_TYPE:
493 case METHOD_TYPE:
494 case FUNCTION_TYPE:
495 dump_type_prefix (t, p);
496 dump_type_suffix (t, p);
497 return;
499 case IDENTIFIER_NODE:
500 sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (t));
501 break;
503 case RECORD_TYPE:
505 if (TREE_READONLY (t) | TREE_VOLATILE (t))
506 dump_readonly_or_volatile (t);
507 if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
508 print_struct = 0;
509 t = TYPE_NAME (t);
510 if (TREE_CODE (t) == TYPE_DECL)
511 t = DECL_NAME (t);
512 if (print_struct)
513 sprintf (inline_bufp, "struct %s ", IDENTIFIER_POINTER (t));
514 else
515 sprintf (inline_bufp, "class %s ", IDENTIFIER_POINTER (t));
516 break;
519 case UNION_TYPE:
521 if (TREE_READONLY (t) | TREE_VOLATILE (t))
522 dump_readonly_or_volatile (t);
523 t = TYPE_NAME (t);
524 if (TREE_CODE (t) == TYPE_DECL)
525 t = DECL_NAME (t);
526 sprintf (inline_bufp, "union %s ", IDENTIFIER_POINTER (t));
528 break;
530 case ENUMERAL_TYPE:
532 if (TREE_READONLY (t) | TREE_VOLATILE (t))
533 dump_readonly_or_volatile (t);
534 t = TYPE_NAME (t);
535 if (TREE_CODE (t) == TYPE_DECL)
536 t = DECL_NAME (t);
537 sprintf (inline_bufp, "enum %s ", IDENTIFIER_POINTER (t));
539 break;
541 case TYPE_DECL:
542 if (TREE_READONLY (t) | TREE_VOLATILE (t))
543 dump_readonly_or_volatile (t);
544 sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (DECL_NAME (t)));
545 break;
547 case INTEGER_TYPE:
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 ");
555 /* fall through. */
556 case REAL_TYPE:
557 case VOID_TYPE:
558 sprintf (inline_bufp, "%s ", TYPE_NAME_STRING (t));
559 break;
561 default:
562 abort ();
564 inline_bufp = new_text_len (inline_bufp);
567 static void
568 dump_decl (t)
569 tree t;
571 int p = 0;
573 if (t == NULL_TREE)
574 return;
576 switch (TREE_CODE (t))
578 case ERROR_MARK:
579 strcpy (inline_bufp, " /* decl error */ ");
580 break;
582 case PARM_DECL:
583 dump_type_prefix (TREE_TYPE (t), &p);
584 if (DECL_NAME (t))
585 dump_decl (DECL_NAME (t));
586 else
588 sprintf (inline_bufp, ANON_PARMNAME_FORMAT, dummy_name++);
589 break;
591 dump_type_suffix (TREE_TYPE (t), &p);
592 return;
594 case CALL_EXPR:
595 dump_decl (TREE_OPERAND (t, 0));
596 OB_PUTC ('(');
597 in_parmlist++;
598 dump_decl (TREE_OPERAND (t, 1));
599 in_parmlist--;
600 t = tree_last (TYPE_ARG_TYPES (TREE_TYPE (t)));
601 if (!t || t != void_list_node)
602 OB_PUTS ("...");
603 OB_PUTC (')');
604 return;
606 case ARRAY_REF:
607 dump_decl (TREE_OPERAND (t, 0));
608 OB_PUTC ('[');
609 dump_decl (TREE_OPERAND (t, 1));
610 OB_PUTC (']');
611 return;
613 case TYPE_DECL:
614 sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (DECL_NAME (t)));
615 break;
617 case TYPE_EXPR:
618 abort ();
619 break;
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);
628 return;
630 else
631 sprintf (inline_bufp, "%s ", IDENTIFIER_POINTER (t));
632 break;
634 case BIT_NOT_EXPR:
635 OB_PUTC2 ('~', ' ');
636 dump_decl (TREE_OPERAND (t, 0));
637 return;
639 case SCOPE_REF:
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));
643 return;
645 case INDIRECT_REF:
646 OB_PUTC ('*');
647 dump_decl (TREE_OPERAND (t, 0));
648 return;
650 case ADDR_EXPR:
651 OB_PUTC ('&');
652 dump_decl (TREE_OPERAND (t, 0));
653 return;
655 default:
656 abort ();
658 inline_bufp = new_text_len (inline_bufp);
661 static void
662 dump_init_list (l)
663 tree l;
665 while (l)
667 dump_init (TREE_VALUE (l));
668 if (TREE_CHAIN (l))
669 OB_PUTC (',');
670 l = TREE_CHAIN (l);
674 static void
675 dump_init (t)
676 tree t;
678 int dummy;
680 switch (TREE_CODE (t))
682 case VAR_DECL:
683 case PARM_DECL:
684 sprintf (inline_bufp, " %s ", IDENTIFIER_POINTER (DECL_NAME (t)));
685 break;
687 case FUNCTION_DECL:
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))
698 dummy = 0;
699 OB_PUTS ("operator ");
700 dump_type (TREE_TYPE (name), &dummy);
702 #if 0
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)));
712 #endif
713 else sprintf (inline_bufp, " %s ",
714 IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (t)));
716 break;
718 case CONST_DECL:
719 dummy = 0;
720 OB_PUTC2 ('(', '(');
721 dump_type (TREE_TYPE (t), &dummy);
722 OB_PUTC (')');
723 dump_init (DECL_INITIAL (t));
724 OB_PUTC (')');
725 return;
727 case INTEGER_CST:
728 sprintf (inline_bufp, " %d ", TREE_INT_CST_LOW (t));
729 break;
731 case REAL_CST:
732 sprintf (inline_bufp, " %g ", TREE_REAL_CST (t));
733 break;
735 case STRING_CST:
737 char *p = TREE_STRING_POINTER (t);
738 int len = TREE_STRING_LENGTH (t) - 1;
739 int i;
741 check_text_len (inline_bufp + len + 2);
742 OB_PUTC ('\"');
743 for (i = 0; i < len; i++)
745 register char c = p[i];
746 if (c == '\"' || c == '\\')
747 OB_PUTC ('\\');
748 if (c >= ' ' && c < 0177)
749 OB_PUTC (c);
750 else
752 sprintf (inline_bufp, "\\%03o", c);
753 inline_bufp = new_text_len (inline_bufp);
756 OB_PUTC ('\"');
758 return;
760 case COMPOUND_EXPR:
761 dump_binary_op (",", t, 1);
762 break;
764 case COND_EXPR:
765 OB_PUTC ('(');
766 dump_init (TREE_OPERAND (t, 0));
767 OB_PUTS (" ? ");
768 dump_init (TREE_OPERAND (t, 1));
769 OB_PUTS (" : ");
770 dump_init (TREE_OPERAND (t, 2));
771 OB_PUTC (')');
772 return;
774 case SAVE_EXPR:
775 if (TREE_HAS_CONSTRUCTOR (t))
777 dummy = 0;
778 OB_PUTS ("new ");
779 dump_type (TREE_TYPE (TREE_TYPE (t)), &dummy);
780 PARM_DECL_EXPR (t) = 1;
782 else
784 sorry ("operand of SAVE_EXPR not understood");
785 *inline_errp = '\0';
786 inline_bufp = inline_errp + 1;
788 return;
790 case NEW_EXPR:
791 strcpy (inline_bufp, TYPE_NAME_STRING (TREE_TYPE (t)));
792 inline_bufp = new_text_len (inline_bufp);
793 OB_PUTC ('(');
794 dump_init_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
795 OB_PUTC (')');
796 return;
798 case CALL_EXPR:
799 OB_PUTC ('(');
800 dump_init (TREE_OPERAND (t, 0));
801 dump_init_list (TREE_OPERAND (t, 1));
802 OB_PUTC (')');
803 return;
805 case MODIFY_EXPR:
806 case PLUS_EXPR:
807 case MINUS_EXPR:
808 case MULT_EXPR:
809 case TRUNC_DIV_EXPR:
810 case TRUNC_MOD_EXPR:
811 case MIN_EXPR:
812 case MAX_EXPR:
813 case LSHIFT_EXPR:
814 case RSHIFT_EXPR:
815 case BIT_IOR_EXPR:
816 case BIT_XOR_EXPR:
817 case BIT_AND_EXPR:
818 case BIT_ANDTC_EXPR:
819 case TRUTH_ANDIF_EXPR:
820 case TRUTH_ORIF_EXPR:
821 case LT_EXPR:
822 case LE_EXPR:
823 case GT_EXPR:
824 case GE_EXPR:
825 case EQ_EXPR:
826 case NE_EXPR:
827 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t,
828 strlen (opname_tab[(int) TREE_CODE (t)]));
829 return;
831 case CEIL_DIV_EXPR:
832 case FLOOR_DIV_EXPR:
833 case ROUND_DIV_EXPR:
834 dump_binary_op ("/", t, 1);
835 return;
837 case CEIL_MOD_EXPR:
838 case FLOOR_MOD_EXPR:
839 case ROUND_MOD_EXPR:
840 dump_binary_op ("%", t, 1);
841 return;
843 case COMPONENT_REF:
844 dump_binary_op (".", t, 1);
845 return;
847 case CONVERT_EXPR:
848 dump_unary_op ("+", t, 1);
849 return;
851 case ADDR_EXPR:
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));
855 else
856 dump_unary_op ("&", t, 1);
857 return;
859 case INDIRECT_REF:
860 dump_unary_op ("*", t, 1);
861 return;
863 case NEGATE_EXPR:
864 case BIT_NOT_EXPR:
865 case TRUTH_NOT_EXPR:
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)]));
870 return;
872 case POSTDECREMENT_EXPR:
873 case POSTINCREMENT_EXPR:
874 OB_PUTC ('(');
875 dump_init (TREE_OPERAND (t, 0));
876 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
877 OB_PUTC (')');
878 return;
880 case NOP_EXPR:
881 dummy = 0;
882 OB_PUTC2 ('(', '(');
883 dump_type (TREE_TYPE (t), &dummy);
884 OB_PUTC (')');
885 dump_init (TREE_OPERAND (t, 0));
886 OB_PUTC (')');
887 return;
889 case CONSTRUCTOR:
890 OB_PUTC ('{');
891 dump_init_list (CONSTRUCTOR_ELTS (t));
892 OB_PUTC ('}');
893 return;
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. */
898 default:
899 sorry ("that operation not supported for default parameters");
901 /* fall through to ERROR_MARK... */
902 case ERROR_MARK:
903 *inline_errp = '\0';
904 inline_bufp = inline_errp + 1;
905 return;
907 inline_bufp = new_text_len (inline_bufp);
910 static void
911 dump_binary_op (opstring, t, len)
912 char *opstring;
913 tree t;
914 int len;
916 OB_PUTC ('(');
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));
921 OB_PUTC (')');
922 check_text_len (inline_bufp);
925 static void
926 dump_unary_op (opstring, t, len)
927 char *opstring;
928 tree t;
929 int len;
931 OB_PUTC ('(');
932 sprintf (inline_bufp, " %s ", opstring);
933 inline_bufp += len + 2;
934 dump_init (TREE_OPERAND (t, 0));
935 OB_PUTC (')');
936 check_text_len (inline_bufp);
939 #ifdef DO_METHODS_THE_OLD_WAY
940 /* Process the currently pending inline function definitions.
941 This entails:
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
949 two.
952 static struct pending_inline *
953 stash_inline_prefix (cname, field)
954 tree cname, field;
956 extern int lineno;
957 struct pending_inline *t;
958 tree name, fndecl, fntype;
959 int p = 0;
960 inline_buffer = (char *)alloca (MAX_INLINE_BUF_SIZE + 4);
961 dummy_name = 0;
963 name = DECL_ORIGINAL_NAME (field);
964 /* We still don't do friends right. */
965 fndecl = field;
966 fntype = TREE_TYPE (fndecl);
968 if (TREE_INLINE (fndecl))
969 strcpy (inline_buffer, "inline ");
970 else
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)))
981 OB_PUTC ('~');
982 #if 0
983 else if (WRAPPER_NAME_P (DECL_NAME (fndecl)))
984 OB_PUTC2 ('(', ')');
985 else if (WRAPPER_PRED_NAME_P (DECL_NAME (fndecl)))
986 OB_PUTS ("()?");
987 else if (ANTI_WRAPPER_NAME_P (DECL_NAME (fndecl)))
988 OB_PUTS ("~()");
989 #endif
991 dump_decl (name);
992 OB_PUTC ('(');
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);
1004 in_parmlist++;
1005 while (parmlist)
1007 dump_decl (parmlist);
1008 #if 0
1009 if (TREE_PURPOSE (typelist))
1011 inline_errp = inline_bufp;
1012 OB_PUTS (" = (");
1013 dump_init (TREE_PURPOSE (typelist));
1014 OB_PUTC (')');
1015 if (*inline_errp == '\0')
1016 inline_bufp = inline_errp;
1018 #endif
1019 if (TREE_CHAIN (parmlist))
1020 OB_PUTC (',');
1021 parmlist = TREE_CHAIN (parmlist);
1022 typelist = TREE_CHAIN (typelist);
1024 in_parmlist--;
1025 if (!typelist || typelist != void_list_node)
1026 OB_PUTS ("...");
1028 OB_PUTC (')');
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))
1045 OB_PUTC ('=');
1046 dump_init (DECL_INITIAL (result));
1047 OB_PUTC (';');
1051 OB_FINISH ();
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);
1058 t->lineno = lineno;
1059 t->filename = input_filename;
1060 t->token = 0;
1061 return t;
1063 #endif
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. */
1074 char *
1075 fndecl_as_string (buf, cname, fndecl, print_ret_type_p)
1076 char *buf;
1077 tree cname, fndecl;
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);
1083 int p = 0;
1084 int spaces = 0;
1086 inline_buffer = buf;
1087 OB_INIT ();
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 ");
1099 if (cname)
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))
1112 OB_PUTC ('~');
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))
1134 #ifdef SOS
1135 if (TYPE_DYNAMIC (TREE_TYPE (TREE_TYPE (DECL_ORIGINAL_NAME (fndecl)))))
1137 OB_PUTS ("dynamic ");
1138 parmtypes = TREE_CHAIN (parmtypes);
1140 #endif
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);
1146 else
1148 #if 0
1149 if (WRAPPER_NAME_P (name))
1150 OB_PUTC2 ('(', ')');
1151 if (WRAPPER_PRED_NAME_P (name))
1152 OB_PUTS ("()?");
1153 else if (ANTI_WRAPPER_NAME_P (name))
1154 OB_PUTS ("~()");
1155 #endif
1156 dump_decl (DECL_ORIGINAL_NAME (fndecl));
1159 OB_PUTC ('(');
1160 if (parmtypes)
1162 in_parmlist++;
1163 if (parmtypes != void_list_node)
1164 spaces = 2;
1165 while (parmtypes && parmtypes != void_list_node)
1167 dump_type (TREE_VALUE (parmtypes), &p);
1168 while (inline_bufp[-1] == ' ')
1169 inline_bufp--;
1170 if (TREE_PURPOSE (parmtypes))
1172 inline_errp = inline_bufp;
1173 OB_PUTS (" (= ");
1174 dump_init (TREE_PURPOSE (parmtypes));
1175 OB_PUTC (')');
1177 OB_PUTC2 (',', ' ');
1178 parmtypes = TREE_CHAIN (parmtypes);
1180 in_parmlist--;
1183 if (parmtypes)
1184 inline_bufp -= spaces;
1185 else
1186 OB_PUTS ("...");
1188 OB_PUTC (')');
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))));
1196 OB_FINISH ();
1197 check_text_len (inline_bufp);
1199 if (strlen (buf) >= OVERLOAD_MAX_LEN)
1201 fprintf (stderr, "fndecl_as_string returns something too large");
1202 abort ();
1204 return buf;
1207 #ifdef FIELD_XREF
1209 char *
1210 type_as_string (buf, typ)
1211 char *buf;
1212 tree typ;
1214 int p = 0;
1215 int spaces = 0;
1217 inline_buffer = buf;
1218 OB_INIT ();
1220 dump_type(typ,&p);
1222 OB_FINISH ();
1224 return buf;
1227 #endif
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'. */
1236 static void
1237 prepare_inline (cname, fndecl)
1238 tree cname, fndecl;
1240 if (DECL_PENDING_INLINE_INFO (fndecl))
1242 struct pending_inline *t1, *t2;
1243 tree args;
1245 t2 = DECL_PENDING_INLINE_INFO (fndecl);
1246 t2->next = pending_inlines;
1247 t2->fndecl = fndecl;
1248 args = DECL_ARGUMENTS (fndecl);
1249 while (args)
1251 DECL_CONTEXT (args) = fndecl;
1252 args = TREE_CHAIN (args);
1254 #ifdef DO_METHODS_THE_OLD_WAY
1255 t1 = stash_inline_prefix (cname, methods);
1256 t1->next = t2;
1257 #else
1258 t1 = t2;
1259 #endif
1260 pending_inlines = t1;
1262 /* Allow this decl to be seen in global scope */
1263 IDENTIFIER_GLOBAL_VALUE (DECL_NAME (fndecl)) = fndecl;
1267 void
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;
1281 while (method)
1283 prepare_inline (cname, method);
1284 method = TREE_CHAIN (method);
1286 methods++;
1289 while (friend_list)
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. */
1298 void
1299 report_type_mismatch (cp, parmtypes, name_kind, err_name)
1300 struct candidate *cp;
1301 tree parmtypes;
1302 char *name_kind, *err_name;
1304 char buf[OVERLOAD_MAX_LEN];
1305 int i = cp->u.bad_arg;
1306 tree ttf, tta;
1308 if (i == -3)
1310 if (TREE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes))))
1311 error ("call to const %s `%s' with non-const object", name_kind, err_name);
1312 else
1313 error ("call to non-const %s `%s' with const object", name_kind, err_name);
1314 return;
1316 if (i == -2)
1318 error ("too few arguments for %s `%s'", name_kind, err_name);
1319 return;
1321 else if (i == -1)
1323 error ("too many arguments for %s `%s'", name_kind, err_name);
1324 return;
1326 if (i == 0)
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);
1332 return;
1335 ttf = TYPE_ARG_TYPES (TREE_TYPE (cp->function));
1336 tta = parmtypes;
1338 while (i-- > 0)
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. */
1348 if (tta)
1350 enum tree_code code = TREE_CODE (TREE_TYPE (TREE_VALUE (tta)));
1351 if (code == ERROR_MARK)
1352 OB_PUTS ("(failed type instatiation)");
1353 else
1355 i = (code == FUNCTION_TYPE || code == METHOD_TYPE);
1356 dump_type (TREE_TYPE (TREE_VALUE (tta)), &i);
1359 else OB_PUTS ("void");
1361 OB_FINISH ();
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);
1365 error (buf);
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. */
1377 static int maxtype;
1379 /* Number of occurances of last type seen. */
1380 static int nrepeats;
1382 /* Nonzero if we should not try folding parameter types. */
1383 static int nofold;
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); } \
1392 } while (0)
1394 /* Code to concatenate an asciified integer to a string,
1395 and return the end of the string. */
1396 static
1397 #ifdef __GNUC__
1398 __inline
1399 #endif
1400 char *
1401 icat (s, i)
1402 char *s;
1403 int i;
1405 if (i < 10)
1407 *s++ = '0' + i;
1408 return s;
1410 s = icat (s, i / 10);
1411 *s++ = '0' + (i % 10);
1412 return s;
1415 static
1416 #ifdef __GNUC__
1417 __inline
1418 #endif
1419 char *
1420 flush_repeats (s, type)
1421 char *s;
1422 tree type;
1424 int tindex = 0;
1425 char *rval;
1427 while (typevec[tindex] != type)
1428 tindex++;
1430 if (nrepeats > 1)
1432 *s++ = 'N';
1433 s = icat (s, nrepeats);
1434 if (nrepeats > 9)
1435 *s++ = '_';
1437 else
1438 *s++ = 'T';
1439 nrepeats = 0;
1440 rval = icat (s, tindex);
1441 if (tindex > 9)
1442 *rval++ = '_';
1443 return rval;
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
1454 is called. */
1456 static char *
1457 build_overload_name (parmtypes, text, text_end)
1458 tree parmtypes;
1459 char *text, *text_end;
1461 char *textp = text;
1462 int just_one;
1463 tree parmtype;
1465 if (just_one = (TREE_CODE (parmtypes) != TREE_LIST))
1467 parmtype = parmtypes;
1468 goto only_one;
1471 while (parmtypes)
1473 if (text_end - text < 4)
1474 fatal ("Out of string space in build_overload_name!");
1475 parmtype = TREE_VALUE (parmtypes);
1477 only_one:
1479 if (! nofold)
1481 if (! just_one)
1482 /* Every argument gets counted. */
1483 typevec[maxtype++] = parmtype;
1485 if (TREE_USED (parmtype))
1487 if (! just_one && parmtype == typevec[maxtype-2])
1488 nrepeats++;
1489 else
1491 if (nrepeats)
1492 textp = flush_repeats (textp, parmtype);
1493 if (! just_one && TREE_CHAIN (parmtypes)
1494 && parmtype == TREE_VALUE (TREE_CHAIN (parmtypes)))
1495 nrepeats++;
1496 else
1498 int tindex = 0;
1500 while (typevec[tindex] != parmtype)
1501 tindex++;
1502 *textp++ = 'T';
1503 textp = icat (textp, tindex);
1504 if (tindex > 9)
1505 *textp++ = '_';
1508 goto next;
1510 if (nrepeats)
1511 textp = flush_repeats (textp, typevec[maxtype-2]);
1512 if (! just_one
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))
1521 *textp++ = 'C';
1522 if (TREE_CODE (parmtype) == INTEGER_TYPE && TREE_UNSIGNED (parmtype))
1523 *textp++ = 'U';
1524 if (TREE_VOLATILE (parmtype))
1525 *textp++ = 'V';
1527 switch (TREE_CODE (parmtype))
1529 case OFFSET_TYPE:
1530 *textp++ = 'O';
1531 textp = build_overload_name (TYPE_OFFSET_BASETYPE (parmtype), textp, text_end);
1532 *textp++ = '_';
1533 textp = build_overload_name (TREE_TYPE (parmtype), textp, text_end);
1534 break;
1536 case REFERENCE_TYPE:
1537 *textp++ = 'R';
1538 goto more;
1540 case ARRAY_TYPE:
1541 #ifdef PARM_CAN_BE_ARRAY_TYPE
1543 tree length;
1545 *textp++ = 'A';
1546 length = array_type_nelts (parmtype);
1547 if (TREE_CODE (length) == INTEGER_CST)
1548 textp = icat (textp, TREE_INT_CST_LOW (length));
1549 *textp++ = '_';
1550 goto more;
1552 #else
1553 *textp++ = 'P';
1554 goto more;
1555 #endif
1557 case POINTER_TYPE:
1558 *textp++ = 'P';
1559 more:
1560 textp = build_overload_name (TREE_TYPE (parmtype), textp, text_end);
1561 break;
1563 case FUNCTION_TYPE:
1564 case METHOD_TYPE:
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;
1570 nofold = 1;
1572 if (nrepeats)
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)
1579 *textp++ = 'F';
1580 if (firstarg == NULL_TREE)
1581 *textp++ = 'e';
1582 else if (firstarg == void_list_node)
1583 *textp++ = 'v';
1584 else
1585 textp = build_overload_name (firstarg, textp, text_end);
1587 else
1589 int constp = TREE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
1590 int volatilep = TREE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
1591 *textp++ = 'M';
1592 firstarg = TREE_CHAIN (firstarg);
1594 textp = build_overload_name (TYPE_METHOD_BASETYPE (parmtype), textp, text_end);
1595 if (constp)
1596 *textp++ = 'C';
1597 if (volatilep)
1598 *textp++ = 'V';
1600 /* For cfront 2.0 compatability. */
1601 *textp++ = 'F';
1603 if (firstarg == NULL_TREE)
1604 *textp++ = 'e';
1605 else if (firstarg == void_list_node)
1606 *textp++ = 'v';
1607 else
1608 textp = build_overload_name (firstarg, textp, text_end);
1611 /* Separate args from return type. */
1612 *textp++ = '_';
1613 textp = build_overload_name (TREE_TYPE (parmtype), textp, text_end);
1614 nofold = old_nofold;
1615 break;
1618 case INTEGER_TYPE:
1619 parmtype = TYPE_MAIN_VARIANT (parmtype);
1620 switch (TYPE_MODE (parmtype))
1622 case TImode:
1623 if (parmtype == long_integer_type_node
1624 || parmtype == long_unsigned_type_node)
1625 *textp++ = 'l';
1626 else
1627 *textp++ = 'q';
1628 break;
1629 case DImode:
1630 if (parmtype == long_integer_type_node
1631 || parmtype == long_unsigned_type_node)
1632 *textp++ = 'l';
1633 else if (parmtype == integer_type_node
1634 || parmtype == unsigned_type_node)
1635 *textp++ = 'i';
1636 else if (parmtype == short_integer_type_node
1637 || parmtype == short_unsigned_type_node)
1638 *textp++ = 's';
1639 else
1640 *textp++ = 'x';
1641 break;
1642 case SImode:
1643 if (parmtype == long_integer_type_node
1644 || parmtype == long_unsigned_type_node)
1645 *textp++ = 'l';
1646 else if (parmtype == short_integer_type_node
1647 || parmtype == short_unsigned_type_node)
1648 *textp++ = 's';
1649 else
1650 *textp++ = 'i';
1651 break;
1652 case HImode:
1653 if (parmtype == integer_type_node
1654 || parmtype == unsigned_type_node)
1655 *textp++ = 'i';
1656 else
1657 *textp++ = 's';
1658 break;
1659 case QImode:
1660 *textp++ = 'c';
1661 break;
1662 default:
1663 abort ();
1665 break;
1667 case REAL_TYPE:
1668 parmtype = TYPE_MAIN_VARIANT (parmtype);
1669 if (parmtype == long_double_type_node)
1670 *textp++ = 'r';
1671 else if (parmtype == double_type_node)
1672 *textp++ = 'd';
1673 else if (parmtype == float_type_node)
1674 *textp++ = 'f';
1675 else abort ();
1676 break;
1678 case VOID_TYPE:
1679 if (! just_one)
1681 #if 0
1682 extern tree void_list_node;
1684 /* See if anybody is wasting memory. */
1685 assert (parmtypes == void_list_node);
1686 #endif
1687 /* This is the end of a parameter list. */
1688 *textp = '\0';
1689 return textp;
1691 *textp++ = 'v';
1692 break;
1694 case ERROR_MARK: /* not right, but nothing is anyway */
1695 break;
1697 /* have to do these */
1698 case UNION_TYPE:
1699 case RECORD_TYPE:
1700 if (! just_one)
1701 /* Make this type signature look incompatible
1702 with AT&T. */
1703 *textp++ = 'G';
1704 goto common;
1705 case ENUMERAL_TYPE:
1706 common:
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);
1715 break;
1718 case UNKNOWN_TYPE:
1719 /* This will take some work. */
1720 *textp++ = '?';
1721 break;
1723 default:
1724 abort ();
1727 next:
1728 if (just_one) break;
1729 parmtypes = TREE_CHAIN (parmtypes);
1731 if (! just_one)
1733 if (nrepeats)
1734 textp = flush_repeats (textp, typevec[maxtype-1]);
1736 /* To get here, parms must end with `...'. */
1737 *textp++ = 'e';
1740 *textp = '\0';
1741 return textp;
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. */
1752 tree
1753 build_decl_overload (name, parms, for_method)
1754 char *name;
1755 tree parms;
1756 int for_method;
1758 int tmp;
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. */
1764 tmp = 0;
1765 else
1767 strcpy (tname, name);
1768 tmp = strlen (tname);
1770 tname[tmp++] = '_';
1771 tname[tmp++] = '_';
1772 if (for_method)
1774 #if 0
1775 /* We can get away without doing this. */
1776 tname[tmp++] = 'M';
1777 #endif
1778 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (TREE_VALUE (parms)), TREE_CHAIN (parms));
1780 else
1781 tname[tmp++] = 'F';
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';
1787 else
1789 ALLOCATE_TYPEVEC (parms);
1790 nofold = 0;
1791 if (for_method)
1793 tmp = build_overload_name (TREE_VALUE (parms), tname+tmp, &tname[OVERLOAD_MAX_LEN]) - tname;
1795 #ifndef LONGERNAMES
1796 typevec[maxtype++] = TREE_VALUE (parms);
1797 TREE_USED (TREE_VALUE (parms)) = 1;
1798 #endif
1800 if (TREE_CHAIN (parms))
1801 build_overload_name (TREE_CHAIN (parms), tname+tmp, &tname[OVERLOAD_MAX_LEN]);
1802 else
1804 tname[tmp++] = 'e';
1805 tname[tmp] = '\0';
1808 else
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. */
1816 tree
1817 build_typename_overload (type)
1818 tree type;
1820 char tname[OVERLOAD_MAX_LEN];
1821 int i = sizeof (OPERATOR_TYPENAME_FORMAT) - 1;
1822 sprintf (tname, OPERATOR_TYPENAME_FORMAT);
1823 #if 0
1824 /* We can get away without doing this--it really gets
1825 overloaded later. */
1826 tname[i++] = '_';
1827 tname[i++] = '_';
1828 tname[i++] = 'M';
1829 #endif
1830 nofold = 1;
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. */
1839 void
1840 declare_overloaded (name)
1841 tree 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));
1850 else
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;
1856 #else
1857 if (current_lang_name == lang_name_cplusplus)
1859 if (0)
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");
1864 else
1865 abort ();
1866 #endif
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)
1875 tree name;
1877 /* @@ */
1878 return (TREE_OVERLOADED (name)
1879 && (! IDENTIFIER_CLASS_VALUE (name) || current_class_type == 0)
1880 && ! IDENTIFIER_LOCAL_VALUE (name));
1882 #endif
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'. */
1905 /* NOSTRICT */
1906 tree
1907 build_opfncall (code, flags, xarg1, xarg2, arg3)
1908 enum tree_code code;
1909 tree xarg1, xarg2;
1910 tree arg3;
1912 tree rval = 0;
1913 tree arg1, arg2;
1914 tree type1, type2, fnname;
1915 tree fields1 = 0, parms = 0;
1916 tree global_fn;
1917 int try_second;
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)
1931 return rval;
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. */
1938 switch (code)
1940 case PREINCREMENT_EXPR:
1941 code = POSTINCREMENT_EXPR;
1942 binary_is_unary = 1;
1943 try_second = 0;
1944 break;
1946 case POSTDECREMENT_EXPR:
1947 code = PREDECREMENT_EXPR;
1948 binary_is_unary = 1;
1949 try_second = 0;
1950 break;
1952 case PREDECREMENT_EXPR:
1953 case POSTINCREMENT_EXPR:
1954 case COMPONENT_REF:
1955 binary_is_unary = 1;
1956 try_second = 0;
1957 break;
1959 /* ARRAY_REFs and CALL_EXPRs must overload successfully.
1960 If they do not, return error_mark_node instead of NULL_TREE. */
1961 case ARRAY_REF:
1962 if (xarg2 == error_mark_node)
1963 return error_mark_node;
1964 case CALL_EXPR:
1965 rval = error_mark_node;
1966 binary_is_unary = 0;
1967 try_second = 0;
1968 break;
1970 case NEW_EXPR:
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),
1987 NULL_TREE, flags);
1988 if (rval == error_mark_node)
1989 /* User might declare fancy operator new, but invoke it
1990 like standard one. */
1991 return rval;
1993 TREE_TYPE (rval) = xarg1;
1994 TREE_CALLS_NEW (rval) = 1;
1995 return rval;
1997 break;
1999 case DELETE_EXPR:
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),
2014 NULL_TREE, flags);
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;
2019 return rval;
2021 break;
2023 default:
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;
2028 break;
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)
2036 return rval;
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);
2046 else
2048 arg1 = xarg1;
2051 if (!IS_AGGR_TYPE (type1))
2053 /* Try to fail. First, fail if unary */
2054 if (! try_second)
2055 return rval;
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);
2065 else
2067 arg2 = xarg2;
2070 if (!IS_AGGR_TYPE (type2))
2071 return rval;
2072 try_second = 0;
2075 if (try_second)
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);
2086 else
2088 arg2 = xarg2;
2091 if (! IS_AGGR_TYPE (type2))
2092 try_second = 0;
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. */
2099 return rval;
2102 if (code == MODIFY_EXPR)
2104 tree op_id = build_opid (MODIFY_EXPR, arg3);
2105 fnname = build_operator_fnname (&op_id, 0, 2);
2107 else
2109 tree op_id = build_opid (0, code);
2110 if (binary_is_unary)
2111 fnname = build_operator_fnname (&op_id, 0, 1);
2112 else
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
2122 argument. */
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)
2128 return rval;
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);
2145 if (global_fn)
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)
2156 parms = NULL_TREE;
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);
2170 else if (fields1)
2172 parms = build_tree_list (NULL_TREE, xarg2);
2173 rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags);
2175 else
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)
2186 return rval;
2187 return 0;
2190 return rval;
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
2195 order of hair:
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
2207 address.
2209 Values which are declared as being of REFERENCE_TYPE are
2210 automatically dereferenced here (as a hack to make the
2211 compiler faster). */
2213 tree
2214 hack_identifier (value, name, yychar)
2215 tree value, name;
2217 tree type;
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);
2224 if (fields)
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");
2231 return fields;
2233 else
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;
2260 if (yychar == '(')
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))
2285 tree path;
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));
2295 else
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;
2308 return value;
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);
2324 return value;
2327 tree
2328 hack_operator (op)
2329 tree op;
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);
2337 return op;
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. */
2344 tree
2345 hack_wrapper (nonwrapper, type, decl)
2346 int nonwrapper;
2347 tree type, decl;
2349 if (type == NULL_TREE || is_aggr_typedef (type, 1))
2351 if (type)
2352 type = TREE_TYPE (type);
2354 switch (nonwrapper)
2356 case 0:
2357 return build_nt (WRAPPER_EXPR, type, decl);
2358 case 1:
2359 return build_nt (ANTI_WRAPPER_EXPR, type, decl);
2360 case 2:
2361 return build_nt (WRAPPER_EXPR, type,
2362 build_nt (COND_EXPR, decl, NULL_TREE, NULL_TREE));
2363 default:
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. */
2372 tree
2373 make_anon_name ()
2375 static int cnt = 0;
2376 char buf[32];
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. */
2395 tree
2396 build_component_type_expr (of, component, basetype_path, protect)
2397 tree of, component, basetype_path;
2398 int protect;
2400 tree cname = NULL_TREE;
2401 tree tmp, last;
2402 tree name;
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);
2409 last = NULL_TREE;
2411 while (tmp)
2413 switch (TREE_CODE (tmp))
2415 case CALL_EXPR:
2416 if (last)
2417 TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
2418 else
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);
2433 else if (of)
2435 tree this_this;
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;
2453 case INDIRECT_REF:
2454 case ADDR_EXPR:
2455 case ARRAY_REF:
2456 break;
2458 case SCOPE_REF:
2459 assert (cname == 0);
2460 cname = TREE_OPERAND (tmp, 0);
2461 tmp = TREE_OPERAND (tmp, 1);
2462 break;
2464 default:
2465 abort ();
2467 last = tmp;
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);
2479 of = NULL_TREE;
2481 else assert (cname == DECL_NAME (of));
2484 if (of)
2486 tree this_this;
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);
2497 else if (cname)
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;