]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/method.c
* lang-options.h (-fmessage-length=): Add missing option.
[gcc.git] / gcc / cp / method.c
CommitLineData
8d08fdba
MS
1/* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
d6a8bdff
JL
3 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000 Free Software Foundation, Inc.
8d08fdba
MS
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
6
e5e809f4 7This file is part of GNU CC.
8d08fdba
MS
8
9GNU CC is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2, or (at your option)
12any later version.
13
14GNU CC is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
21the Free Software Foundation, 59 Temple Place - Suite 330,
22Boston, MA 02111-1307, USA. */
8d08fdba
MS
23
24
8d08fdba 25/* Handle method declarations. */
8d08fdba 26#include "config.h"
e817b5e3 27#include "system.h"
8d08fdba
MS
28#include "tree.h"
29#include "cp-tree.h"
8d08fdba 30#include "obstack.h"
8926095f
MS
31#include "rtl.h"
32#include "expr.h"
33#include "output.h"
34#include "hard-reg-set.h"
35#include "flags.h"
54f92bfb 36#include "toplev.h"
9cd64686 37#include "ggc.h"
b1afd7f4 38#include "tm_p.h"
8d08fdba 39
858a0ff1
MM
40/* Various flags to control the mangling process. */
41
42enum mangling_flags
43{
44 /* No flags. */
45 mf_none = 0,
46 /* The thing we are presently mangling is part of a template type,
47 rather than a fully instantiated type. Therefore, we may see
48 complex expressions where we would normally expect to see a
49 simple integer constant. */
50 mf_maybe_uninstantiated = 1,
51 /* When mangling a numeric value, use the form `_XX_' (instead of
52 just `XX') if the value has more than one digit. */
53 mf_use_underscores_around_value = 2,
54};
55
56typedef enum mangling_flags mangling_flags;
57
8d08fdba
MS
58/* TREE_LIST of the current inline functions that need to be
59 processed. */
60struct pending_inline *pending_inlines;
61
62#define obstack_chunk_alloc xmalloc
63#define obstack_chunk_free free
64
65/* Obstack where we build text strings for overloading, etc. */
66static struct obstack scratch_obstack;
67static char *scratch_firstobj;
68
158991b7
KG
69static void icat PARAMS ((HOST_WIDE_INT));
70static void dicat PARAMS ((HOST_WIDE_INT, HOST_WIDE_INT));
71static int old_backref_index PARAMS ((tree));
72static int flush_repeats PARAMS ((int, tree));
73static void build_overload_identifier PARAMS ((tree));
74static void build_overload_nested_name PARAMS ((tree));
75static void mangle_expression PARAMS ((tree));
76static void build_overload_int PARAMS ((tree, mangling_flags));
77static void build_overload_identifier PARAMS ((tree));
78static void build_qualified_name PARAMS ((tree));
79static void build_overload_value PARAMS ((tree, tree, mangling_flags));
80static void issue_nrepeats PARAMS ((int, tree));
81static char *build_mangled_name PARAMS ((tree,int,int));
82static void process_modifiers PARAMS ((tree));
83static void process_overload_item PARAMS ((tree,int));
84static void do_build_assign_ref PARAMS ((tree));
85static void do_build_copy_constructor PARAMS ((tree));
86static void build_template_template_parm_names PARAMS ((tree));
87static void build_template_parm_names PARAMS ((tree, tree));
88static void build_underscore_int PARAMS ((int));
89static void start_squangling PARAMS ((void));
90static void end_squangling PARAMS ((void));
91static int check_ktype PARAMS ((tree, int));
92static int issue_ktype PARAMS ((tree));
93static void build_overload_scope_ref PARAMS ((tree));
94static void build_mangled_template_parm_index PARAMS ((const char *, tree));
e833cb11 95#if HOST_BITS_PER_WIDE_INT >= 64
158991b7 96static void build_mangled_C9x_name PARAMS ((int));
e833cb11 97#endif
158991b7
KG
98static int is_back_referenceable_type PARAMS ((tree));
99static int check_btype PARAMS ((tree));
100static void build_mangled_name_for_type PARAMS ((tree));
101static void build_mangled_name_for_type_with_Gcode PARAMS ((tree, int));
49c249e1 102
8d08fdba
MS
103# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
104# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
105# define OB_PUTC2(C1,C2) \
106 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
107# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
108# define OB_PUTID(ID) \
109 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
110 IDENTIFIER_LENGTH (ID)))
111# define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
112# define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
db5ae43f 113# define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
8d08fdba 114
9cd64686
MM
115/* type tables for K and B type compression */
116static varray_type btypelist;
117static varray_type ktypelist;
118
119/* number of each type seen */
120static size_t maxbtype;
121static size_t maxktype;
122
123/* Array of types seen so far in top-level call to `build_mangled_name'.
124 Allocated and deallocated by caller. */
125static varray_type typevec;
126
127/* Number of types interned by `build_mangled_name' so far. */
128static size_t maxtype;
129
130/* Called once to initialize method.c. */
131
8d08fdba
MS
132void
133init_method ()
134{
135 gcc_obstack_init (&scratch_obstack);
136 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
9cd64686
MM
137 ggc_add_tree_varray_root (&btypelist, 1);
138 ggc_add_tree_varray_root (&ktypelist, 1);
139 ggc_add_tree_varray_root (&typevec, 1);
8d08fdba
MS
140}
141
142/* This must be large enough to hold any printed integer or floating-point
143 value. */
144static char digit_buffer[128];
145
8d08fdba 146\f
8d08fdba
MS
147/* Here is where overload code starts. */
148
8d08fdba
MS
149/* Nonzero if we should not try folding parameter types. */
150static int nofold;
151
858a0ff1
MM
152/* Nonzero if an underscore is required before adding a digit to the
153 mangled name currently being built. */
ed22c95e 154static int numeric_output_need_bar;
8d08fdba 155
f9c4f105 156static inline void
ed22c95e
AM
157start_squangling ()
158{
159 if (flag_do_squangling)
160 {
ed22c95e 161 nofold = 0;
ed22c95e
AM
162 maxbtype = 0;
163 maxktype = 0;
9cd64686
MM
164 VARRAY_TREE_INIT (btypelist, 50, "btypelist");
165 VARRAY_TREE_INIT (ktypelist, 50, "ktypelist");
ed22c95e
AM
166 }
167}
168
f9c4f105 169static inline void
ed22c95e
AM
170end_squangling ()
171{
172 if (flag_do_squangling)
173 {
9cd64686
MM
174 VARRAY_FREE (ktypelist);
175 VARRAY_FREE (btypelist);
ed22c95e
AM
176 maxbtype = 0;
177 maxktype = 0;
ed22c95e
AM
178 }
179}
8d08fdba
MS
180
181/* Code to concatenate an asciified integer to a string. */
e92cc029 182
f9c4f105 183static inline void
8d08fdba 184icat (i)
bd6dd845 185 HOST_WIDE_INT i;
8d08fdba 186{
bd6dd845
MS
187 unsigned HOST_WIDE_INT ui;
188
8d08fdba 189 /* Handle this case first, to go really quickly. For many common values,
bd6dd845 190 the result of ui/10 below is 1. */
8d08fdba
MS
191 if (i == 1)
192 {
193 OB_PUTC ('1');
194 return;
195 }
196
bd6dd845
MS
197 if (i >= 0)
198 ui = i;
199 else
8d08fdba
MS
200 {
201 OB_PUTC ('m');
bd6dd845
MS
202 ui = -i;
203 }
204
205 if (ui >= 10)
206 icat (ui / 10);
207
208 OB_PUTC ('0' + (ui % 10));
209}
210
211static void
212dicat (lo, hi)
213 HOST_WIDE_INT lo, hi;
214{
215 unsigned HOST_WIDE_INT ulo, uhi, qlo, qhi;
216
217 if (hi >= 0)
218 {
219 uhi = hi;
220 ulo = lo;
8d08fdba 221 }
8d08fdba
MS
222 else
223 {
bd6dd845
MS
224 uhi = (lo == 0 ? -hi : -hi-1);
225 ulo = -lo;
226 }
227 if (uhi == 0
228 && ulo < ((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)))
229 {
230 icat (ulo);
231 return;
8d08fdba 232 }
bd6dd845
MS
233 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
234 qhi = uhi / 10;
235 uhi = uhi % 10;
236 qlo = uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) / 5);
237 qlo += ulo / 10;
238 ulo = ulo % 10;
239 ulo += uhi * (((unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT - 1)) % 5)
240 * 2;
241 qlo += ulo / 10;
242 ulo = ulo % 10;
243 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
244 dicat (qlo, qhi);
245 OB_PUTC ('0' + ulo);
8d08fdba
MS
246}
247
f921acee 248/* Returns the index of TYPE in the typevec, or -1 if it's not there. */
407f03b8 249
f9c4f105 250static inline int
f921acee 251old_backref_index (type)
8d08fdba
MS
252 tree type;
253{
9cd64686 254 size_t tindex;
8d08fdba 255
407f03b8 256 if (! is_back_referenceable_type (type))
f921acee 257 return -1;
8d08fdba 258
407f03b8
JM
259 /* The entry for this parm is at maxtype-1, so don't look there for
260 something to repeat. */
261 for (tindex = 0; tindex < maxtype - 1; ++tindex)
9cd64686 262 if (same_type_p (VARRAY_TREE (typevec, tindex), type))
407f03b8
JM
263 break;
264
265 if (tindex == maxtype - 1)
f921acee
JM
266 return -1;
267
268 return tindex;
269}
270
271/* Old mangling style: If TYPE has already been used in the parameter list,
272 emit a backward reference and return non-zero; otherwise, return 0.
273
274 NREPEATS is the number of repeats we've recorded of this type, or 0 if
275 this is the first time we've seen it and we're just looking to see if
276 it had been used before. */
277
f9c4f105 278static inline int
f921acee
JM
279flush_repeats (nrepeats, type)
280 int nrepeats;
281 tree type;
282{
283 int tindex = old_backref_index (type);
284
285 if (tindex == -1)
286 {
287 my_friendly_assert (nrepeats == 0, 990316);
288 return 0;
289 }
407f03b8 290
f921acee
JM
291 if (nrepeats > 1)
292 {
293 OB_PUTC ('N');
294 icat (nrepeats);
295 if (nrepeats > 9)
296 OB_PUTC ('_');
297 }
298 else
299 OB_PUTC ('T');
8d08fdba
MS
300 icat (tindex);
301 if (tindex > 9)
302 OB_PUTC ('_');
407f03b8
JM
303
304 return 1;
8d08fdba
MS
305}
306
59e621fc
MM
307/* Returns nonzero iff this is a type to which we will want to make
308 back-references (using the `B' code). */
ed22c95e 309
e9659ab0 310static int
59e621fc
MM
311is_back_referenceable_type (type)
312 tree type;
ed22c95e 313{
407f03b8
JM
314 /* For some reason, the Java folks don't want back refs on these. */
315 if (TYPE_FOR_JAVA (type))
59e621fc
MM
316 return 0;
317
318 switch (TREE_CODE (type))
ed22c95e 319 {
9223feaa
MM
320 case BOOLEAN_TYPE:
321 if (!flag_do_squangling)
322 /* Even though the mangling of this is just `b', we did
323 historically generate back-references for it. */
324 return 1;
325 /* Fall through. */
326
59e621fc
MM
327 case INTEGER_TYPE:
328 case REAL_TYPE:
329 case VOID_TYPE:
59e621fc
MM
330 /* These types have single-character manglings, so there's no
331 point in generating back-references. */
332 return 0;
333
334 case TEMPLATE_TYPE_PARM:
335 /* It would be a bit complex to demangle signatures correctly if
336 we generated back-references to these, and the manglings of
337 type parameters are short. */
338 return 0;
339
340 default:
341 return 1;
ed22c95e 342 }
ed22c95e
AM
343}
344
59e621fc
MM
345/* Issue the squangling code indicating NREPEATS repetitions of TYPE,
346 which was the last parameter type output. */
347
348static void
349issue_nrepeats (nrepeats, type)
350 int nrepeats;
351 tree type;
352{
353 if (nrepeats == 1 && !is_back_referenceable_type (type))
354 /* For types whose manglings are short, don't bother using the
355 repetition code if there's only one repetition, since the
356 repetition code will be about as long as the ordinary mangling. */
357 build_mangled_name_for_type (type);
358 else
359 {
360 OB_PUTC ('n');
361 icat (nrepeats);
362 if (nrepeats > 9)
363 OB_PUTC ('_');
364 }
365}
ed22c95e 366
407f03b8
JM
367/* Check to see if a tree node has been entered into the Kcode typelist.
368 If not, add it. Returns -1 if it isn't found, otherwise returns the
369 index. */
370
ed22c95e
AM
371static int
372check_ktype (node, add)
373 tree node;
374 int add;
375{
9cd64686 376 size_t x;
ed22c95e
AM
377 tree localnode = node;
378
379 if (ktypelist == NULL)
380 return -1;
381
382 if (TREE_CODE (node) == TYPE_DECL)
383 localnode = TREE_TYPE (node);
384
9cd64686 385 for (x = 0; x < maxktype; x++)
ed22c95e 386 {
9cd64686 387 if (same_type_p (localnode, VARRAY_TREE (ktypelist, x)))
407f03b8 388 return x;
ed22c95e 389 }
407f03b8 390 /* Didn't find it, so add it here. */
ed22c95e
AM
391 if (add)
392 {
9cd64686
MM
393 if (VARRAY_SIZE (ktypelist) <= maxktype)
394 VARRAY_GROW (ktypelist,
395 VARRAY_SIZE (ktypelist) * 3 / 2);
396 VARRAY_TREE (ktypelist, maxktype) = localnode;
397 maxktype++;
ed22c95e
AM
398 }
399 return -1;
400}
401
402
f9c4f105 403static inline int
ed22c95e
AM
404issue_ktype (decl)
405 tree decl;
406{
407 int kindex;
408 kindex = check_ktype (decl, FALSE);
409 if (kindex != -1)
410 {
411 OB_PUTC ('K');
412 icat (kindex);
413 if (kindex > 9)
414 OB_PUTC ('_');
415 return TRUE;
416 }
417 return FALSE;
418}
59e621fc
MM
419
420/* Build a representation for DECL, which may be an entity not at
421 global scope. If so, a marker indicating that the name is
422 qualified has already been output, but the qualifying context has
423 not. */
8d08fdba
MS
424
425static void
db5ae43f
MS
426build_overload_nested_name (decl)
427 tree decl;
8d08fdba 428{
cb0dbb9a
JM
429 tree context;
430
ed22c95e
AM
431 if (ktypelist && issue_ktype (decl))
432 return;
433
2c73f9f5
ML
434 if (decl == global_namespace)
435 return;
436
cb0dbb9a
JM
437 context = CP_DECL_CONTEXT (decl);
438
439 /* try to issue a K type, and if we can't continue the normal path */
440 if (!(ktypelist && issue_ktype (context)))
441 {
442 /* For a template type parameter, we want to output an 'Xn'
443 rather than 'T' or some such. */
444 if (TREE_CODE (context) == TEMPLATE_TYPE_PARM
445 || TREE_CODE (context) == TEMPLATE_TEMPLATE_PARM)
59e621fc 446 build_mangled_name_for_type (context);
cb0dbb9a 447 else
8d08fdba 448 {
cb0dbb9a
JM
449 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
450 context = TYPE_NAME (context);
451 build_overload_nested_name (context);
8d08fdba 452 }
cb0dbb9a 453 }
ed22c95e 454
db5ae43f
MS
455 if (TREE_CODE (decl) == FUNCTION_DECL)
456 {
39c76b4f
MM
457 static int static_labelno;
458
db5ae43f
MS
459 tree name = DECL_ASSEMBLER_NAME (decl);
460 char *label;
db5ae43f 461
42976354
BK
462 ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), static_labelno);
463 static_labelno++;
db5ae43f 464
8cb9cd5d 465 if (numeric_output_need_bar)
42976354 466 OB_PUTC ('_');
db5ae43f
MS
467 icat (strlen (label));
468 OB_PUTCP (label);
42976354 469 numeric_output_need_bar = 1;
db5ae43f 470 }
30394414
JM
471 else if (TREE_CODE (decl) == NAMESPACE_DECL)
472 build_overload_identifier (DECL_NAME (decl));
db5ae43f 473 else /* TYPE_DECL */
5566b478 474 build_overload_identifier (decl);
8d08fdba
MS
475}
476
59e621fc
MM
477/* Output the decimal representation of I. If I > 9, the decimal
478 representation is preceeded and followed by an underscore. */
479
386b8a85 480static void
c8907853
JL
481build_underscore_int (i)
482 int i;
386b8a85
JM
483{
484 if (i > 9)
485 OB_PUTC ('_');
486 icat (i);
487 if (i > 9)
c32381b1 488 OB_PUTC ('_');
386b8a85
JM
489}
490
050367a3
MM
491static void
492build_overload_scope_ref (value)
493 tree value;
494{
495 OB_PUTC2 ('Q', '2');
496 numeric_output_need_bar = 0;
59e621fc 497 build_mangled_name_for_type (TREE_OPERAND (value, 0));
050367a3
MM
498 build_overload_identifier (TREE_OPERAND (value, 1));
499}
500
858a0ff1
MM
501/* VALUE is a complex expression. Produce an appropriate mangling.
502 (We are forced to mangle complex expressions when dealing with
503 templates, and an expression involving template parameters appears
504 in the type of a function parameter.) */
e92cc029 505
e1b7b0cb 506static void
858a0ff1 507mangle_expression (value)
e1b7b0cb
RK
508 tree value;
509{
858a0ff1 510 if (TREE_CODE (value) == SCOPE_REF)
5566b478 511 {
858a0ff1
MM
512 build_overload_scope_ref (value);
513 return;
514 }
050367a3 515
858a0ff1
MM
516 OB_PUTC ('E');
517 numeric_output_need_bar = 0;
050367a3 518
858a0ff1
MM
519 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value))))
520 {
521 int i;
522 int operands = tree_code_length[(int) TREE_CODE (value)];
523 tree id;
524 const char *name;
525
526 id = ansi_opname [(int) TREE_CODE (value)];
527 my_friendly_assert (id != NULL_TREE, 0);
528 name = IDENTIFIER_POINTER (id);
529 if (name[0] != '_' || name[1] != '_')
530 /* On some erroneous inputs, we can get here with VALUE a
531 LOOKUP_EXPR. In that case, the NAME will be the
532 identifier for "<invalid operator>". We must survive
533 this routine in order to issue a sensible error
534 message, so we fall through to the case below. */
535 goto bad_value;
536
537 for (i = 0; i < operands; ++i)
050367a3 538 {
858a0ff1
MM
539 tree operand;
540 enum tree_code tc;
050367a3 541
858a0ff1
MM
542 /* We just outputted either the `E' or the name of the
543 operator. */
544 numeric_output_need_bar = 0;
050367a3 545
858a0ff1
MM
546 if (i != 0)
547 /* Skip the leading underscores. */
548 OB_PUTCP (name + 2);
050367a3 549
858a0ff1
MM
550 operand = TREE_OPERAND (value, i);
551 tc = TREE_CODE (operand);
050367a3 552
858a0ff1
MM
553 if (TREE_CODE_CLASS (tc) == 't')
554 /* We can get here with sizeof, e.g.:
050367a3 555
858a0ff1
MM
556 template <class T> void f(A<sizeof(T)>); */
557 build_mangled_name_for_type (operand);
558 else
559 build_overload_value (TREE_TYPE (operand),
560 operand,
561 mf_maybe_uninstantiated);
050367a3 562 }
858a0ff1
MM
563 }
564 else
565 {
566 /* We don't ever want this output, but it's
567 inconvenient not to be able to build the string.
568 This should cause assembler errors we'll notice. */
050367a3 569
858a0ff1
MM
570 static int n;
571 bad_value:
572 sprintf (digit_buffer, " *%d", n++);
573 OB_PUTCP (digit_buffer);
574 }
050367a3 575
858a0ff1
MM
576 OB_PUTC ('W');
577 numeric_output_need_bar = 0;
578}
579
580/* Encoding for an INTEGER_CST value. */
581
582static void
583build_overload_int (value, flags)
584 tree value;
585 mangling_flags flags;
586{
587 int multiple_words_p = 0;
588 int multiple_digits_p = 0;
589
590 if ((flags & mf_maybe_uninstantiated) && TREE_CODE (value) != INTEGER_CST)
591 {
592 mangle_expression (value);
5566b478
MS
593 return;
594 }
595
858a0ff1
MM
596 /* Unless we were looking at an uninstantiated template, integers
597 should always be represented by constants. */
e1b7b0cb 598 my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243);
858a0ff1
MM
599
600 /* If the high-order word is not merely a sign-extension of the
601 low-order word, we must use a special output routine that can
602 deal with this. */
603 if (TREE_INT_CST_HIGH (value)
604 != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1)))
e1b7b0cb 605 {
858a0ff1
MM
606 multiple_words_p = 1;
607 /* And there is certainly going to be more than one digit. */
608 multiple_digits_p = 1;
609 }
610 else
611 multiple_digits_p = (TREE_INT_CST_LOW (value) > 9
612 || TREE_INT_CST_LOW (value) < -9);
613
614 /* If necessary, add a leading underscore. */
615 if (multiple_digits_p && (flags & mf_use_underscores_around_value))
616 OB_PUTC ('_');
617
618 /* Output the number itself. */
619 if (multiple_words_p)
620 dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value));
621 else
622 icat (TREE_INT_CST_LOW (value));
623
624 if (flags & mf_use_underscores_around_value)
625 {
626 if (multiple_digits_p)
627 OB_PUTC ('_');
628 /* Whether or not there were multiple digits, we don't need an
629 underscore. We've either terminated the number with an
630 underscore, or else it only had one digit. */
631 numeric_output_need_bar = 0;
e1b7b0cb 632 }
858a0ff1
MM
633 else
634 /* We just output a numeric value. */
635 numeric_output_need_bar = 1;
e1b7b0cb
RK
636}
637
f84b4be9
JM
638
639/* Output S followed by a representation of the TEMPLATE_PARM_INDEX
640 supplied in INDEX. */
641
642static void
643build_mangled_template_parm_index (s, index)
9c0758dd 644 const char *s;
f84b4be9
JM
645 tree index;
646{
647 OB_PUTCP (s);
648 build_underscore_int (TEMPLATE_PARM_IDX (index));
649 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
650 representation of the function from the point of view of its
651 type. */
652 build_underscore_int (TEMPLATE_PARM_LEVEL (index));
653}
654
655
25f3d2f4
BK
656/* Mangling for C9X integer types (and Cygnus extensions for 128-bit
657 and other types) is based on the letter "I" followed by the hex
658 representations of the bitsize for the type in question. For
659 encodings that result in larger than two digits, a leading and
660 trailing underscore is added.
661
662 Thus:
663 int1_t = 001 = I01
664 int8_t = 008 = I08
665 int16_t = 010 = I10
666 int24_t = 018 = I18
667 int32_t = 020 = I20
668 int64_t = 040 = I40
669 int80_t = 050 = I50
670 int128_t = 080 = I80
671 int256_t = 100 = I_100_
672 int512_t = 200 = I_200_
673
674 Given an integer in decimal format, mangle according to this scheme. */
675
e833cb11 676#if HOST_BITS_PER_WIDE_INT >= 64
25f3d2f4
BK
677static void
678build_mangled_C9x_name (bits)
679 int bits;
680{
681 char mangled[10] = "";
682
683 if (bits > 255)
684 sprintf (mangled, "I_%x_", bits);
685 else
686 sprintf (mangled, "I%.2x", bits);
687
688 OB_PUTCP (mangled);
689}
e833cb11 690#endif
25f3d2f4 691
8d08fdba 692static void
858a0ff1 693build_overload_value (type, value, flags)
8d08fdba 694 tree type, value;
858a0ff1 695 mangling_flags flags;
8d08fdba 696{
61a127b3
MM
697 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type)) == 't', 0);
698
8d08fdba
MS
699 while (TREE_CODE (value) == NON_LVALUE_EXPR
700 || TREE_CODE (value) == NOP_EXPR)
701 value = TREE_OPERAND (value, 0);
050367a3 702
e1b7b0cb
RK
703 if (numeric_output_need_bar)
704 {
705 OB_PUTC ('_');
706 numeric_output_need_bar = 0;
707 }
708
f84b4be9 709 if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
2636fde4 710 {
f84b4be9 711 build_mangled_template_parm_index ("Y", value);
2636fde4
JM
712 return;
713 }
714
61a127b3 715 if (TYPE_PTRMEM_P (type))
8145f082 716 {
61a127b3
MM
717 if (TREE_CODE (value) != PTRMEM_CST)
718 /* We should have already rejected this pointer to member,
719 since it is not a constant. */
720 my_friendly_abort (0);
721
722 /* Get the actual FIELD_DECL. */
723 value = PTRMEM_CST_MEMBER (value);
724 my_friendly_assert (TREE_CODE (value) == FIELD_DECL, 0);
725
726 /* Output the name of the field. */
727 build_overload_identifier (DECL_NAME (value));
728 return;
8145f082 729 }
858a0ff1
MM
730 else if (INTEGRAL_TYPE_P (type))
731 {
732 build_overload_int (value, flags);
733 return;
734 }
735
736 /* The only case where we use the extra underscores here is when
737 forming the mangling for an integral non-type template argument.
738 If that didn't happen, stop now. */
739 flags &= ~mf_use_underscores_around_value;
8145f082 740
8d08fdba
MS
741 switch (TREE_CODE (type))
742 {
8d08fdba
MS
743 case REAL_TYPE:
744 {
745 REAL_VALUE_TYPE val;
746 char *bufp = digit_buffer;
8d08fdba 747
858a0ff1
MM
748 /* We must handle non-constants in templates. */
749 if (TREE_CODE (value) != REAL_CST)
750 {
751 mangle_expression (value);
752 break;
753 }
bd6dd845 754
8d08fdba 755 val = TREE_REAL_CST (value);
bd6dd845 756 if (REAL_VALUE_ISNAN (val))
8d08fdba 757 {
bd6dd845 758 sprintf (bufp, "NaN");
8d08fdba 759 }
8d08fdba
MS
760 else
761 {
bd6dd845 762 if (REAL_VALUE_NEGATIVE (val))
8d08fdba 763 {
bd6dd845 764 val = REAL_VALUE_NEGATE (val);
8d08fdba
MS
765 *bufp++ = 'm';
766 }
bd6dd845 767 if (REAL_VALUE_ISINF (val))
8d08fdba 768 {
bd6dd845 769 sprintf (bufp, "Infinity");
8d08fdba 770 }
bd6dd845 771 else
8d08fdba 772 {
3d015f46 773 REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
bd6dd845
MS
774 bufp = (char *) index (bufp, 'e');
775 if (!bufp)
776 strcat (digit_buffer, "e0");
777 else
778 {
779 char *p;
780 bufp++;
781 if (*bufp == '-')
782 {
783 *bufp++ = 'm';
784 }
785 p = bufp;
786 if (*p == '+')
787 p++;
788 while (*p == '0')
789 p++;
790 if (*p == 0)
791 {
792 *bufp++ = '0';
793 *bufp = 0;
794 }
795 else if (p != bufp)
796 {
797 while (*p)
798 *bufp++ = *p++;
799 *bufp = 0;
800 }
801 }
802#ifdef NO_DOT_IN_LABEL
803 bufp = (char *) index (bufp, '.');
804 if (bufp)
805 *bufp = '_';
806#endif
8d08fdba
MS
807 }
808 }
809 OB_PUTCP (digit_buffer);
e1b7b0cb 810 numeric_output_need_bar = 1;
8d08fdba
MS
811 return;
812 }
8d08fdba 813 case POINTER_TYPE:
f84b4be9 814 if (TREE_CODE (value) == INTEGER_CST)
f30432d7 815 {
858a0ff1 816 build_overload_int (value, flags);
f30432d7
MS
817 return;
818 }
f84b4be9
JM
819 else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
820 {
821 build_mangled_template_parm_index ("", value);
822 numeric_output_need_bar = 1;
823 return;
824 }
825
8d08fdba 826 value = TREE_OPERAND (value, 0);
5c0aa6d0
MM
827
828 /* Fall through. */
829
830 case REFERENCE_TYPE:
8d08fdba
MS
831 if (TREE_CODE (value) == VAR_DECL)
832 {
833 my_friendly_assert (DECL_NAME (value) != 0, 245);
e76a2646 834 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
8d08fdba
MS
835 return;
836 }
837 else if (TREE_CODE (value) == FUNCTION_DECL)
838 {
839 my_friendly_assert (DECL_NAME (value) != 0, 246);
e76a2646 840 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
8d08fdba
MS
841 return;
842 }
aa36c081 843 else if (TREE_CODE (value) == SCOPE_REF)
050367a3 844 build_overload_scope_ref (value);
8d08fdba
MS
845 else
846 my_friendly_abort (71);
847 break; /* not really needed */
848
e08a8f45
MM
849 case RECORD_TYPE:
850 {
851 tree delta;
852 tree idx;
853 tree pfn;
854 tree delta2;
c7e266a6 855 tree fn;
e08a8f45
MM
856
857 my_friendly_assert (TYPE_PTRMEMFUNC_P (type), 0);
82bed870
MM
858
859 /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're
860 mangling, an instantiation of something like:
861
862 template <class T, void (T::*fp)()> class C {};
863 template <class T> C<T, &T::f> x();
864
865 We mangle the return type of the function, and that
866 contains template parameters. */
867 if (TREE_CODE (value) == ADDR_EXPR
868 && TREE_CODE (TREE_OPERAND (value, 0)) == SCOPE_REF)
869 {
870 build_overload_scope_ref (TREE_OPERAND (value, 0));
871 break;
872 }
873
e08a8f45
MM
874 my_friendly_assert (TREE_CODE (value) == PTRMEM_CST, 0);
875
876 expand_ptrmemfunc_cst (value, &delta, &idx, &pfn, &delta2);
c7e266a6 877 fn = PTRMEM_CST_MEMBER (value);
858a0ff1 878 build_overload_int (delta, flags);
e08a8f45 879 OB_PUTC ('_');
c7e266a6
MM
880 if (!flag_new_abi)
881 {
882 build_overload_int (idx, flags);
883 OB_PUTC ('_');
884 }
885 else if (DECL_VIRTUAL_P (fn))
886 {
887 build_overload_int (DECL_VINDEX (fn), flags);
888 OB_PUTC ('_');
889 }
890
891 if (!DECL_VIRTUAL_P (fn))
e08a8f45
MM
892 {
893 numeric_output_need_bar = 0;
c7e266a6 894 build_overload_identifier (DECL_ASSEMBLER_NAME (fn));
e08a8f45 895 }
c7e266a6 896 else if (!flag_new_abi)
e08a8f45
MM
897 {
898 OB_PUTC ('i');
858a0ff1 899 build_overload_int (delta2, flags);
e08a8f45
MM
900 }
901 }
902 break;
903
8d08fdba
MS
904 default:
905 sorry ("conversion of %s as template parameter",
906 tree_code_name [(int) TREE_CODE (type)]);
907 my_friendly_abort (72);
908 }
909}
910
386b8a85 911
73b0fce8 912/* Add encodings for the declaration of template template parameters.
407f03b8 913 PARMLIST must be a TREE_VEC. */
73b0fce8
KL
914
915static void
916build_template_template_parm_names (parmlist)
917 tree parmlist;
918{
919 int i, nparms;
920
921 my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
922 nparms = TREE_VEC_LENGTH (parmlist);
923 icat (nparms);
924 for (i = 0; i < nparms; i++)
925 {
926 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
927 if (TREE_CODE (parm) == TYPE_DECL)
928 {
929 /* This parameter is a type. */
930 OB_PUTC ('Z');
931 }
932 else if (TREE_CODE (parm) == TEMPLATE_DECL)
933 {
934 /* This parameter is a template. */
935 OB_PUTC ('z');
936 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
937 }
938 else
59e621fc
MM
939 /* It's a PARM_DECL. */
940 build_mangled_name_for_type (TREE_TYPE (parm));
73b0fce8
KL
941 }
942}
943
944
386b8a85
JM
945/* Add encodings for the vector of template parameters in PARMLIST,
946 given the vector of arguments to be substituted in ARGLIST. */
947
4966381a 948static void
386b8a85
JM
949build_template_parm_names (parmlist, arglist)
950 tree parmlist;
951 tree arglist;
952{
953 int i, nparms;
e4a84209
MM
954 tree inner_args = innermost_args (arglist);
955
386b8a85
JM
956 nparms = TREE_VEC_LENGTH (parmlist);
957 icat (nparms);
958 for (i = 0; i < nparms; i++)
959 {
960 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
e4a84209 961 tree arg = TREE_VEC_ELT (inner_args, i);
386b8a85
JM
962 if (TREE_CODE (parm) == TYPE_DECL)
963 {
964 /* This parameter is a type. */
965 OB_PUTC ('Z');
59e621fc 966 build_mangled_name_for_type (arg);
386b8a85 967 }
73b0fce8
KL
968 else if (TREE_CODE (parm) == TEMPLATE_DECL)
969 {
407f03b8 970 /* This parameter is a template. */
73b0fce8 971 if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
407f03b8 972 /* Output parameter declaration, argument index and level. */
59e621fc 973 build_mangled_name_for_type (arg);
73b0fce8
KL
974 else
975 {
976 /* A TEMPLATE_DECL node, output the parameter declaration
977 and template name */
978
979 OB_PUTC ('z');
407f03b8
JM
980 build_template_template_parm_names
981 (DECL_INNERMOST_TEMPLATE_PARMS (parm));
73b0fce8
KL
982 icat (IDENTIFIER_LENGTH (DECL_NAME (arg)));
983 OB_PUTID (DECL_NAME (arg));
984 }
985 }
386b8a85
JM
986 else
987 {
4393e105 988 parm = tsubst (parm, arglist, /*complain=*/1, NULL_TREE);
386b8a85 989 /* It's a PARM_DECL. */
59e621fc 990 build_mangled_name_for_type (TREE_TYPE (parm));
61a127b3 991 build_overload_value (TREE_TYPE (parm), arg,
858a0ff1
MM
992 ((mf_maybe_uninstantiated
993 * uses_template_parms (arglist))
994 | mf_use_underscores_around_value));
386b8a85
JM
995 }
996 }
997 }
998
59e621fc
MM
999/* Output the representation for NAME, which is either a TYPE_DECL or
1000 an IDENTIFIER. */
386b8a85 1001
8d08fdba
MS
1002static void
1003build_overload_identifier (name)
1004 tree name;
1005{
5566b478 1006 if (TREE_CODE (name) == TYPE_DECL
7ddedda4 1007 && CLASS_TYPE_P (TREE_TYPE (name))
5566b478 1008 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
e1467ff2 1009 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))
3ebc5c52
MM
1010 || (TREE_CODE (CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
1011 (TREE_TYPE (name))))
e1467ff2 1012 == FUNCTION_DECL)))
8d08fdba 1013 {
59e621fc 1014 /* NAME is the TYPE_DECL for a template specialization. */
8d08fdba 1015 tree template, parmlist, arglist, tname;
e4a84209
MM
1016 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name));
1017 arglist = CLASSTYPE_TI_ARGS (TREE_TYPE (name));
8d08fdba 1018 tname = DECL_NAME (template);
98c1c668 1019 parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
8d08fdba
MS
1020 OB_PUTC ('t');
1021 icat (IDENTIFIER_LENGTH (tname));
1022 OB_PUTID (tname);
386b8a85 1023 build_template_parm_names (parmlist, arglist);
8d08fdba
MS
1024 }
1025 else
1026 {
5566b478
MS
1027 if (TREE_CODE (name) == TYPE_DECL)
1028 name = DECL_NAME (name);
8cb9cd5d 1029 if (numeric_output_need_bar)
f376e137
MS
1030 {
1031 OB_PUTC ('_');
8cb9cd5d 1032 numeric_output_need_bar = 0;
f376e137 1033 }
8d08fdba
MS
1034 icat (IDENTIFIER_LENGTH (name));
1035 OB_PUTID (name);
1036 }
1037}
1038
42976354 1039/* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
ed22c95e 1040 the mangling for it. Used by build_mangled_name and build_static_name. */
42976354
BK
1041
1042static void
1043build_qualified_name (decl)
1044 tree decl;
1045{
1046 tree context;
1047 int i = 1;
1048
1049 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
1050 decl = TYPE_NAME (decl);
1051
1052 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1053 if (TREE_CODE (decl) == TYPE_DECL
ed22c95e 1054 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling)
42976354 1055 {
050367a3
MM
1056 tree id = DECL_ASSEMBLER_NAME (decl);
1057 OB_PUTID (id);
faa25e97 1058 if (ISDIGIT (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1]))
050367a3 1059 numeric_output_need_bar = 1;
42976354
BK
1060 return;
1061 }
1062
1063 context = decl;
407f03b8 1064 /* If we can't find a Ktype, do it the hard way. */
ed22c95e 1065 if (check_ktype (context, FALSE) == -1)
30394414 1066 {
407f03b8
JM
1067 /* Count type and namespace scopes. */
1068 while (1)
30394414 1069 {
407f03b8
JM
1070 context = CP_DECL_CONTEXT (context);
1071 if (context == global_namespace)
1072 break;
30394414 1073 i += 1;
407f03b8
JM
1074 if (check_ktype (context, FALSE) != -1)
1075 /* Found one! */
30394414
JM
1076 break;
1077 if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
1078 context = TYPE_NAME (context);
1079 }
30394414 1080 }
42976354
BK
1081
1082 if (i > 1)
1083 {
1084 OB_PUTC ('Q');
050367a3 1085 build_underscore_int (i);
42976354
BK
1086 numeric_output_need_bar = 0;
1087 }
1088 build_overload_nested_name (decl);
1089}
1090
59e621fc
MM
1091/* Output the mangled representation for TYPE. If EXTRA_GCODE is
1092 non-zero, mangled names for structure/union types are intentionally
1093 mangled differently from the method described in the ARM. */
1094
e9659ab0 1095static void
59e621fc
MM
1096build_mangled_name_for_type_with_Gcode (type, extra_Gcode)
1097 tree type;
1098 int extra_Gcode;
1099{
1100 if (TYPE_PTRMEMFUNC_P (type))
1101 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
59e621fc
MM
1102 process_modifiers (type);
1103 process_overload_item (type, extra_Gcode);
1104}
1105
1106/* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1107 `G'. */
1108
e9659ab0 1109static void
59e621fc
MM
1110build_mangled_name_for_type (type)
1111 tree type;
1112{
1113 build_mangled_name_for_type_with_Gcode (type, 0);
1114}
1115
8d08fdba
MS
1116/* Given a list of parameters in PARMTYPES, create an unambiguous
1117 overload string. Should distinguish any type that C (or C++) can
1118 distinguish. I.e., pointers to functions are treated correctly.
1119
1120 Caller must deal with whether a final `e' goes on the end or not.
1121
1122 Any default conversions must take place before this function
1123 is called.
1124
1125 BEGIN and END control initialization and finalization of the
1126 obstack where we build the string. */
1127
1128char *
1129build_overload_name (parmtypes, begin, end)
1130 tree parmtypes;
1131 int begin, end;
1132{
ed22c95e
AM
1133 char *ret;
1134 start_squangling ();
1135 ret = build_mangled_name (parmtypes, begin, end);
1136 end_squangling ();
1137 return ret ;
1138}
1139
59e621fc
MM
1140/* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1141 TREE_LIST, then it is a list of parameter types. Otherwise,
1142 PARMTYPES must be a single type. */
1143
ed22c95e
AM
1144static char *
1145build_mangled_name (parmtypes, begin, end)
1146 tree parmtypes;
1147 int begin, end;
1148{
ed22c95e
AM
1149 if (begin)
1150 OB_INIT ();
8d08fdba 1151
59e621fc
MM
1152 if (TREE_CODE (parmtypes) != TREE_LIST)
1153 /* There is only one type. */
1154 build_mangled_name_for_type (parmtypes);
1155 else
8d08fdba 1156 {
59e621fc
MM
1157 /* There are several types in a parameter list. */
1158 int nrepeats = 0;
1159 int old_style_repeats = !flag_do_squangling && !nofold && typevec;
1160 tree last_type = NULL_TREE;
1161
1162 for (; parmtypes && parmtypes != void_list_node;
1163 parmtypes = TREE_CHAIN (parmtypes))
1164 {
407f03b8
JM
1165 /* We used to call canonical_type_variant here, but that isn't
1166 good enough; it doesn't handle pointers to typedef types. So
1167 we can't just set TREE_USED to say we've seen a type already;
1168 we have to check each of the earlier types with same_type_p. */
1169 tree parmtype = TREE_VALUE (parmtypes);
59e621fc
MM
1170
1171 if (old_style_repeats)
1172 {
1173 /* Every argument gets counted. */
9cd64686
MM
1174 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1175 VARRAY_TREE (typevec, maxtype) = parmtype;
1176 maxtype++;
59e621fc 1177 }
f921acee
JM
1178
1179 if (last_type && same_type_p (parmtype, last_type))
59e621fc 1180 {
f921acee
JM
1181 if (flag_do_squangling
1182 || (old_style_repeats
1183 && is_back_referenceable_type (parmtype)))
59e621fc
MM
1184 {
1185 /* The next type is the same as this one. Keep
1186 track of the repetition, and output the repeat
1187 count later. */
1188 nrepeats++;
1189 continue;
1190 }
f921acee
JM
1191 }
1192 else if (nrepeats != 0)
1193 {
1194 /* Indicate how many times the previous parameter was
1195 repeated. */
1196 if (old_style_repeats)
1197 flush_repeats (nrepeats, last_type);
1198 else
1199 issue_nrepeats (nrepeats, last_type);
1200 nrepeats = 0;
59e621fc 1201 }
407f03b8
JM
1202
1203 last_type = parmtype;
1204
f921acee
JM
1205 /* Note that for bug-compatibility with 2.7.2, we can't build up
1206 repeats of types other than the most recent one. So we call
1207 flush_repeats every round, if we get this far. */
1208 if (old_style_repeats && flush_repeats (0, parmtype))
407f03b8 1209 continue;
59e621fc
MM
1210
1211 /* Output the PARMTYPE. */
1212 build_mangled_name_for_type_with_Gcode (parmtype, 1);
1213 }
1214
1215 /* Output the repeat count for the last parameter, if
1216 necessary. */
1217 if (nrepeats != 0)
1218 {
f921acee
JM
1219 if (old_style_repeats)
1220 flush_repeats (nrepeats, last_type);
1221 else
1222 issue_nrepeats (nrepeats, last_type);
59e621fc
MM
1223 nrepeats = 0;
1224 }
1225
1226 if (!parmtypes)
1227 /* The parameter list ends in an ellipsis. */
1228 OB_PUTC ('e');
1229 }
8d08fdba 1230
ed22c95e
AM
1231 if (end)
1232 OB_FINISH ();
1233 return (char *)obstack_base (&scratch_obstack);
1234}
8d08fdba 1235
8be64d09
JM
1236/* Emit modifiers such as constant, read-only, and volatile. */
1237
e9659ab0 1238static void
ed22c95e
AM
1239process_modifiers (parmtype)
1240 tree parmtype;
1241{
91063b51
MM
1242 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1243 we describe types recursively; we will get the `const' in
1244 `const int ()[10]' when processing the `const int' part. */
1245 if (TYPE_READONLY (parmtype))
ed22c95e 1246 OB_PUTC ('C');
a1774733 1247 if (TREE_CODE (parmtype) == INTEGER_TYPE
8be64d09
JM
1248 && parmtype != char_type_node
1249 && parmtype != wchar_type_node
a1774733
BK
1250 && (TYPE_MAIN_VARIANT (parmtype)
1251 == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
ea419909 1252 && ! TYPE_FOR_JAVA (parmtype))
59e621fc 1253 OB_PUTC ('U');
ed22c95e
AM
1254 if (TYPE_VOLATILE (parmtype))
1255 OB_PUTC ('V');
91063b51
MM
1256 /* It would be better to use `R' for `restrict', but that's already
1257 used for reference types. And `r' is used for `long double'. */
1258 if (TYPE_RESTRICT (parmtype))
1259 OB_PUTC ('u');
ed22c95e 1260}
a5894242 1261
59e621fc
MM
1262/* Check to see if TYPE has been entered into the Bcode typelist. If
1263 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1264 to the list of back-referenceable types and return 0. */
1265
e9659ab0 1266static int
59e621fc
MM
1267check_btype (type)
1268 tree type;
ed22c95e 1269{
9cd64686 1270 size_t x;
a5894242 1271
ed22c95e
AM
1272 if (btypelist == NULL)
1273 return 0;
8d08fdba 1274
59e621fc
MM
1275 if (!is_back_referenceable_type (type))
1276 return 0;
31bebb60 1277
ed22c95e 1278 for (x = 0; x < maxbtype; x++)
9cd64686 1279 if (same_type_p (type, VARRAY_TREE (btypelist, x)))
59e621fc
MM
1280 {
1281 OB_PUTC ('B');
1282 icat (x);
1283 if (x > 9)
1284 OB_PUTC ('_');
1285 return 1 ;
1286 }
1287
9cd64686
MM
1288 if (VARRAY_SIZE (btypelist) <= maxbtype)
1289 /* Enlarge the table. */
1290 VARRAY_GROW (btypelist,
1291 VARRAY_SIZE (btypelist) * 3 / 2);
1292
59e621fc 1293 /* Register the TYPE. */
9cd64686
MM
1294 VARRAY_TREE (btypelist, maxbtype) = type;
1295 maxbtype++;
59e621fc 1296
ed22c95e
AM
1297 return 0;
1298}
8d08fdba 1299
8be64d09
JM
1300/* Emit the correct code for various node types. */
1301
ed22c95e
AM
1302static void
1303process_overload_item (parmtype, extra_Gcode)
1304 tree parmtype;
1305 int extra_Gcode;
1306{
59e621fc 1307 numeric_output_need_bar = 0;
8d08fdba 1308
407f03b8
JM
1309 /* Our caller should have already handed any qualifiers, so pull out the
1310 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1311 for arrays, because they are transparent to qualifiers. Sigh. */
1312 if (TREE_CODE (parmtype) == ARRAY_TYPE)
1313 parmtype = canonical_type_variant (parmtype);
1314 else
1315 parmtype = TYPE_MAIN_VARIANT (parmtype);
1316
8be64d09
JM
1317 /* These tree types are considered modifiers for B code squangling,
1318 and therefore should not get entries in the Btypelist. They are,
1319 however, repeatable types. */
8d08fdba 1320
ed22c95e
AM
1321 switch (TREE_CODE (parmtype))
1322 {
1323 case REFERENCE_TYPE:
1324 OB_PUTC ('R');
1325 goto more;
8d08fdba 1326
ed22c95e 1327 case ARRAY_TYPE:
ed22c95e 1328 {
ed22c95e
AM
1329 OB_PUTC ('A');
1330 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
2d914461 1331 OB_PUTC ('_');
ed22c95e 1332 else
53929c47
JM
1333 {
1334 tree length = array_type_nelts (parmtype);
1335 if (TREE_CODE (length) != INTEGER_CST || flag_do_squangling)
1336 {
1337 length = fold (build (PLUS_EXPR, TREE_TYPE (length),
1338 length, integer_one_node));
1339 STRIP_NOPS (length);
1340 }
1341 build_overload_value (sizetype, length, 1);
1342 }
1343 if (numeric_output_need_bar && ! flag_do_squangling)
1344 OB_PUTC ('_');
ed22c95e
AM
1345 goto more;
1346 }
8d08fdba 1347
ed22c95e
AM
1348 case POINTER_TYPE:
1349 OB_PUTC ('P');
1350 more:
59e621fc 1351 build_mangled_name_for_type (TREE_TYPE (parmtype));
ed22c95e
AM
1352 return;
1353 break;
31bebb60
KG
1354
1355 default:
1356 break;
ed22c95e
AM
1357 }
1358
59e621fc
MM
1359 if (flag_do_squangling && check_btype (parmtype))
1360 /* If PARMTYPE is already in the list of back-referenceable types,
1361 then check_btype will output the appropriate reference, and
1362 there's nothing more to do. */
1363 return;
8d08fdba 1364
ed22c95e
AM
1365 switch (TREE_CODE (parmtype))
1366 {
1367 case OFFSET_TYPE:
1368 OB_PUTC ('O');
59e621fc 1369 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype));
ed22c95e 1370 OB_PUTC ('_');
59e621fc 1371 build_mangled_name_for_type (TREE_TYPE (parmtype));
ed22c95e 1372 break;
8d08fdba 1373
ed22c95e
AM
1374 case FUNCTION_TYPE:
1375 case METHOD_TYPE:
1376 {
59e621fc 1377 tree parms = TYPE_ARG_TYPES (parmtype);
ed22c95e 1378
59e621fc
MM
1379 /* Rather than implementing a reentrant TYPEVEC, we turn off
1380 repeat codes here, unless we're squangling. Squangling
1381 doesn't make use of the TYPEVEC, so there's no reentrancy
1382 problem. */
1383 int old_nofold = nofold;
1384 if (!flag_do_squangling)
1385 nofold = 1;
1386
1387 if (TREE_CODE (parmtype) == METHOD_TYPE)
1388 {
1389 /* Mark this as a method. */
ed22c95e 1390 OB_PUTC ('M');
59e621fc
MM
1391 /* Output the class of which this method is a member. */
1392 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype));
1393 /* Output any qualifiers for the `this' parameter. */
1394 process_modifiers (TREE_TYPE (TREE_VALUE (parms)));
1395 }
ed22c95e 1396
59e621fc
MM
1397 /* Output the parameter types. */
1398 OB_PUTC ('F');
1399 if (parms == NULL_TREE)
1400 OB_PUTC ('e');
1401 else if (parms == void_list_node)
1402 OB_PUTC ('v');
1403 else
1404 build_mangled_name (parms, 0, 0);
1405
1406 /* Output the return type. */
ed22c95e 1407 OB_PUTC ('_');
59e621fc
MM
1408 build_mangled_name_for_type (TREE_TYPE (parmtype));
1409
ed22c95e
AM
1410 nofold = old_nofold;
1411 break;
1412 }
8d08fdba 1413
ed22c95e 1414 case INTEGER_TYPE:
ed22c95e 1415 if (parmtype == integer_type_node
ea419909
PB
1416 || parmtype == unsigned_type_node
1417 || parmtype == java_int_type_node)
ed22c95e
AM
1418 OB_PUTC ('i');
1419 else if (parmtype == long_integer_type_node
1420 || parmtype == long_unsigned_type_node)
1421 OB_PUTC ('l');
1422 else if (parmtype == short_integer_type_node
ea419909
PB
1423 || parmtype == short_unsigned_type_node
1424 || parmtype == java_short_type_node)
ed22c95e
AM
1425 OB_PUTC ('s');
1426 else if (parmtype == signed_char_type_node)
1427 {
1428 OB_PUTC ('S');
1429 OB_PUTC ('c');
1430 }
1431 else if (parmtype == char_type_node
ea419909
PB
1432 || parmtype == unsigned_char_type_node
1433 || parmtype == java_byte_type_node)
ed22c95e 1434 OB_PUTC ('c');
ea419909
PB
1435 else if (parmtype == wchar_type_node
1436 || parmtype == java_char_type_node)
ed22c95e
AM
1437 OB_PUTC ('w');
1438 else if (parmtype == long_long_integer_type_node
ea419909
PB
1439 || parmtype == long_long_unsigned_type_node
1440 || parmtype == java_long_type_node)
ed22c95e 1441 OB_PUTC ('x');
ea419909
PB
1442 else if (parmtype == java_boolean_type_node)
1443 OB_PUTC ('b');
25f3d2f4 1444#if HOST_BITS_PER_WIDE_INT >= 64
f2655b99 1445 else
25f3d2f4 1446 {
25f3d2f4
BK
1447 int bits = TREE_INT_CST_LOW (TYPE_SIZE (parmtype));
1448 build_mangled_C9x_name (bits);
1449 }
f2655b99 1450#else
ed22c95e 1451 else
f2655b99
AH
1452 my_friendly_abort (73);
1453#endif
ed22c95e 1454 break;
42976354 1455
ed22c95e
AM
1456 case BOOLEAN_TYPE:
1457 OB_PUTC ('b');
1458 break;
8d08fdba 1459
ed22c95e 1460 case REAL_TYPE:
ed22c95e
AM
1461 if (parmtype == long_double_type_node)
1462 OB_PUTC ('r');
ea419909
PB
1463 else if (parmtype == double_type_node
1464 || parmtype == java_double_type_node)
ed22c95e 1465 OB_PUTC ('d');
ea419909
PB
1466 else if (parmtype == float_type_node
1467 || parmtype == java_float_type_node)
ed22c95e
AM
1468 OB_PUTC ('f');
1469 else my_friendly_abort (74);
1470 break;
1471
1472 case COMPLEX_TYPE:
1473 OB_PUTC ('J');
59e621fc 1474 build_mangled_name_for_type (TREE_TYPE (parmtype));
ed22c95e
AM
1475 break;
1476
1477 case VOID_TYPE:
1478 OB_PUTC ('v');
1479 break;
1480
1481 case ERROR_MARK: /* not right, but nothing is anyway */
1482 break;
1483
1484 /* have to do these */
1485 case UNION_TYPE:
1486 case RECORD_TYPE:
1487 {
1488 if (extra_Gcode)
1489 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1490 /* drop through into next case */
1491 }
1492 case ENUMERAL_TYPE:
1493 {
1494 tree name = TYPE_NAME (parmtype);
73b0fce8 1495
ed22c95e 1496 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
73b0fce8 1497
ed22c95e
AM
1498 build_qualified_name (name);
1499 break;
1500 }
8d08fdba 1501
ed22c95e
AM
1502 case UNKNOWN_TYPE:
1503 /* This will take some work. */
1504 OB_PUTC ('?');
1505 break;
1506
1507 case TEMPLATE_TEMPLATE_PARM:
1508 /* Find and output the original template parameter
1509 declaration. */
7ddedda4 1510 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype))
ed22c95e 1511 {
f84b4be9
JM
1512 build_mangled_template_parm_index ("tzX",
1513 TEMPLATE_TYPE_PARM_INDEX
1514 (parmtype));
1515 build_template_parm_names
7ddedda4
MM
1516 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype)),
1517 TYPE_TI_ARGS (parmtype));
ed22c95e
AM
1518 }
1519 else
1520 {
f84b4be9
JM
1521 build_mangled_template_parm_index ("ZzX",
1522 TEMPLATE_TYPE_PARM_INDEX
1523 (parmtype));
1524 build_template_template_parm_names
1525 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
ed22c95e
AM
1526 }
1527 break;
1528
1529 case TEMPLATE_TYPE_PARM:
f84b4be9
JM
1530 build_mangled_template_parm_index ("X",
1531 TEMPLATE_TYPE_PARM_INDEX
1532 (parmtype));
ed22c95e
AM
1533 break;
1534
1535 case TYPENAME_TYPE:
1536 /* When mangling the type of a function template whose
1537 declaration looks like:
1538
1539 template <class T> void foo(typename T::U)
1540
1541 we have to mangle these. */
1542 build_qualified_name (parmtype);
1543 break;
8d08fdba 1544
ed22c95e
AM
1545 default:
1546 my_friendly_abort (75);
8d08fdba
MS
1547 }
1548
8d08fdba 1549}
f376e137 1550
42976354
BK
1551/* Produce the mangling for a variable named NAME in CONTEXT, which can
1552 be either a class TYPE or a FUNCTION_DECL. */
1553
f376e137 1554tree
42976354
BK
1555build_static_name (context, name)
1556 tree context, name;
f376e137 1557{
42976354
BK
1558 OB_INIT ();
1559 numeric_output_need_bar = 0;
ed22c95e 1560 start_squangling ();
42976354
BK
1561#ifdef JOINER
1562 OB_PUTC ('_');
1563 build_qualified_name (context);
1564 OB_PUTC (JOINER);
1565#else
1566 OB_PUTS ("__static_");
1567 build_qualified_name (context);
a6f02587 1568 OB_PUTC ('_');
42976354
BK
1569#endif
1570 OB_PUTID (name);
1571 OB_FINISH ();
ed22c95e 1572 end_squangling ();
42976354
BK
1573
1574 return get_identifier ((char *)obstack_base (&scratch_obstack));
1575}
8d08fdba 1576\f
36a117a5
MM
1577/* FOR_METHOD should be 1 if the declaration in question is for a member
1578 of a class (including a static member) and 2 if the declaration is
1579 for a constructor. */
1580tree
386b8a85
JM
1581build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1582 for_method)
8d08fdba
MS
1583 tree dname;
1584 tree parms;
386b8a85
JM
1585 tree ret_type;
1586 tree tparms;
1587 tree targs;
8d08fdba
MS
1588 int for_method;
1589{
9c0758dd 1590 const char *name = IDENTIFIER_POINTER (dname);
8d08fdba 1591
a28e3c7f 1592 /* member operators new and delete look like methods at this point. */
64f1326a
ML
1593 if (! for_method && current_namespace == global_namespace
1594 && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
047f64a3 1595 && TREE_CHAIN (parms) == void_list_node)
a28e3c7f 1596 {
00595019
MS
1597 if (dname == ansi_opname[(int) DELETE_EXPR])
1598 return get_identifier ("__builtin_delete");
1599 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1600 return get_identifier ("__builtin_vec_delete");
047f64a3
JM
1601 if (dname == ansi_opname[(int) NEW_EXPR])
1602 return get_identifier ("__builtin_new");
1603 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1604 return get_identifier ("__builtin_vec_new");
a28e3c7f 1605 }
8d08fdba 1606
ed22c95e 1607 start_squangling ();
8d08fdba
MS
1608 OB_INIT ();
1609 if (for_method != 2)
1610 OB_PUTCP (name);
1611 /* Otherwise, we can divine that this is a constructor,
1612 and figure out its name without any extra encoding. */
1613
1614 OB_PUTC2 ('_', '_');
c27be9b9 1615 numeric_output_need_bar = 0;
386b8a85
JM
1616
1617 if (tparms)
1618 {
59e621fc 1619 OB_PUTC ('H');
386b8a85
JM
1620 build_template_parm_names (tparms, targs);
1621 OB_PUTC ('_');
1622 }
59e621fc
MM
1623 else if (!for_method && current_namespace == global_namespace)
1624 /* XXX this works only if we call this in the same namespace
1625 as the declaration. Unfortunately, we don't have the _DECL,
1626 only its name */
1627 OB_PUTC ('F');
26877584
JM
1628
1629 if (!for_method && current_namespace != global_namespace)
59e621fc 1630 /* qualify with namespace */
30394414
JM
1631 build_qualified_name (current_namespace);
1632
8d08fdba 1633 if (parms == NULL_TREE)
386b8a85 1634 OB_PUTC ('e');
8d08fdba 1635 else if (parms == void_list_node)
386b8a85 1636 OB_PUTC ('v');
8d08fdba
MS
1637 else
1638 {
407f03b8 1639 if (!flag_do_squangling)
ed22c95e 1640 {
407f03b8 1641 /* Allocate typevec array. */
9cd64686 1642 size_t typevec_size = list_length (parms);
ed22c95e 1643 maxtype = 0;
2c73f9f5 1644 if (!for_method && current_namespace != global_namespace)
407f03b8 1645 /* The namespace of a global function needs one slot. */
2c73f9f5 1646 typevec_size++;
9cd64686 1647 VARRAY_TREE_INIT (typevec, typevec_size, "typevec");
ed22c95e 1648 }
8d08fdba 1649 nofold = 0;
59e621fc 1650
8d08fdba
MS
1651 if (for_method)
1652 {
6eabb241 1653 tree this_type = TREE_TYPE (TREE_VALUE (parms));
59e621fc
MM
1654
1655 build_mangled_name_for_type (this_type);
1656
1657 if (!flag_do_squangling)
1658 {
9cd64686
MM
1659 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1660 VARRAY_TREE (typevec, maxtype) = this_type;
1661 maxtype++;
59e621fc 1662 }
8d08fdba
MS
1663
1664 if (TREE_CHAIN (parms))
ed22c95e 1665 build_mangled_name (TREE_CHAIN (parms), 0, 0);
8d08fdba 1666 else
386b8a85 1667 OB_PUTC ('e');
8d08fdba
MS
1668 }
1669 else
30394414
JM
1670 {
1671 /* the namespace qualifier for a global function
1672 will count as type */
1673 if (current_namespace != global_namespace
1674 && !flag_do_squangling)
2c73f9f5 1675 {
9cd64686
MM
1676 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1677 VARRAY_TREE (typevec, maxtype) = current_namespace;
1678 maxtype++;
2c73f9f5 1679 }
30394414
JM
1680 build_mangled_name (parms, 0, 0);
1681 }
ed22c95e 1682
407f03b8
JM
1683 if (!flag_do_squangling)
1684 /* Deallocate typevec array. */
9cd64686 1685 VARRAY_FREE (typevec);
8d08fdba 1686 }
386b8a85 1687
1f06b267 1688 if (ret_type != NULL_TREE && for_method != 2)
386b8a85
JM
1689 {
1690 /* Add the return type. */
1691 OB_PUTC ('_');
59e621fc 1692 build_mangled_name_for_type (ret_type);
386b8a85
JM
1693 }
1694
1695 OB_FINISH ();
ed22c95e 1696 end_squangling ();
8d08fdba
MS
1697 {
1698 tree n = get_identifier (obstack_base (&scratch_obstack));
1699 if (IDENTIFIER_OPNAME_P (dname))
1700 IDENTIFIER_OPNAME_P (n) = 1;
1701 return n;
1702 }
1703}
1704
386b8a85
JM
1705/* Change the name of a function definition so that it may be
1706 overloaded. NAME is the name of the function to overload,
1707 PARMS is the parameter list (which determines what name the
1708 final function obtains).
1709
1710 FOR_METHOD is 1 if this overload is being performed
1711 for a method, rather than a function type. It is 2 if
1712 this overload is being performed for a constructor. */
1713
1714tree
1715build_decl_overload (dname, parms, for_method)
1716 tree dname;
1717 tree parms;
1718 int for_method;
1719{
1720 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1721 NULL_TREE, for_method);
1722}
1723
36a117a5 1724/* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
386b8a85 1725
c1def683 1726void
36a117a5 1727set_mangled_name_for_decl (decl)
9a68c51f 1728 tree decl;
386b8a85 1729{
6b4b3deb
MM
1730 tree parm_types;
1731
1732 if (processing_template_decl)
1733 /* There's no need to mangle the name of a template function. */
1734 return;
1735
1736 parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9a68c51f 1737
36a117a5
MM
1738 if (DECL_STATIC_FUNCTION_P (decl))
1739 parm_types =
4f1c5b7d 1740 hash_tree_chain (build_pointer_type (DECL_CONTEXT (decl)),
36a117a5
MM
1741 parm_types);
1742 else
1743 /* The only member functions whose type is a FUNCTION_TYPE, rather
1744 than a METHOD_TYPE, should be static members. */
1745 my_friendly_assert (!DECL_CONTEXT (decl)
1746 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl)))
1747 || TREE_CODE (TREE_TYPE (decl)) != FUNCTION_TYPE,
1748 0);
1749
1750 DECL_ASSEMBLER_NAME (decl)
1751 = build_decl_overload (DECL_NAME (decl), parm_types,
1752 DECL_FUNCTION_MEMBER_P (decl)
1753 + DECL_CONSTRUCTOR_P (decl));
386b8a85
JM
1754}
1755
8d08fdba 1756/* Build an overload name for the type expression TYPE. */
e92cc029 1757
8d08fdba
MS
1758tree
1759build_typename_overload (type)
1760 tree type;
1761{
1762 tree id;
1763
1764 OB_INIT ();
1765 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1766 nofold = 1;
ed22c95e
AM
1767 start_squangling ();
1768 build_mangled_name (type, 0, 1);
8d08fdba
MS
1769 id = get_identifier (obstack_base (&scratch_obstack));
1770 IDENTIFIER_OPNAME_P (id) = 1;
a0a33927 1771#if 0
d2e5ee5c 1772 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
a0a33927 1773#endif
51c184be 1774 TREE_TYPE (id) = type;
ed22c95e 1775 end_squangling ();
8d08fdba
MS
1776 return id;
1777}
1778
8d08fdba 1779tree
6b5fbb55
MS
1780build_overload_with_type (name, type)
1781 tree name, type;
8d08fdba
MS
1782{
1783 OB_INIT ();
6b5fbb55 1784 OB_PUTID (name);
8d08fdba
MS
1785 nofold = 1;
1786
ed22c95e
AM
1787 start_squangling ();
1788 build_mangled_name (type, 0, 1);
1789 end_squangling ();
8d08fdba
MS
1790 return get_identifier (obstack_base (&scratch_obstack));
1791}
1792
67d743fe
MS
1793tree
1794get_id_2 (name, name2)
9c0758dd 1795 const char *name;
67d743fe
MS
1796 tree name2;
1797{
1798 OB_INIT ();
1799 OB_PUTCP (name);
1800 OB_PUTID (name2);
1801 OB_FINISH ();
1802 return get_identifier (obstack_base (&scratch_obstack));
1803}
711734a9
JM
1804
1805/* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1806
1807tree
1808build_destructor_name (type)
1809 tree type;
1810{
1811 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX),
1812 type);
1813}
8d08fdba
MS
1814\f
1815/* Given a tree_code CODE, and some arguments (at least one),
1816 attempt to use an overloaded operator on the arguments.
1817
1818 For unary operators, only the first argument need be checked.
1819 For binary operators, both arguments may need to be checked.
1820
1821 Member functions can convert class references to class pointers,
1822 for one-level deep indirection. More than that is not supported.
1823 Operators [](), ()(), and ->() must be member functions.
1824
1825 We call function call building calls with LOOKUP_COMPLAIN if they
1826 are our only hope. This is true when we see a vanilla operator
1827 applied to something of aggregate type. If this fails, we are free
1828 to return `error_mark_node', because we will have reported the
1829 error.
1830
1831 Operators NEW and DELETE overload in funny ways: operator new takes
1832 a single `size' parameter, and operator delete takes a pointer to the
1833 storage being deleted. When overloading these operators, success is
1834 assumed. If there is a failure, report an error message and return
1835 `error_mark_node'. */
1836
1837/* NOSTRICT */
1838tree
1839build_opfncall (code, flags, xarg1, xarg2, arg3)
1840 enum tree_code code;
1841 int flags;
1842 tree xarg1, xarg2, arg3;
1843{
277294d7 1844 return build_new_op (code, flags, xarg1, xarg2, arg3);
8d08fdba
MS
1845}
1846\f
1847/* This function takes an identifier, ID, and attempts to figure out what
1848 it means. There are a number of possible scenarios, presented in increasing
1849 order of hair:
1850
1851 1) not in a class's scope
1852 2) in class's scope, member name of the class's method
1853 3) in class's scope, but not a member name of the class
1854 4) in class's scope, member name of a class's variable
1855
1856 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1857 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
8d08fdba
MS
1858
1859 As a last ditch, try to look up the name as a label and return that
1860 address.
1861
1862 Values which are declared as being of REFERENCE_TYPE are
1863 automatically dereferenced here (as a hack to make the
1864 compiler faster). */
1865
1866tree
5566b478 1867hack_identifier (value, name)
8d08fdba 1868 tree value, name;
8d08fdba 1869{
de22184b 1870 tree type;
8d08fdba 1871
bd6dd845 1872 if (value == error_mark_node)
8d08fdba
MS
1873 {
1874 if (current_class_name)
1875 {
1876 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1877 if (fields == error_mark_node)
1878 return error_mark_node;
1879 if (fields)
1880 {
1881 tree fndecl;
1882
1883 fndecl = TREE_VALUE (fields);
1884 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
2c73f9f5
ML
1885 /* I could not trigger this code. MvL */
1886 my_friendly_abort (980325);
1887#ifdef DEAD
8d08fdba
MS
1888 if (DECL_CHAIN (fndecl) == NULL_TREE)
1889 {
8251199e 1890 warning ("methods cannot be converted to function pointers");
8d08fdba
MS
1891 return fndecl;
1892 }
1893 else
1894 {
8251199e 1895 error ("ambiguous request for method pointer `%s'",
8d08fdba
MS
1896 IDENTIFIER_POINTER (name));
1897 return error_mark_node;
1898 }
2c73f9f5 1899#endif
8d08fdba
MS
1900 }
1901 }
1902 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1903 {
1904 return IDENTIFIER_LABEL_VALUE (name);
1905 }
1906 return error_mark_node;
1907 }
1908
1909 type = TREE_TYPE (value);
1910 if (TREE_CODE (value) == FIELD_DECL)
1911 {
4ac14744 1912 if (current_class_ptr == NULL_TREE)
8d08fdba 1913 {
672476cb
MM
1914 if (current_function_decl
1915 && DECL_STATIC_FUNCTION_P (current_function_decl))
8251199e 1916 cp_error ("invalid use of member `%D' in static member function",
672476cb
MM
1917 value);
1918 else
1919 /* We can get here when processing a bad default
1920 argument, like:
1921 struct S { int a; void f(int i = a); } */
8251199e 1922 cp_error ("invalid use of member `%D'", value);
672476cb 1923
8d08fdba
MS
1924 return error_mark_node;
1925 }
4ac14744 1926 TREE_USED (current_class_ptr) = 1;
a5894242 1927
8d08fdba
MS
1928 /* Mark so that if we are in a constructor, and then find that
1929 this field was initialized by a base initializer,
1930 we can emit an error message. */
1931 TREE_USED (value) = 1;
4ac14744 1932 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
8d08fdba 1933 }
8f032717
MM
1934 else if ((TREE_CODE (value) == FUNCTION_DECL
1935 && DECL_FUNCTION_MEMBER_P (value))
1936 || (TREE_CODE (value) == OVERLOAD
1937 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
51924768
JM
1938 {
1939 tree decl;
1940
8f032717
MM
1941 if (TREE_CODE (value) == OVERLOAD)
1942 value = OVL_CURRENT (value);
1943
4f1c5b7d 1944 decl = maybe_dummy_object (DECL_CONTEXT (value), 0);
51924768
JM
1945 value = build_component_ref (decl, name, NULL_TREE, 1);
1946 }
6b5fbb55 1947 else if (really_overloaded_fn (value))
8f032717 1948 ;
2c73f9f5
ML
1949 else if (TREE_CODE (value) == OVERLOAD)
1950 /* not really overloaded function */
1951 mark_used (OVL_FUNCTION (value));
a5ef9010
JM
1952 else if (TREE_CODE (value) == TREE_LIST)
1953 {
72b7eeff 1954 /* Ambiguous reference to base members, possibly other cases?. */
a5ef9010
JM
1955 tree t = value;
1956 while (t && TREE_CODE (t) == TREE_LIST)
1957 {
72b7eeff 1958 mark_used (TREE_VALUE (t));
a5ef9010
JM
1959 t = TREE_CHAIN (t);
1960 }
1961 }
2c73f9f5 1962 else if (TREE_CODE (value) == NAMESPACE_DECL)
0e607f34 1963 {
8251199e 1964 cp_error ("use of namespace `%D' as expression", value);
0e607f34
JM
1965 return error_mark_node;
1966 }
1967 else if (DECL_CLASS_TEMPLATE_P (value))
1968 {
8251199e 1969 cp_error ("use of class template `%T' as expression", value);
0e607f34
JM
1970 return error_mark_node;
1971 }
8d08fdba 1972 else
72b7eeff 1973 mark_used (value);
8d08fdba 1974
c6882a35
JM
1975 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
1976 || TREE_CODE (value) == RESULT_DECL)
5566b478
MS
1977 {
1978 tree context = decl_function_context (value);
1979 if (context != NULL_TREE && context != current_function_decl
1980 && ! TREE_STATIC (value))
1981 {
8251199e 1982 cp_error ("use of %s from containing function",
5566b478
MS
1983 (TREE_CODE (value) == VAR_DECL
1984 ? "`auto' variable" : "parameter"));
8251199e 1985 cp_error_at (" `%#D' declared here", value);
e76a2646 1986 value = error_mark_node;
5566b478
MS
1987 }
1988 }
1989
8d08fdba
MS
1990 if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value))
1991 {
70adf8a9 1992 if (DECL_CLASS_SCOPE_P (value)
4f1c5b7d 1993 && DECL_CONTEXT (value) != current_class_type)
8d08fdba 1994 {
d6479fe7 1995 tree path;
4f1c5b7d 1996 path = currently_open_derived_class (DECL_CONTEXT (value));
70adf8a9 1997 enforce_access (path, value);
8d08fdba 1998 }
8d08fdba 1999 }
280f9385
MM
2000 else if (TREE_CODE (value) == TREE_LIST
2001 && TREE_TYPE (value) == error_mark_node)
8d08fdba 2002 {
0cfdd854
ML
2003 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2004 IDENTIFIER_POINTER (name));
66543169 2005 print_candidates (value);
0cfdd854 2006 return error_mark_node;
8d08fdba
MS
2007 }
2008
75d587eb 2009 if (! processing_template_decl)
6b5fbb55 2010 value = convert_from_reference (value);
8d08fdba
MS
2011 return value;
2012}
2013
8926095f 2014\f
8926095f 2015tree
c0bbf652 2016make_thunk (function, delta, vcall_index)
8926095f
MS
2017 tree function;
2018 int delta;
c0bbf652 2019 int vcall_index;
8926095f 2020{
b87692e5 2021 tree thunk_id;
8926095f 2022 tree thunk;
8926095f 2023 tree func_decl;
cc600f33 2024
8926095f
MS
2025 if (TREE_CODE (function) != ADDR_EXPR)
2026 abort ();
2027 func_decl = TREE_OPERAND (function, 0);
2028 if (TREE_CODE (func_decl) != FUNCTION_DECL)
2029 abort ();
cc600f33
JM
2030
2031 OB_INIT ();
2032 OB_PUTS ("__thunk_");
2033 if (delta > 0)
2034 {
2035 OB_PUTC ('n');
2036 icat (delta);
2037 }
5edb8b93 2038 else
cc600f33
JM
2039 icat (-delta);
2040 OB_PUTC ('_');
2041 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl));
c0bbf652
MM
2042 if (vcall_index)
2043 {
2044 OB_PUTC ('_');
2045 icat (vcall_index);
2046 }
cc600f33
JM
2047 OB_FINISH ();
2048 thunk_id = get_identifier (obstack_base (&scratch_obstack));
2049
a0a33927
MS
2050 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
2051 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
2052 {
8251199e 2053 cp_error ("implementation-reserved name `%D' used", thunk_id);
2c73f9f5
ML
2054 thunk = NULL_TREE;
2055 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
a0a33927
MS
2056 }
2057 if (thunk == NULL_TREE)
2058 {
eb448459
MS
2059 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
2060 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
2061 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
7fcdf4c2 2062 comdat_linkage (thunk);
72b7eeff 2063 TREE_SET_CODE (thunk, THUNK_DECL);
a0a33927
MS
2064 DECL_INITIAL (thunk) = function;
2065 THUNK_DELTA (thunk) = delta;
c0bbf652
MM
2066 THUNK_VCALL_OFFSET (thunk)
2067 = vcall_index * TREE_INT_CST_LOW (TYPE_SIZE (vtable_entry_type));
72b7eeff 2068 DECL_EXTERNAL (thunk) = 1;
eb448459 2069 DECL_ARTIFICIAL (thunk) = 1;
a0a33927
MS
2070 /* So that finish_file can write out any thunks that need to be: */
2071 pushdecl_top_level (thunk);
2072 }
8926095f
MS
2073 return thunk;
2074}
2075
eb448459
MS
2076/* Emit the definition of a C++ multiple inheritance vtable thunk. */
2077
8926095f
MS
2078void
2079emit_thunk (thunk_fndecl)
824b9a4c 2080 tree thunk_fndecl;
8926095f 2081{
8926095f
MS
2082 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
2083 int delta = THUNK_DELTA (thunk_fndecl);
8926095f
MS
2084
2085 if (TREE_ASM_WRITTEN (thunk_fndecl))
2086 return;
2087
a0a33927
MS
2088 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
2089
809c8c30
JM
2090 TREE_ADDRESSABLE (function) = 1;
2091 mark_used (function);
2092
8926095f
MS
2093 if (current_function_decl)
2094 abort ();
a0128b67
MS
2095
2096 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
eb66be0e 2097
a80e4195 2098#ifdef ASM_OUTPUT_MI_THUNK
3b62f224
MM
2099 if (!flag_syntax_only)
2100 {
2101 char *fnname;
2102 current_function_decl = thunk_fndecl;
2103 /* Make sure we build up its RTL before we go onto the
2104 temporary obstack. */
2105 make_function_rtl (thunk_fndecl);
3b62f224
MM
2106 DECL_RESULT (thunk_fndecl)
2107 = build_decl (RESULT_DECL, 0, integer_type_node);
2108 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2109 init_function_start (thunk_fndecl, input_filename, lineno);
2110 current_function_is_thunk = 1;
2111 assemble_start_function (thunk_fndecl, fnname);
2112 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
2113 assemble_end_function (thunk_fndecl, fnname);
3b62f224 2114 current_function_decl = 0;
01d939e8 2115 cfun = 0;
3b62f224 2116 }
eb66be0e 2117#else /* ASM_OUTPUT_MI_THUNK */
3b62f224 2118 {
eb448459
MS
2119 /* If we don't have the necessary macro for efficient thunks, generate a
2120 thunk function that just makes a call to the real function.
2121 Unfortunately, this doesn't work for varargs. */
2122
eb66be0e 2123 tree a, t;
8926095f 2124
eb448459 2125 if (varargs_function_p (function))
8251199e 2126 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
eb448459
MS
2127 function);
2128
eb66be0e
MS
2129 /* Set up clone argument trees for the thunk. */
2130 t = NULL_TREE;
2131 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
2132 {
2133 tree x = copy_node (a);
2134 TREE_CHAIN (x) = t;
2135 DECL_CONTEXT (x) = thunk_fndecl;
2136 t = x;
2137 }
2138 a = nreverse (t);
2139 DECL_ARGUMENTS (thunk_fndecl) = a;
2140 DECL_RESULT (thunk_fndecl) = NULL_TREE;
eb448459
MS
2141 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
2142 copy_lang_decl (thunk_fndecl);
2143 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
2144 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
eb66be0e 2145
a8f73d4b
MM
2146 start_function (NULL_TREE, thunk_fndecl, NULL_TREE,
2147 SF_DEFAULT | SF_PRE_PARSED);
eb66be0e 2148 store_parm_decls ();
eb448459 2149 current_function_is_thunk = 1;
eb66be0e
MS
2150
2151 /* Build up the call to the real function. */
2152 t = build_int_2 (delta, -1 * (delta < 0));
2153 TREE_TYPE (t) = signed_type (sizetype);
2154 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
e1b3e07d 2155 t = tree_cons (NULL_TREE, t, NULL_TREE);
eb66be0e 2156 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
e1b3e07d 2157 t = tree_cons (NULL_TREE, a, t);
eb66be0e
MS
2158 t = nreverse (t);
2159 t = build_call (function, TREE_TYPE (TREE_TYPE (function)), t);
62409b39 2160 finish_return_stmt (t);
eb66be0e 2161
b35d4555 2162 expand_body (finish_function (lineno, 0));
4d6efa25
JM
2163
2164 /* Don't let the backend defer this function. */
2165 if (DECL_DEFER_OUTPUT (thunk_fndecl))
cd9f6678 2166 output_inline_function (thunk_fndecl);
eb448459 2167 }
3b62f224 2168#endif /* ASM_OUTPUT_MI_THUNK */
8926095f 2169
eb66be0e 2170 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
8926095f 2171}
f376e137
MS
2172\f
2173/* Code for synthesizing methods which have default semantics defined. */
2174
f376e137 2175/* Generate code for default X(X&) constructor. */
e92cc029 2176
824b9a4c 2177static void
db5ae43f 2178do_build_copy_constructor (fndecl)
f376e137
MS
2179 tree fndecl;
2180{
2181 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2182 tree t;
2183
f376e137
MS
2184 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2185 parm = TREE_CHAIN (parm);
2186 parm = convert_from_reference (parm);
2187
a59ca936
JM
2188 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
2189 && is_empty_class (current_class_type))
2190 /* Don't copy the padding byte; it might not have been allocated
2191 if *this is a base subobject. */;
2192 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
f376e137 2193 {
4ac14744 2194 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
f1dedc31 2195 finish_expr_stmt (t);
f376e137
MS
2196 }
2197 else
2198 {
2199 tree fields = TYPE_FIELDS (current_class_type);
2200 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2201 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2202 int i;
2203
1b5f5f76 2204 /* Initialize all the base-classes. */
f376e137
MS
2205 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2206 t = TREE_CHAIN (t))
1b5f5f76
MM
2207 current_base_init_list
2208 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
f376e137
MS
2209 for (i = 0; i < n_bases; ++i)
2210 {
1b5f5f76
MM
2211 t = TREE_VEC_ELT (binfos, i);
2212 if (TREE_VIA_VIRTUAL (t))
8ccc31eb 2213 continue;
f376e137 2214
1b5f5f76
MM
2215 current_base_init_list
2216 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
f376e137 2217 }
1b5f5f76 2218
f376e137
MS
2219 for (; fields; fields = TREE_CHAIN (fields))
2220 {
de22184b 2221 tree init, t;
a5894242
MS
2222 tree field = fields;
2223
2224 if (TREE_CODE (field) != FIELD_DECL)
f376e137 2225 continue;
8dff1027
MS
2226
2227 init = parm;
a5894242 2228 if (DECL_NAME (field))
f376e137 2229 {
a5894242 2230 if (VFIELD_NAME_P (DECL_NAME (field)))
f376e137 2231 continue;
a5894242 2232 if (VBASE_NAME_P (DECL_NAME (field)))
f376e137
MS
2233 continue;
2234
2235 /* True for duplicate members. */
a5894242 2236 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
f376e137
MS
2237 continue;
2238 }
a5894242 2239 else if ((t = TREE_TYPE (field)) != NULL_TREE
6bdb8141 2240 && ANON_AGGR_TYPE_P (t)
0171aeab 2241 && TYPE_FIELDS (t) != NULL_TREE)
6bdb8141
JM
2242 /* Just use the field; anonymous types can't have
2243 nontrivial copy ctors or assignment ops. */;
0171aeab
JM
2244 else
2245 continue;
f376e137 2246
8dff1027 2247 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
f376e137
MS
2248 init = build_tree_list (NULL_TREE, init);
2249
2250 current_member_init_list
6bdb8141 2251 = tree_cons (field, init, current_member_init_list);
f376e137
MS
2252 }
2253 current_member_init_list = nreverse (current_member_init_list);
faae18ab 2254 current_base_init_list = nreverse (current_base_init_list);
f376e137
MS
2255 setup_vtbl_ptr ();
2256 }
f376e137
MS
2257}
2258
824b9a4c 2259static void
db5ae43f 2260do_build_assign_ref (fndecl)
f376e137
MS
2261 tree fndecl;
2262{
2263 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
f1dedc31 2264 tree compound_stmt;
f376e137 2265
f1dedc31 2266 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
f376e137
MS
2267 parm = convert_from_reference (parm);
2268
a59ca936
JM
2269 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
2270 && is_empty_class (current_class_type))
2271 /* Don't copy the padding byte; it might not have been allocated
2272 if *this is a base subobject. */;
2273 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
f376e137 2274 {
4ac14744 2275 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
f1dedc31 2276 finish_expr_stmt (t);
f376e137
MS
2277 }
2278 else
2279 {
2280 tree fields = TYPE_FIELDS (current_class_type);
2281 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2282 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2283 int i;
2284
2285 for (i = 0; i < n_bases; ++i)
2286 {
2287 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
e349ee73
MS
2288 tree p = convert_to_reference
2289 (build_reference_type (basetype), parm,
2290 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2291 p = convert_from_reference (p);
2292 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
051e6fd7 2293 build_tree_list (NULL_TREE, p));
62409b39 2294 finish_expr_stmt (p);
f376e137
MS
2295 }
2296 for (; fields; fields = TREE_CHAIN (fields))
2297 {
0171aeab 2298 tree comp, init, t;
a5894242
MS
2299 tree field = fields;
2300
2301 if (TREE_CODE (field) != FIELD_DECL)
f376e137 2302 continue;
e349ee73 2303
1b8899d1 2304 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
e349ee73
MS
2305 {
2306 if (DECL_NAME (field))
8251199e 2307 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
e349ee73 2308 else
8251199e 2309 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
e349ee73
MS
2310 continue;
2311 }
2312 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2313 {
2314 if (DECL_NAME (field))
8251199e 2315 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
e349ee73 2316 else
8251199e 2317 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
e349ee73
MS
2318 continue;
2319 }
2320
8dff1027
MS
2321 comp = current_class_ref;
2322 init = parm;
2323
a5894242 2324 if (DECL_NAME (field))
f376e137 2325 {
a5894242 2326 if (VFIELD_NAME_P (DECL_NAME (field)))
f376e137 2327 continue;
a5894242 2328 if (VBASE_NAME_P (DECL_NAME (field)))
f376e137
MS
2329 continue;
2330
2331 /* True for duplicate members. */
a5894242 2332 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
f376e137
MS
2333 continue;
2334 }
a5894242 2335 else if ((t = TREE_TYPE (field)) != NULL_TREE
6bdb8141 2336 && ANON_AGGR_TYPE_P (t)
0171aeab 2337 && TYPE_FIELDS (t) != NULL_TREE)
6bdb8141
JM
2338 /* Just use the field; anonymous types can't have
2339 nontrivial copy ctors or assignment ops. */;
0171aeab
JM
2340 else
2341 continue;
f376e137 2342
8dff1027
MS
2343 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2344 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
f376e137 2345
62409b39 2346 finish_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
f376e137
MS
2347 }
2348 }
62409b39 2349 finish_return_stmt (current_class_ref);
f1dedc31 2350 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
f376e137
MS
2351}
2352
2353void
db5ae43f 2354synthesize_method (fndecl)
f376e137
MS
2355 tree fndecl;
2356{
db5ae43f 2357 int nested = (current_function_decl != NULL_TREE);
4f1c5b7d 2358 tree context = decl_function_context (fndecl);
62409b39 2359 int need_body = 1;
db5ae43f 2360
b7067a12
JM
2361 if (at_eof)
2362 import_export_decl (fndecl);
2363
9a3b49ac
MS
2364 if (! context)
2365 push_to_top_level ();
2366 else if (nested)
99dccabc 2367 push_function_context_to (context);
db5ae43f 2368
62409b39
MM
2369 /* Put the function definition at the position where it is needed,
2370 rather than within the body of the class. That way, an error
2371 during the generation of the implicit body points at the place
2372 where the attempt to generate the function occurs, giving the
2373 user a hint as to why we are attempting to generate the
2374 function. */
2375 DECL_SOURCE_LINE (fndecl) = lineno;
2376 DECL_SOURCE_FILE (fndecl) = input_filename;
2377
e76a2646 2378 interface_unknown = 1;
a8f73d4b 2379 start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
f376e137 2380 store_parm_decls ();
f1dedc31 2381 clear_last_expr ();
db5ae43f
MS
2382
2383 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
62409b39
MM
2384 {
2385 do_build_assign_ref (fndecl);
2386 need_body = 0;
2387 }
db5ae43f 2388 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
018fc244 2389 setup_vtbl_ptr ();
db5ae43f
MS
2390 else
2391 {
2392 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2393 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2394 arg_chain = TREE_CHAIN (arg_chain);
2395 if (arg_chain != void_list_node)
2396 do_build_copy_constructor (fndecl);
2397 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
62409b39
MM
2398 setup_vtbl_ptr ();
2399 }
f18a14bc 2400
62409b39
MM
2401 /* If we haven't yet generated the body of the function, just
2402 generate an empty compound statement. */
2403 if (need_body)
2404 {
2405 tree compound_stmt;
2406 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
2407 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
db5ae43f
MS
2408 }
2409
b35d4555 2410 expand_body (finish_function (lineno, 0));
28cbf42c 2411
db5ae43f 2412 extract_interface_info ();
9a3b49ac
MS
2413 if (! context)
2414 pop_from_top_level ();
2415 else if (nested)
99dccabc 2416 pop_function_context_from (context);
f376e137 2417}
This page took 0.997551 seconds and 5 git commands to generate.