* method.c (synthesize_method): Call setup_vtbl_ptr for destructors.
[official-gcc.git] / gcc / cp / method.c
blobf50f0eb37f5392acbc72c369030c6fa31be1458e
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, 1999 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #ifndef __GNUC__
25 #define __inline
26 #endif
28 #ifndef PARM_CAN_BE_ARRAY_TYPE
29 #define PARM_CAN_BE_ARRAY_TYPE 1
30 #endif
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 #include "toplev.h"
44 #include "ggc.h"
46 /* TREE_LIST of the current inline functions that need to be
47 processed. */
48 struct pending_inline *pending_inlines;
50 #define obstack_chunk_alloc xmalloc
51 #define obstack_chunk_free free
53 /* Obstack where we build text strings for overloading, etc. */
54 static struct obstack scratch_obstack;
55 static char *scratch_firstobj;
57 static void icat PROTO((HOST_WIDE_INT));
58 static void dicat PROTO((HOST_WIDE_INT, HOST_WIDE_INT));
59 static int old_backref_index PROTO((tree));
60 static int flush_repeats PROTO((int, tree));
61 static void build_overload_identifier PROTO((tree));
62 static void build_overload_nested_name PROTO((tree));
63 static void build_overload_int PROTO((tree, int));
64 static void build_overload_identifier PROTO((tree));
65 static void build_qualified_name PROTO((tree));
66 static void build_overload_value PROTO((tree, tree, int));
67 static void issue_nrepeats PROTO((int, tree));
68 static char *build_mangled_name PROTO((tree,int,int));
69 static void process_modifiers PROTO((tree));
70 static void process_overload_item PROTO((tree,int));
71 static void do_build_assign_ref PROTO((tree));
72 static void do_build_copy_constructor PROTO((tree));
73 static void build_template_template_parm_names PROTO((tree));
74 static void build_template_parm_names PROTO((tree, tree));
75 static void build_underscore_int PROTO((int));
76 static void start_squangling PROTO((void));
77 static void end_squangling PROTO((void));
78 static int check_ktype PROTO((tree, int));
79 static int issue_ktype PROTO((tree));
80 static void build_overload_scope_ref PROTO((tree));
81 static void build_mangled_template_parm_index PROTO((const char *, tree));
82 #if HOST_BITS_PER_WIDE_INT >= 64
83 static void build_mangled_C9x_name PROTO((int));
84 #endif
85 static int is_back_referenceable_type PROTO((tree));
86 static int check_btype PROTO((tree));
87 static void build_mangled_name_for_type PROTO((tree));
88 static void build_mangled_name_for_type_with_Gcode PROTO((tree, int));
90 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
91 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
92 # define OB_PUTC2(C1,C2) \
93 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
94 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
95 # define OB_PUTID(ID) \
96 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
97 IDENTIFIER_LENGTH (ID)))
98 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
99 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
100 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
102 /* type tables for K and B type compression */
103 static varray_type btypelist;
104 static varray_type ktypelist;
106 /* number of each type seen */
107 static size_t maxbtype;
108 static size_t maxktype;
110 /* Array of types seen so far in top-level call to `build_mangled_name'.
111 Allocated and deallocated by caller. */
112 static varray_type typevec;
114 /* Number of types interned by `build_mangled_name' so far. */
115 static size_t maxtype;
117 /* Called once to initialize method.c. */
119 void
120 init_method ()
122 gcc_obstack_init (&scratch_obstack);
123 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
124 ggc_add_tree_varray_root (&btypelist, 1);
125 ggc_add_tree_varray_root (&ktypelist, 1);
126 ggc_add_tree_varray_root (&typevec, 1);
129 /* This must be large enough to hold any printed integer or floating-point
130 value. */
131 static char digit_buffer[128];
133 /* Move inline function definitions out of structure so that they
134 can be processed normally. CNAME is the name of the class
135 we are working from, METHOD_LIST is the list of method lists
136 of the structure. We delete friend methods here, after
137 saving away their inline function definitions (if any). */
139 void
140 do_inline_function_hair (type, friend_list)
141 tree type, friend_list;
143 tree method = TYPE_METHODS (type);
145 if (method && TREE_CODE (method) == TREE_VEC)
147 if (TREE_VEC_ELT (method, 1))
148 method = TREE_VEC_ELT (method, 1);
149 else if (TREE_VEC_ELT (method, 0))
150 method = TREE_VEC_ELT (method, 0);
151 else
152 method = TREE_VEC_ELT (method, 2);
155 while (method)
157 /* Do inline member functions. */
158 struct pending_inline *info = DECL_PENDING_INLINE_INFO (method);
159 if (info)
161 tree args;
163 my_friendly_assert (info->fndecl == method, 238);
164 args = DECL_ARGUMENTS (method);
165 while (args)
167 DECL_CONTEXT (args) = method;
168 args = TREE_CHAIN (args);
171 method = TREE_CHAIN (method);
173 while (friend_list)
175 tree fndecl = TREE_VALUE (friend_list);
176 struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl);
177 if (info)
179 tree args;
181 my_friendly_assert (info->fndecl == fndecl, 239);
182 args = DECL_ARGUMENTS (fndecl);
183 while (args)
185 DECL_CONTEXT (args) = fndecl;
186 args = TREE_CHAIN (args);
190 friend_list = TREE_CHAIN (friend_list);
194 /* Here is where overload code starts. */
196 /* Nonzero if we should not try folding parameter types. */
197 static int nofold;
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;
203 static __inline void
204 start_squangling ()
206 if (flag_do_squangling)
208 nofold = 0;
209 maxbtype = 0;
210 maxktype = 0;
211 VARRAY_TREE_INIT (btypelist, 50, "btypelist");
212 VARRAY_TREE_INIT (ktypelist, 50, "ktypelist");
216 static __inline void
217 end_squangling ()
219 if (flag_do_squangling)
221 VARRAY_FREE (ktypelist);
222 VARRAY_FREE (btypelist);
223 maxbtype = 0;
224 maxktype = 0;
228 /* Code to concatenate an asciified integer to a string. */
230 static __inline void
231 icat (i)
232 HOST_WIDE_INT i;
234 unsigned HOST_WIDE_INT ui;
236 /* Handle this case first, to go really quickly. For many common values,
237 the result of ui/10 below is 1. */
238 if (i == 1)
240 OB_PUTC ('1');
241 return;
244 if (i >= 0)
245 ui = i;
246 else
248 OB_PUTC ('m');
249 ui = -i;
252 if (ui >= 10)
253 icat (ui / 10);
255 OB_PUTC ('0' + (ui % 10));
258 static void
259 dicat (lo, hi)
260 HOST_WIDE_INT lo, hi;
262 unsigned HOST_WIDE_INT ulo, uhi, qlo, qhi;
264 if (hi >= 0)
266 uhi = hi;
267 ulo = lo;
269 else
271 uhi = (lo == 0 ? -hi : -hi-1);
272 ulo = -lo;
274 if (uhi == 0
275 && ulo < ((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)))
277 icat (ulo);
278 return;
280 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
281 qhi = uhi / 10;
282 uhi = uhi % 10;
283 qlo = uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) / 5);
284 qlo += ulo / 10;
285 ulo = ulo % 10;
286 ulo += uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) % 5)
287 * 2;
288 qlo += ulo / 10;
289 ulo = ulo % 10;
290 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
291 dicat (qlo, qhi);
292 OB_PUTC ('0' + ulo);
295 /* Returns the index of TYPE in the typevec, or -1 if it's not there. */
297 static __inline int
298 old_backref_index (type)
299 tree type;
301 size_t tindex;
303 if (! is_back_referenceable_type (type))
304 return -1;
306 /* The entry for this parm is at maxtype-1, so don't look there for
307 something to repeat. */
308 for (tindex = 0; tindex < maxtype - 1; ++tindex)
309 if (same_type_p (VARRAY_TREE (typevec, tindex), type))
310 break;
312 if (tindex == maxtype - 1)
313 return -1;
315 return tindex;
318 /* Old mangling style: If TYPE has already been used in the parameter list,
319 emit a backward reference and return non-zero; otherwise, return 0.
321 NREPEATS is the number of repeats we've recorded of this type, or 0 if
322 this is the first time we've seen it and we're just looking to see if
323 it had been used before. */
325 static __inline int
326 flush_repeats (nrepeats, type)
327 int nrepeats;
328 tree type;
330 int tindex = old_backref_index (type);
332 if (tindex == -1)
334 my_friendly_assert (nrepeats == 0, 990316);
335 return 0;
338 if (nrepeats > 1)
340 OB_PUTC ('N');
341 icat (nrepeats);
342 if (nrepeats > 9)
343 OB_PUTC ('_');
345 else
346 OB_PUTC ('T');
347 icat (tindex);
348 if (tindex > 9)
349 OB_PUTC ('_');
351 return 1;
354 /* Returns nonzero iff this is a type to which we will want to make
355 back-references (using the `B' code). */
357 static int
358 is_back_referenceable_type (type)
359 tree type;
361 /* For some reason, the Java folks don't want back refs on these. */
362 if (TYPE_FOR_JAVA (type))
363 return 0;
365 switch (TREE_CODE (type))
367 case BOOLEAN_TYPE:
368 if (!flag_do_squangling)
369 /* Even though the mangling of this is just `b', we did
370 historically generate back-references for it. */
371 return 1;
372 /* Fall through. */
374 case INTEGER_TYPE:
375 case REAL_TYPE:
376 case VOID_TYPE:
377 /* These types have single-character manglings, so there's no
378 point in generating back-references. */
379 return 0;
381 case TEMPLATE_TYPE_PARM:
382 /* It would be a bit complex to demangle signatures correctly if
383 we generated back-references to these, and the manglings of
384 type parameters are short. */
385 return 0;
387 default:
388 return 1;
392 /* Issue the squangling code indicating NREPEATS repetitions of TYPE,
393 which was the last parameter type output. */
395 static void
396 issue_nrepeats (nrepeats, type)
397 int nrepeats;
398 tree type;
400 if (nrepeats == 1 && !is_back_referenceable_type (type))
401 /* For types whose manglings are short, don't bother using the
402 repetition code if there's only one repetition, since the
403 repetition code will be about as long as the ordinary mangling. */
404 build_mangled_name_for_type (type);
405 else
407 OB_PUTC ('n');
408 icat (nrepeats);
409 if (nrepeats > 9)
410 OB_PUTC ('_');
414 /* Check to see if a tree node has been entered into the Kcode typelist.
415 If not, add it. Returns -1 if it isn't found, otherwise returns the
416 index. */
418 static int
419 check_ktype (node, add)
420 tree node;
421 int add;
423 size_t x;
424 tree localnode = node;
426 if (ktypelist == NULL)
427 return -1;
429 if (TREE_CODE (node) == TYPE_DECL)
430 localnode = TREE_TYPE (node);
432 for (x = 0; x < maxktype; x++)
434 if (same_type_p (localnode, VARRAY_TREE (ktypelist, x)))
435 return x;
437 /* Didn't find it, so add it here. */
438 if (add)
440 if (VARRAY_SIZE (ktypelist) <= maxktype)
441 VARRAY_GROW (ktypelist,
442 VARRAY_SIZE (ktypelist) * 3 / 2);
443 VARRAY_TREE (ktypelist, maxktype) = localnode;
444 maxktype++;
446 return -1;
450 static __inline int
451 issue_ktype (decl)
452 tree decl;
454 int kindex;
455 kindex = check_ktype (decl, FALSE);
456 if (kindex != -1)
458 OB_PUTC ('K');
459 icat (kindex);
460 if (kindex > 9)
461 OB_PUTC ('_');
462 return TRUE;
464 return FALSE;
467 /* Build a representation for DECL, which may be an entity not at
468 global scope. If so, a marker indicating that the name is
469 qualified has already been output, but the qualifying context has
470 not. */
472 static void
473 build_overload_nested_name (decl)
474 tree decl;
476 tree context;
478 if (ktypelist && issue_ktype (decl))
479 return;
481 if (decl == global_namespace)
482 return;
484 context = CP_DECL_CONTEXT (decl);
486 /* try to issue a K type, and if we can't continue the normal path */
487 if (!(ktypelist && issue_ktype (context)))
489 /* For a template type parameter, we want to output an 'Xn'
490 rather than 'T' or some such. */
491 if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
492 || TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
493 build_mangled_name_for_type (context);
494 else
496 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
497 context = TYPE_NAME (context);
498 build_overload_nested_name (context);
502 if (TREE_CODE (decl) == FUNCTION_DECL)
504 static int static_labelno;
506 tree name = DECL_ASSEMBLER_NAME (decl);
507 char *label;
509 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), static_labelno);
510 static_labelno++;
512 if (numeric_output_need_bar)
513 OB_PUTC ('_');
514 icat (strlen (label));
515 OB_PUTCP (label);
516 numeric_output_need_bar = 1;
518 else if (TREE_CODE (decl) == NAMESPACE_DECL)
519 build_overload_identifier (DECL_NAME (decl));
520 else /* TYPE_DECL */
521 build_overload_identifier (decl);
524 /* Output the decimal representation of I. If I > 9, the decimal
525 representation is preceeded and followed by an underscore. */
527 static void
528 build_underscore_int (i)
529 int i;
531 if (i > 9)
532 OB_PUTC ('_');
533 icat (i);
534 if (i > 9)
535 OB_PUTC ('_');
538 static void
539 build_overload_scope_ref (value)
540 tree value;
542 OB_PUTC2 ('Q', '2');
543 numeric_output_need_bar = 0;
544 build_mangled_name_for_type (TREE_OPERAND (value, 0));
545 build_overload_identifier (TREE_OPERAND (value, 1));
548 /* Encoding for an INTEGER_CST value. */
550 static void
551 build_overload_int (value, in_template)
552 tree value;
553 int in_template;
555 if (in_template && TREE_CODE (value) != INTEGER_CST)
557 if (TREE_CODE (value) == SCOPE_REF)
559 build_overload_scope_ref (value);
560 return;
563 OB_PUTC ('E');
564 numeric_output_need_bar = 0;
566 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value))))
568 int i;
569 int operands = tree_code_length[(int) TREE_CODE (value)];
570 tree id;
571 const char *name;
573 id = ansi_opname [(int) TREE_CODE (value)];
574 my_friendly_assert (id != NULL_TREE, 0);
575 name = IDENTIFIER_POINTER (id);
576 if (name[0] != '_' || name[1] != '_')
577 /* On some erroneous inputs, we can get here with VALUE a
578 LOOKUP_EXPR. In that case, the NAME will be the
579 identifier for "<invalid operator>". We must survive
580 this routine in order to issue a sensible error
581 message, so we fall through to the case below. */
582 goto bad_value;
584 for (i = 0; i < operands; ++i)
586 tree operand;
587 enum tree_code tc;
589 /* We just outputted either the `E' or the name of the
590 operator. */
591 numeric_output_need_bar = 0;
593 if (i != 0)
594 /* Skip the leading underscores. */
595 OB_PUTCP (name + 2);
597 operand = TREE_OPERAND (value, i);
598 tc = TREE_CODE (operand);
600 if (TREE_CODE_CLASS (tc) == 't')
601 /* We can get here with sizeof, e.g.:
603 template <class T> void f(A<sizeof(T)>); */
604 build_mangled_name_for_type (operand);
605 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc)))
606 build_overload_int (operand, in_template);
607 else
608 build_overload_value (TREE_TYPE (operand),
609 operand,
610 in_template);
613 else
615 /* We don't ever want this output, but it's
616 inconvenient not to be able to build the string.
617 This should cause assembler errors we'll notice. */
619 static int n;
620 bad_value:
621 sprintf (digit_buffer, " *%d", n++);
622 OB_PUTCP (digit_buffer);
625 OB_PUTC ('W');
626 numeric_output_need_bar = 0;
627 return;
630 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
631 if (TYPE_PRECISION (TREE_TYPE (value)) == 2 * HOST_BITS_PER_WIDE_INT)
633 if (TREE_INT_CST_HIGH (value)
634 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
636 /* need to print a DImode value in decimal */
637 dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value));
638 numeric_output_need_bar = 1;
639 return;
641 /* else fall through to print in smaller mode */
643 /* Wordsize or smaller */
644 icat (TREE_INT_CST_LOW (value));
645 numeric_output_need_bar = 1;
649 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
650 supplied in INDEX. */
652 static void
653 build_mangled_template_parm_index (s, index)
654 const char *s;
655 tree index;
657 OB_PUTCP (s);
658 build_underscore_int (TEMPLATE_PARM_IDX (index));
659 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
660 representation of the function from the point of view of its
661 type. */
662 build_underscore_int (TEMPLATE_PARM_LEVEL (index));
666 /* Mangling for C9X integer types (and Cygnus extensions for 128-bit
667 and other types) is based on the letter "I" followed by the hex
668 representations of the bitsize for the type in question. For
669 encodings that result in larger than two digits, a leading and
670 trailing underscore is added.
672 Thus:
673 int1_t = 001 = I01
674 int8_t = 008 = I08
675 int16_t = 010 = I10
676 int24_t = 018 = I18
677 int32_t = 020 = I20
678 int64_t = 040 = I40
679 int80_t = 050 = I50
680 int128_t = 080 = I80
681 int256_t = 100 = I_100_
682 int512_t = 200 = I_200_
684 Given an integer in decimal format, mangle according to this scheme. */
686 #if HOST_BITS_PER_WIDE_INT >= 64
687 static void
688 build_mangled_C9x_name (bits)
689 int bits;
691 char mangled[10] = "";
693 if (bits > 255)
694 sprintf (mangled, "I_%x_", bits);
695 else
696 sprintf (mangled, "I%.2x", bits);
698 OB_PUTCP (mangled);
700 #endif
702 static void
703 build_overload_value (type, value, in_template)
704 tree type, value;
705 int in_template;
707 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type)) == 't', 0);
709 while (TREE_CODE (value) == NON_LVALUE_EXPR
710 || TREE_CODE (value) == NOP_EXPR)
711 value = TREE_OPERAND (value, 0);
713 if (numeric_output_need_bar)
715 OB_PUTC ('_');
716 numeric_output_need_bar = 0;
719 if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
721 build_mangled_template_parm_index ("Y", value);
722 return;
725 if (TYPE_PTRMEM_P (type))
727 if (TREE_CODE (value) != PTRMEM_CST)
728 /* We should have already rejected this pointer to member,
729 since it is not a constant. */
730 my_friendly_abort (0);
732 /* Get the actual FIELD_DECL. */
733 value = PTRMEM_CST_MEMBER (value);
734 my_friendly_assert (TREE_CODE (value) == FIELD_DECL, 0);
736 /* Output the name of the field. */
737 build_overload_identifier (DECL_NAME (value));
738 return;
741 switch (TREE_CODE (type))
743 case INTEGER_TYPE:
744 case ENUMERAL_TYPE:
745 case BOOLEAN_TYPE:
747 build_overload_int (value, in_template);
748 return;
750 case REAL_TYPE:
752 REAL_VALUE_TYPE val;
753 char *bufp = digit_buffer;
755 pedwarn ("ANSI C++ forbids floating-point template arguments");
757 my_friendly_assert (TREE_CODE (value) == REAL_CST, 244);
758 val = TREE_REAL_CST (value);
759 if (REAL_VALUE_ISNAN (val))
761 sprintf (bufp, "NaN");
763 else
765 if (REAL_VALUE_NEGATIVE (val))
767 val = REAL_VALUE_NEGATE (val);
768 *bufp++ = 'm';
770 if (REAL_VALUE_ISINF (val))
772 sprintf (bufp, "Infinity");
774 else
776 REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
777 bufp = (char *) index (bufp, 'e');
778 if (!bufp)
779 strcat (digit_buffer, "e0");
780 else
782 char *p;
783 bufp++;
784 if (*bufp == '-')
786 *bufp++ = 'm';
788 p = bufp;
789 if (*p == '+')
790 p++;
791 while (*p == '0')
792 p++;
793 if (*p == 0)
795 *bufp++ = '0';
796 *bufp = 0;
798 else if (p != bufp)
800 while (*p)
801 *bufp++ = *p++;
802 *bufp = 0;
805 #ifdef NO_DOT_IN_LABEL
806 bufp = (char *) index (bufp, '.');
807 if (bufp)
808 *bufp = '_';
809 #endif
812 OB_PUTCP (digit_buffer);
813 numeric_output_need_bar = 1;
814 return;
816 case POINTER_TYPE:
817 if (TREE_CODE (value) == INTEGER_CST)
819 build_overload_int (value, in_template);
820 return;
822 else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
824 build_mangled_template_parm_index ("", value);
825 numeric_output_need_bar = 1;
826 return;
829 value = TREE_OPERAND (value, 0);
831 /* Fall through. */
833 case REFERENCE_TYPE:
834 if (TREE_CODE (value) == VAR_DECL)
836 my_friendly_assert (DECL_NAME (value) != 0, 245);
837 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
838 return;
840 else if (TREE_CODE (value) == FUNCTION_DECL)
842 my_friendly_assert (DECL_NAME (value) != 0, 246);
843 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
844 return;
846 else if (TREE_CODE (value) == SCOPE_REF)
847 build_overload_scope_ref (value);
848 else
849 my_friendly_abort (71);
850 break; /* not really needed */
852 case RECORD_TYPE:
854 tree delta;
855 tree idx;
856 tree pfn;
857 tree delta2;
859 my_friendly_assert (TYPE_PTRMEMFUNC_P (type), 0);
861 /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're
862 mangling, an instantiation of something like:
864 template <class T, void (T::*fp)()> class C {};
865 template <class T> C<T, &T::f> x();
867 We mangle the return type of the function, and that
868 contains template parameters. */
869 if (TREE_CODE (value) == ADDR_EXPR
870 && TREE_CODE (TREE_OPERAND (value, 0)) == SCOPE_REF)
872 build_overload_scope_ref (TREE_OPERAND (value, 0));
873 break;
876 my_friendly_assert (TREE_CODE (value) == PTRMEM_CST, 0);
878 expand_ptrmemfunc_cst (value, &delta, &idx, &pfn, &delta2);
879 build_overload_int (delta, in_template);
880 OB_PUTC ('_');
881 build_overload_int (idx, in_template);
882 OB_PUTC ('_');
883 if (pfn)
885 numeric_output_need_bar = 0;
886 build_overload_identifier (DECL_ASSEMBLER_NAME
887 (PTRMEM_CST_MEMBER (value)));
889 else
891 OB_PUTC ('i');
892 build_overload_int (delta2, in_template);
895 break;
897 default:
898 sorry ("conversion of %s as template parameter",
899 tree_code_name [(int) TREE_CODE (type)]);
900 my_friendly_abort (72);
905 /* Add encodings for the declaration of template template parameters.
906 PARMLIST must be a TREE_VEC. */
908 static void
909 build_template_template_parm_names (parmlist)
910 tree parmlist;
912 int i, nparms;
914 my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
915 nparms = TREE_VEC_LENGTH (parmlist);
916 icat (nparms);
917 for (i = 0; i < nparms; i++)
919 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
920 if (TREE_CODE (parm) == TYPE_DECL)
922 /* This parameter is a type. */
923 OB_PUTC ('Z');
925 else if (TREE_CODE (parm) == TEMPLATE_DECL)
927 /* This parameter is a template. */
928 OB_PUTC ('z');
929 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
931 else
932 /* It's a PARM_DECL. */
933 build_mangled_name_for_type (TREE_TYPE (parm));
938 /* Add encodings for the vector of template parameters in PARMLIST,
939 given the vector of arguments to be substituted in ARGLIST. */
941 static void
942 build_template_parm_names (parmlist, arglist)
943 tree parmlist;
944 tree arglist;
946 int i, nparms;
947 tree inner_args = innermost_args (arglist);
949 nparms = TREE_VEC_LENGTH (parmlist);
950 icat (nparms);
951 for (i = 0; i < nparms; i++)
953 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
954 tree arg = TREE_VEC_ELT (inner_args, i);
955 if (TREE_CODE (parm) == TYPE_DECL)
957 /* This parameter is a type. */
958 OB_PUTC ('Z');
959 build_mangled_name_for_type (arg);
961 else if (TREE_CODE (parm) == TEMPLATE_DECL)
963 /* This parameter is a template. */
964 if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
965 /* Output parameter declaration, argument index and level. */
966 build_mangled_name_for_type (arg);
967 else
969 /* A TEMPLATE_DECL node, output the parameter declaration
970 and template name */
972 OB_PUTC ('z');
973 build_template_template_parm_names
974 (DECL_INNERMOST_TEMPLATE_PARMS (parm));
975 icat (IDENTIFIER_LENGTH (DECL_NAME (arg)));
976 OB_PUTID (DECL_NAME (arg));
979 else
981 parm = tsubst (parm, arglist, /*complain=*/1, NULL_TREE);
982 /* It's a PARM_DECL. */
983 build_mangled_name_for_type (TREE_TYPE (parm));
984 build_overload_value (TREE_TYPE (parm), arg,
985 uses_template_parms (arglist));
990 /* Output the representation for NAME, which is either a TYPE_DECL or
991 an IDENTIFIER. */
993 static void
994 build_overload_identifier (name)
995 tree name;
997 if (TREE_CODE (name) == TYPE_DECL
998 && CLASS_TYPE_P (TREE_TYPE (name))
999 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
1000 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))
1001 || (TREE_CODE (CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
1002 (TREE_TYPE (name))))
1003 == FUNCTION_DECL)))
1005 /* NAME is the TYPE_DECL for a template specialization. */
1006 tree template, parmlist, arglist, tname;
1007 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name));
1008 arglist = CLASSTYPE_TI_ARGS (TREE_TYPE (name));
1009 tname = DECL_NAME (template);
1010 parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
1011 OB_PUTC ('t');
1012 icat (IDENTIFIER_LENGTH (tname));
1013 OB_PUTID (tname);
1014 build_template_parm_names (parmlist, arglist);
1016 else
1018 if (TREE_CODE (name) == TYPE_DECL)
1019 name = DECL_NAME (name);
1020 if (numeric_output_need_bar)
1022 OB_PUTC ('_');
1023 numeric_output_need_bar = 0;
1025 icat (IDENTIFIER_LENGTH (name));
1026 OB_PUTID (name);
1030 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
1031 the mangling for it. Used by build_mangled_name and build_static_name. */
1033 static void
1034 build_qualified_name (decl)
1035 tree decl;
1037 tree context;
1038 int i = 1;
1040 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
1041 decl = TYPE_NAME (decl);
1043 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1044 if (TREE_CODE (decl) == TYPE_DECL
1045 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling)
1047 tree id = DECL_ASSEMBLER_NAME (decl);
1048 OB_PUTID (id);
1049 if (ISDIGIT (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1]))
1050 numeric_output_need_bar = 1;
1051 return;
1054 context = decl;
1055 /* If we can't find a Ktype, do it the hard way. */
1056 if (check_ktype (context, FALSE) == -1)
1058 /* Count type and namespace scopes. */
1059 while (1)
1061 context = CP_DECL_CONTEXT (context);
1062 if (context == global_namespace)
1063 break;
1064 i += 1;
1065 if (check_ktype (context, FALSE) != -1)
1066 /* Found one! */
1067 break;
1068 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
1069 context = TYPE_NAME (context);
1073 if (i > 1)
1075 OB_PUTC ('Q');
1076 build_underscore_int (i);
1077 numeric_output_need_bar = 0;
1079 build_overload_nested_name (decl);
1082 /* Output the mangled representation for TYPE. If EXTRA_GCODE is
1083 non-zero, mangled names for structure/union types are intentionally
1084 mangled differently from the method described in the ARM. */
1086 static void
1087 build_mangled_name_for_type_with_Gcode (type, extra_Gcode)
1088 tree type;
1089 int extra_Gcode;
1091 if (TYPE_PTRMEMFUNC_P (type))
1092 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
1093 process_modifiers (type);
1094 process_overload_item (type, extra_Gcode);
1097 /* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1098 `G'. */
1100 static void
1101 build_mangled_name_for_type (type)
1102 tree type;
1104 build_mangled_name_for_type_with_Gcode (type, 0);
1107 /* Given a list of parameters in PARMTYPES, create an unambiguous
1108 overload string. Should distinguish any type that C (or C++) can
1109 distinguish. I.e., pointers to functions are treated correctly.
1111 Caller must deal with whether a final `e' goes on the end or not.
1113 Any default conversions must take place before this function
1114 is called.
1116 BEGIN and END control initialization and finalization of the
1117 obstack where we build the string. */
1119 char *
1120 build_overload_name (parmtypes, begin, end)
1121 tree parmtypes;
1122 int begin, end;
1124 char *ret;
1125 start_squangling ();
1126 ret = build_mangled_name (parmtypes, begin, end);
1127 end_squangling ();
1128 return ret ;
1131 /* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1132 TREE_LIST, then it is a list of parameter types. Otherwise,
1133 PARMTYPES must be a single type. */
1135 static char *
1136 build_mangled_name (parmtypes, begin, end)
1137 tree parmtypes;
1138 int begin, end;
1140 if (begin)
1141 OB_INIT ();
1143 if (TREE_CODE (parmtypes) != TREE_LIST)
1144 /* There is only one type. */
1145 build_mangled_name_for_type (parmtypes);
1146 else
1148 /* There are several types in a parameter list. */
1149 int nrepeats = 0;
1150 int old_style_repeats = !flag_do_squangling && !nofold && typevec;
1151 tree last_type = NULL_TREE;
1153 for (; parmtypes && parmtypes != void_list_node;
1154 parmtypes = TREE_CHAIN (parmtypes))
1156 /* We used to call canonical_type_variant here, but that isn't
1157 good enough; it doesn't handle pointers to typedef types. So
1158 we can't just set TREE_USED to say we've seen a type already;
1159 we have to check each of the earlier types with same_type_p. */
1160 tree parmtype = TREE_VALUE (parmtypes);
1162 if (old_style_repeats)
1164 /* Every argument gets counted. */
1165 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1166 VARRAY_TREE (typevec, maxtype) = parmtype;
1167 maxtype++;
1170 if (last_type && same_type_p (parmtype, last_type))
1172 if (flag_do_squangling
1173 || (old_style_repeats
1174 && is_back_referenceable_type (parmtype)))
1176 /* The next type is the same as this one. Keep
1177 track of the repetition, and output the repeat
1178 count later. */
1179 nrepeats++;
1180 continue;
1183 else if (nrepeats != 0)
1185 /* Indicate how many times the previous parameter was
1186 repeated. */
1187 if (old_style_repeats)
1188 flush_repeats (nrepeats, last_type);
1189 else
1190 issue_nrepeats (nrepeats, last_type);
1191 nrepeats = 0;
1194 last_type = parmtype;
1196 /* Note that for bug-compatibility with 2.7.2, we can't build up
1197 repeats of types other than the most recent one. So we call
1198 flush_repeats every round, if we get this far. */
1199 if (old_style_repeats && flush_repeats (0, parmtype))
1200 continue;
1202 /* Output the PARMTYPE. */
1203 build_mangled_name_for_type_with_Gcode (parmtype, 1);
1206 /* Output the repeat count for the last parameter, if
1207 necessary. */
1208 if (nrepeats != 0)
1210 if (old_style_repeats)
1211 flush_repeats (nrepeats, last_type);
1212 else
1213 issue_nrepeats (nrepeats, last_type);
1214 nrepeats = 0;
1217 if (!parmtypes)
1218 /* The parameter list ends in an ellipsis. */
1219 OB_PUTC ('e');
1222 if (end)
1223 OB_FINISH ();
1224 return (char *)obstack_base (&scratch_obstack);
1227 /* Emit modifiers such as constant, read-only, and volatile. */
1229 static void
1230 process_modifiers (parmtype)
1231 tree parmtype;
1233 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1234 we describe types recursively; we will get the `const' in
1235 `const int ()[10]' when processing the `const int' part. */
1236 if (TYPE_READONLY (parmtype))
1237 OB_PUTC ('C');
1238 if (TREE_CODE (parmtype) == INTEGER_TYPE
1239 && parmtype != char_type_node
1240 && parmtype != wchar_type_node
1241 && (TYPE_MAIN_VARIANT (parmtype)
1242 == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
1243 && ! TYPE_FOR_JAVA (parmtype))
1244 OB_PUTC ('U');
1245 if (TYPE_VOLATILE (parmtype))
1246 OB_PUTC ('V');
1247 /* It would be better to use `R' for `restrict', but that's already
1248 used for reference types. And `r' is used for `long double'. */
1249 if (TYPE_RESTRICT (parmtype))
1250 OB_PUTC ('u');
1253 /* Check to see if TYPE has been entered into the Bcode typelist. If
1254 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1255 to the list of back-referenceable types and return 0. */
1257 static int
1258 check_btype (type)
1259 tree type;
1261 size_t x;
1263 if (btypelist == NULL)
1264 return 0;
1266 if (!is_back_referenceable_type (type))
1267 return 0;
1269 for (x = 0; x < maxbtype; x++)
1270 if (same_type_p (type, VARRAY_TREE (btypelist, x)))
1272 OB_PUTC ('B');
1273 icat (x);
1274 if (x > 9)
1275 OB_PUTC ('_');
1276 return 1 ;
1279 if (VARRAY_SIZE (btypelist) <= maxbtype)
1280 /* Enlarge the table. */
1281 VARRAY_GROW (btypelist,
1282 VARRAY_SIZE (btypelist) * 3 / 2);
1284 /* Register the TYPE. */
1285 VARRAY_TREE (btypelist, maxbtype) = type;
1286 maxbtype++;
1288 return 0;
1291 /* Emit the correct code for various node types. */
1293 static void
1294 process_overload_item (parmtype, extra_Gcode)
1295 tree parmtype;
1296 int extra_Gcode;
1298 numeric_output_need_bar = 0;
1300 /* Our caller should have already handed any qualifiers, so pull out the
1301 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1302 for arrays, because they are transparent to qualifiers. Sigh. */
1303 if (TREE_CODE (parmtype) == ARRAY_TYPE)
1304 parmtype = canonical_type_variant (parmtype);
1305 else
1306 parmtype = TYPE_MAIN_VARIANT (parmtype);
1308 /* These tree types are considered modifiers for B code squangling,
1309 and therefore should not get entries in the Btypelist. They are,
1310 however, repeatable types. */
1312 switch (TREE_CODE (parmtype))
1314 case REFERENCE_TYPE:
1315 OB_PUTC ('R');
1316 goto more;
1318 case ARRAY_TYPE:
1319 #if PARM_CAN_BE_ARRAY_TYPE
1321 OB_PUTC ('A');
1322 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
1323 OB_PUTC ('_');
1324 else
1326 tree length = array_type_nelts (parmtype);
1327 if (TREE_CODE (length) != INTEGER_CST || flag_do_squangling)
1329 length = fold (build (PLUS_EXPR, TREE_TYPE (length),
1330 length, integer_one_node));
1331 STRIP_NOPS (length);
1333 build_overload_value (sizetype, length, 1);
1335 if (numeric_output_need_bar && ! flag_do_squangling)
1336 OB_PUTC ('_');
1337 goto more;
1339 #else
1340 OB_PUTC ('P');
1341 goto more;
1342 #endif
1344 case POINTER_TYPE:
1345 OB_PUTC ('P');
1346 more:
1347 build_mangled_name_for_type (TREE_TYPE (parmtype));
1348 return;
1349 break;
1351 default:
1352 break;
1355 if (flag_do_squangling && check_btype (parmtype))
1356 /* If PARMTYPE is already in the list of back-referenceable types,
1357 then check_btype will output the appropriate reference, and
1358 there's nothing more to do. */
1359 return;
1361 switch (TREE_CODE (parmtype))
1363 case OFFSET_TYPE:
1364 OB_PUTC ('O');
1365 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype));
1366 OB_PUTC ('_');
1367 build_mangled_name_for_type (TREE_TYPE (parmtype));
1368 break;
1370 case FUNCTION_TYPE:
1371 case METHOD_TYPE:
1373 tree parms = TYPE_ARG_TYPES (parmtype);
1375 /* Rather than implementing a reentrant TYPEVEC, we turn off
1376 repeat codes here, unless we're squangling. Squangling
1377 doesn't make use of the TYPEVEC, so there's no reentrancy
1378 problem. */
1379 int old_nofold = nofold;
1380 if (!flag_do_squangling)
1381 nofold = 1;
1383 if (TREE_CODE (parmtype) == METHOD_TYPE)
1385 /* Mark this as a method. */
1386 OB_PUTC ('M');
1387 /* Output the class of which this method is a member. */
1388 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype));
1389 /* Output any qualifiers for the `this' parameter. */
1390 process_modifiers (TREE_TYPE (TREE_VALUE (parms)));
1393 /* Output the parameter types. */
1394 OB_PUTC ('F');
1395 if (parms == NULL_TREE)
1396 OB_PUTC ('e');
1397 else if (parms == void_list_node)
1398 OB_PUTC ('v');
1399 else
1400 build_mangled_name (parms, 0, 0);
1402 /* Output the return type. */
1403 OB_PUTC ('_');
1404 build_mangled_name_for_type (TREE_TYPE (parmtype));
1406 nofold = old_nofold;
1407 break;
1410 case INTEGER_TYPE:
1411 if (parmtype == integer_type_node
1412 || parmtype == unsigned_type_node
1413 || parmtype == java_int_type_node)
1414 OB_PUTC ('i');
1415 else if (parmtype == long_integer_type_node
1416 || parmtype == long_unsigned_type_node)
1417 OB_PUTC ('l');
1418 else if (parmtype == short_integer_type_node
1419 || parmtype == short_unsigned_type_node
1420 || parmtype == java_short_type_node)
1421 OB_PUTC ('s');
1422 else if (parmtype == signed_char_type_node)
1424 OB_PUTC ('S');
1425 OB_PUTC ('c');
1427 else if (parmtype == char_type_node
1428 || parmtype == unsigned_char_type_node
1429 || parmtype == java_byte_type_node)
1430 OB_PUTC ('c');
1431 else if (parmtype == wchar_type_node
1432 || parmtype == java_char_type_node)
1433 OB_PUTC ('w');
1434 else if (parmtype == long_long_integer_type_node
1435 || parmtype == long_long_unsigned_type_node
1436 || parmtype == java_long_type_node)
1437 OB_PUTC ('x');
1438 else if (parmtype == java_boolean_type_node)
1439 OB_PUTC ('b');
1440 #if HOST_BITS_PER_WIDE_INT >= 64
1441 else
1443 int bits = TREE_INT_CST_LOW (TYPE_SIZE (parmtype));
1444 build_mangled_C9x_name (bits);
1446 #else
1447 else
1448 my_friendly_abort (73);
1449 #endif
1450 break;
1452 case BOOLEAN_TYPE:
1453 OB_PUTC ('b');
1454 break;
1456 case REAL_TYPE:
1457 if (parmtype == long_double_type_node)
1458 OB_PUTC ('r');
1459 else if (parmtype == double_type_node
1460 || parmtype == java_double_type_node)
1461 OB_PUTC ('d');
1462 else if (parmtype == float_type_node
1463 || parmtype == java_float_type_node)
1464 OB_PUTC ('f');
1465 else my_friendly_abort (74);
1466 break;
1468 case COMPLEX_TYPE:
1469 OB_PUTC ('J');
1470 build_mangled_name_for_type (TREE_TYPE (parmtype));
1471 break;
1473 case VOID_TYPE:
1474 OB_PUTC ('v');
1475 break;
1477 case ERROR_MARK: /* not right, but nothing is anyway */
1478 break;
1480 /* have to do these */
1481 case UNION_TYPE:
1482 case RECORD_TYPE:
1484 if (extra_Gcode)
1485 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1486 /* drop through into next case */
1488 case ENUMERAL_TYPE:
1490 tree name = TYPE_NAME (parmtype);
1492 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
1494 build_qualified_name (name);
1495 break;
1498 case UNKNOWN_TYPE:
1499 /* This will take some work. */
1500 OB_PUTC ('?');
1501 break;
1503 case TEMPLATE_TEMPLATE_PARM:
1504 /* Find and output the original template parameter
1505 declaration. */
1506 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype))
1508 build_mangled_template_parm_index ("tzX",
1509 TEMPLATE_TYPE_PARM_INDEX
1510 (parmtype));
1511 build_template_parm_names
1512 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype)),
1513 TYPE_TI_ARGS (parmtype));
1515 else
1517 build_mangled_template_parm_index ("ZzX",
1518 TEMPLATE_TYPE_PARM_INDEX
1519 (parmtype));
1520 build_template_template_parm_names
1521 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
1523 break;
1525 case TEMPLATE_TYPE_PARM:
1526 build_mangled_template_parm_index ("X",
1527 TEMPLATE_TYPE_PARM_INDEX
1528 (parmtype));
1529 break;
1531 case TYPENAME_TYPE:
1532 /* When mangling the type of a function template whose
1533 declaration looks like:
1535 template <class T> void foo(typename T::U)
1537 we have to mangle these. */
1538 build_qualified_name (parmtype);
1539 break;
1541 default:
1542 my_friendly_abort (75);
1547 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1548 be either a class TYPE or a FUNCTION_DECL. */
1550 tree
1551 build_static_name (context, name)
1552 tree context, name;
1554 OB_INIT ();
1555 numeric_output_need_bar = 0;
1556 start_squangling ();
1557 #ifdef JOINER
1558 OB_PUTC ('_');
1559 build_qualified_name (context);
1560 OB_PUTC (JOINER);
1561 #else
1562 OB_PUTS ("__static_");
1563 build_qualified_name (context);
1564 OB_PUTC ('_');
1565 #endif
1566 OB_PUTID (name);
1567 OB_FINISH ();
1568 end_squangling ();
1570 return get_identifier ((char *)obstack_base (&scratch_obstack));
1573 /* FOR_METHOD should be 1 if the declaration in question is for a member
1574 of a class (including a static member) and 2 if the declaration is
1575 for a constructor. */
1576 tree
1577 build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1578 for_method)
1579 tree dname;
1580 tree parms;
1581 tree ret_type;
1582 tree tparms;
1583 tree targs;
1584 int for_method;
1586 const char *name = IDENTIFIER_POINTER (dname);
1588 /* member operators new and delete look like methods at this point. */
1589 if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
1590 && TREE_CHAIN (parms) == void_list_node)
1592 if (dname == ansi_opname[(int) DELETE_EXPR])
1593 return get_identifier ("__builtin_delete");
1594 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1595 return get_identifier ("__builtin_vec_delete");
1596 if (dname == ansi_opname[(int) NEW_EXPR])
1597 return get_identifier ("__builtin_new");
1598 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1599 return get_identifier ("__builtin_vec_new");
1602 start_squangling ();
1603 OB_INIT ();
1604 if (for_method != 2)
1605 OB_PUTCP (name);
1606 /* Otherwise, we can divine that this is a constructor,
1607 and figure out its name without any extra encoding. */
1609 OB_PUTC2 ('_', '_');
1610 numeric_output_need_bar = 0;
1612 if (tparms)
1614 OB_PUTC ('H');
1615 build_template_parm_names (tparms, targs);
1616 OB_PUTC ('_');
1618 else if (!for_method && current_namespace == global_namespace)
1619 /* XXX this works only if we call this in the same namespace
1620 as the declaration. Unfortunately, we don't have the _DECL,
1621 only its name */
1622 OB_PUTC ('F');
1624 if (!for_method && current_namespace != global_namespace)
1625 /* qualify with namespace */
1626 build_qualified_name (current_namespace);
1628 if (parms == NULL_TREE)
1629 OB_PUTC ('e');
1630 else if (parms == void_list_node)
1631 OB_PUTC ('v');
1632 else
1634 if (!flag_do_squangling)
1636 /* Allocate typevec array. */
1637 size_t typevec_size = list_length (parms);
1638 maxtype = 0;
1639 if (!for_method && current_namespace != global_namespace)
1640 /* The namespace of a global function needs one slot. */
1641 typevec_size++;
1642 VARRAY_TREE_INIT (typevec, typevec_size, "typevec");
1644 nofold = 0;
1646 if (for_method)
1648 tree this_type = TREE_TYPE (TREE_VALUE (parms));
1650 build_mangled_name_for_type (this_type);
1652 if (!flag_do_squangling)
1654 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1655 VARRAY_TREE (typevec, maxtype) = this_type;
1656 maxtype++;
1659 if (TREE_CHAIN (parms))
1660 build_mangled_name (TREE_CHAIN (parms), 0, 0);
1661 else
1662 OB_PUTC ('e');
1664 else
1666 /* the namespace qualifier for a global function
1667 will count as type */
1668 if (current_namespace != global_namespace
1669 && !flag_do_squangling)
1671 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1672 VARRAY_TREE (typevec, maxtype) = current_namespace;
1673 maxtype++;
1675 build_mangled_name (parms, 0, 0);
1678 if (!flag_do_squangling)
1679 /* Deallocate typevec array. */
1680 VARRAY_FREE (typevec);
1683 if (ret_type != NULL_TREE && for_method != 2)
1685 /* Add the return type. */
1686 OB_PUTC ('_');
1687 build_mangled_name_for_type (ret_type);
1690 OB_FINISH ();
1691 end_squangling ();
1693 tree n = get_identifier (obstack_base (&scratch_obstack));
1694 if (IDENTIFIER_OPNAME_P (dname))
1695 IDENTIFIER_OPNAME_P (n) = 1;
1696 return n;
1700 /* Change the name of a function definition so that it may be
1701 overloaded. NAME is the name of the function to overload,
1702 PARMS is the parameter list (which determines what name the
1703 final function obtains).
1705 FOR_METHOD is 1 if this overload is being performed
1706 for a method, rather than a function type. It is 2 if
1707 this overload is being performed for a constructor. */
1709 tree
1710 build_decl_overload (dname, parms, for_method)
1711 tree dname;
1712 tree parms;
1713 int for_method;
1715 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1716 NULL_TREE, for_method);
1719 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
1721 void
1722 set_mangled_name_for_decl (decl)
1723 tree decl;
1725 tree parm_types;
1727 if (processing_template_decl)
1728 /* There's no need to mangle the name of a template function. */
1729 return;
1731 parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
1733 if (DECL_STATIC_FUNCTION_P (decl))
1734 parm_types =
1735 hash_tree_chain (build_pointer_type (DECL_CLASS_CONTEXT (decl)),
1736 parm_types);
1737 else
1738 /* The only member functions whose type is a FUNCTION_TYPE, rather
1739 than a METHOD_TYPE, should be static members. */
1740 my_friendly_assert (!DECL_CONTEXT (decl)
1741 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl)))
1742 || TREE_CODE (TREE_TYPE (decl)) != FUNCTION_TYPE,
1745 DECL_ASSEMBLER_NAME (decl)
1746 = build_decl_overload (DECL_NAME (decl), parm_types,
1747 DECL_FUNCTION_MEMBER_P (decl)
1748 + DECL_CONSTRUCTOR_P (decl));
1751 /* Build an overload name for the type expression TYPE. */
1753 tree
1754 build_typename_overload (type)
1755 tree type;
1757 tree id;
1759 OB_INIT ();
1760 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1761 nofold = 1;
1762 start_squangling ();
1763 build_mangled_name (type, 0, 1);
1764 id = get_identifier (obstack_base (&scratch_obstack));
1765 IDENTIFIER_OPNAME_P (id) = 1;
1766 #if 0
1767 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
1768 #endif
1769 TREE_TYPE (id) = type;
1770 end_squangling ();
1771 return id;
1774 tree
1775 build_overload_with_type (name, type)
1776 tree name, type;
1778 OB_INIT ();
1779 OB_PUTID (name);
1780 nofold = 1;
1782 start_squangling ();
1783 build_mangled_name (type, 0, 1);
1784 end_squangling ();
1785 return get_identifier (obstack_base (&scratch_obstack));
1788 tree
1789 get_id_2 (name, name2)
1790 const char *name;
1791 tree name2;
1793 OB_INIT ();
1794 OB_PUTCP (name);
1795 OB_PUTID (name2);
1796 OB_FINISH ();
1797 return get_identifier (obstack_base (&scratch_obstack));
1800 /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1802 tree
1803 build_destructor_name (type)
1804 tree type;
1806 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX),
1807 type);
1810 /* Given a tree_code CODE, and some arguments (at least one),
1811 attempt to use an overloaded operator on the arguments.
1813 For unary operators, only the first argument need be checked.
1814 For binary operators, both arguments may need to be checked.
1816 Member functions can convert class references to class pointers,
1817 for one-level deep indirection. More than that is not supported.
1818 Operators [](), ()(), and ->() must be member functions.
1820 We call function call building calls with LOOKUP_COMPLAIN if they
1821 are our only hope. This is true when we see a vanilla operator
1822 applied to something of aggregate type. If this fails, we are free
1823 to return `error_mark_node', because we will have reported the
1824 error.
1826 Operators NEW and DELETE overload in funny ways: operator new takes
1827 a single `size' parameter, and operator delete takes a pointer to the
1828 storage being deleted. When overloading these operators, success is
1829 assumed. If there is a failure, report an error message and return
1830 `error_mark_node'. */
1832 /* NOSTRICT */
1833 tree
1834 build_opfncall (code, flags, xarg1, xarg2, arg3)
1835 enum tree_code code;
1836 int flags;
1837 tree xarg1, xarg2, arg3;
1839 return build_new_op (code, flags, xarg1, xarg2, arg3);
1842 /* This function takes an identifier, ID, and attempts to figure out what
1843 it means. There are a number of possible scenarios, presented in increasing
1844 order of hair:
1846 1) not in a class's scope
1847 2) in class's scope, member name of the class's method
1848 3) in class's scope, but not a member name of the class
1849 4) in class's scope, member name of a class's variable
1851 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1852 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1854 As a last ditch, try to look up the name as a label and return that
1855 address.
1857 Values which are declared as being of REFERENCE_TYPE are
1858 automatically dereferenced here (as a hack to make the
1859 compiler faster). */
1861 tree
1862 hack_identifier (value, name)
1863 tree value, name;
1865 tree type;
1867 if (value == error_mark_node)
1869 if (current_class_name)
1871 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1872 if (fields == error_mark_node)
1873 return error_mark_node;
1874 if (fields)
1876 tree fndecl;
1878 fndecl = TREE_VALUE (fields);
1879 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
1880 /* I could not trigger this code. MvL */
1881 my_friendly_abort (980325);
1882 #ifdef DEAD
1883 if (DECL_CHAIN (fndecl) == NULL_TREE)
1885 warning ("methods cannot be converted to function pointers");
1886 return fndecl;
1888 else
1890 error ("ambiguous request for method pointer `%s'",
1891 IDENTIFIER_POINTER (name));
1892 return error_mark_node;
1894 #endif
1897 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1899 return IDENTIFIER_LABEL_VALUE (name);
1901 return error_mark_node;
1904 type = TREE_TYPE (value);
1905 if (TREE_CODE (value) == FIELD_DECL)
1907 if (current_class_ptr == NULL_TREE)
1909 if (current_function_decl
1910 && DECL_STATIC_FUNCTION_P (current_function_decl))
1911 cp_error ("invalid use of member `%D' in static member function",
1912 value);
1913 else
1914 /* We can get here when processing a bad default
1915 argument, like:
1916 struct S { int a; void f(int i = a); } */
1917 cp_error ("invalid use of member `%D'", value);
1919 return error_mark_node;
1921 TREE_USED (current_class_ptr) = 1;
1923 /* Mark so that if we are in a constructor, and then find that
1924 this field was initialized by a base initializer,
1925 we can emit an error message. */
1926 TREE_USED (value) = 1;
1927 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
1929 else if ((TREE_CODE (value) == FUNCTION_DECL
1930 && DECL_FUNCTION_MEMBER_P (value))
1931 || (TREE_CODE (value) == OVERLOAD
1932 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
1934 tree decl;
1936 if (TREE_CODE (value) == OVERLOAD)
1937 value = OVL_CURRENT (value);
1939 decl = maybe_dummy_object (DECL_CLASS_CONTEXT (value), 0);
1940 value = build_component_ref (decl, name, NULL_TREE, 1);
1942 else if (really_overloaded_fn (value))
1944 else if (TREE_CODE (value) == OVERLOAD)
1945 /* not really overloaded function */
1946 mark_used (OVL_FUNCTION (value));
1947 else if (TREE_CODE (value) == TREE_LIST)
1949 /* Ambiguous reference to base members, possibly other cases?. */
1950 tree t = value;
1951 while (t && TREE_CODE (t) == TREE_LIST)
1953 mark_used (TREE_VALUE (t));
1954 t = TREE_CHAIN (t);
1957 else if (TREE_CODE (value) == NAMESPACE_DECL)
1959 cp_error ("use of namespace `%D' as expression", value);
1960 return error_mark_node;
1962 else if (DECL_CLASS_TEMPLATE_P (value))
1964 cp_error ("use of class template `%T' as expression", value);
1965 return error_mark_node;
1967 else
1968 mark_used (value);
1970 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
1971 || TREE_CODE (value) == RESULT_DECL)
1973 tree context = decl_function_context (value);
1974 if (context != NULL_TREE && context != current_function_decl
1975 && ! TREE_STATIC (value))
1977 cp_error ("use of %s from containing function",
1978 (TREE_CODE (value) == VAR_DECL
1979 ? "`auto' variable" : "parameter"));
1980 cp_error_at (" `%#D' declared here", value);
1981 value = error_mark_node;
1985 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1987 if (DECL_LANG_SPECIFIC (value)
1988 && DECL_CLASS_CONTEXT (value) != current_class_type)
1990 tree path;
1991 register tree context
1992 = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value))
1993 ? DECL_CLASS_CONTEXT (value)
1994 : DECL_CONTEXT (value);
1996 get_base_distance (context, current_class_type, 0, &path);
1997 if (path && !enforce_access (current_class_type, value))
1998 return error_mark_node;
2001 else if (TREE_CODE (value) == TREE_LIST
2002 && TREE_TYPE (value) == error_mark_node)
2004 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2005 IDENTIFIER_POINTER (name));
2006 print_candidates (value);
2007 return error_mark_node;
2010 if (! processing_template_decl)
2011 value = convert_from_reference (value);
2012 return value;
2016 tree
2017 make_thunk (function, delta)
2018 tree function;
2019 int delta;
2021 tree thunk_id;
2022 tree thunk;
2023 tree func_decl;
2025 if (TREE_CODE (function) != ADDR_EXPR)
2026 abort ();
2027 func_decl = TREE_OPERAND (function, 0);
2028 if (TREE_CODE (func_decl) != FUNCTION_DECL)
2029 abort ();
2031 OB_INIT ();
2032 OB_PUTS ("__thunk_");
2033 if (delta > 0)
2035 OB_PUTC ('n');
2036 icat (delta);
2038 else
2039 icat (-delta);
2040 OB_PUTC ('_');
2041 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl));
2042 OB_FINISH ();
2043 thunk_id = get_identifier (obstack_base (&scratch_obstack));
2045 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
2046 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
2048 cp_error ("implementation-reserved name `%D' used", thunk_id);
2049 thunk = NULL_TREE;
2050 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
2052 if (thunk == NULL_TREE)
2054 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
2055 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
2056 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
2057 comdat_linkage (thunk);
2058 TREE_SET_CODE (thunk, THUNK_DECL);
2059 DECL_INITIAL (thunk) = function;
2060 THUNK_DELTA (thunk) = delta;
2061 DECL_EXTERNAL (thunk) = 1;
2062 DECL_ARTIFICIAL (thunk) = 1;
2063 /* So that finish_file can write out any thunks that need to be: */
2064 pushdecl_top_level (thunk);
2066 return thunk;
2069 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2071 void
2072 emit_thunk (thunk_fndecl)
2073 tree thunk_fndecl;
2075 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
2076 int delta = THUNK_DELTA (thunk_fndecl);
2078 if (TREE_ASM_WRITTEN (thunk_fndecl))
2079 return;
2081 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
2083 TREE_ADDRESSABLE (function) = 1;
2084 mark_used (function);
2086 if (current_function_decl)
2087 abort ();
2089 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
2091 #ifdef ASM_OUTPUT_MI_THUNK
2092 if (!flag_syntax_only)
2094 char *fnname;
2095 current_function_decl = thunk_fndecl;
2096 /* Make sure we build up its RTL before we go onto the
2097 temporary obstack. */
2098 make_function_rtl (thunk_fndecl);
2099 temporary_allocation ();
2100 DECL_RESULT (thunk_fndecl)
2101 = build_decl (RESULT_DECL, 0, integer_type_node);
2102 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2103 init_function_start (thunk_fndecl, input_filename, lineno);
2104 current_function_is_thunk = 1;
2105 assemble_start_function (thunk_fndecl, fnname);
2106 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
2107 assemble_end_function (thunk_fndecl, fnname);
2108 permanent_allocation (1);
2109 current_function_decl = 0;
2110 current_function = 0;
2112 #else /* ASM_OUTPUT_MI_THUNK */
2114 /* If we don't have the necessary macro for efficient thunks, generate a
2115 thunk function that just makes a call to the real function.
2116 Unfortunately, this doesn't work for varargs. */
2118 tree a, t;
2120 if (varargs_function_p (function))
2121 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2122 function);
2124 /* Set up clone argument trees for the thunk. */
2125 t = NULL_TREE;
2126 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
2128 tree x = copy_node (a);
2129 TREE_CHAIN (x) = t;
2130 DECL_CONTEXT (x) = thunk_fndecl;
2131 t = x;
2133 a = nreverse (t);
2134 DECL_ARGUMENTS (thunk_fndecl) = a;
2135 DECL_RESULT (thunk_fndecl) = NULL_TREE;
2136 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
2137 copy_lang_decl (thunk_fndecl);
2138 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
2139 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
2141 start_function (NULL_TREE, thunk_fndecl, NULL_TREE,
2142 SF_DEFAULT | SF_PRE_PARSED);
2143 store_parm_decls ();
2144 current_function_is_thunk = 1;
2146 /* Build up the call to the real function. */
2147 t = build_int_2 (delta, -1 * (delta < 0));
2148 TREE_TYPE (t) = signed_type (sizetype);
2149 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
2150 t = tree_cons (NULL_TREE, t, NULL_TREE);
2151 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
2152 t = tree_cons (NULL_TREE, a, t);
2153 t = nreverse (t);
2154 t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t);
2155 finish_return_stmt (t);
2157 expand_body (finish_function (lineno, 0));
2159 /* Don't let the backend defer this function. */
2160 if (DECL_DEFER_OUTPUT (thunk_fndecl))
2162 output_inline_function (thunk_fndecl);
2163 permanent_allocation (1);
2166 #endif /* ASM_OUTPUT_MI_THUNK */
2168 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
2171 /* Code for synthesizing methods which have default semantics defined. */
2173 /* Generate code for default X(X&) constructor. */
2175 static void
2176 do_build_copy_constructor (fndecl)
2177 tree fndecl;
2179 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2180 tree t;
2182 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2183 parm = TREE_CHAIN (parm);
2184 parm = convert_from_reference (parm);
2186 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
2187 && is_empty_class (current_class_type))
2188 /* Don't copy the padding byte; it might not have been allocated
2189 if *this is a base subobject. */;
2190 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
2192 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
2193 finish_expr_stmt (t);
2195 else
2197 tree fields = TYPE_FIELDS (current_class_type);
2198 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2199 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2200 int i;
2202 /* Initialize all the base-classes. */
2203 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2204 t = TREE_CHAIN (t))
2205 current_base_init_list
2206 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
2207 for (i = 0; i < n_bases; ++i)
2209 t = TREE_VEC_ELT (binfos, i);
2210 if (TREE_VIA_VIRTUAL (t))
2211 continue;
2213 current_base_init_list
2214 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
2217 for (; fields; fields = TREE_CHAIN (fields))
2219 tree init, t;
2220 tree field = fields;
2222 if (TREE_CODE (field) != FIELD_DECL)
2223 continue;
2225 init = parm;
2226 if (DECL_NAME (field))
2228 if (VFIELD_NAME_P (DECL_NAME (field)))
2229 continue;
2230 if (VBASE_NAME_P (DECL_NAME (field)))
2231 continue;
2233 /* True for duplicate members. */
2234 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2235 continue;
2237 else if ((t = TREE_TYPE (field)) != NULL_TREE
2238 && ANON_AGGR_TYPE_P (t)
2239 && TYPE_FIELDS (t) != NULL_TREE)
2240 /* Just use the field; anonymous types can't have
2241 nontrivial copy ctors or assignment ops. */;
2242 else
2243 continue;
2245 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2246 init = build_tree_list (NULL_TREE, init);
2248 current_member_init_list
2249 = tree_cons (field, init, current_member_init_list);
2251 current_member_init_list = nreverse (current_member_init_list);
2252 current_base_init_list = nreverse (current_base_init_list);
2253 setup_vtbl_ptr ();
2257 static void
2258 do_build_assign_ref (fndecl)
2259 tree fndecl;
2261 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2262 tree compound_stmt;
2264 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
2265 parm = convert_from_reference (parm);
2267 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
2268 && is_empty_class (current_class_type))
2269 /* Don't copy the padding byte; it might not have been allocated
2270 if *this is a base subobject. */;
2271 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
2273 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
2274 finish_expr_stmt (t);
2276 else
2278 tree fields = TYPE_FIELDS (current_class_type);
2279 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2280 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2281 int i;
2283 for (i = 0; i < n_bases; ++i)
2285 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
2286 tree p = convert_to_reference
2287 (build_reference_type (basetype), parm,
2288 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2289 p = convert_from_reference (p);
2290 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
2291 build_expr_list (NULL_TREE, p));
2292 finish_expr_stmt (p);
2294 for (; fields; fields = TREE_CHAIN (fields))
2296 tree comp, init, t;
2297 tree field = fields;
2299 if (TREE_CODE (field) != FIELD_DECL)
2300 continue;
2302 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
2304 if (DECL_NAME (field))
2305 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
2306 else
2307 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
2308 continue;
2310 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2312 if (DECL_NAME (field))
2313 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
2314 else
2315 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
2316 continue;
2319 comp = current_class_ref;
2320 init = parm;
2322 if (DECL_NAME (field))
2324 if (VFIELD_NAME_P (DECL_NAME (field)))
2325 continue;
2326 if (VBASE_NAME_P (DECL_NAME (field)))
2327 continue;
2329 /* True for duplicate members. */
2330 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
2331 continue;
2333 else if ((t = TREE_TYPE (field)) != NULL_TREE
2334 && ANON_AGGR_TYPE_P (t)
2335 && TYPE_FIELDS (t) != NULL_TREE)
2336 /* Just use the field; anonymous types can't have
2337 nontrivial copy ctors or assignment ops. */;
2338 else
2339 continue;
2341 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2342 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
2344 finish_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
2347 finish_return_stmt (current_class_ref);
2348 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
2351 void
2352 synthesize_method (fndecl)
2353 tree fndecl;
2355 int nested = (current_function_decl != NULL_TREE);
2356 tree context = hack_decl_function_context (fndecl);
2357 int need_body = 1;
2359 if (at_eof)
2360 import_export_decl (fndecl);
2362 if (! context)
2363 push_to_top_level ();
2364 else if (nested)
2365 push_function_context_to (context);
2367 /* Put the function definition at the position where it is needed,
2368 rather than within the body of the class. That way, an error
2369 during the generation of the implicit body points at the place
2370 where the attempt to generate the function occurs, giving the
2371 user a hint as to why we are attempting to generate the
2372 function. */
2373 DECL_SOURCE_LINE (fndecl) = lineno;
2374 DECL_SOURCE_FILE (fndecl) = input_filename;
2376 interface_unknown = 1;
2377 start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
2378 store_parm_decls ();
2379 clear_last_expr ();
2381 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
2383 do_build_assign_ref (fndecl);
2384 need_body = 0;
2386 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2387 setup_vtbl_ptr ();
2388 else
2390 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2391 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2392 arg_chain = TREE_CHAIN (arg_chain);
2393 if (arg_chain != void_list_node)
2394 do_build_copy_constructor (fndecl);
2395 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
2396 setup_vtbl_ptr ();
2399 /* If we haven't yet generated the body of the function, just
2400 generate an empty compound statement. */
2401 if (need_body)
2403 tree compound_stmt;
2404 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
2405 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
2408 expand_body (finish_function (lineno, 0));
2410 extract_interface_info ();
2411 if (! context)
2412 pop_from_top_level ();
2413 else if (nested)
2414 pop_function_context_from (context);