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