OSDN Git Service

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