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