OSDN Git Service

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