]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/method.c
6e20848102eec153cc93c884341cf73cc97230d3
[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 (ktypelist, 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 && ! is_java_type (parmtype))
1049 {
1050 Nrepeats++;
1051 continue;
1052 }
1053
1054 if (Nrepeats)
1055 flush_repeats (typevec[maxtype-2]);
1056
1057 if (TREE_USED (parmtype))
1058 {
1059 #if 0
1060 /* We can turn this on at some point when we want
1061 improved symbol mangling. */
1062 Nrepeats++;
1063 #else
1064 /* This is bug compatible with 2.7.x */
1065 flush_repeats (parmtype);
1066 #endif
1067 continue;
1068 }
1069
1070 /* Only cache types which take more than one character. */
1071 if ((parmtype != TYPE_MAIN_VARIANT (parmtype)
1072 || (TREE_CODE (parmtype) != INTEGER_TYPE
1073 && TREE_CODE (parmtype) != REAL_TYPE))
1074 && ! is_java_type (parmtype))
1075 TREE_USED (parmtype) = 1;
1076 }
1077 if (TYPE_PTRMEMFUNC_P (parmtype))
1078 parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype);
1079 process_modifiers (parmtype);
1080 if (TREE_CODE(parmtype)==VOID_TYPE)
1081 {
1082 #if 0
1083 extern tree void_list_node;
1084
1085 /* See if anybody is wasting memory. */
1086 my_friendly_assert (parmtypes == void_list_node, 247);
1087 #endif
1088 /* This is the end of a parameter list. */
1089 if (end)
1090 OB_FINISH ();
1091 return (char *)obstack_base (&scratch_obstack);
1092 }
1093 process_overload_item (parmtype, TRUE);
1094 }
1095 if (flag_do_squangling && nrepeats != 0)
1096 issue_nrepeats (lasttype);
1097 else
1098 if (Nrepeats && typevec)
1099 flush_repeats (typevec[maxtype-1]);
1100
1101 /* To get here, parms must end with `...'. */
1102 OB_PUTC ('e');
1103 }
1104 if (end)
1105 OB_FINISH ();
1106 return (char *)obstack_base (&scratch_obstack);
1107 }
1108
1109 /* handles emitting modifiers such as Constant, read-only, and volatile */
1110 void
1111 process_modifiers (parmtype)
1112 tree parmtype;
1113 {
1114
1115
1116 if (TREE_READONLY (parmtype))
1117 OB_PUTC ('C');
1118 if (TREE_CODE (parmtype) == INTEGER_TYPE
1119 && (TYPE_MAIN_VARIANT (parmtype)
1120 == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
1121 && ! is_java_type (parmtype))
1122 {
1123 OB_PUTC ('U');
1124 }
1125 if (TYPE_VOLATILE (parmtype))
1126 OB_PUTC ('V');
1127 }
1128
1129 /* True iff TYPE was declared as a "Java" type (inside extern "Java"). */
1130
1131 int
1132 is_java_type (type)
1133 tree type;
1134 {
1135 if (TYPE_NAME (type) != NULL_TREE)
1136 {
1137 tree decl = TYPE_NAME (type);
1138 if (TREE_CODE (decl) == TYPE_DECL
1139 && DECL_LANG_SPECIFIC (decl) != NULL
1140 && DECL_LANGUAGE (decl) == lang_java)
1141 return 1;
1142 }
1143 return 0;
1144 }
1145
1146 /* Check to see if a tree node has been entered into the Bcode typelist
1147 if not, add it. Otherwise emit the code and return TRUE */
1148 static int
1149 check_btype (node)
1150 tree node;
1151 {
1152 int x;
1153
1154 if (btypelist == NULL)
1155 return 0;
1156
1157 switch (TREE_CODE (node))
1158 {
1159 case INTEGER_TYPE:
1160 case REAL_TYPE:
1161 case VOID_TYPE:
1162 case BOOLEAN_TYPE:
1163 return 0; /* don't compress single char basic types */
1164
1165 default:
1166 break;
1167 }
1168
1169 node = TYPE_MAIN_VARIANT (node);
1170 for (x = 0; x < maxbtype; x++)
1171 {
1172 if (node == btypelist[x])
1173 {
1174 OB_PUTC ('B');
1175 icat (x);
1176 if (x > 9)
1177 OB_PUTC ('_');
1178 return 1 ;
1179 }
1180 }
1181 /* didn't find it, so add it here */
1182 if (maxbsize <= maxbtype)
1183 {
1184 maxbsize = maxbsize * 3 / 2;
1185 btypelist = (tree *)xrealloc (btypelist, sizeof (tree) * maxbsize);
1186 }
1187 btypelist[maxbtype++] = node;
1188 return 0;
1189 }
1190
1191 /* handle emitting the correct code for various node types */
1192 static void
1193 process_overload_item (parmtype, extra_Gcode)
1194 tree parmtype;
1195 int extra_Gcode;
1196 {
1197
1198 /* These tree types are considered modifiers for B code squangling , */
1199 /* and therefore should not get entries in the Btypelist */
1200 /* they are, however, repeatable types */
1201
1202 switch (TREE_CODE (parmtype))
1203 {
1204 case REFERENCE_TYPE:
1205 OB_PUTC ('R');
1206 goto more;
1207
1208 case ARRAY_TYPE:
1209 #if PARM_CAN_BE_ARRAY_TYPE
1210 {
1211 tree length;
1212
1213 OB_PUTC ('A');
1214 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
1215 error("pointer/reference to array of unknown bound in parm type");
1216 else
1217 {
1218 length = array_type_nelts (parmtype);
1219 if (TREE_CODE (length) == INTEGER_CST)
1220 icat (TREE_INT_CST_LOW (length) + 1);
1221 }
1222 OB_PUTC ('_');
1223 goto more;
1224 }
1225 #else
1226 OB_PUTC ('P');
1227 goto more;
1228 #endif
1229
1230 case POINTER_TYPE:
1231 OB_PUTC ('P');
1232 more:
1233 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1234 return;
1235 break;
1236
1237 default:
1238 break;
1239 }
1240
1241 /* check if type is already in the typelist. If not, add it now */
1242
1243 if (flag_do_squangling && btypelist != NULL) {
1244 if (check_btype (parmtype)) /* emits the code if it finds it */
1245 return;
1246 }
1247
1248 switch (TREE_CODE (parmtype))
1249 {
1250 case OFFSET_TYPE:
1251 OB_PUTC ('O');
1252 build_mangled_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0);
1253 OB_PUTC ('_');
1254 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1255 break;
1256
1257 case FUNCTION_TYPE:
1258 case METHOD_TYPE:
1259 {
1260 tree firstarg = TYPE_ARG_TYPES (parmtype);
1261 /* Otherwise have to implement reentrant typevecs,
1262 unmark and remark types, etc. */
1263 int old_nofold = nofold;
1264 if (!flag_do_squangling) {
1265 nofold = 1;
1266 if (Nrepeats)
1267 flush_repeats (typevec[maxtype-1]);
1268 }
1269 else
1270 if (nrepeats != 0)
1271 issue_nrepeats (lasttype);
1272
1273 /* @@ It may be possible to pass a function type in
1274 which is not preceded by a 'P'. */
1275 if (TREE_CODE (parmtype) == FUNCTION_TYPE)
1276 {
1277 OB_PUTC ('F');
1278 if (firstarg == NULL_TREE)
1279 OB_PUTC ('e');
1280 else if (firstarg == void_list_node)
1281 OB_PUTC ('v');
1282 else
1283 build_mangled_name (firstarg, 0, 0);
1284 }
1285 else
1286 {
1287 int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg)));
1288 int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg)));
1289 OB_PUTC ('M');
1290 firstarg = TREE_CHAIN (firstarg);
1291
1292 build_mangled_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0);
1293 if (constp)
1294 OB_PUTC ('C');
1295 if (volatilep)
1296 OB_PUTC ('V');
1297
1298 /* For cfront 2.0 compatibility. */
1299 OB_PUTC ('F');
1300
1301 if (firstarg == NULL_TREE)
1302 OB_PUTC ('e');
1303 else if (firstarg == void_list_node)
1304 OB_PUTC ('v');
1305 else
1306 build_mangled_name (firstarg, 0, 0);
1307 }
1308
1309 /* Separate args from return type. */
1310 OB_PUTC ('_');
1311 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1312 nofold = old_nofold;
1313 break;
1314 }
1315
1316 case INTEGER_TYPE:
1317 /* "Java" integer types should mangle the same on all platforms,
1318 and only depend on precision, not target 'int' size. */
1319 if (is_java_type (parmtype))
1320 {
1321 if (TREE_UNSIGNED (parmtype))
1322 {
1323 switch (TYPE_PRECISION (parmtype))
1324 {
1325 case 8: OB_PUTC ('b'); return;
1326 case 16: OB_PUTC ('w'); return;
1327 }
1328 }
1329 else
1330 {
1331 switch (TYPE_PRECISION (parmtype))
1332 {
1333 case 8: OB_PUTC ('c'); return;
1334 case 16: OB_PUTC ('s'); return;
1335 case 32: OB_PUTC ('i'); return;
1336 case 64: OB_PUTC ('x'); return;
1337 }
1338 }
1339 }
1340
1341 parmtype = TYPE_MAIN_VARIANT (parmtype);
1342 if (parmtype == integer_type_node
1343 || parmtype == unsigned_type_node)
1344 OB_PUTC ('i');
1345 else if (parmtype == long_integer_type_node
1346 || parmtype == long_unsigned_type_node)
1347 OB_PUTC ('l');
1348 else if (parmtype == short_integer_type_node
1349 || parmtype == short_unsigned_type_node)
1350 OB_PUTC ('s');
1351 else if (parmtype == signed_char_type_node)
1352 {
1353 OB_PUTC ('S');
1354 OB_PUTC ('c');
1355 }
1356 else if (parmtype == char_type_node
1357 || parmtype == unsigned_char_type_node)
1358 OB_PUTC ('c');
1359 else if (parmtype == wchar_type_node)
1360 OB_PUTC ('w');
1361 else if (parmtype == long_long_integer_type_node
1362 || parmtype == long_long_unsigned_type_node)
1363 OB_PUTC ('x');
1364 #if 0
1365 /* it would seem there is no way to enter these in source code,
1366 yet. (mrs) */
1367 else if (parmtype == long_long_long_integer_type_node
1368 || parmtype == long_long_long_unsigned_type_node)
1369 OB_PUTC ('q');
1370 #endif
1371 else
1372 my_friendly_abort (73);
1373 break;
1374
1375 case BOOLEAN_TYPE:
1376 OB_PUTC ('b');
1377 break;
1378
1379 case REAL_TYPE:
1380 parmtype = TYPE_MAIN_VARIANT (parmtype);
1381 if (parmtype == long_double_type_node)
1382 OB_PUTC ('r');
1383 else if (parmtype == double_type_node)
1384 OB_PUTC ('d');
1385 else if (parmtype == float_type_node)
1386 OB_PUTC ('f');
1387 else my_friendly_abort (74);
1388 break;
1389
1390 case COMPLEX_TYPE:
1391 OB_PUTC ('J');
1392 build_mangled_name (TREE_TYPE (parmtype), 0, 0);
1393 break;
1394
1395 case VOID_TYPE:
1396 OB_PUTC ('v');
1397 break;
1398
1399 case ERROR_MARK: /* not right, but nothing is anyway */
1400 break;
1401
1402 /* have to do these */
1403 case UNION_TYPE:
1404 case RECORD_TYPE:
1405 {
1406 if (extra_Gcode)
1407 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1408 /* drop through into next case */
1409 }
1410 case ENUMERAL_TYPE:
1411 {
1412 tree name = TYPE_NAME (parmtype);
1413
1414 if (TREE_CODE (name) == IDENTIFIER_NODE)
1415 {
1416 build_overload_identifier (TYPE_NAME (parmtype));
1417 break;
1418 }
1419 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
1420
1421 build_qualified_name (name);
1422 break;
1423 }
1424
1425 case UNKNOWN_TYPE:
1426 /* This will take some work. */
1427 OB_PUTC ('?');
1428 break;
1429
1430 case TEMPLATE_TEMPLATE_PARM:
1431 /* Find and output the original template parameter
1432 declaration. */
1433 if (CLASSTYPE_TEMPLATE_INFO (parmtype))
1434 {
1435 build_mangled_template_parm_index ("tzX",
1436 TEMPLATE_TYPE_PARM_INDEX
1437 (parmtype));
1438 build_template_parm_names
1439 (DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype)),
1440 CLASSTYPE_TI_ARGS (parmtype));
1441 }
1442 else
1443 {
1444 build_mangled_template_parm_index ("ZzX",
1445 TEMPLATE_TYPE_PARM_INDEX
1446 (parmtype));
1447 build_template_template_parm_names
1448 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
1449 }
1450 break;
1451
1452 case TEMPLATE_TYPE_PARM:
1453 build_mangled_template_parm_index ("X",
1454 TEMPLATE_TYPE_PARM_INDEX
1455 (parmtype));
1456 break;
1457
1458 case TYPENAME_TYPE:
1459 /* When mangling the type of a function template whose
1460 declaration looks like:
1461
1462 template <class T> void foo(typename T::U)
1463
1464 we have to mangle these. */
1465 build_qualified_name (parmtype);
1466 break;
1467
1468 default:
1469 my_friendly_abort (75);
1470 }
1471
1472 }
1473
1474 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1475 be either a class TYPE or a FUNCTION_DECL. */
1476
1477 tree
1478 build_static_name (context, name)
1479 tree context, name;
1480 {
1481 OB_INIT ();
1482 numeric_output_need_bar = 0;
1483 start_squangling ();
1484 #ifdef JOINER
1485 OB_PUTC ('_');
1486 build_qualified_name (context);
1487 OB_PUTC (JOINER);
1488 #else
1489 OB_PUTS ("__static_");
1490 build_qualified_name (context);
1491 OB_PUTC ('_');
1492 #endif
1493 OB_PUTID (name);
1494 OB_FINISH ();
1495 end_squangling ();
1496
1497 return get_identifier ((char *)obstack_base (&scratch_obstack));
1498 }
1499 \f
1500 static tree
1501 build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1502 for_method)
1503 tree dname;
1504 tree parms;
1505 tree ret_type;
1506 tree tparms;
1507 tree targs;
1508 int for_method;
1509 {
1510 char *name = IDENTIFIER_POINTER (dname);
1511
1512 /* member operators new and delete look like methods at this point. */
1513 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
1514 && TREE_CHAIN (parms) == void_list_node)
1515 {
1516 if (dname == ansi_opname[(int) DELETE_EXPR])
1517 return get_identifier ("__builtin_delete");
1518 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1519 return get_identifier ("__builtin_vec_delete");
1520 if (dname == ansi_opname[(int) NEW_EXPR])
1521 return get_identifier ("__builtin_new");
1522 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1523 return get_identifier ("__builtin_vec_new");
1524 }
1525
1526 start_squangling ();
1527 OB_INIT ();
1528 if (for_method != 2)
1529 OB_PUTCP (name);
1530 /* Otherwise, we can divine that this is a constructor,
1531 and figure out its name without any extra encoding. */
1532
1533 OB_PUTC2 ('_', '_');
1534 if (for_method)
1535 {
1536 #if 0
1537 /* We can get away without doing this. */
1538 OB_PUTC ('M');
1539 #endif
1540 if (tparms != NULL_TREE)
1541 OB_PUTC ('H');
1542 {
1543 tree this_type = TREE_VALUE (parms);
1544
1545 if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */
1546 parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type),
1547 TREE_CHAIN (parms));
1548 else
1549 parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type),
1550 TREE_CHAIN (parms));
1551 }
1552 }
1553 else if (tparms)
1554 OB_PUTC ('H');
1555 /* XXX this works only if we call this in the same namespace
1556 as the declaration. Unfortunately, we don't have the _DECL,
1557 only its name */
1558 else if (current_namespace == global_namespace)
1559 OB_PUTC ('F');
1560
1561 if (tparms)
1562 {
1563 build_template_parm_names (tparms, targs);
1564 OB_PUTC ('_');
1565 }
1566
1567 /* qualify with namespace */
1568 if (!for_method && current_namespace != global_namespace)
1569 build_qualified_name (current_namespace);
1570
1571 if (parms == NULL_TREE)
1572 OB_PUTC ('e');
1573 else if (parms == void_list_node)
1574 OB_PUTC ('v');
1575 else
1576 {
1577 if (!flag_do_squangling) /* Allocate typevec array. */
1578 {
1579 maxtype = 0;
1580 Nrepeats = 0;
1581 typevec = (tree *)alloca (list_length (parms) * sizeof (tree));
1582 }
1583 nofold = 0;
1584 if (for_method)
1585 {
1586 build_mangled_name (TREE_VALUE (parms), 0, 0);
1587
1588 if (!flag_do_squangling) {
1589 typevec[maxtype++] = TREE_VALUE (parms);
1590 TREE_USED (TREE_VALUE (parms)) = 1;
1591 }
1592
1593 if (TREE_CHAIN (parms))
1594 build_mangled_name (TREE_CHAIN (parms), 0, 0);
1595 else
1596 OB_PUTC ('e');
1597 }
1598 else
1599 {
1600 /* the namespace qualifier for a global function
1601 will count as type */
1602 if (current_namespace != global_namespace
1603 && !flag_do_squangling)
1604 typevec[maxtype++] = current_namespace;
1605 build_mangled_name (parms, 0, 0);
1606 }
1607
1608 if (!flag_do_squangling) /* Deallocate typevec array */
1609 {
1610 tree t = parms;
1611 typevec = NULL;
1612 while (t)
1613 {
1614 TREE_USED (TREE_VALUE (t)) = 0;
1615 t = TREE_CHAIN (t);
1616 }
1617 }
1618 }
1619
1620 if (ret_type != NULL_TREE && for_method != 2)
1621 {
1622 /* Add the return type. */
1623 OB_PUTC ('_');
1624 build_mangled_name (ret_type, 0, 0);
1625 }
1626
1627 OB_FINISH ();
1628 end_squangling ();
1629 {
1630 tree n = get_identifier (obstack_base (&scratch_obstack));
1631 if (IDENTIFIER_OPNAME_P (dname))
1632 IDENTIFIER_OPNAME_P (n) = 1;
1633 return n;
1634 }
1635 }
1636
1637 /* Change the name of a function definition so that it may be
1638 overloaded. NAME is the name of the function to overload,
1639 PARMS is the parameter list (which determines what name the
1640 final function obtains).
1641
1642 FOR_METHOD is 1 if this overload is being performed
1643 for a method, rather than a function type. It is 2 if
1644 this overload is being performed for a constructor. */
1645
1646 tree
1647 build_decl_overload (dname, parms, for_method)
1648 tree dname;
1649 tree parms;
1650 int for_method;
1651 {
1652 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1653 NULL_TREE, for_method);
1654 }
1655
1656
1657 /* Like build_decl_overload, but for template functions. */
1658
1659 tree
1660 build_template_decl_overload (dname, parms, ret_type, tparms, targs,
1661 for_method)
1662 tree dname;
1663 tree parms;
1664 tree ret_type;
1665 tree tparms;
1666 tree targs;
1667 int for_method;
1668 {
1669 return build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1670 for_method);
1671 }
1672
1673
1674 /* Build an overload name for the type expression TYPE. */
1675
1676 tree
1677 build_typename_overload (type)
1678 tree type;
1679 {
1680 tree id;
1681
1682 OB_INIT ();
1683 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1684 nofold = 1;
1685 start_squangling ();
1686 build_mangled_name (type, 0, 1);
1687 id = get_identifier (obstack_base (&scratch_obstack));
1688 IDENTIFIER_OPNAME_P (id) = 1;
1689 #if 0
1690 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1691 #endif
1692 TREE_TYPE (id) = type;
1693 end_squangling ();
1694 return id;
1695 }
1696
1697 tree
1698 build_overload_with_type (name, type)
1699 tree name, type;
1700 {
1701 OB_INIT ();
1702 OB_PUTID (name);
1703 nofold = 1;
1704
1705 start_squangling ();
1706 build_mangled_name (type, 0, 1);
1707 end_squangling ();
1708 return get_identifier (obstack_base (&scratch_obstack));
1709 }
1710
1711 tree
1712 get_id_2 (name, name2)
1713 char *name;
1714 tree name2;
1715 {
1716 OB_INIT ();
1717 OB_PUTCP (name);
1718 OB_PUTID (name2);
1719 OB_FINISH ();
1720 return get_identifier (obstack_base (&scratch_obstack));
1721 }
1722 \f
1723 /* Given a tree_code CODE, and some arguments (at least one),
1724 attempt to use an overloaded operator on the arguments.
1725
1726 For unary operators, only the first argument need be checked.
1727 For binary operators, both arguments may need to be checked.
1728
1729 Member functions can convert class references to class pointers,
1730 for one-level deep indirection. More than that is not supported.
1731 Operators [](), ()(), and ->() must be member functions.
1732
1733 We call function call building calls with LOOKUP_COMPLAIN if they
1734 are our only hope. This is true when we see a vanilla operator
1735 applied to something of aggregate type. If this fails, we are free
1736 to return `error_mark_node', because we will have reported the
1737 error.
1738
1739 Operators NEW and DELETE overload in funny ways: operator new takes
1740 a single `size' parameter, and operator delete takes a pointer to the
1741 storage being deleted. When overloading these operators, success is
1742 assumed. If there is a failure, report an error message and return
1743 `error_mark_node'. */
1744
1745 /* NOSTRICT */
1746 tree
1747 build_opfncall (code, flags, xarg1, xarg2, arg3)
1748 enum tree_code code;
1749 int flags;
1750 tree xarg1, xarg2, arg3;
1751 {
1752 return build_new_op (code, flags, xarg1, xarg2, arg3);
1753 }
1754 \f
1755 /* This function takes an identifier, ID, and attempts to figure out what
1756 it means. There are a number of possible scenarios, presented in increasing
1757 order of hair:
1758
1759 1) not in a class's scope
1760 2) in class's scope, member name of the class's method
1761 3) in class's scope, but not a member name of the class
1762 4) in class's scope, member name of a class's variable
1763
1764 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1765 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1766
1767 As a last ditch, try to look up the name as a label and return that
1768 address.
1769
1770 Values which are declared as being of REFERENCE_TYPE are
1771 automatically dereferenced here (as a hack to make the
1772 compiler faster). */
1773
1774 tree
1775 hack_identifier (value, name)
1776 tree value, name;
1777 {
1778 tree type;
1779
1780 if (value == error_mark_node)
1781 {
1782 if (current_class_name)
1783 {
1784 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1785 if (fields == error_mark_node)
1786 return error_mark_node;
1787 if (fields)
1788 {
1789 tree fndecl;
1790
1791 fndecl = TREE_VALUE (fields);
1792 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1793 if (DECL_CHAIN (fndecl) == NULL_TREE)
1794 {
1795 warning ("methods cannot be converted to function pointers");
1796 return fndecl;
1797 }
1798 else
1799 {
1800 error ("ambiguous request for method pointer `%s'",
1801 IDENTIFIER_POINTER (name));
1802 return error_mark_node;
1803 }
1804 }
1805 }
1806 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1807 {
1808 return IDENTIFIER_LABEL_VALUE (name);
1809 }
1810 return error_mark_node;
1811 }
1812
1813 type = TREE_TYPE (value);
1814 if (TREE_CODE (value) == FIELD_DECL)
1815 {
1816 if (current_class_ptr == NULL_TREE)
1817 {
1818 error ("request for member `%s' in static member function",
1819 IDENTIFIER_POINTER (DECL_NAME (value)));
1820 return error_mark_node;
1821 }
1822 TREE_USED (current_class_ptr) = 1;
1823
1824 /* Mark so that if we are in a constructor, and then find that
1825 this field was initialized by a base initializer,
1826 we can emit an error message. */
1827 TREE_USED (value) = 1;
1828 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
1829 }
1830 else if (really_overloaded_fn (value))
1831 {
1832 #if 0
1833 tree t = get_first_fn (value);
1834 for (; t; t = DECL_CHAIN (t))
1835 {
1836 if (TREE_CODE (t) == TEMPLATE_DECL)
1837 continue;
1838
1839 assemble_external (t);
1840 TREE_USED (t) = 1;
1841 }
1842 #endif
1843 }
1844 else if (TREE_CODE (value) == TREE_LIST)
1845 {
1846 /* Ambiguous reference to base members, possibly other cases?. */
1847 tree t = value;
1848 while (t && TREE_CODE (t) == TREE_LIST)
1849 {
1850 mark_used (TREE_VALUE (t));
1851 t = TREE_CHAIN (t);
1852 }
1853 }
1854 else
1855 mark_used (value);
1856
1857 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL)
1858 {
1859 tree context = decl_function_context (value);
1860 if (context != NULL_TREE && context != current_function_decl
1861 && ! TREE_STATIC (value))
1862 {
1863 cp_error ("use of %s from containing function",
1864 (TREE_CODE (value) == VAR_DECL
1865 ? "`auto' variable" : "parameter"));
1866 cp_error_at (" `%#D' declared here", value);
1867 value = error_mark_node;
1868 }
1869 }
1870
1871 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1872 {
1873 if (DECL_LANG_SPECIFIC (value)
1874 && DECL_CLASS_CONTEXT (value) != current_class_type)
1875 {
1876 tree path, access;
1877 register tree context
1878 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1879 ? DECL_CLASS_CONTEXT (value)
1880 : DECL_CONTEXT (value);
1881
1882 get_base_distance (context, current_class_type, 0, &path);
1883 if (path)
1884 {
1885 access = compute_access (path, value);
1886 if (access != access_public_node)
1887 {
1888 if (TREE_CODE (value) == VAR_DECL)
1889 error ("static member `%s' is %s",
1890 IDENTIFIER_POINTER (name),
1891 TREE_PRIVATE (value) ? "private"
1892 : "from a private base class");
1893 else
1894 error ("enum `%s' is from private base class",
1895 IDENTIFIER_POINTER (name));
1896 return error_mark_node;
1897 }
1898 }
1899 }
1900 }
1901 else if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value))
1902 {
1903 if (type == 0)
1904 {
1905 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1906 IDENTIFIER_POINTER (name));
1907 return error_mark_node;
1908 }
1909
1910 return value;
1911 }
1912
1913 if (TREE_CODE (type) == REFERENCE_TYPE && ! processing_template_decl)
1914 value = convert_from_reference (value);
1915 return value;
1916 }
1917
1918 \f
1919 tree
1920 make_thunk (function, delta)
1921 tree function;
1922 int delta;
1923 {
1924 char *buffer;
1925 tree thunk_id;
1926 tree thunk;
1927 char *func_name;
1928 tree func_decl;
1929 if (TREE_CODE (function) != ADDR_EXPR)
1930 abort ();
1931 func_decl = TREE_OPERAND (function, 0);
1932 if (TREE_CODE (func_decl) != FUNCTION_DECL)
1933 abort ();
1934 func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl));
1935 buffer = (char *)alloca (strlen (func_name) + 32);
1936 if (delta<=0)
1937 sprintf (buffer, "__thunk_%d_%s", -delta, func_name);
1938 else
1939 sprintf (buffer, "__thunk_n%d_%s", delta, func_name);
1940 thunk_id = get_identifier (buffer);
1941 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
1942 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
1943 {
1944 cp_error ("implementation-reserved name `%D' used", thunk_id);
1945 IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE;
1946 }
1947 if (thunk == NULL_TREE)
1948 {
1949 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
1950 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
1951 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
1952 comdat_linkage (thunk);
1953 TREE_SET_CODE (thunk, THUNK_DECL);
1954 DECL_INITIAL (thunk) = function;
1955 THUNK_DELTA (thunk) = delta;
1956 DECL_EXTERNAL (thunk) = 1;
1957 DECL_ARTIFICIAL (thunk) = 1;
1958 /* So that finish_file can write out any thunks that need to be: */
1959 pushdecl_top_level (thunk);
1960 }
1961 return thunk;
1962 }
1963
1964 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
1965
1966 void
1967 emit_thunk (thunk_fndecl)
1968 tree thunk_fndecl;
1969 {
1970 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
1971 int delta = THUNK_DELTA (thunk_fndecl);
1972
1973 if (TREE_ASM_WRITTEN (thunk_fndecl))
1974 return;
1975
1976 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
1977
1978 TREE_ADDRESSABLE (function) = 1;
1979 mark_used (function);
1980
1981 if (current_function_decl)
1982 abort ();
1983
1984 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
1985
1986 {
1987 #ifdef ASM_OUTPUT_MI_THUNK
1988 char *fnname;
1989 current_function_decl = thunk_fndecl;
1990 /* Make sure we build up its RTL before we go onto the
1991 temporary obstack. */
1992 make_function_rtl (thunk_fndecl);
1993 temporary_allocation ();
1994 DECL_RESULT (thunk_fndecl)
1995 = build_decl (RESULT_DECL, 0, integer_type_node);
1996 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
1997 init_function_start (thunk_fndecl, input_filename, lineno);
1998 assemble_start_function (thunk_fndecl, fnname);
1999 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
2000 assemble_end_function (thunk_fndecl, fnname);
2001 permanent_allocation (1);
2002 current_function_decl = 0;
2003 #else /* ASM_OUTPUT_MI_THUNK */
2004 /* If we don't have the necessary macro for efficient thunks, generate a
2005 thunk function that just makes a call to the real function.
2006 Unfortunately, this doesn't work for varargs. */
2007
2008 tree a, t;
2009
2010 if (varargs_function_p (function))
2011 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2012 function);
2013
2014 /* Set up clone argument trees for the thunk. */
2015 t = NULL_TREE;
2016 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
2017 {
2018 tree x = copy_node (a);
2019 TREE_CHAIN (x) = t;
2020 DECL_CONTEXT (x) = thunk_fndecl;
2021 t = x;
2022 }
2023 a = nreverse (t);
2024 DECL_ARGUMENTS (thunk_fndecl) = a;
2025 DECL_RESULT (thunk_fndecl) = NULL_TREE;
2026 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
2027 copy_lang_decl (thunk_fndecl);
2028 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
2029 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
2030
2031 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, 1);
2032 store_parm_decls ();
2033 current_function_is_thunk = 1;
2034
2035 /* Build up the call to the real function. */
2036 t = build_int_2 (delta, -1 * (delta < 0));
2037 TREE_TYPE (t) = signed_type (sizetype);
2038 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
2039 t = expr_tree_cons (NULL_TREE, t, NULL_TREE);
2040 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
2041 t = expr_tree_cons (NULL_TREE, a, t);
2042 t = nreverse (t);
2043 t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t);
2044 c_expand_return (t);
2045
2046 finish_function (lineno, 0, 0);
2047
2048 /* Don't let the backend defer this function. */
2049 if (DECL_DEFER_OUTPUT (thunk_fndecl))
2050 {
2051 output_inline_function (thunk_fndecl);
2052 permanent_allocation (1);
2053 }
2054 #endif /* ASM_OUTPUT_MI_THUNK */
2055 }
2056
2057 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
2058 }
2059 \f
2060 /* Code for synthesizing methods which have default semantics defined. */
2061
2062 /* For the anonymous union in TYPE, return the member that is at least as
2063 large as the rest of the members, so we can copy it. */
2064
2065 static tree
2066 largest_union_member (type)
2067 tree type;
2068 {
2069 tree f, type_size = TYPE_SIZE (type);
2070
2071 for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
2072 if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
2073 return f;
2074
2075 /* We should always find one. */
2076 my_friendly_abort (323);
2077 return NULL_TREE;
2078 }
2079
2080 /* Generate code for default X(X&) constructor. */
2081
2082 static void
2083 do_build_copy_constructor (fndecl)
2084 tree fndecl;
2085 {
2086 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2087 tree t;
2088
2089 clear_last_expr ();
2090 push_momentary ();
2091
2092 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2093 parm = TREE_CHAIN (parm);
2094 parm = convert_from_reference (parm);
2095
2096 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
2097 && is_empty_class (current_class_type))
2098 /* Don't copy the padding byte; it might not have been allocated
2099 if *this is a base subobject. */;
2100 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2101 {
2102 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
2103 TREE_SIDE_EFFECTS (t) = 1;
2104 cplus_expand_expr_stmt (t);
2105 }
2106 else
2107 {
2108 tree fields = TYPE_FIELDS (current_class_type);
2109 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2110 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2111 int i;
2112
2113 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2114 t = TREE_CHAIN (t))
2115 {
2116 tree basetype = BINFO_TYPE (t);
2117 tree p = convert_to_reference
2118 (build_reference_type (basetype), parm,
2119 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2120 p = convert_from_reference (p);
2121
2122 if (p == error_mark_node)
2123 cp_error ("in default copy constructor");
2124 else
2125 current_base_init_list = tree_cons (basetype,
2126 p, current_base_init_list);
2127 }
2128
2129 for (i = 0; i < n_bases; ++i)
2130 {
2131 tree p, basetype = TREE_VEC_ELT (binfos, i);
2132 if (TREE_VIA_VIRTUAL (basetype))
2133 continue;
2134
2135 basetype = BINFO_TYPE (basetype);
2136 p = convert_to_reference
2137 (build_reference_type (basetype), parm,
2138 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2139
2140 if (p == error_mark_node)
2141 cp_error ("in default copy constructor");
2142 else
2143 {
2144 p = convert_from_reference (p);
2145 current_base_init_list = tree_cons (basetype,
2146 p, current_base_init_list);
2147 }
2148 }
2149 for (; fields; fields = TREE_CHAIN (fields))
2150 {
2151 tree init, t;
2152 tree field = fields;
2153
2154 if (TREE_CODE (field) != FIELD_DECL)
2155 continue;
2156
2157 init = parm;
2158 if (DECL_NAME (field))
2159 {
2160 if (VFIELD_NAME_P (DECL_NAME (field)))
2161 continue;
2162 if (VBASE_NAME_P (DECL_NAME (field)))
2163 continue;
2164
2165 /* True for duplicate members. */
2166 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2167 continue;
2168 }
2169 else if ((t = TREE_TYPE (field)) != NULL_TREE
2170 && TREE_CODE (t) == UNION_TYPE
2171 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2172 && TYPE_FIELDS (t) != NULL_TREE)
2173 {
2174 do
2175 {
2176 init = build (COMPONENT_REF, t, init, field);
2177 field = largest_union_member (t);
2178 }
2179 while ((t = TREE_TYPE (field)) != NULL_TREE
2180 && TREE_CODE (t) == UNION_TYPE
2181 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2182 && TYPE_FIELDS (t) != NULL_TREE);
2183 }
2184 else
2185 continue;
2186
2187 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2188 init = build_tree_list (NULL_TREE, init);
2189
2190 current_member_init_list
2191 = tree_cons (DECL_NAME (field), init, current_member_init_list);
2192 }
2193 current_member_init_list = nreverse (current_member_init_list);
2194 current_base_init_list = nreverse (current_base_init_list);
2195 setup_vtbl_ptr ();
2196 }
2197
2198 pop_momentary ();
2199 }
2200
2201 static void
2202 do_build_assign_ref (fndecl)
2203 tree fndecl;
2204 {
2205 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2206
2207 clear_last_expr ();
2208 push_momentary ();
2209
2210 parm = convert_from_reference (parm);
2211
2212 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
2213 && is_empty_class (current_class_type))
2214 /* Don't copy the padding byte; it might not have been allocated
2215 if *this is a base subobject. */;
2216 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2217 {
2218 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
2219 TREE_SIDE_EFFECTS (t) = 1;
2220 cplus_expand_expr_stmt (t);
2221 }
2222 else
2223 {
2224 tree fields = TYPE_FIELDS (current_class_type);
2225 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2226 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2227 int i;
2228
2229 for (i = 0; i < n_bases; ++i)
2230 {
2231 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2232 tree p = convert_to_reference
2233 (build_reference_type (basetype), parm,
2234 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2235 p = convert_from_reference (p);
2236 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2237 build_expr_list (NULL_TREE, p));
2238 expand_expr_stmt (p);
2239 }
2240 for (; fields; fields = TREE_CHAIN (fields))
2241 {
2242 tree comp, init, t;
2243 tree field = fields;
2244
2245 if (TREE_CODE (field) != FIELD_DECL)
2246 continue;
2247
2248 if (TREE_READONLY (field))
2249 {
2250 if (DECL_NAME (field))
2251 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
2252 else
2253 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
2254 continue;
2255 }
2256 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2257 {
2258 if (DECL_NAME (field))
2259 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
2260 else
2261 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
2262 continue;
2263 }
2264
2265 comp = current_class_ref;
2266 init = parm;
2267
2268 if (DECL_NAME (field))
2269 {
2270 if (VFIELD_NAME_P (DECL_NAME (field)))
2271 continue;
2272 if (VBASE_NAME_P (DECL_NAME (field)))
2273 continue;
2274
2275 /* True for duplicate members. */
2276 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2277 continue;
2278 }
2279 else if ((t = TREE_TYPE (field)) != NULL_TREE
2280 && TREE_CODE (t) == UNION_TYPE
2281 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2282 && TYPE_FIELDS (t) != NULL_TREE)
2283 {
2284 do
2285 {
2286 comp = build (COMPONENT_REF, t, comp, field);
2287 init = build (COMPONENT_REF, t, init, field);
2288 field = largest_union_member (t);
2289 }
2290 while ((t = TREE_TYPE (field)) != NULL_TREE
2291 && TREE_CODE (t) == UNION_TYPE
2292 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))
2293 && TYPE_FIELDS (t) != NULL_TREE);
2294 }
2295 else
2296 continue;
2297
2298 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2299 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2300
2301 expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2302 }
2303 }
2304 c_expand_return (current_class_ref);
2305 pop_momentary ();
2306 }
2307
2308 void
2309 synthesize_method (fndecl)
2310 tree fndecl;
2311 {
2312 int nested = (current_function_decl != NULL_TREE);
2313 tree context = hack_decl_function_context (fndecl);
2314
2315 if (at_eof)
2316 import_export_decl (fndecl);
2317
2318 if (! context)
2319 push_to_top_level ();
2320 else if (nested)
2321 push_cp_function_context (context);
2322
2323 interface_unknown = 1;
2324 start_function (NULL_TREE, fndecl, NULL_TREE, 1);
2325 store_parm_decls ();
2326
2327 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2328 do_build_assign_ref (fndecl);
2329 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2330 ;
2331 else
2332 {
2333 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2334 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2335 arg_chain = TREE_CHAIN (arg_chain);
2336 if (arg_chain != void_list_node)
2337 do_build_copy_constructor (fndecl);
2338 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2339 setup_vtbl_ptr ();
2340 }
2341
2342 finish_function (lineno, 0, nested);
2343
2344 extract_interface_info ();
2345 if (! context)
2346 pop_from_top_level ();
2347 else if (nested)
2348 pop_cp_function_context (context);
2349 }
This page took 0.141964 seconds and 5 git commands to generate.