04d674d5a4b22e854e09ad6fa3909ec81356a090
[gcc.git] / gcc / cp / method.c
1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 89, 92-97, 1998 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23
24 #ifndef __GNUC__
25 #define __inline
26 #endif
27
28 #ifndef PARM_CAN_BE_ARRAY_TYPE
29 #define PARM_CAN_BE_ARRAY_TYPE 1
30 #endif
31
32 /* Handle method declarations. */
33 #include "config.h"
34 #include "system.h"
35 #include "tree.h"
36 #include "cp-tree.h"
37 #include "obstack.h"
38 #include "rtl.h"
39 #include "expr.h"
40 #include "output.h"
41 #include "hard-reg-set.h"
42 #include "flags.h"
43
44 /* TREE_LIST of the current inline functions that need to be
45 processed. */
46 struct pending_inline *pending_inlines;
47
48 int static_labelno;
49
50 #define obstack_chunk_alloc xmalloc
51 #define obstack_chunk_free free
52
53 /* Obstack where we build text strings for overloading, etc. */
54 static struct obstack scratch_obstack;
55 static char *scratch_firstobj;
56
57 static void icat PROTO((HOST_WIDE_INT));
58 static void dicat PROTO((HOST_WIDE_INT, HOST_WIDE_INT));
59 static void flush_repeats PROTO((tree));
60 static void build_overload_identifier PROTO((tree));
61 static void build_overload_nested_name PROTO((tree));
62 static void build_overload_int PROTO((tree, int));
63 static void build_overload_identifier PROTO((tree));
64 static void build_qualified_name PROTO((tree));
65 static void build_overload_value PROTO((tree, tree, int));
66 static void issue_nrepeats PROTO((tree));
67 static char *build_mangled_name PROTO((tree,int,int));
68 static void process_modifiers PROTO((tree));
69 static void process_overload_item PROTO((tree,int));
70 static void do_build_assign_ref PROTO((tree));
71 static void do_build_copy_constructor PROTO((tree));
72 static tree largest_union_member PROTO((tree));
73 static tree build_decl_overload_real PROTO((tree, tree, tree, tree,
74 tree, int));
75 static void build_template_template_parm_names PROTO((tree));
76 static void build_template_parm_names PROTO((tree, tree));
77 static void build_underscore_int PROTO((int));
78
79 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
80 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
81 # define OB_PUTC2(C1,C2) \
82 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
83 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
84 # define OB_PUTID(ID) \
85 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
86 IDENTIFIER_LENGTH (ID)))
87 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
88 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
89 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
90
91 void
92 init_method ()
93 {
94 gcc_obstack_init (&scratch_obstack);
95 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
96 }
97
98 /* This must be large enough to hold any printed integer or floating-point
99 value. */
100 static char digit_buffer[128];
101
102 /* Move inline function definitions out of structure so that they
103 can be processed normally. CNAME is the name of the class
104 we are working from, METHOD_LIST is the list of method lists
105 of the structure. We delete friend methods here, after
106 saving away their inline function definitions (if any). */
107
108 void
109 do_inline_function_hair (type, friend_list)
110 tree type, friend_list;
111 {
112 tree method = TYPE_METHODS (type);
113
114 if (method && TREE_CODE (method) == TREE_VEC)
115 {
116 if (TREE_VEC_ELT (method, 1))
117 method = TREE_VEC_ELT (method, 1);
118 else if (TREE_VEC_ELT (method, 0))
119 method = TREE_VEC_ELT (method, 0);
120 else
121 method = TREE_VEC_ELT (method, 2);
122 }
123
124 while (method)
125 {
126 /* Do inline member functions. */
127 struct pending_inline *info = DECL_PENDING_INLINE_INFO (method);
128 if (info)
129 {
130 tree args;
131
132 my_friendly_assert (info->fndecl == method, 238);
133 args = DECL_ARGUMENTS (method);
134 while (args)
135 {
136 DECL_CONTEXT (args) = method;
137 args = TREE_CHAIN (args);
138 }
139 }
140 method = TREE_CHAIN (method);
141 }
142 while (friend_list)
143 {
144 tree fndecl = TREE_VALUE (friend_list);
145 struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl);
146 if (info)
147 {
148 tree args;
149
150 my_friendly_assert (info->fndecl == fndecl, 239);
151 args = DECL_ARGUMENTS (fndecl);
152 while (args)
153 {
154 DECL_CONTEXT (args) = fndecl;
155 args = TREE_CHAIN (args);
156 }
157 }
158
159 friend_list = TREE_CHAIN (friend_list);
160 }
161 }
162 \f
163 /* Here is where overload code starts. */
164
165 /* type tables for K and B type compression */
166 static tree *btypelist = NULL;
167 static tree *ktypelist = NULL;
168 static tree lasttype = NULL;
169 static int maxbsize = 0;
170 static int maxksize = 0;
171
172 /* number of each type seen */
173 static int maxbtype = 0;
174 static int maxktype = 0;
175
176 /* Number of occurrences of last b type seen. */
177 static int nrepeats = 0;
178
179 /* Array of types seen so far in top-level call to `build_mangled_name'.
180 Allocated and deallocated by caller. */
181 static tree *typevec = NULL;
182
183 /* Number of types interned by `build_mangled_name' so far. */
184 static int maxtype = 0;
185
186 /* Number of occurrences of last type seen. */
187 static int Nrepeats = 0;
188
189 /* Nonzero if we should not try folding parameter types. */
190 static int nofold;
191
192 /* This appears to be set to true if an underscore is required to be
193 comcatenated before another number can be outputed. */
194 static int numeric_output_need_bar;
195
196 static __inline void
197 start_squangling ()
198 {
199 if (flag_do_squangling)
200 {
201 lasttype = NULL;
202 nofold = 0;
203 nrepeats = 0;
204 maxbtype = 0;
205 maxktype = 0;
206 maxbsize = 50;
207 maxksize = 50;
208 btypelist = (tree *)xmalloc (sizeof (tree) * maxbsize);
209 ktypelist = (tree *)xmalloc (sizeof (tree) * maxksize);
210 }
211 }
212
213 static __inline void
214 end_squangling ()
215 {
216 if (flag_do_squangling)
217 {
218 lasttype = NULL;
219 if (ktypelist)
220 free (ktypelist);
221 if (btypelist)
222 free (btypelist);
223 maxbsize = 0;
224 maxksize = 0;
225 maxbtype = 0;
226 maxktype = 0;
227 ktypelist = NULL;
228 btypelist = NULL;
229 }
230 }
231
232 /* Code to concatenate an asciified integer to a string. */
233
234 static __inline void
235 icat (i)
236 HOST_WIDE_INT i;
237 {
238 unsigned HOST_WIDE_INT ui;
239
240 /* Handle this case first, to go really quickly. For many common values,
241 the result of ui/10 below is 1. */
242 if (i == 1)
243 {
244 OB_PUTC ('1');
245 return;
246 }
247
248 if (i >= 0)
249 ui = i;
250 else
251 {
252 OB_PUTC ('m');
253 ui = -i;
254 }
255
256 if (ui >= 10)
257 icat (ui / 10);
258
259 OB_PUTC ('0' + (ui % 10));
260 }
261
262 static void
263 dicat (lo, hi)
264 HOST_WIDE_INT lo, hi;
265 {
266 unsigned HOST_WIDE_INT ulo, uhi, qlo, qhi;
267
268 if (hi >= 0)
269 {
270 uhi = hi;
271 ulo = lo;
272 }
273 else
274 {
275 uhi = (lo == 0 ? -hi : -hi-1);
276 ulo = -lo;
277 }
278 if (uhi == 0
279 && ulo < ((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)))
280 {
281 icat (ulo);
282 return;
283 }
284 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
285 qhi = uhi / 10;
286 uhi = uhi % 10;
287 qlo = uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) / 5);
288 qlo += ulo / 10;
289 ulo = ulo % 10;
290 ulo += uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) % 5)
291 * 2;
292 qlo += ulo / 10;
293 ulo = ulo % 10;
294 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
295 dicat (qlo, qhi);
296 OB_PUTC ('0' + ulo);
297 }
298
299 static __inline void
300 flush_repeats (type)
301 tree type;
302 {
303 int tindex = 0;
304
305 while (typevec[tindex] != type)
306 tindex++;
307
308 if (Nrepeats > 1)
309 {
310 OB_PUTC ('N');
311 icat (Nrepeats);
312 if (Nrepeats > 9)
313 OB_PUTC ('_');
314 }
315 else
316 OB_PUTC ('T');
317 Nrepeats = 0;
318 icat (tindex);
319 if (tindex > 9)
320 OB_PUTC ('_');
321 }
322
323
324 /* issue squangling type repeating */
325 static void
326 issue_nrepeats (lasttype)
327 tree lasttype;
328 {
329 if (nrepeats == 1)
330 {
331 switch (TREE_CODE (lasttype))
332 {
333 case INTEGER_TYPE:
334 case REAL_TYPE:
335 case VOID_TYPE:
336 case BOOLEAN_TYPE:
337 process_overload_item (lasttype, FALSE);
338 nrepeats = 0;
339 return;
340
341 default:
342 break;
343 }
344 }
345 OB_PUTC ('n');
346 icat (nrepeats);
347 if (nrepeats > 9)
348 OB_PUTC ('_');
349 nrepeats = 0;
350 }
351
352
353 /* Check to see if a tree node has been entered into the Kcode typelist */
354 /* if not, add it. Return -1 if it isn't found, otherwise return the index */
355 static int
356 check_ktype (node, add)
357 tree node;
358 int add;
359 {
360 int x;
361 tree localnode = node;
362
363 if (ktypelist == NULL)
364 return -1;
365
366 if (TREE_CODE (node) == TYPE_DECL)
367 localnode = TREE_TYPE (node);
368
369 for (x=0; x < maxktype; x++)
370 {
371 if (localnode == ktypelist[x])
372 return x ;
373 }
374 /* Didn't find it, so add it here */
375 if (add)
376 {
377 if (maxksize <= maxktype)
378 {
379 maxksize = maxksize* 3 / 2;
380 ktypelist = (tree *)xrealloc (sizeof (tree) * maxksize);
381 }
382 ktypelist[maxktype++] = localnode;
383 }
384 return -1;
385 }
386
387
388 static __inline int
389 issue_ktype (decl)
390 tree decl;
391 {
392 int kindex;
393 kindex = check_ktype (decl, FALSE);
394 if (kindex != -1)
395 {
396 OB_PUTC ('K');
397 icat (kindex);
398 if (kindex > 9)
399 OB_PUTC ('_');
400 return TRUE;
401 }
402 return FALSE;
403 }
404
405 static void
406 build_overload_nested_name (decl)
407 tree decl;
408 {
409
410 if (ktypelist && issue_ktype (decl))
411 return;
412
413 if (DECL_CONTEXT (decl))
414 {
415 tree context = DECL_CONTEXT (decl);
416
417 /* try to issue a K type, and if we can't continue the normal path */
418 if (!(ktypelist && issue_ktype (context)))
419 {
420 /* For a template type parameter, we want to output an 'Xn'
421 rather than 'T' or some such. */
422 if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
423 || TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
424 build_mangled_name (context, 0, 0);
425 else
426 {
427 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
428 context = TYPE_NAME (context);
429 build_overload_nested_name (context);
430 }
431 }
432 }
433 else if (decl == global_namespace)
434 return;
435 else if (DECL_NAMESPACE (decl))
436 build_overload_nested_name (DECL_NAMESPACE (decl));
437 else
438 /* XXX the above does not work for non-namespaces */
439 if (current_namespace && TREE_CODE (decl) != NAMESPACE_DECL)
440 build_overload_nested_name (current_namespace);
441
442 if (TREE_CODE (decl) == FUNCTION_DECL)
443 {
444 tree name = DECL_ASSEMBLER_NAME (decl);
445 char *label;
446
447 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), static_labelno);
448 static_labelno++;
449
450 if (numeric_output_need_bar)
451 OB_PUTC ('_');
452 icat (strlen (label));
453 OB_PUTCP (label);
454 numeric_output_need_bar = 1;
455 }
456 else if (TREE_CODE (decl) == NAMESPACE_DECL)
457 build_overload_identifier (DECL_NAME (decl));
458 else /* TYPE_DECL */
459 build_overload_identifier (decl);
460 }
461
462 static void
463 build_underscore_int (i)
464 int i;
465 {
466 if (i > 9)
467 OB_PUTC ('_');
468 icat (i);
469 if (i > 9)
470 OB_PUTC ('_');
471 }
472
473 static void
474 build_overload_scope_ref (value)
475 tree value;
476 {
477 OB_PUTC2 ('Q', '2');
478 numeric_output_need_bar = 0;
479 build_mangled_name (TREE_OPERAND (value, 0), 0, 0);
480 build_overload_identifier (TREE_OPERAND (value, 1));
481 }
482
483 /* Encoding for an INTEGER_CST value. */
484
485 static void
486 build_overload_int (value, in_template)
487 tree value;
488 int in_template;
489 {
490 if (in_template && TREE_CODE (value) != INTEGER_CST)
491 {
492 if (TREE_CODE (value) == SCOPE_REF)
493 {
494 build_overload_scope_ref (value);
495 return;
496 }
497
498 OB_PUTC ('E');
499 numeric_output_need_bar = 0;
500
501 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value))))
502 {
503 int i;
504 int operands = tree_code_length[(int) TREE_CODE (value)];
505 tree id;
506 char* name;
507
508 id = ansi_opname [(int) TREE_CODE (value)];
509 my_friendly_assert (id != NULL_TREE, 0);
510 name = IDENTIFIER_POINTER (id);
511 my_friendly_assert (name[0] == '_' && name[1] == '_', 0);
512
513 for (i = 0; i < operands; ++i)
514 {
515 tree operand;
516 enum tree_code tc;
517
518 /* We just outputted either the `E' or the name of the
519 operator. */
520 numeric_output_need_bar = 0;
521
522 if (i != 0)
523 /* Skip the leading underscores. */
524 OB_PUTCP (name + 2);
525
526 operand = TREE_OPERAND (value, i);
527 tc = TREE_CODE (operand);
528
529 if (TREE_CODE_CLASS (tc) == 't')
530 /* We can get here with sizeof, e.g.:
531
532 template <class T> void f(A<sizeof(T)>); */
533 process_overload_item (operand, 0);
534 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc)))
535 build_overload_int (operand, in_template);
536 else
537 build_overload_value (TREE_TYPE (operand),
538 operand,
539 in_template);
540 }
541 }
542 else
543 {
544 /* We don't ever want this output, but it's
545 inconvenient not to be able to build the string.
546 This should cause assembler errors we'll notice. */
547
548 static int n;
549 sprintf (digit_buffer, " *%d", n++);
550 OB_PUTCP (digit_buffer);
551 }
552
553 OB_PUTC ('W');
554 numeric_output_need_bar = 0;
555 return;
556 }
557
558 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
559 if (TYPE_PRECISION (TREE_TYPE (value)) == 2 * HOST_BITS_PER_WIDE_INT)
560 {
561 if (TREE_INT_CST_HIGH (value)
562 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
563 {
564 /* need to print a DImode value in decimal */
565 dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value));
566 numeric_output_need_bar = 1;
567 return;
568 }
569 /* else fall through to print in smaller mode */
570 }
571 /* Wordsize or smaller */
572 icat (TREE_INT_CST_LOW (value));
573 numeric_output_need_bar = 1;
574 }
575
576
577 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
578 supplied in INDEX. */
579
580 static void
581 build_mangled_template_parm_index (s, index)
582 char* s;
583 tree index;
584 {
585 OB_PUTCP (s);
586 build_underscore_int (TEMPLATE_PARM_IDX (index));
587 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
588 representation of the function from the point of view of its
589 type. */
590 build_underscore_int (TEMPLATE_PARM_LEVEL (index));
591 }
592
593
594 static void
595 build_overload_value (type, value, in_template)
596 tree type, value;
597 int in_template;
598 {
599 while (TREE_CODE (value) == NON_LVALUE_EXPR
600 || TREE_CODE (value) == NOP_EXPR)
601 value = TREE_OPERAND (value, 0);
602
603 if (TREE_CODE (type) == PARM_DECL)
604 type = TREE_TYPE (type);
605
606 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type)) == 't', 0);
607
608 if (numeric_output_need_bar)
609 {
610 OB_PUTC ('_');
611 numeric_output_need_bar = 0;
612 }
613
614 if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
615 {
616 build_mangled_template_parm_index ("Y", value);
617 return;
618 }
619
620 if (TREE_CODE (type) == POINTER_TYPE
621 && TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE)
622 {
623 /* Handle a pointer to data member as a template instantiation
624 parameter, boy, what fun! */
625 type = integer_type_node;
626 if (TREE_CODE (value) != INTEGER_CST)
627 {
628 sorry ("unknown pointer to member constant");
629 return;
630 }
631 }
632
633 if (TYPE_PTRMEMFUNC_P (type))
634 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
635
636 switch (TREE_CODE (type))
637 {
638 case INTEGER_TYPE:
639 case ENUMERAL_TYPE:
640 case BOOLEAN_TYPE:
641 {
642 build_overload_int (value, in_template);
643 return;
644 }
645 case REAL_TYPE:
646 {
647 REAL_VALUE_TYPE val;
648 char *bufp = digit_buffer;
649
650 pedwarn ("ANSI C++ forbids floating-point template arguments");
651
652 my_friendly_assert (TREE_CODE (value) == REAL_CST, 244);
653 val = TREE_REAL_CST (value);
654 if (REAL_VALUE_ISNAN (val))
655 {
656 sprintf (bufp, "NaN");
657 }
658 else
659 {
660 if (REAL_VALUE_NEGATIVE (val))
661 {
662 val = REAL_VALUE_NEGATE (val);
663 *bufp++ = 'm';
664 }
665 if (REAL_VALUE_ISINF (val))
666 {
667 sprintf (bufp, "Infinity");
668 }
669 else
670 {
671 REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
672 bufp = (char *) index (bufp, 'e');
673 if (!bufp)
674 strcat (digit_buffer, "e0");
675 else
676 {
677 char *p;
678 bufp++;
679 if (*bufp == '-')
680 {
681 *bufp++ = 'm';
682 }
683 p = bufp;
684 if (*p == '+')
685 p++;
686 while (*p == '0')
687 p++;
688 if (*p == 0)
689 {
690 *bufp++ = '0';
691 *bufp = 0;
692 }
693 else if (p != bufp)
694 {
695 while (*p)
696 *bufp++ = *p++;
697 *bufp = 0;
698 }
699 }
700 #ifdef NO_DOT_IN_LABEL
701 bufp = (char *) index (bufp, '.');
702 if (bufp)
703 *bufp = '_';
704 #endif
705 }
706 }
707 OB_PUTCP (digit_buffer);
708 numeric_output_need_bar = 1;
709 return;
710 }
711 case POINTER_TYPE:
712 if (TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE
713 && TREE_CODE (value) != ADDR_EXPR)
714 {
715 if (TREE_CODE (value) == CONSTRUCTOR)
716 {
717 /* This is dangerous code, crack built up pointer to members. */
718 tree args = CONSTRUCTOR_ELTS (value);
719 tree a1 = TREE_VALUE (args);
720 tree a2 = TREE_VALUE (TREE_CHAIN (args));
721 tree a3 = CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args))));
722 a3 = TREE_VALUE (a3);
723 STRIP_NOPS (a3);
724 if (TREE_CODE (a1) == INTEGER_CST
725 && TREE_CODE (a2) == INTEGER_CST)
726 {
727 build_overload_int (a1, in_template);
728 OB_PUTC ('_');
729 build_overload_int (a2, in_template);
730 OB_PUTC ('_');
731 if (TREE_CODE (a3) == ADDR_EXPR)
732 {
733 a3 = TREE_OPERAND (a3, 0);
734 if (TREE_CODE (a3) == FUNCTION_DECL)
735 {
736 numeric_output_need_bar = 0;
737 build_overload_identifier (DECL_ASSEMBLER_NAME (a3));
738 return;
739 }
740 }
741 else if (TREE_CODE (a3) == INTEGER_CST)
742 {
743 OB_PUTC ('i');
744 build_overload_int (a3, in_template);
745 return;
746 }
747 }
748 }
749 sorry ("template instantiation with pointer to method that is too complex");
750 return;
751 }
752 if (TREE_CODE (value) == INTEGER_CST)
753 {
754 build_overload_int (value, in_template);
755 return;
756 }
757 else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
758 {
759 build_mangled_template_parm_index ("", value);
760 numeric_output_need_bar = 1;
761 return;
762 }
763
764 value = TREE_OPERAND (value, 0);
765 if (TREE_CODE (value) == VAR_DECL)
766 {
767 my_friendly_assert (DECL_NAME (value) != 0, 245);
768 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
769 return;
770 }
771 else if (TREE_CODE (value) == FUNCTION_DECL)
772 {
773 my_friendly_assert (DECL_NAME (value) != 0, 246);
774 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
775 return;
776 }
777 else if (TREE_CODE (value) == SCOPE_REF)
778 build_overload_scope_ref (value);
779 else
780 my_friendly_abort (71);
781 break; /* not really needed */
782
783 default:
784 sorry ("conversion of %s as template parameter",
785 tree_code_name [(int) TREE_CODE (type)]);
786 my_friendly_abort (72);
787 }
788 }
789
790
791 /* Add encodings for the declaration of template template parameters.
792 PARMLIST must be a TREE_VEC */
793
794 static void
795 build_template_template_parm_names (parmlist)
796 tree parmlist;
797 {
798 int i, nparms;
799
800 my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
801 nparms = TREE_VEC_LENGTH (parmlist);
802 icat (nparms);
803 for (i = 0; i < nparms; i++)
804 {
805 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
806 if (TREE_CODE (parm) == TYPE_DECL)
807 {
808 /* This parameter is a type. */
809 OB_PUTC ('Z');
810 }
811 else if (TREE_CODE (parm) == TEMPLATE_DECL)
812 {
813 /* This parameter is a template. */
814 OB_PUTC ('z');
815 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
816 }
817 else
818 {
819 /* It's a PARM_DECL. */
820 build_mangled_name (TREE_TYPE (parm), 0, 0);
821 }
822 }
823 }
824
825
826 /* Add encodings for the vector of template parameters in PARMLIST,
827 given the vector of arguments to be substituted in ARGLIST. */
828
829 static void
830 build_template_parm_names (parmlist, arglist)
831 tree parmlist;
832 tree arglist;
833 {
834 int i, nparms;
835
836 nparms = TREE_VEC_LENGTH (parmlist);
837 icat (nparms);
838 for (i = 0; i < nparms; i++)
839 {
840 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
841 tree arg = TREE_VEC_ELT (arglist, i);
842 if (TREE_CODE (parm) == TYPE_DECL)
843 {
844 /* This parameter is a type. */
845 OB_PUTC ('Z');
846 build_mangled_name (arg, 0, 0);
847 }
848 else if (TREE_CODE (parm) == TEMPLATE_DECL)
849 {
850 /* This parameter is a template. */
851 if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
852 /* Output parameter declaration, argument index and level */
853 build_mangled_name (arg, 0, 0);
854 else
855 {
856 /* A TEMPLATE_DECL node, output the parameter declaration
857 and template name */
858
859 OB_PUTC ('z');
860 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
861 icat (IDENTIFIER_LENGTH (DECL_NAME (arg)));
862 OB_PUTID (DECL_NAME (arg));
863 }
864 }
865 else
866 {
867 parm = tsubst (parm, arglist, NULL_TREE);
868 /* It's a PARM_DECL. */
869 build_mangled_name (TREE_TYPE (parm), 0, 0);
870 build_overload_value (parm, arg, uses_template_parms (arglist));
871 }
872 }
873 }
874
875
876 static void
877 build_overload_identifier (name)
878 tree name;
879 {
880 if (TREE_CODE (name) == TYPE_DECL
881 && IS_AGGR_TYPE (TREE_TYPE (name))
882 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
883 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))
884 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
885 (TREE_TYPE (name))))
886 == FUNCTION_DECL)))
887 {
888 tree template, parmlist, arglist, tname;
889 template = CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name));
890 arglist = TREE_VALUE (template);
891 template = TREE_PURPOSE (template);
892 tname = DECL_NAME (template);
893 parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
894 OB_PUTC ('t');
895 icat (IDENTIFIER_LENGTH (tname));
896 OB_PUTID (tname);
897 build_template_parm_names (parmlist, arglist);
898 }
899 else
900 {
901 if (TREE_CODE (name) == TYPE_DECL)
902 name = DECL_NAME (name);
903 if (numeric_output_need_bar)
904 {
905 OB_PUTC ('_');
906 numeric_output_need_bar = 0;
907 }
908 icat (IDENTIFIER_LENGTH (name));
909 OB_PUTID (name);
910 }
911 }
912
913 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
914 the mangling for it. Used by build_mangled_name and build_static_name. */
915
916 static void
917 build_qualified_name (decl)
918 tree decl;
919 {
920 tree context;
921 int i = 1;
922
923 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
924 decl = TYPE_NAME (decl);
925
926 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
927 if (TREE_CODE (decl) == TYPE_DECL
928 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling)
929 {
930 tree id = DECL_ASSEMBLER_NAME (decl);
931 OB_PUTID (id);
932 if (isdigit (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1]))
933 numeric_output_need_bar = 1;
934 return;
935 }
936
937 context = decl;
938 /* if we can't find a Ktype, do it the hard way */
939 if (check_ktype (context, FALSE) == -1)
940 {
941 /* count type scopes */
942 while (DECL_CONTEXT (context))
943 {
944 i += 1;
945 context = DECL_CONTEXT (context);
946 if (check_ktype (context, FALSE) != -1) /* found it! */
947 break;
948 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
949 context = TYPE_NAME (context);
950 }
951 /* now count namespace scopes */
952 if (TREE_CODE (decl) == NAMESPACE_DECL)
953 {
954 i = 0; /* we have nothing done, yet: reset */
955 context = decl;
956 }
957 else
958 /* decl must be a type, which we have to scope with the
959 namespace */
960 {
961 /* XXX MvL somehow, types have no lang_decl, so no namespace */
962 context = current_namespace;
963 }
964 }
965
966 while (context != global_namespace)
967 {
968 i += 1;
969 context = DECL_NAMESPACE (context);
970 }
971
972 if (i > 1)
973 {
974 OB_PUTC ('Q');
975 build_underscore_int (i);
976 numeric_output_need_bar = 0;
977 }
978 build_overload_nested_name (decl);
979 }
980
981 /* Given a list of parameters in PARMTYPES, create an unambiguous
982 overload string. Should distinguish any type that C (or C++) can
983 distinguish. I.e., pointers to functions are treated correctly.
984
985 Caller must deal with whether a final `e' goes on the end or not.
986
987 Any default conversions must take place before this function
988 is called.
989
990 BEGIN and END control initialization and finalization of the
991 obstack where we build the string. */
992
993 char *
994 build_overload_name (parmtypes, begin, end)
995 tree parmtypes;
996 int begin, end;
997 {
998 char *ret;
999 start_squangling ();
1000 ret = build_mangled_name (parmtypes, begin, end);
1001 end_squangling ();
1002 return ret ;
1003 }
1004
1005 static char *
1006 build_mangled_name (parmtypes, begin, end)
1007 tree parmtypes;
1008 int begin, end;
1009 {
1010 tree parmtype;
1011
1012 if (begin)
1013 OB_INIT ();
1014 numeric_output_need_bar = 0;
1015
1016 if (TREE_CODE (parmtypes) != TREE_LIST) /* just one item */
1017 {
1018 if (TYPE_PTRMEMFUNC_P (parmtypes))
1019 parmtypes = TYPE_PTRMEMFUNC_FN_TYPE (parmtypes);
1020 process_modifiers (parmtypes);
1021 process_overload_item (parmtypes, FALSE);
1022 }
1023 else {
1024 for ( ; parmtypes!=NULL; parmtypes = TREE_CHAIN (parmtypes))
1025 {
1026 parmtype = TREE_VALUE (parmtypes);
1027 if (flag_do_squangling) /* squangling style repeats */
1028 {
1029 if (parmtype == lasttype)
1030 {
1031 nrepeats++;
1032 continue;
1033 }
1034 else
1035 if (nrepeats != 0)
1036 {
1037 issue_nrepeats (lasttype);
1038 }
1039 lasttype = parmtype;
1040 }
1041 else
1042 if (!nofold && typevec)
1043 {
1044 /* Every argument gets counted. */
1045 typevec[maxtype++] = parmtype;
1046
1047 if (TREE_USED (parmtype) && parmtype == typevec[maxtype-2])
1048 {
1049 Nrepeats++;
1050 continue;
1051 }
1052
1053 if (Nrepeats)
1054 flush_repeats (typevec[maxtype-2]);
1055
1056 if (TREE_USED (parmtype))
1057 {
1058 #if 0
1059 /* We can turn this on at some point when we want
1060 improved symbol mangling. */
1061 Nrepeats++;
1062 #else
1063 /* This is bug compatible with 2.7.x */
1064 flush_repeats (parmtype);
1065 #endif
1066 continue;
1067 }
1068
1069 /* Only cache types which take more than one character. */
1070 if (parmtype != TYPE_MAIN_VARIANT (parmtype)
1071 || (TREE_CODE (parmtype) != INTEGER_TYPE
1072 && TREE_CODE (parmtype) != REAL_TYPE))
1073 TREE_USED (parmtype) = 1;
1074 }
1075 if (TYPE_PTRMEMFUNC_P (parmtype))
1076 parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype);
1077 process_modifiers (parmtype);
1078 if (TREE_CODE(parmtype)==VOID_TYPE)
1079 {
1080 #if 0
1081 extern tree void_list_node;
1082
1083 /* See if anybody is wasting memory. */
1084 my_friendly_assert (parmtypes == void_list_node, 247);
1085 #endif
1086 /* This is the end of a parameter list. */
1087 if (end)
1088 OB_FINISH ();
1089 return (char *)obstack_base (&scratch_obstack);
1090 }
1091 process_overload_item (parmtype, TRUE);
1092 }
1093 if (flag_do_squangling && nrepeats != 0)
1094 issue_nrepeats (lasttype);
1095 else
1096 if (Nrepeats && typevec)
1097 flush_repeats (typevec[maxtype-1]);
1098
1099 /* To get here, parms must end with `...'. */
1100 OB_PUTC ('e');
1101 }
1102 if (end)
1103 OB_FINISH ();
1104 return (char *)obstack_base (&scratch_obstack);
1105 }
1106
1107 /* handles emitting modifiers such as Constant, read-only, and volatile */
1108 void
1109 process_modifiers (parmtype)
1110 tree parmtype;
1111 {
1112
1113
1114 if (TREE_READONLY (parmtype))
1115 OB_PUTC ('C');
1116 if (TREE_CODE (parmtype) == INTEGER_TYPE &&
1117 TYPE_MAIN_VARIANT (parmtype) ==
1118 unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
1119 OB_PUTC ('U');
1120 if (TYPE_VOLATILE (parmtype))
1121 OB_PUTC ('V');
1122 }
1123
1124 /* Check to see if a tree node has been entered into the Bcode typelist
1125 if not, add it. Otherwise emit the code and return TRUE */
1126 static int
1127 check_btype (node)
1128 tree node;
1129 {
1130 int x;
1131
1132 if (btypelist == NULL)
1133 return 0;
1134
1135 switch (TREE_CODE (node))
1136 {
1137 case INTEGER_TYPE:
1138 case REAL_TYPE:
1139 case VOID_TYPE:
1140 case BOOLEAN_TYPE:
1141 return 0; /* don't compress single char basic types */
1142
1143 default:
1144 break;
1145 }
1146
1147 node = TYPE_MAIN_VARIANT (node);
1148 for (x = 0; x < maxbtype; x++)
1149 {
1150 if (node == btypelist[x])
1151 {
1152 OB_PUTC ('B');
1153 icat (x);
1154 if (x > 9)
1155 OB_PUTC ('_');
1156 return 1 ;
1157 }
1158 }
1159 /* didn't find it, so add it here */
1160 if (maxbsize <= maxbtype)
1161 {
1162 maxbsize = maxbsize * 3 / 2;
1163 btypelist = (tree *)xrealloc (sizeof (tree) * maxbsize);
1164 }
1165 btypelist[maxbtype++] = node;
1166 return 0;
1167 }
1168
1169 /* handle emitting the correct code for various node types */
1170 static void
1171 process_overload_item (parmtype, extra_Gcode)
1172 tree parmtype;
1173 int extra_Gcode;
1174 {
1175
1176 /* These tree types are considered modifiers for B code squangling , */
1177 /* and therefore should not get entries in the Btypelist */
1178 /* they are, however, repeatable types */
1179
1180 switch (TREE_CODE (parmtype))
1181 {
1182 case REFERENCE_TYPE:
1183 OB_PUTC ('R');
1184 goto more;
1185
1186 case ARRAY_TYPE:
1187 #if PARM_CAN_BE_ARRAY_TYPE
1188 {
1189 tree length;
1190
1191 OB_PUTC ('A');
1192 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
1193 error("pointer/reference to array of unknown bound in parm type");
1194 else
1195 {
1196 length = array_type_nelts (parmtype);
1197 if (TREE_CODE (length) == INTEGER_CST)
1198 icat (TREE_INT_CST_LOW (length) + 1);
1199 }
1200 OB_PUTC ('_');
1201 goto more;
1202 }
1203 #else
1204 OB_PUTC ('P');
1205 goto more;
1206 #endif
1207
1208 case POINTER_TYPE:
1209 OB_PUTC ('P');
1210 more:
1211 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1212 return;
1213 break;
1214
1215 default:
1216 break;
1217 }
1218
1219 /* check if type is already in the typelist. If not, add it now */
1220
1221 if (flag_do_squangling && btypelist != NULL) {
1222 if (check_btype (parmtype)) /* emits the code if it finds it */
1223 return;
1224 }
1225
1226 switch (TREE_CODE (parmtype))
1227 {
1228 case OFFSET_TYPE:
1229 OB_PUTC ('O');
1230 build_mangled_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0);
1231 OB_PUTC ('_');
1232 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1233 break;
1234
1235 case FUNCTION_TYPE:
1236 case METHOD_TYPE:
1237 {
1238 tree firstarg = TYPE_ARG_TYPES (parmtype);
1239 /* Otherwise have to implement reentrant typevecs,
1240 unmark and remark types, etc. */
1241 int old_nofold = nofold;
1242 if (!flag_do_squangling) {
1243 nofold = 1;
1244 if (Nrepeats)
1245 flush_repeats (typevec[maxtype-1]);
1246 }
1247 else
1248 if (nrepeats != 0)
1249 issue_nrepeats (lasttype);
1250
1251 /* @@ It may be possible to pass a function type in
1252 which is not preceded by a 'P'. */
1253 if (TREE_CODE (parmtype) == FUNCTION_TYPE)
1254 {
1255 OB_PUTC ('F');
1256 if (firstarg == NULL_TREE)
1257 OB_PUTC ('e');
1258 else if (firstarg == void_list_node)
1259 OB_PUTC ('v');
1260 else
1261 build_mangled_name (firstarg, 0, 0);
1262 }
1263 else
1264 {
1265 int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
1266 int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
1267 OB_PUTC ('M');
1268 firstarg = TREE_CHAIN (firstarg);
1269
1270 build_mangled_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0);
1271 if (constp)
1272 OB_PUTC ('C');
1273 if (volatilep)
1274 OB_PUTC ('V');
1275
1276 /* For cfront 2.0 compatibility. */
1277 OB_PUTC ('F');
1278
1279 if (firstarg == NULL_TREE)
1280 OB_PUTC ('e');
1281 else if (firstarg == void_list_node)
1282 OB_PUTC ('v');
1283 else
1284 build_mangled_name (firstarg, 0, 0);
1285 }
1286
1287 /* Separate args from return type. */
1288 OB_PUTC ('_');
1289 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1290 nofold = old_nofold;
1291 break;
1292 }
1293
1294 case INTEGER_TYPE:
1295 parmtype = TYPE_MAIN_VARIANT (parmtype);
1296 if (parmtype == integer_type_node
1297 || parmtype == unsigned_type_node)
1298 OB_PUTC ('i');
1299 else if (parmtype == long_integer_type_node
1300 || parmtype == long_unsigned_type_node)
1301 OB_PUTC ('l');
1302 else if (parmtype == short_integer_type_node
1303 || parmtype == short_unsigned_type_node)
1304 OB_PUTC ('s');
1305 else if (parmtype == signed_char_type_node)
1306 {
1307 OB_PUTC ('S');
1308 OB_PUTC ('c');
1309 }
1310 else if (parmtype == char_type_node
1311 || parmtype == unsigned_char_type_node)
1312 OB_PUTC ('c');
1313 else if (parmtype == wchar_type_node)
1314 OB_PUTC ('w');
1315 else if (parmtype == long_long_integer_type_node
1316 || parmtype == long_long_unsigned_type_node)
1317 OB_PUTC ('x');
1318 #if 0
1319 /* it would seem there is no way to enter these in source code,
1320 yet. (mrs) */
1321 else if (parmtype == long_long_long_integer_type_node
1322 || parmtype == long_long_long_unsigned_type_node)
1323 OB_PUTC ('q');
1324 #endif
1325 else
1326 my_friendly_abort (73);
1327 break;
1328
1329 case BOOLEAN_TYPE:
1330 OB_PUTC ('b');
1331 break;
1332
1333 case REAL_TYPE:
1334 parmtype = TYPE_MAIN_VARIANT (parmtype);
1335 if (parmtype == long_double_type_node)
1336 OB_PUTC ('r');
1337 else if (parmtype == double_type_node)
1338 OB_PUTC ('d');
1339 else if (parmtype == float_type_node)
1340 OB_PUTC ('f');
1341 else my_friendly_abort (74);
1342 break;
1343
1344 case COMPLEX_TYPE:
1345 OB_PUTC ('J');
1346 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1347 break;
1348
1349 case VOID_TYPE:
1350 OB_PUTC ('v');
1351 break;
1352
1353 case ERROR_MARK: /* not right, but nothing is anyway */
1354 break;
1355
1356 /* have to do these */
1357 case UNION_TYPE:
1358 case RECORD_TYPE:
1359 {
1360 if (extra_Gcode)
1361 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1362 /* drop through into next case */
1363 }
1364 case ENUMERAL_TYPE:
1365 {
1366 tree name = TYPE_NAME (parmtype);
1367
1368 if (TREE_CODE (name) == IDENTIFIER_NODE)
1369 {
1370 build_overload_identifier (TYPE_NAME (parmtype));
1371 break;
1372 }
1373 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
1374
1375 build_qualified_name (name);
1376 break;
1377 }
1378
1379 case UNKNOWN_TYPE:
1380 /* This will take some work. */
1381 OB_PUTC ('?');
1382 break;
1383
1384 case TEMPLATE_TEMPLATE_PARM:
1385 /* Find and output the original template parameter
1386 declaration. */
1387 if (CLASSTYPE_TEMPLATE_INFO (parmtype))
1388 {
1389 build_mangled_template_parm_index ("tzX",
1390 TEMPLATE_TYPE_PARM_INDEX
1391 (parmtype));
1392 build_template_parm_names
1393 (DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype)),
1394 CLASSTYPE_TI_ARGS (parmtype));
1395 }
1396 else
1397 {
1398 build_mangled_template_parm_index ("ZzX",
1399 TEMPLATE_TYPE_PARM_INDEX
1400 (parmtype));
1401 build_template_template_parm_names
1402 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
1403 }
1404 break;
1405
1406 case TEMPLATE_TYPE_PARM:
1407 build_mangled_template_parm_index ("X",
1408 TEMPLATE_TYPE_PARM_INDEX
1409 (parmtype));
1410 break;
1411
1412 case TYPENAME_TYPE:
1413 /* When mangling the type of a function template whose
1414 declaration looks like:
1415
1416 template <class T> void foo(typename T::U)
1417
1418 we have to mangle these. */
1419 build_qualified_name (parmtype);
1420 break;
1421
1422 default:
1423 my_friendly_abort (75);
1424 }
1425
1426 }
1427
1428 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1429 be either a class TYPE or a FUNCTION_DECL. */
1430
1431 tree
1432 build_static_name (context, name)
1433 tree context, name;
1434 {
1435 OB_INIT ();
1436 numeric_output_need_bar = 0;
1437 start_squangling ();
1438 #ifdef JOINER
1439 OB_PUTC ('_');
1440 build_qualified_name (context);
1441 OB_PUTC (JOINER);
1442 #else
1443 OB_PUTS ("__static_");
1444 build_qualified_name (context);
1445 OB_PUTC ('_');
1446 #endif
1447 OB_PUTID (name);
1448 OB_FINISH ();
1449 end_squangling ();
1450
1451 return get_identifier ((char *)obstack_base (&scratch_obstack));
1452 }
1453 \f
1454 static tree
1455 build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1456 for_method)
1457 tree dname;
1458 tree parms;
1459 tree ret_type;
1460 tree tparms;
1461 tree targs;
1462 int for_method;
1463 {
1464 char *name = IDENTIFIER_POINTER (dname);
1465
1466 /* member operators new and delete look like methods at this point. */
1467 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
1468 && TREE_CHAIN (parms) == void_list_node)
1469 {
1470 if (dname == ansi_opname[(int) DELETE_EXPR])
1471 return get_identifier ("__builtin_delete");
1472 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1473 return get_identifier ("__builtin_vec_delete");
1474 if (dname == ansi_opname[(int) NEW_EXPR])
1475 return get_identifier ("__builtin_new");
1476 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1477 return get_identifier ("__builtin_vec_new");
1478 }
1479
1480 start_squangling ();
1481 OB_INIT ();
1482 if (for_method != 2)
1483 OB_PUTCP (name);
1484 /* Otherwise, we can divine that this is a constructor,
1485 and figure out its name without any extra encoding. */
1486
1487 OB_PUTC2 ('_', '_');
1488 if (for_method)
1489 {
1490 #if 0
1491 /* We can get away without doing this. */
1492 OB_PUTC ('M');
1493 #endif
1494 if (tparms != NULL_TREE)
1495 OB_PUTC ('H');
1496 {
1497 tree this_type = TREE_VALUE (parms);
1498
1499 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
1500 parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type),
1501 TREE_CHAIN (parms));
1502 else
1503 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type),
1504 TREE_CHAIN (parms));
1505 }
1506 }
1507 else if (tparms)
1508 OB_PUTC ('H');
1509 /* XXX this works only if we call this in the same namespace
1510 as the declaration. Unfortunately, we don't have the _DECL,
1511 only its name */
1512 else if (current_namespace == global_namespace)
1513 OB_PUTC ('F');
1514
1515 if (tparms)
1516 {
1517 build_template_parm_names (tparms, targs);
1518 OB_PUTC ('_');
1519 }
1520
1521 /* qualify with namespace */
1522 if (!for_method && current_namespace != global_namespace)
1523 build_qualified_name (current_namespace);
1524
1525 if (parms == NULL_TREE)
1526 OB_PUTC ('e');
1527 else if (parms == void_list_node)
1528 OB_PUTC ('v');
1529 else
1530 {
1531 if (!flag_do_squangling) /* Allocate typevec array. */
1532 {
1533 maxtype = 0;
1534 Nrepeats = 0;
1535 typevec = (tree *)alloca (list_length (parms) * sizeof (tree));
1536 }
1537 nofold = 0;
1538 if (for_method)
1539 {
1540 build_mangled_name (TREE_VALUE (parms), 0, 0);
1541
1542 if (!flag_do_squangling) {
1543 typevec[maxtype++] = TREE_VALUE (parms);
1544 TREE_USED (TREE_VALUE (parms)) = 1;
1545 }
1546
1547 if (TREE_CHAIN (parms))
1548 build_mangled_name (TREE_CHAIN (parms), 0, 0);
1549 else
1550 OB_PUTC ('e');
1551 }
1552 else
1553 {
1554 /* the namespace qualifier for a global function
1555 will count as type */
1556 if (current_namespace != global_namespace
1557 && !flag_do_squangling)
1558 typevec[maxtype++] = current_namespace;
1559 build_mangled_name (parms, 0, 0);
1560 }
1561
1562 if (!flag_do_squangling) /* Deallocate typevec array */
1563 {
1564 tree t = parms;
1565 typevec = NULL;
1566 while (t)
1567 {
1568 TREE_USED (TREE_VALUE (t)) = 0;
1569 t = TREE_CHAIN (t);
1570 }
1571 }
1572 }
1573
1574 if (ret_type != NULL_TREE && for_method != 2)
1575 {
1576 /* Add the return type. */
1577 OB_PUTC ('_');
1578 build_mangled_name (ret_type, 0, 0);
1579 }
1580
1581 OB_FINISH ();
1582 end_squangling ();
1583 {
1584 tree n = get_identifier (obstack_base (&scratch_obstack));
1585 if (IDENTIFIER_OPNAME_P (dname))
1586 IDENTIFIER_OPNAME_P (n) = 1;
1587 return n;
1588 }
1589 }
1590
1591 /* Change the name of a function definition so that it may be
1592 overloaded. NAME is the name of the function to overload,
1593 PARMS is the parameter list (which determines what name the
1594 final function obtains).
1595
1596 FOR_METHOD is 1 if this overload is being performed
1597 for a method, rather than a function type. It is 2 if
1598 this overload is being performed for a constructor. */
1599
1600 tree
1601 build_decl_overload (dname, parms, for_method)
1602 tree dname;
1603 tree parms;
1604 int for_method;
1605 {
1606 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1607 NULL_TREE, for_method);
1608 }
1609
1610
1611 /* Like build_decl_overload, but for template functions. */
1612
1613 tree
1614 build_template_decl_overload (dname, parms, ret_type, tparms, targs,
1615 for_method)
1616 tree dname;
1617 tree parms;
1618 tree ret_type;
1619 tree tparms;
1620 tree targs;
1621 int for_method;
1622 {
1623 return build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1624 for_method);
1625 }
1626
1627
1628 /* Build an overload name for the type expression TYPE. */
1629
1630 tree
1631 build_typename_overload (type)
1632 tree type;
1633 {
1634 tree id;
1635
1636 OB_INIT ();
1637 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1638 nofold = 1;
1639 start_squangling ();
1640 build_mangled_name (type, 0, 1);
1641 id = get_identifier (obstack_base (&scratch_obstack));
1642 IDENTIFIER_OPNAME_P (id) = 1;
1643 #if 0
1644 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1645 #endif
1646 TREE_TYPE (id) = type;
1647 end_squangling ();
1648 return id;
1649 }
1650
1651 tree
1652 build_overload_with_type (name, type)
1653 tree name, type;
1654 {
1655 OB_INIT ();
1656 OB_PUTID (name);
1657 nofold = 1;
1658
1659 start_squangling ();
1660 build_mangled_name (type, 0, 1);
1661 end_squangling ();
1662 return get_identifier (obstack_base (&scratch_obstack));
1663 }
1664
1665 tree
1666 get_id_2 (name, name2)
1667 char *name;
1668 tree name2;
1669 {
1670 OB_INIT ();
1671 OB_PUTCP (name);
1672 OB_PUTID (name2);
1673 OB_FINISH ();
1674 return get_identifier (obstack_base (&scratch_obstack));
1675 }
1676 \f
1677 /* Given a tree_code CODE, and some arguments (at least one),
1678 attempt to use an overloaded operator on the arguments.
1679
1680 For unary operators, only the first argument need be checked.
1681 For binary operators, both arguments may need to be checked.
1682
1683 Member functions can convert class references to class pointers,
1684 for one-level deep indirection. More than that is not supported.
1685 Operators [](), ()(), and ->() must be member functions.
1686
1687 We call function call building calls with LOOKUP_COMPLAIN if they
1688 are our only hope. This is true when we see a vanilla operator
1689 applied to something of aggregate type. If this fails, we are free
1690 to return `error_mark_node', because we will have reported the
1691 error.
1692
1693 Operators NEW and DELETE overload in funny ways: operator new takes
1694 a single `size' parameter, and operator delete takes a pointer to the
1695 storage being deleted. When overloading these operators, success is
1696 assumed. If there is a failure, report an error message and return
1697 `error_mark_node'. */
1698
1699 /* NOSTRICT */
1700 tree
1701 build_opfncall (code, flags, xarg1, xarg2, arg3)
1702 enum tree_code code;
1703 int flags;
1704 tree xarg1, xarg2, arg3;
1705 {
1706 return build_new_op (code, flags, xarg1, xarg2, arg3);
1707 }
1708 \f
1709 /* This function takes an identifier, ID, and attempts to figure out what
1710 it means. There are a number of possible scenarios, presented in increasing
1711 order of hair:
1712
1713 1) not in a class's scope
1714 2) in class's scope, member name of the class's method
1715 3) in class's scope, but not a member name of the class
1716 4) in class's scope, member name of a class's variable
1717
1718 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1719 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1720
1721 As a last ditch, try to look up the name as a label and return that
1722 address.
1723
1724 Values which are declared as being of REFERENCE_TYPE are
1725 automatically dereferenced here (as a hack to make the
1726 compiler faster). */
1727
1728 tree
1729 hack_identifier (value, name)
1730 tree value, name;
1731 {
1732 tree type;
1733
1734 if (value == error_mark_node)
1735 {
1736 if (current_class_name)
1737 {
1738 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1739 if (fields == error_mark_node)
1740 return error_mark_node;
1741 if (fields)
1742 {
1743 tree fndecl;
1744
1745 fndecl = TREE_VALUE (fields);
1746 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1747 if (DECL_CHAIN (fndecl) == NULL_TREE)
1748 {
1749 warning ("methods cannot be converted to function pointers");
1750 return fndecl;
1751 }
1752 else
1753 {
1754 error ("ambiguous request for method pointer `%s'",
1755 IDENTIFIER_POINTER (name));
1756 return error_mark_node;
1757 }
1758 }
1759 }
1760 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1761 {
1762 return IDENTIFIER_LABEL_VALUE (name);
1763 }
1764 return error_mark_node;
1765 }
1766
1767 type = TREE_TYPE (value);
1768 if (TREE_CODE (value) == FIELD_DECL)
1769 {
1770 if (current_class_ptr == NULL_TREE)
1771 {
1772 error ("request for member `%s' in static member function",
1773 IDENTIFIER_POINTER (DECL_NAME (value)));
1774 return error_mark_node;
1775 }
1776 TREE_USED (current_class_ptr) = 1;
1777
1778 /* Mark so that if we are in a constructor, and then find that
1779 this field was initialized by a base initializer,
1780 we can emit an error message. */
1781 TREE_USED (value) = 1;
1782 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
1783 }
1784 else if (really_overloaded_fn (value))
1785 {
1786 #if 0
1787 tree t = get_first_fn (value);
1788 for (; t; t = DECL_CHAIN (t))
1789 {
1790 if (TREE_CODE (t) == TEMPLATE_DECL)
1791 continue;
1792
1793 assemble_external (t);
1794 TREE_USED (t) = 1;
1795 }
1796 #endif
1797 }
1798 else if (TREE_CODE (value) == TREE_LIST)
1799 {
1800 /* Ambiguous reference to base members, possibly other cases?. */
1801 tree t = value;
1802 while (t && TREE_CODE (t) == TREE_LIST)
1803 {
1804 mark_used (TREE_VALUE (t));
1805 t = TREE_CHAIN (t);
1806 }
1807 }
1808 else
1809 mark_used (value);
1810
1811 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL)
1812 {
1813 tree context = decl_function_context (value);
1814 if (context != NULL_TREE && context != current_function_decl
1815 && ! TREE_STATIC (value))
1816 {
1817 cp_error ("use of %s from containing function",
1818 (TREE_CODE (value) == VAR_DECL
1819 ? "`auto' variable" : "parameter"));
1820 cp_error_at (" `%#D' declared here", value);
1821 value = error_mark_node;
1822 }
1823 }
1824
1825 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1826 {
1827 if (DECL_LANG_SPECIFIC (value)
1828 && DECL_CLASS_CONTEXT (value) != current_class_type)
1829 {
1830 tree path, access;
1831 register tree context
1832 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1833 ? DECL_CLASS_CONTEXT (value)
1834 : DECL_CONTEXT (value);
1835
1836 get_base_distance (context, current_class_type, 0, &path);
1837 if (path)
1838 {
1839 access = compute_access (path, value);
1840 if (access != access_public_node)
1841 {
1842 if (TREE_CODE (value) == VAR_DECL)
1843 error ("static member `%s' is %s",
1844 IDENTIFIER_POINTER (name),
1845 TREE_PRIVATE (value) ? "private"
1846 : "from a private base class");
1847 else
1848 error ("enum `%s' is from private base class",
1849 IDENTIFIER_POINTER (name));
1850 return error_mark_node;
1851 }
1852 }
1853 }
1854 }
1855 else if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1856 {
1857 if (type == 0)
1858 {
1859 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1860 IDENTIFIER_POINTER (name));
1861 return error_mark_node;
1862 }
1863
1864 return value;
1865 }
1866
1867 if (TREE_CODE (type) == REFERENCE_TYPE && ! processing_template_decl)
1868 value = convert_from_reference (value);
1869 return value;
1870 }
1871
1872 \f
1873 tree
1874 make_thunk (function, delta)
1875 tree function;
1876 int delta;
1877 {
1878 char *buffer;
1879 tree thunk_id;
1880 tree thunk;
1881 char *func_name;
1882 tree func_decl;
1883 if (TREE_CODE (function) != ADDR_EXPR)
1884 abort ();
1885 func_decl = TREE_OPERAND (function, 0);
1886 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1887 abort ();
1888 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1889 buffer = (char *)alloca (strlen (func_name) + 32);
1890 if (delta<=0)
1891 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1892 else
1893 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1894 thunk_id = get_identifier (buffer);
1895 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1896 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1897 {
1898 cp_error ("implementation-reserved name `%D' used", thunk_id);
1899 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1900 }
1901 if (thunk == NULL_TREE)
1902 {
1903 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
1904 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
1905 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
1906 comdat_linkage (thunk);
1907 TREE_SET_CODE (thunk, THUNK_DECL);
1908 DECL_INITIAL (thunk) = function;
1909 THUNK_DELTA (thunk) = delta;
1910 DECL_EXTERNAL (thunk) = 1;
1911 DECL_ARTIFICIAL (thunk) = 1;
1912 /* So that finish_file can write out any thunks that need to be: */
1913 pushdecl_top_level (thunk);
1914 }
1915 return thunk;
1916 }
1917
1918 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1919
1920 void
1921 emit_thunk (thunk_fndecl)
1922 tree thunk_fndecl;
1923 {
1924 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1925 int delta = THUNK_DELTA (thunk_fndecl);
1926
1927 if (TREE_ASM_WRITTEN (thunk_fndecl))
1928 return;
1929
1930 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1931
1932 TREE_ADDRESSABLE (function) = 1;
1933 mark_used (function);
1934
1935 if (current_function_decl)
1936 abort ();
1937
1938 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
1939
1940 {
1941 #ifdef ASM_OUTPUT_MI_THUNK
1942 char *fnname;
1943 current_function_decl = thunk_fndecl;
1944 /* Make sure we build up its RTL before we go onto the
1945 temporary obstack. */
1946 make_function_rtl (thunk_fndecl);
1947 temporary_allocation ();
1948 DECL_RESULT (thunk_fndecl)
1949 = build_decl (RESULT_DECL, 0, integer_type_node);
1950 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
1951 init_function_start (thunk_fndecl, input_filename, lineno);
1952 assemble_start_function (thunk_fndecl, fnname);
1953 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
1954 assemble_end_function (thunk_fndecl, fnname);
1955 permanent_allocation (1);
1956 current_function_decl = 0;
1957 #else /* ASM_OUTPUT_MI_THUNK */
1958 /* If we don't have the necessary macro for efficient thunks, generate a
1959 thunk function that just makes a call to the real function.
1960 Unfortunately, this doesn't work for varargs. */
1961
1962 tree a, t;
1963
1964 if (varargs_function_p (function))
1965 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
1966 function);
1967
1968 /* Set up clone argument trees for the thunk. */
1969 t = NULL_TREE;
1970 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
1971 {
1972 tree x = copy_node (a);
1973 TREE_CHAIN (x) = t;
1974 DECL_CONTEXT (x) = thunk_fndecl;
1975 t = x;
1976 }
1977 a = nreverse (t);
1978 DECL_ARGUMENTS (thunk_fndecl) = a;
1979 DECL_RESULT (thunk_fndecl) = NULL_TREE;
1980 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
1981 copy_lang_decl (thunk_fndecl);
1982 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
1983 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
1984
1985 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, 1);
1986 store_parm_decls ();
1987 current_function_is_thunk = 1;
1988
1989 /* Build up the call to the real function. */
1990 t = build_int_2 (delta, -1 * (delta < 0));
1991 TREE_TYPE (t) = signed_type (sizetype);
1992 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
1993 t = expr_tree_cons (NULL_TREE, t, NULL_TREE);
1994 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
1995 t = expr_tree_cons (NULL_TREE, a, t);
1996 t = nreverse (t);
1997 t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t);
1998 c_expand_return (t);
1999
2000 finish_function (lineno, 0, 0);
2001
2002 /* Don't let the backend defer this function. */
2003 if (DECL_DEFER_OUTPUT (thunk_fndecl))
2004 {
2005 output_inline_function (thunk_fndecl);
2006 permanent_allocation (1);
2007 }
2008 #endif /* ASM_OUTPUT_MI_THUNK */
2009 }
2010
2011 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
2012 }
2013 \f
2014 /* Code for synthesizing methods which have default semantics defined. */
2015
2016 /* For the anonymous union in TYPE, return the member that is at least as
2017 large as the rest of the members, so we can copy it. */
2018
2019 static tree
2020 largest_union_member (type)
2021 tree type;
2022 {
2023 tree f, type_size = TYPE_SIZE (type);
2024
2025 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
2026 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
2027 return f;
2028
2029 /* We should always find one. */
2030 my_friendly_abort (323);
2031 return NULL_TREE;
2032 }
2033
2034 /* Generate code for default X(X&) constructor. */
2035
2036 static void
2037 do_build_copy_constructor (fndecl)
2038 tree fndecl;
2039 {
2040 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2041 tree t;
2042
2043 clear_last_expr ();
2044 push_momentary ();
2045
2046 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2047 parm = TREE_CHAIN (parm);
2048 parm = convert_from_reference (parm);
2049
2050 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2051 {
2052 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
2053 TREE_SIDE_EFFECTS (t) = 1;
2054 cplus_expand_expr_stmt (t);
2055 }
2056 else
2057 {
2058 tree fields = TYPE_FIELDS (current_class_type);
2059 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2060 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2061 int i;
2062
2063 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2064 t = TREE_CHAIN (t))
2065 {
2066 tree basetype = BINFO_TYPE (t);
2067 tree p = convert_to_reference
2068 (build_reference_type (basetype), parm,
2069 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2070 p = convert_from_reference (p);
2071
2072 if (p == error_mark_node)
2073 cp_error ("in default copy constructor");
2074 else
2075 current_base_init_list = tree_cons (basetype,
2076 p, current_base_init_list);
2077 }
2078
2079 for (i = 0; i < n_bases; ++i)
2080 {
2081 tree p, basetype = TREE_VEC_ELT (binfos, i);
2082 if (TREE_VIA_VIRTUAL (basetype))
2083 continue;
2084
2085 basetype = BINFO_TYPE (basetype);
2086 p = convert_to_reference
2087 (build_reference_type (basetype), parm,
2088 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2089
2090 if (p == error_mark_node)
2091 cp_error ("in default copy constructor");
2092 else
2093 {
2094 p = convert_from_reference (p);
2095 current_base_init_list = tree_cons (basetype,
2096 p, current_base_init_list);
2097 }
2098 }
2099 for (; fields; fields = TREE_CHAIN (fields))
2100 {
2101 tree init, t;
2102 tree field = fields;
2103
2104 if (TREE_CODE (field) != FIELD_DECL)
2105 continue;
2106
2107 init = parm;
2108 if (DECL_NAME (field))
2109 {
2110 if (VFIELD_NAME_P (DECL_NAME (field)))
2111 continue;
2112 if (VBASE_NAME_P (DECL_NAME (field)))
2113 continue;
2114
2115 /* True for duplicate members. */
2116 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2117 continue;
2118 }
2119 else if ((t = TREE_TYPE (field)) != NULL_TREE
2120 && TREE_CODE (t) == UNION_TYPE
2121 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2122 && TYPE_FIELDS (t) != NULL_TREE)
2123 {
2124 do
2125 {
2126 init = build (COMPONENT_REF, t, init, field);
2127 field = largest_union_member (t);
2128 }
2129 while ((t = TREE_TYPE (field)) != NULL_TREE
2130 && TREE_CODE (t) == UNION_TYPE
2131 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2132 && TYPE_FIELDS (t) != NULL_TREE);
2133 }
2134 else
2135 continue;
2136
2137 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2138 init = build_tree_list (NULL_TREE, init);
2139
2140 current_member_init_list
2141 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2142 }
2143 current_member_init_list = nreverse (current_member_init_list);
2144 current_base_init_list = nreverse (current_base_init_list);
2145 setup_vtbl_ptr ();
2146 }
2147
2148 pop_momentary ();
2149 }
2150
2151 static void
2152 do_build_assign_ref (fndecl)
2153 tree fndecl;
2154 {
2155 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2156
2157 clear_last_expr ();
2158 push_momentary ();
2159
2160 parm = convert_from_reference (parm);
2161
2162 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2163 {
2164 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
2165 TREE_SIDE_EFFECTS (t) = 1;
2166 cplus_expand_expr_stmt (t);
2167 }
2168 else
2169 {
2170 tree fields = TYPE_FIELDS (current_class_type);
2171 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2172 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2173 int i;
2174
2175 for (i = 0; i < n_bases; ++i)
2176 {
2177 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2178 tree p = convert_to_reference
2179 (build_reference_type (basetype), parm,
2180 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2181 p = convert_from_reference (p);
2182 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2183 build_expr_list (NULL_TREE, p));
2184 expand_expr_stmt (p);
2185 }
2186 for (; fields; fields = TREE_CHAIN (fields))
2187 {
2188 tree comp, init, t;
2189 tree field = fields;
2190
2191 if (TREE_CODE (field) != FIELD_DECL)
2192 continue;
2193
2194 if (TREE_READONLY (field))
2195 {
2196 if (DECL_NAME (field))
2197 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
2198 else
2199 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
2200 continue;
2201 }
2202 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2203 {
2204 if (DECL_NAME (field))
2205 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
2206 else
2207 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
2208 continue;
2209 }
2210
2211 comp = current_class_ref;
2212 init = parm;
2213
2214 if (DECL_NAME (field))
2215 {
2216 if (VFIELD_NAME_P (DECL_NAME (field)))
2217 continue;
2218 if (VBASE_NAME_P (DECL_NAME (field)))
2219 continue;
2220
2221 /* True for duplicate members. */
2222 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2223 continue;
2224 }
2225 else if ((t = TREE_TYPE (field)) != NULL_TREE
2226 && TREE_CODE (t) == UNION_TYPE
2227 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2228 && TYPE_FIELDS (t) != NULL_TREE)
2229 {
2230 do
2231 {
2232 comp = build (COMPONENT_REF, t, comp, field);
2233 init = build (COMPONENT_REF, t, init, field);
2234 field = largest_union_member (t);
2235 }
2236 while ((t = TREE_TYPE (field)) != NULL_TREE
2237 && TREE_CODE (t) == UNION_TYPE
2238 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2239 && TYPE_FIELDS (t) != NULL_TREE);
2240 }
2241 else
2242 continue;
2243
2244 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2245 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2246
2247 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2248 }
2249 }
2250 c_expand_return (current_class_ref);
2251 pop_momentary ();
2252 }
2253
2254 void
2255 synthesize_method (fndecl)
2256 tree fndecl;
2257 {
2258 int nested = (current_function_decl != NULL_TREE);
2259 tree context = hack_decl_function_context (fndecl);
2260
2261 if (at_eof)
2262 import_export_decl (fndecl);
2263
2264 if (! context)
2265 push_to_top_level ();
2266 else if (nested)
2267 push_cp_function_context (context);
2268
2269 interface_unknown = 1;
2270 start_function (NULL_TREE, fndecl, NULL_TREE, 1);
2271 store_parm_decls ();
2272
2273 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2274 do_build_assign_ref (fndecl);
2275 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2276 ;
2277 else
2278 {
2279 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2280 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2281 arg_chain = TREE_CHAIN (arg_chain);
2282 if (arg_chain != void_list_node)
2283 do_build_copy_constructor (fndecl);
2284 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2285 setup_vtbl_ptr ();
2286 }
2287
2288 finish_function (lineno, 0, nested);
2289
2290 extract_interface_info ();
2291 if (! context)
2292 pop_from_top_level ();
2293 else if (nested)
2294 pop_cp_function_context (context);
2295 }