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