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