OSDN Git Service

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