OSDN Git Service

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