OSDN Git Service

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