]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/method.c
Restore accidentally nuked changelog entries Mon Apr 10 07:21:13 2000 Richard...
[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 {
2f939d94 449 if (TYPE_P (context))
cb0dbb9a
JM
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 599
10bd7f8c
JW
600 /* If value doesn't fit in a single HOST_WIDE_INT, we must use a
601 special output routine that can deal with this. */
602 if (! host_integerp (value, 0))
e1b7b0cb 603 {
858a0ff1
MM
604 multiple_words_p = 1;
605 /* And there is certainly going to be more than one digit. */
606 multiple_digits_p = 1;
607 }
608 else
05bccae2
RK
609 multiple_digits_p = ((HOST_WIDE_INT) TREE_INT_CST_LOW (value) > 9
610 || (HOST_WIDE_INT) TREE_INT_CST_LOW (value) < -9);
858a0ff1
MM
611
612 /* If necessary, add a leading underscore. */
613 if (multiple_digits_p && (flags & mf_use_underscores_around_value))
614 OB_PUTC ('_');
615
616 /* Output the number itself. */
617 if (multiple_words_p)
618 dicat (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value));
619 else
620 icat (TREE_INT_CST_LOW (value));
621
622 if (flags & mf_use_underscores_around_value)
623 {
624 if (multiple_digits_p)
625 OB_PUTC ('_');
626 /* Whether or not there were multiple digits, we don't need an
627 underscore. We've either terminated the number with an
628 underscore, or else it only had one digit. */
629 numeric_output_need_bar = 0;
e1b7b0cb 630 }
858a0ff1
MM
631 else
632 /* We just output a numeric value. */
633 numeric_output_need_bar = 1;
e1b7b0cb
RK
634}
635
f84b4be9
JM
636
637/* Output S followed by a representation of the TEMPLATE_PARM_INDEX
638 supplied in INDEX. */
639
640static void
641build_mangled_template_parm_index (s, index)
9c0758dd 642 const char *s;
f84b4be9
JM
643 tree index;
644{
645 OB_PUTCP (s);
646 build_underscore_int (TEMPLATE_PARM_IDX (index));
647 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
648 representation of the function from the point of view of its
649 type. */
650 build_underscore_int (TEMPLATE_PARM_LEVEL (index));
651}
652
653
25f3d2f4
BK
654/* Mangling for C9X integer types (and Cygnus extensions for 128-bit
655 and other types) is based on the letter "I" followed by the hex
656 representations of the bitsize for the type in question. For
657 encodings that result in larger than two digits, a leading and
658 trailing underscore is added.
659
660 Thus:
661 int1_t = 001 = I01
662 int8_t = 008 = I08
663 int16_t = 010 = I10
664 int24_t = 018 = I18
665 int32_t = 020 = I20
666 int64_t = 040 = I40
667 int80_t = 050 = I50
668 int128_t = 080 = I80
669 int256_t = 100 = I_100_
670 int512_t = 200 = I_200_
671
672 Given an integer in decimal format, mangle according to this scheme. */
673
e833cb11 674#if HOST_BITS_PER_WIDE_INT >= 64
25f3d2f4
BK
675static void
676build_mangled_C9x_name (bits)
677 int bits;
678{
679 char mangled[10] = "";
680
681 if (bits > 255)
682 sprintf (mangled, "I_%x_", bits);
683 else
684 sprintf (mangled, "I%.2x", bits);
685
686 OB_PUTCP (mangled);
687}
e833cb11 688#endif
25f3d2f4 689
8d08fdba 690static void
858a0ff1 691build_overload_value (type, value, flags)
8d08fdba 692 tree type, value;
858a0ff1 693 mangling_flags flags;
8d08fdba 694{
2f939d94 695 my_friendly_assert (TYPE_P (type), 0);
61a127b3 696
8d08fdba
MS
697 while (TREE_CODE (value) == NON_LVALUE_EXPR
698 || TREE_CODE (value) == NOP_EXPR)
699 value = TREE_OPERAND (value, 0);
050367a3 700
e1b7b0cb
RK
701 if (numeric_output_need_bar)
702 {
703 OB_PUTC ('_');
704 numeric_output_need_bar = 0;
705 }
706
f84b4be9 707 if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
2636fde4 708 {
f84b4be9 709 build_mangled_template_parm_index ("Y", value);
2636fde4
JM
710 return;
711 }
712
61a127b3 713 if (TYPE_PTRMEM_P (type))
8145f082 714 {
61a127b3
MM
715 if (TREE_CODE (value) != PTRMEM_CST)
716 /* We should have already rejected this pointer to member,
717 since it is not a constant. */
718 my_friendly_abort (0);
719
720 /* Get the actual FIELD_DECL. */
721 value = PTRMEM_CST_MEMBER (value);
722 my_friendly_assert (TREE_CODE (value) == FIELD_DECL, 0);
723
724 /* Output the name of the field. */
725 build_overload_identifier (DECL_NAME (value));
726 return;
8145f082 727 }
858a0ff1
MM
728 else if (INTEGRAL_TYPE_P (type))
729 {
730 build_overload_int (value, flags);
731 return;
732 }
733
734 /* The only case where we use the extra underscores here is when
735 forming the mangling for an integral non-type template argument.
736 If that didn't happen, stop now. */
737 flags &= ~mf_use_underscores_around_value;
8145f082 738
8d08fdba
MS
739 switch (TREE_CODE (type))
740 {
8d08fdba
MS
741 case REAL_TYPE:
742 {
743 REAL_VALUE_TYPE val;
744 char *bufp = digit_buffer;
8d08fdba 745
858a0ff1
MM
746 /* We must handle non-constants in templates. */
747 if (TREE_CODE (value) != REAL_CST)
748 {
749 mangle_expression (value);
750 break;
751 }
bd6dd845 752
8d08fdba 753 val = TREE_REAL_CST (value);
bd6dd845 754 if (REAL_VALUE_ISNAN (val))
8d08fdba 755 {
bd6dd845 756 sprintf (bufp, "NaN");
8d08fdba 757 }
8d08fdba
MS
758 else
759 {
bd6dd845 760 if (REAL_VALUE_NEGATIVE (val))
8d08fdba 761 {
bd6dd845 762 val = REAL_VALUE_NEGATE (val);
8d08fdba
MS
763 *bufp++ = 'm';
764 }
bd6dd845 765 if (REAL_VALUE_ISINF (val))
8d08fdba 766 {
bd6dd845 767 sprintf (bufp, "Infinity");
8d08fdba 768 }
bd6dd845 769 else
8d08fdba 770 {
3d015f46 771 REAL_VALUE_TO_DECIMAL (val, "%.20e", bufp);
bd6dd845
MS
772 bufp = (char *) index (bufp, 'e');
773 if (!bufp)
774 strcat (digit_buffer, "e0");
775 else
776 {
777 char *p;
778 bufp++;
779 if (*bufp == '-')
780 {
781 *bufp++ = 'm';
782 }
783 p = bufp;
784 if (*p == '+')
785 p++;
786 while (*p == '0')
787 p++;
788 if (*p == 0)
789 {
790 *bufp++ = '0';
791 *bufp = 0;
792 }
793 else if (p != bufp)
794 {
795 while (*p)
796 *bufp++ = *p++;
797 *bufp = 0;
798 }
799 }
800#ifdef NO_DOT_IN_LABEL
801 bufp = (char *) index (bufp, '.');
802 if (bufp)
803 *bufp = '_';
804#endif
8d08fdba
MS
805 }
806 }
807 OB_PUTCP (digit_buffer);
e1b7b0cb 808 numeric_output_need_bar = 1;
8d08fdba
MS
809 return;
810 }
8d08fdba 811 case POINTER_TYPE:
f84b4be9 812 if (TREE_CODE (value) == INTEGER_CST)
f30432d7 813 {
858a0ff1 814 build_overload_int (value, flags);
f30432d7
MS
815 return;
816 }
f84b4be9
JM
817 else if (TREE_CODE (value) == TEMPLATE_PARM_INDEX)
818 {
819 build_mangled_template_parm_index ("", value);
820 numeric_output_need_bar = 1;
821 return;
822 }
823
8d08fdba 824 value = TREE_OPERAND (value, 0);
5c0aa6d0
MM
825
826 /* Fall through. */
827
828 case REFERENCE_TYPE:
8d08fdba
MS
829 if (TREE_CODE (value) == VAR_DECL)
830 {
831 my_friendly_assert (DECL_NAME (value) != 0, 245);
e76a2646 832 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
8d08fdba
MS
833 return;
834 }
835 else if (TREE_CODE (value) == FUNCTION_DECL)
836 {
837 my_friendly_assert (DECL_NAME (value) != 0, 246);
e76a2646 838 build_overload_identifier (DECL_ASSEMBLER_NAME (value));
8d08fdba
MS
839 return;
840 }
aa36c081 841 else if (TREE_CODE (value) == SCOPE_REF)
050367a3 842 build_overload_scope_ref (value);
8d08fdba
MS
843 else
844 my_friendly_abort (71);
845 break; /* not really needed */
846
e08a8f45
MM
847 case RECORD_TYPE:
848 {
849 tree delta;
850 tree idx;
851 tree pfn;
852 tree delta2;
c7e266a6 853 tree fn;
e08a8f45
MM
854
855 my_friendly_assert (TYPE_PTRMEMFUNC_P (type), 0);
82bed870
MM
856
857 /* We'll get a ADDR_EXPR of a SCOPE_REF here if we're
858 mangling, an instantiation of something like:
859
860 template <class T, void (T::*fp)()> class C {};
861 template <class T> C<T, &T::f> x();
862
863 We mangle the return type of the function, and that
864 contains template parameters. */
865 if (TREE_CODE (value) == ADDR_EXPR
866 && TREE_CODE (TREE_OPERAND (value, 0)) == SCOPE_REF)
867 {
868 build_overload_scope_ref (TREE_OPERAND (value, 0));
869 break;
870 }
871
e08a8f45
MM
872 my_friendly_assert (TREE_CODE (value) == PTRMEM_CST, 0);
873
874 expand_ptrmemfunc_cst (value, &delta, &idx, &pfn, &delta2);
c7e266a6 875 fn = PTRMEM_CST_MEMBER (value);
858a0ff1 876 build_overload_int (delta, flags);
e08a8f45 877 OB_PUTC ('_');
c7e266a6
MM
878 if (!flag_new_abi)
879 {
880 build_overload_int (idx, flags);
881 OB_PUTC ('_');
882 }
883 else if (DECL_VIRTUAL_P (fn))
884 {
885 build_overload_int (DECL_VINDEX (fn), flags);
886 OB_PUTC ('_');
887 }
888
889 if (!DECL_VIRTUAL_P (fn))
e08a8f45
MM
890 {
891 numeric_output_need_bar = 0;
c7e266a6 892 build_overload_identifier (DECL_ASSEMBLER_NAME (fn));
e08a8f45 893 }
c7e266a6 894 else if (!flag_new_abi)
e08a8f45
MM
895 {
896 OB_PUTC ('i');
858a0ff1 897 build_overload_int (delta2, flags);
e08a8f45
MM
898 }
899 }
900 break;
901
8d08fdba
MS
902 default:
903 sorry ("conversion of %s as template parameter",
904 tree_code_name [(int) TREE_CODE (type)]);
905 my_friendly_abort (72);
906 }
907}
908
386b8a85 909
73b0fce8 910/* Add encodings for the declaration of template template parameters.
407f03b8 911 PARMLIST must be a TREE_VEC. */
73b0fce8
KL
912
913static void
914build_template_template_parm_names (parmlist)
915 tree parmlist;
916{
917 int i, nparms;
918
919 my_friendly_assert (TREE_CODE (parmlist) == TREE_VEC, 246.5);
920 nparms = TREE_VEC_LENGTH (parmlist);
921 icat (nparms);
922 for (i = 0; i < nparms; i++)
923 {
924 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
925 if (TREE_CODE (parm) == TYPE_DECL)
926 {
927 /* This parameter is a type. */
928 OB_PUTC ('Z');
929 }
930 else if (TREE_CODE (parm) == TEMPLATE_DECL)
931 {
932 /* This parameter is a template. */
933 OB_PUTC ('z');
934 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm));
935 }
936 else
59e621fc
MM
937 /* It's a PARM_DECL. */
938 build_mangled_name_for_type (TREE_TYPE (parm));
73b0fce8
KL
939 }
940}
941
942
386b8a85
JM
943/* Add encodings for the vector of template parameters in PARMLIST,
944 given the vector of arguments to be substituted in ARGLIST. */
945
4966381a 946static void
386b8a85
JM
947build_template_parm_names (parmlist, arglist)
948 tree parmlist;
949 tree arglist;
950{
951 int i, nparms;
e4a84209
MM
952 tree inner_args = innermost_args (arglist);
953
386b8a85
JM
954 nparms = TREE_VEC_LENGTH (parmlist);
955 icat (nparms);
956 for (i = 0; i < nparms; i++)
957 {
958 tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i));
e4a84209 959 tree arg = TREE_VEC_ELT (inner_args, i);
386b8a85
JM
960 if (TREE_CODE (parm) == TYPE_DECL)
961 {
962 /* This parameter is a type. */
963 OB_PUTC ('Z');
59e621fc 964 build_mangled_name_for_type (arg);
386b8a85 965 }
73b0fce8
KL
966 else if (TREE_CODE (parm) == TEMPLATE_DECL)
967 {
407f03b8 968 /* This parameter is a template. */
73b0fce8 969 if (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
407f03b8 970 /* Output parameter declaration, argument index and level. */
59e621fc 971 build_mangled_name_for_type (arg);
73b0fce8
KL
972 else
973 {
974 /* A TEMPLATE_DECL node, output the parameter declaration
975 and template name */
976
977 OB_PUTC ('z');
407f03b8
JM
978 build_template_template_parm_names
979 (DECL_INNERMOST_TEMPLATE_PARMS (parm));
73b0fce8
KL
980 icat (IDENTIFIER_LENGTH (DECL_NAME (arg)));
981 OB_PUTID (DECL_NAME (arg));
982 }
983 }
386b8a85
JM
984 else
985 {
4393e105 986 parm = tsubst (parm, arglist, /*complain=*/1, NULL_TREE);
386b8a85 987 /* It's a PARM_DECL. */
59e621fc 988 build_mangled_name_for_type (TREE_TYPE (parm));
61a127b3 989 build_overload_value (TREE_TYPE (parm), arg,
858a0ff1
MM
990 ((mf_maybe_uninstantiated
991 * uses_template_parms (arglist))
992 | mf_use_underscores_around_value));
386b8a85
JM
993 }
994 }
995 }
996
59e621fc
MM
997/* Output the representation for NAME, which is either a TYPE_DECL or
998 an IDENTIFIER. */
386b8a85 999
8d08fdba
MS
1000static void
1001build_overload_identifier (name)
1002 tree name;
1003{
5566b478 1004 if (TREE_CODE (name) == TYPE_DECL
7ddedda4 1005 && CLASS_TYPE_P (TREE_TYPE (name))
5566b478 1006 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name))
e1467ff2 1007 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name)))
3ebc5c52
MM
1008 || (TREE_CODE (CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
1009 (TREE_TYPE (name))))
e1467ff2 1010 == FUNCTION_DECL)))
8d08fdba 1011 {
59e621fc 1012 /* NAME is the TYPE_DECL for a template specialization. */
8d08fdba 1013 tree template, parmlist, arglist, tname;
e4a84209
MM
1014 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name));
1015 arglist = CLASSTYPE_TI_ARGS (TREE_TYPE (name));
8d08fdba 1016 tname = DECL_NAME (template);
98c1c668 1017 parmlist = DECL_INNERMOST_TEMPLATE_PARMS (template);
8d08fdba
MS
1018 OB_PUTC ('t');
1019 icat (IDENTIFIER_LENGTH (tname));
1020 OB_PUTID (tname);
386b8a85 1021 build_template_parm_names (parmlist, arglist);
8d08fdba
MS
1022 }
1023 else
1024 {
5566b478
MS
1025 if (TREE_CODE (name) == TYPE_DECL)
1026 name = DECL_NAME (name);
8cb9cd5d 1027 if (numeric_output_need_bar)
f376e137
MS
1028 {
1029 OB_PUTC ('_');
8cb9cd5d 1030 numeric_output_need_bar = 0;
f376e137 1031 }
8d08fdba
MS
1032 icat (IDENTIFIER_LENGTH (name));
1033 OB_PUTID (name);
1034 }
1035}
1036
42976354 1037/* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
ed22c95e 1038 the mangling for it. Used by build_mangled_name and build_static_name. */
42976354
BK
1039
1040static void
1041build_qualified_name (decl)
1042 tree decl;
1043{
1044 tree context;
1045 int i = 1;
1046
2f939d94 1047 if (TYPE_P (decl))
42976354
BK
1048 decl = TYPE_NAME (decl);
1049
1050 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
1051 if (TREE_CODE (decl) == TYPE_DECL
ed22c95e 1052 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) && !flag_do_squangling)
42976354 1053 {
050367a3
MM
1054 tree id = DECL_ASSEMBLER_NAME (decl);
1055 OB_PUTID (id);
faa25e97 1056 if (ISDIGIT (IDENTIFIER_POINTER (id) [IDENTIFIER_LENGTH (id) - 1]))
050367a3 1057 numeric_output_need_bar = 1;
42976354
BK
1058 return;
1059 }
1060
1061 context = decl;
407f03b8 1062 /* If we can't find a Ktype, do it the hard way. */
ed22c95e 1063 if (check_ktype (context, FALSE) == -1)
30394414 1064 {
407f03b8
JM
1065 /* Count type and namespace scopes. */
1066 while (1)
30394414 1067 {
407f03b8
JM
1068 context = CP_DECL_CONTEXT (context);
1069 if (context == global_namespace)
1070 break;
30394414 1071 i += 1;
407f03b8
JM
1072 if (check_ktype (context, FALSE) != -1)
1073 /* Found one! */
30394414 1074 break;
2f939d94 1075 if (TYPE_P (context))
30394414
JM
1076 context = TYPE_NAME (context);
1077 }
30394414 1078 }
42976354
BK
1079
1080 if (i > 1)
1081 {
1082 OB_PUTC ('Q');
050367a3 1083 build_underscore_int (i);
42976354
BK
1084 numeric_output_need_bar = 0;
1085 }
1086 build_overload_nested_name (decl);
1087}
1088
59e621fc
MM
1089/* Output the mangled representation for TYPE. If EXTRA_GCODE is
1090 non-zero, mangled names for structure/union types are intentionally
1091 mangled differently from the method described in the ARM. */
1092
e9659ab0 1093static void
59e621fc
MM
1094build_mangled_name_for_type_with_Gcode (type, extra_Gcode)
1095 tree type;
1096 int extra_Gcode;
1097{
1098 if (TYPE_PTRMEMFUNC_P (type))
1099 type = TYPE_PTRMEMFUNC_FN_TYPE (type);
59e621fc
MM
1100 process_modifiers (type);
1101 process_overload_item (type, extra_Gcode);
1102}
1103
1104/* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1105 `G'. */
1106
e9659ab0 1107static void
59e621fc
MM
1108build_mangled_name_for_type (type)
1109 tree type;
1110{
1111 build_mangled_name_for_type_with_Gcode (type, 0);
1112}
1113
8d08fdba
MS
1114/* Given a list of parameters in PARMTYPES, create an unambiguous
1115 overload string. Should distinguish any type that C (or C++) can
1116 distinguish. I.e., pointers to functions are treated correctly.
1117
1118 Caller must deal with whether a final `e' goes on the end or not.
1119
1120 Any default conversions must take place before this function
1121 is called.
1122
1123 BEGIN and END control initialization and finalization of the
1124 obstack where we build the string. */
1125
1126char *
1127build_overload_name (parmtypes, begin, end)
1128 tree parmtypes;
1129 int begin, end;
1130{
ed22c95e
AM
1131 char *ret;
1132 start_squangling ();
1133 ret = build_mangled_name (parmtypes, begin, end);
1134 end_squangling ();
1135 return ret ;
1136}
1137
59e621fc
MM
1138/* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1139 TREE_LIST, then it is a list of parameter types. Otherwise,
1140 PARMTYPES must be a single type. */
1141
ed22c95e
AM
1142static char *
1143build_mangled_name (parmtypes, begin, end)
1144 tree parmtypes;
1145 int begin, end;
1146{
ed22c95e
AM
1147 if (begin)
1148 OB_INIT ();
8d08fdba 1149
59e621fc
MM
1150 if (TREE_CODE (parmtypes) != TREE_LIST)
1151 /* There is only one type. */
1152 build_mangled_name_for_type (parmtypes);
1153 else
8d08fdba 1154 {
59e621fc
MM
1155 /* There are several types in a parameter list. */
1156 int nrepeats = 0;
1157 int old_style_repeats = !flag_do_squangling && !nofold && typevec;
1158 tree last_type = NULL_TREE;
1159
1160 for (; parmtypes && parmtypes != void_list_node;
1161 parmtypes = TREE_CHAIN (parmtypes))
1162 {
407f03b8
JM
1163 /* We used to call canonical_type_variant here, but that isn't
1164 good enough; it doesn't handle pointers to typedef types. So
1165 we can't just set TREE_USED to say we've seen a type already;
1166 we have to check each of the earlier types with same_type_p. */
1167 tree parmtype = TREE_VALUE (parmtypes);
59e621fc
MM
1168
1169 if (old_style_repeats)
1170 {
1171 /* Every argument gets counted. */
9cd64686
MM
1172 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1173 VARRAY_TREE (typevec, maxtype) = parmtype;
1174 maxtype++;
59e621fc 1175 }
f921acee
JM
1176
1177 if (last_type && same_type_p (parmtype, last_type))
59e621fc 1178 {
f921acee
JM
1179 if (flag_do_squangling
1180 || (old_style_repeats
1181 && is_back_referenceable_type (parmtype)))
59e621fc
MM
1182 {
1183 /* The next type is the same as this one. Keep
1184 track of the repetition, and output the repeat
1185 count later. */
1186 nrepeats++;
1187 continue;
1188 }
f921acee
JM
1189 }
1190 else if (nrepeats != 0)
1191 {
1192 /* Indicate how many times the previous parameter was
1193 repeated. */
1194 if (old_style_repeats)
1195 flush_repeats (nrepeats, last_type);
1196 else
1197 issue_nrepeats (nrepeats, last_type);
1198 nrepeats = 0;
59e621fc 1199 }
407f03b8
JM
1200
1201 last_type = parmtype;
1202
f921acee
JM
1203 /* Note that for bug-compatibility with 2.7.2, we can't build up
1204 repeats of types other than the most recent one. So we call
1205 flush_repeats every round, if we get this far. */
1206 if (old_style_repeats && flush_repeats (0, parmtype))
407f03b8 1207 continue;
59e621fc
MM
1208
1209 /* Output the PARMTYPE. */
1210 build_mangled_name_for_type_with_Gcode (parmtype, 1);
1211 }
1212
1213 /* Output the repeat count for the last parameter, if
1214 necessary. */
1215 if (nrepeats != 0)
1216 {
f921acee
JM
1217 if (old_style_repeats)
1218 flush_repeats (nrepeats, last_type);
1219 else
1220 issue_nrepeats (nrepeats, last_type);
59e621fc
MM
1221 nrepeats = 0;
1222 }
1223
1224 if (!parmtypes)
1225 /* The parameter list ends in an ellipsis. */
1226 OB_PUTC ('e');
1227 }
8d08fdba 1228
ed22c95e
AM
1229 if (end)
1230 OB_FINISH ();
770ae6cc 1231 return (char *) obstack_base (&scratch_obstack);
ed22c95e 1232}
8d08fdba 1233
8be64d09
JM
1234/* Emit modifiers such as constant, read-only, and volatile. */
1235
e9659ab0 1236static void
ed22c95e
AM
1237process_modifiers (parmtype)
1238 tree parmtype;
1239{
91063b51
MM
1240 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1241 we describe types recursively; we will get the `const' in
1242 `const int ()[10]' when processing the `const int' part. */
1243 if (TYPE_READONLY (parmtype))
ed22c95e 1244 OB_PUTC ('C');
a1774733 1245 if (TREE_CODE (parmtype) == INTEGER_TYPE
8be64d09
JM
1246 && parmtype != char_type_node
1247 && parmtype != wchar_type_node
a1774733
BK
1248 && (TYPE_MAIN_VARIANT (parmtype)
1249 == unsigned_type (TYPE_MAIN_VARIANT (parmtype)))
ea419909 1250 && ! TYPE_FOR_JAVA (parmtype))
59e621fc 1251 OB_PUTC ('U');
ed22c95e
AM
1252 if (TYPE_VOLATILE (parmtype))
1253 OB_PUTC ('V');
91063b51
MM
1254 /* It would be better to use `R' for `restrict', but that's already
1255 used for reference types. And `r' is used for `long double'. */
1256 if (TYPE_RESTRICT (parmtype))
1257 OB_PUTC ('u');
ed22c95e 1258}
a5894242 1259
59e621fc
MM
1260/* Check to see if TYPE has been entered into the Bcode typelist. If
1261 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1262 to the list of back-referenceable types and return 0. */
1263
e9659ab0 1264static int
59e621fc
MM
1265check_btype (type)
1266 tree type;
ed22c95e 1267{
9cd64686 1268 size_t x;
a5894242 1269
ed22c95e
AM
1270 if (btypelist == NULL)
1271 return 0;
8d08fdba 1272
59e621fc
MM
1273 if (!is_back_referenceable_type (type))
1274 return 0;
31bebb60 1275
ed22c95e 1276 for (x = 0; x < maxbtype; x++)
9cd64686 1277 if (same_type_p (type, VARRAY_TREE (btypelist, x)))
59e621fc
MM
1278 {
1279 OB_PUTC ('B');
1280 icat (x);
1281 if (x > 9)
1282 OB_PUTC ('_');
1283 return 1 ;
1284 }
1285
9cd64686
MM
1286 if (VARRAY_SIZE (btypelist) <= maxbtype)
1287 /* Enlarge the table. */
1288 VARRAY_GROW (btypelist,
1289 VARRAY_SIZE (btypelist) * 3 / 2);
1290
59e621fc 1291 /* Register the TYPE. */
9cd64686
MM
1292 VARRAY_TREE (btypelist, maxbtype) = type;
1293 maxbtype++;
59e621fc 1294
ed22c95e
AM
1295 return 0;
1296}
8d08fdba 1297
8be64d09
JM
1298/* Emit the correct code for various node types. */
1299
ed22c95e
AM
1300static void
1301process_overload_item (parmtype, extra_Gcode)
1302 tree parmtype;
1303 int extra_Gcode;
1304{
59e621fc 1305 numeric_output_need_bar = 0;
8d08fdba 1306
407f03b8
JM
1307 /* Our caller should have already handed any qualifiers, so pull out the
1308 TYPE_MAIN_VARIANT to avoid typedef confusion. Except we can't do that
1309 for arrays, because they are transparent to qualifiers. Sigh. */
1310 if (TREE_CODE (parmtype) == ARRAY_TYPE)
1311 parmtype = canonical_type_variant (parmtype);
1312 else
1313 parmtype = TYPE_MAIN_VARIANT (parmtype);
1314
8be64d09
JM
1315 /* These tree types are considered modifiers for B code squangling,
1316 and therefore should not get entries in the Btypelist. They are,
1317 however, repeatable types. */
8d08fdba 1318
ed22c95e
AM
1319 switch (TREE_CODE (parmtype))
1320 {
1321 case REFERENCE_TYPE:
1322 OB_PUTC ('R');
1323 goto more;
8d08fdba 1324
ed22c95e 1325 case ARRAY_TYPE:
ed22c95e 1326 {
ed22c95e
AM
1327 OB_PUTC ('A');
1328 if (TYPE_DOMAIN (parmtype) == NULL_TREE)
2d914461 1329 OB_PUTC ('_');
ed22c95e 1330 else
53929c47
JM
1331 {
1332 tree length = array_type_nelts (parmtype);
1333 if (TREE_CODE (length) != INTEGER_CST || flag_do_squangling)
1334 {
1335 length = fold (build (PLUS_EXPR, TREE_TYPE (length),
1336 length, integer_one_node));
1337 STRIP_NOPS (length);
1338 }
1339 build_overload_value (sizetype, length, 1);
1340 }
1341 if (numeric_output_need_bar && ! flag_do_squangling)
1342 OB_PUTC ('_');
ed22c95e
AM
1343 goto more;
1344 }
8d08fdba 1345
ed22c95e
AM
1346 case POINTER_TYPE:
1347 OB_PUTC ('P');
1348 more:
59e621fc 1349 build_mangled_name_for_type (TREE_TYPE (parmtype));
ed22c95e
AM
1350 return;
1351 break;
31bebb60
KG
1352
1353 default:
1354 break;
ed22c95e
AM
1355 }
1356
59e621fc
MM
1357 if (flag_do_squangling && check_btype (parmtype))
1358 /* If PARMTYPE is already in the list of back-referenceable types,
1359 then check_btype will output the appropriate reference, and
1360 there's nothing more to do. */
1361 return;
8d08fdba 1362
ed22c95e
AM
1363 switch (TREE_CODE (parmtype))
1364 {
1365 case OFFSET_TYPE:
1366 OB_PUTC ('O');
59e621fc 1367 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype));
ed22c95e 1368 OB_PUTC ('_');
59e621fc 1369 build_mangled_name_for_type (TREE_TYPE (parmtype));
ed22c95e 1370 break;
8d08fdba 1371
ed22c95e
AM
1372 case FUNCTION_TYPE:
1373 case METHOD_TYPE:
1374 {
59e621fc 1375 tree parms = TYPE_ARG_TYPES (parmtype);
ed22c95e 1376
59e621fc
MM
1377 /* Rather than implementing a reentrant TYPEVEC, we turn off
1378 repeat codes here, unless we're squangling. Squangling
1379 doesn't make use of the TYPEVEC, so there's no reentrancy
1380 problem. */
1381 int old_nofold = nofold;
1382 if (!flag_do_squangling)
1383 nofold = 1;
1384
1385 if (TREE_CODE (parmtype) == METHOD_TYPE)
1386 {
1387 /* Mark this as a method. */
ed22c95e 1388 OB_PUTC ('M');
59e621fc
MM
1389 /* Output the class of which this method is a member. */
1390 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype));
1391 /* Output any qualifiers for the `this' parameter. */
1392 process_modifiers (TREE_TYPE (TREE_VALUE (parms)));
1393 }
ed22c95e 1394
59e621fc
MM
1395 /* Output the parameter types. */
1396 OB_PUTC ('F');
1397 if (parms == NULL_TREE)
1398 OB_PUTC ('e');
1399 else if (parms == void_list_node)
1400 OB_PUTC ('v');
1401 else
1402 build_mangled_name (parms, 0, 0);
1403
1404 /* Output the return type. */
ed22c95e 1405 OB_PUTC ('_');
59e621fc
MM
1406 build_mangled_name_for_type (TREE_TYPE (parmtype));
1407
ed22c95e
AM
1408 nofold = old_nofold;
1409 break;
1410 }
8d08fdba 1411
ed22c95e 1412 case INTEGER_TYPE:
ed22c95e 1413 if (parmtype == integer_type_node
ea419909
PB
1414 || parmtype == unsigned_type_node
1415 || parmtype == java_int_type_node)
ed22c95e
AM
1416 OB_PUTC ('i');
1417 else if (parmtype == long_integer_type_node
1418 || parmtype == long_unsigned_type_node)
1419 OB_PUTC ('l');
1420 else if (parmtype == short_integer_type_node
ea419909
PB
1421 || parmtype == short_unsigned_type_node
1422 || parmtype == java_short_type_node)
ed22c95e
AM
1423 OB_PUTC ('s');
1424 else if (parmtype == signed_char_type_node)
1425 {
1426 OB_PUTC ('S');
1427 OB_PUTC ('c');
1428 }
1429 else if (parmtype == char_type_node
ea419909
PB
1430 || parmtype == unsigned_char_type_node
1431 || parmtype == java_byte_type_node)
ed22c95e 1432 OB_PUTC ('c');
ea419909
PB
1433 else if (parmtype == wchar_type_node
1434 || parmtype == java_char_type_node)
ed22c95e
AM
1435 OB_PUTC ('w');
1436 else if (parmtype == long_long_integer_type_node
ea419909
PB
1437 || parmtype == long_long_unsigned_type_node
1438 || parmtype == java_long_type_node)
ed22c95e 1439 OB_PUTC ('x');
ea419909
PB
1440 else if (parmtype == java_boolean_type_node)
1441 OB_PUTC ('b');
25f3d2f4 1442#if HOST_BITS_PER_WIDE_INT >= 64
f2655b99 1443 else
25f3d2f4 1444 {
25f3d2f4
BK
1445 int bits = TREE_INT_CST_LOW (TYPE_SIZE (parmtype));
1446 build_mangled_C9x_name (bits);
1447 }
f2655b99 1448#else
ed22c95e 1449 else
f2655b99
AH
1450 my_friendly_abort (73);
1451#endif
ed22c95e 1452 break;
42976354 1453
ed22c95e
AM
1454 case BOOLEAN_TYPE:
1455 OB_PUTC ('b');
1456 break;
8d08fdba 1457
ed22c95e 1458 case REAL_TYPE:
ed22c95e
AM
1459 if (parmtype == long_double_type_node)
1460 OB_PUTC ('r');
ea419909
PB
1461 else if (parmtype == double_type_node
1462 || parmtype == java_double_type_node)
ed22c95e 1463 OB_PUTC ('d');
ea419909
PB
1464 else if (parmtype == float_type_node
1465 || parmtype == java_float_type_node)
ed22c95e
AM
1466 OB_PUTC ('f');
1467 else my_friendly_abort (74);
1468 break;
1469
1470 case COMPLEX_TYPE:
1471 OB_PUTC ('J');
59e621fc 1472 build_mangled_name_for_type (TREE_TYPE (parmtype));
ed22c95e
AM
1473 break;
1474
1475 case VOID_TYPE:
1476 OB_PUTC ('v');
1477 break;
1478
1479 case ERROR_MARK: /* not right, but nothing is anyway */
1480 break;
1481
1482 /* have to do these */
1483 case UNION_TYPE:
1484 case RECORD_TYPE:
1485 {
1486 if (extra_Gcode)
1487 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1488 /* drop through into next case */
1489 }
1490 case ENUMERAL_TYPE:
1491 {
1492 tree name = TYPE_NAME (parmtype);
73b0fce8 1493
ed22c95e 1494 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 248);
73b0fce8 1495
ed22c95e
AM
1496 build_qualified_name (name);
1497 break;
1498 }
8d08fdba 1499
ed22c95e
AM
1500 case UNKNOWN_TYPE:
1501 /* This will take some work. */
1502 OB_PUTC ('?');
1503 break;
1504
1505 case TEMPLATE_TEMPLATE_PARM:
1506 /* Find and output the original template parameter
1507 declaration. */
7ddedda4 1508 if (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parmtype))
ed22c95e 1509 {
f84b4be9
JM
1510 build_mangled_template_parm_index ("tzX",
1511 TEMPLATE_TYPE_PARM_INDEX
1512 (parmtype));
1513 build_template_parm_names
7ddedda4
MM
1514 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (parmtype)),
1515 TYPE_TI_ARGS (parmtype));
ed22c95e
AM
1516 }
1517 else
1518 {
f84b4be9
JM
1519 build_mangled_template_parm_index ("ZzX",
1520 TEMPLATE_TYPE_PARM_INDEX
1521 (parmtype));
1522 build_template_template_parm_names
1523 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype)));
ed22c95e
AM
1524 }
1525 break;
1526
1527 case TEMPLATE_TYPE_PARM:
f84b4be9
JM
1528 build_mangled_template_parm_index ("X",
1529 TEMPLATE_TYPE_PARM_INDEX
1530 (parmtype));
ed22c95e
AM
1531 break;
1532
1533 case TYPENAME_TYPE:
1534 /* When mangling the type of a function template whose
1535 declaration looks like:
1536
1537 template <class T> void foo(typename T::U)
1538
1539 we have to mangle these. */
1540 build_qualified_name (parmtype);
1541 break;
8d08fdba 1542
ed22c95e
AM
1543 default:
1544 my_friendly_abort (75);
8d08fdba
MS
1545 }
1546
8d08fdba 1547}
f376e137 1548
42976354
BK
1549/* Produce the mangling for a variable named NAME in CONTEXT, which can
1550 be either a class TYPE or a FUNCTION_DECL. */
1551
f376e137 1552tree
42976354
BK
1553build_static_name (context, name)
1554 tree context, name;
f376e137 1555{
42976354
BK
1556 OB_INIT ();
1557 numeric_output_need_bar = 0;
ed22c95e 1558 start_squangling ();
42976354
BK
1559#ifdef JOINER
1560 OB_PUTC ('_');
1561 build_qualified_name (context);
1562 OB_PUTC (JOINER);
1563#else
1564 OB_PUTS ("__static_");
1565 build_qualified_name (context);
a6f02587 1566 OB_PUTC ('_');
42976354
BK
1567#endif
1568 OB_PUTID (name);
1569 OB_FINISH ();
ed22c95e 1570 end_squangling ();
42976354
BK
1571
1572 return get_identifier ((char *)obstack_base (&scratch_obstack));
1573}
8d08fdba 1574\f
36a117a5
MM
1575/* FOR_METHOD should be 1 if the declaration in question is for a member
1576 of a class (including a static member) and 2 if the declaration is
1577 for a constructor. */
1578tree
386b8a85
JM
1579build_decl_overload_real (dname, parms, ret_type, tparms, targs,
1580 for_method)
8d08fdba
MS
1581 tree dname;
1582 tree parms;
386b8a85
JM
1583 tree ret_type;
1584 tree tparms;
1585 tree targs;
8d08fdba
MS
1586 int for_method;
1587{
9c0758dd 1588 const char *name = IDENTIFIER_POINTER (dname);
8d08fdba 1589
a28e3c7f 1590 /* member operators new and delete look like methods at this point. */
64f1326a
ML
1591 if (! for_method && current_namespace == global_namespace
1592 && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST
047f64a3 1593 && TREE_CHAIN (parms) == void_list_node)
a28e3c7f 1594 {
00595019
MS
1595 if (dname == ansi_opname[(int) DELETE_EXPR])
1596 return get_identifier ("__builtin_delete");
1597 else if (dname == ansi_opname[(int) VEC_DELETE_EXPR])
1598 return get_identifier ("__builtin_vec_delete");
047f64a3
JM
1599 if (dname == ansi_opname[(int) NEW_EXPR])
1600 return get_identifier ("__builtin_new");
1601 else if (dname == ansi_opname[(int) VEC_NEW_EXPR])
1602 return get_identifier ("__builtin_vec_new");
a28e3c7f 1603 }
8d08fdba 1604
ed22c95e 1605 start_squangling ();
8d08fdba
MS
1606 OB_INIT ();
1607 if (for_method != 2)
1608 OB_PUTCP (name);
1609 /* Otherwise, we can divine that this is a constructor,
1610 and figure out its name without any extra encoding. */
1611
1612 OB_PUTC2 ('_', '_');
c27be9b9 1613 numeric_output_need_bar = 0;
386b8a85
JM
1614
1615 if (tparms)
1616 {
59e621fc 1617 OB_PUTC ('H');
386b8a85
JM
1618 build_template_parm_names (tparms, targs);
1619 OB_PUTC ('_');
1620 }
59e621fc
MM
1621 else if (!for_method && current_namespace == global_namespace)
1622 /* XXX this works only if we call this in the same namespace
1623 as the declaration. Unfortunately, we don't have the _DECL,
1624 only its name */
1625 OB_PUTC ('F');
26877584
JM
1626
1627 if (!for_method && current_namespace != global_namespace)
59e621fc 1628 /* qualify with namespace */
30394414
JM
1629 build_qualified_name (current_namespace);
1630
8d08fdba 1631 if (parms == NULL_TREE)
386b8a85 1632 OB_PUTC ('e');
8d08fdba 1633 else if (parms == void_list_node)
386b8a85 1634 OB_PUTC ('v');
8d08fdba
MS
1635 else
1636 {
407f03b8 1637 if (!flag_do_squangling)
ed22c95e 1638 {
407f03b8 1639 /* Allocate typevec array. */
9cd64686 1640 size_t typevec_size = list_length (parms);
ed22c95e 1641 maxtype = 0;
2c73f9f5 1642 if (!for_method && current_namespace != global_namespace)
407f03b8 1643 /* The namespace of a global function needs one slot. */
2c73f9f5 1644 typevec_size++;
9cd64686 1645 VARRAY_TREE_INIT (typevec, typevec_size, "typevec");
ed22c95e 1646 }
8d08fdba 1647 nofold = 0;
59e621fc 1648
8d08fdba
MS
1649 if (for_method)
1650 {
6eabb241 1651 tree this_type = TREE_TYPE (TREE_VALUE (parms));
59e621fc
MM
1652
1653 build_mangled_name_for_type (this_type);
1654
1655 if (!flag_do_squangling)
1656 {
9cd64686
MM
1657 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1658 VARRAY_TREE (typevec, maxtype) = this_type;
1659 maxtype++;
59e621fc 1660 }
8d08fdba
MS
1661
1662 if (TREE_CHAIN (parms))
ed22c95e 1663 build_mangled_name (TREE_CHAIN (parms), 0, 0);
8d08fdba 1664 else
386b8a85 1665 OB_PUTC ('e');
8d08fdba
MS
1666 }
1667 else
30394414
JM
1668 {
1669 /* the namespace qualifier for a global function
1670 will count as type */
1671 if (current_namespace != global_namespace
1672 && !flag_do_squangling)
2c73f9f5 1673 {
9cd64686
MM
1674 my_friendly_assert (maxtype < VARRAY_SIZE (typevec), 387);
1675 VARRAY_TREE (typevec, maxtype) = current_namespace;
1676 maxtype++;
2c73f9f5 1677 }
30394414
JM
1678 build_mangled_name (parms, 0, 0);
1679 }
ed22c95e 1680
407f03b8
JM
1681 if (!flag_do_squangling)
1682 /* Deallocate typevec array. */
9cd64686 1683 VARRAY_FREE (typevec);
8d08fdba 1684 }
386b8a85 1685
1f06b267 1686 if (ret_type != NULL_TREE && for_method != 2)
386b8a85
JM
1687 {
1688 /* Add the return type. */
1689 OB_PUTC ('_');
59e621fc 1690 build_mangled_name_for_type (ret_type);
386b8a85
JM
1691 }
1692
1693 OB_FINISH ();
ed22c95e 1694 end_squangling ();
8d08fdba
MS
1695 {
1696 tree n = get_identifier (obstack_base (&scratch_obstack));
1697 if (IDENTIFIER_OPNAME_P (dname))
1698 IDENTIFIER_OPNAME_P (n) = 1;
1699 return n;
1700 }
1701}
1702
386b8a85
JM
1703/* Change the name of a function definition so that it may be
1704 overloaded. NAME is the name of the function to overload,
1705 PARMS is the parameter list (which determines what name the
1706 final function obtains).
1707
1708 FOR_METHOD is 1 if this overload is being performed
1709 for a method, rather than a function type. It is 2 if
1710 this overload is being performed for a constructor. */
1711
1712tree
1713build_decl_overload (dname, parms, for_method)
1714 tree dname;
1715 tree parms;
1716 int for_method;
1717{
1718 return build_decl_overload_real (dname, parms, NULL_TREE, NULL_TREE,
1719 NULL_TREE, for_method);
1720}
1721
36a117a5 1722/* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
386b8a85 1723
c1def683 1724void
36a117a5 1725set_mangled_name_for_decl (decl)
9a68c51f 1726 tree decl;
386b8a85 1727{
6b4b3deb
MM
1728 tree parm_types;
1729
1730 if (processing_template_decl)
1731 /* There's no need to mangle the name of a template function. */
1732 return;
1733
1734 parm_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9a68c51f 1735
36a117a5
MM
1736 if (DECL_STATIC_FUNCTION_P (decl))
1737 parm_types =
4f1c5b7d 1738 hash_tree_chain (build_pointer_type (DECL_CONTEXT (decl)),
36a117a5
MM
1739 parm_types);
1740 else
1741 /* The only member functions whose type is a FUNCTION_TYPE, rather
1742 than a METHOD_TYPE, should be static members. */
1743 my_friendly_assert (!DECL_CONTEXT (decl)
1744 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl)))
1745 || TREE_CODE (TREE_TYPE (decl)) != FUNCTION_TYPE,
1746 0);
1747
1748 DECL_ASSEMBLER_NAME (decl)
1749 = build_decl_overload (DECL_NAME (decl), parm_types,
1750 DECL_FUNCTION_MEMBER_P (decl)
1751 + DECL_CONSTRUCTOR_P (decl));
386b8a85
JM
1752}
1753
8d08fdba 1754/* Build an overload name for the type expression TYPE. */
e92cc029 1755
8d08fdba
MS
1756tree
1757build_typename_overload (type)
1758 tree type;
1759{
1760 tree id;
1761
1762 OB_INIT ();
1763 OB_PUTID (ansi_opname[(int) TYPE_EXPR]);
1764 nofold = 1;
ed22c95e
AM
1765 start_squangling ();
1766 build_mangled_name (type, 0, 1);
8d08fdba
MS
1767 id = get_identifier (obstack_base (&scratch_obstack));
1768 IDENTIFIER_OPNAME_P (id) = 1;
a0a33927 1769#if 0
d2e5ee5c 1770 IDENTIFIER_GLOBAL_VALUE (id) = TYPE_MAIN_DECL (type);
a0a33927 1771#endif
51c184be 1772 TREE_TYPE (id) = type;
ed22c95e 1773 end_squangling ();
8d08fdba
MS
1774 return id;
1775}
1776
8d08fdba 1777tree
6b5fbb55
MS
1778build_overload_with_type (name, type)
1779 tree name, type;
8d08fdba
MS
1780{
1781 OB_INIT ();
6b5fbb55 1782 OB_PUTID (name);
8d08fdba
MS
1783 nofold = 1;
1784
ed22c95e
AM
1785 start_squangling ();
1786 build_mangled_name (type, 0, 1);
1787 end_squangling ();
8d08fdba
MS
1788 return get_identifier (obstack_base (&scratch_obstack));
1789}
1790
67d743fe
MS
1791tree
1792get_id_2 (name, name2)
9c0758dd 1793 const char *name;
67d743fe
MS
1794 tree name2;
1795{
1796 OB_INIT ();
1797 OB_PUTCP (name);
1798 OB_PUTID (name2);
1799 OB_FINISH ();
1800 return get_identifier (obstack_base (&scratch_obstack));
1801}
711734a9
JM
1802
1803/* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1804
1805tree
1806build_destructor_name (type)
1807 tree type;
1808{
1809 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX),
1810 type);
1811}
8d08fdba
MS
1812\f
1813/* Given a tree_code CODE, and some arguments (at least one),
1814 attempt to use an overloaded operator on the arguments.
1815
1816 For unary operators, only the first argument need be checked.
1817 For binary operators, both arguments may need to be checked.
1818
1819 Member functions can convert class references to class pointers,
1820 for one-level deep indirection. More than that is not supported.
1821 Operators [](), ()(), and ->() must be member functions.
1822
1823 We call function call building calls with LOOKUP_COMPLAIN if they
1824 are our only hope. This is true when we see a vanilla operator
1825 applied to something of aggregate type. If this fails, we are free
1826 to return `error_mark_node', because we will have reported the
1827 error.
1828
1829 Operators NEW and DELETE overload in funny ways: operator new takes
1830 a single `size' parameter, and operator delete takes a pointer to the
1831 storage being deleted. When overloading these operators, success is
1832 assumed. If there is a failure, report an error message and return
1833 `error_mark_node'. */
1834
1835/* NOSTRICT */
1836tree
1837build_opfncall (code, flags, xarg1, xarg2, arg3)
1838 enum tree_code code;
1839 int flags;
1840 tree xarg1, xarg2, arg3;
1841{
277294d7 1842 return build_new_op (code, flags, xarg1, xarg2, arg3);
8d08fdba
MS
1843}
1844\f
1845/* This function takes an identifier, ID, and attempts to figure out what
1846 it means. There are a number of possible scenarios, presented in increasing
1847 order of hair:
1848
1849 1) not in a class's scope
1850 2) in class's scope, member name of the class's method
1851 3) in class's scope, but not a member name of the class
1852 4) in class's scope, member name of a class's variable
1853
1854 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1855 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
8d08fdba
MS
1856
1857 As a last ditch, try to look up the name as a label and return that
1858 address.
1859
1860 Values which are declared as being of REFERENCE_TYPE are
1861 automatically dereferenced here (as a hack to make the
1862 compiler faster). */
1863
1864tree
5566b478 1865hack_identifier (value, name)
8d08fdba 1866 tree value, name;
8d08fdba 1867{
de22184b 1868 tree type;
8d08fdba 1869
bd6dd845 1870 if (value == error_mark_node)
8d08fdba
MS
1871 {
1872 if (current_class_name)
1873 {
1874 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1);
1875 if (fields == error_mark_node)
1876 return error_mark_node;
1877 if (fields)
1878 {
1879 tree fndecl;
1880
1881 fndecl = TREE_VALUE (fields);
1882 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
2c73f9f5
ML
1883 /* I could not trigger this code. MvL */
1884 my_friendly_abort (980325);
1885#ifdef DEAD
8d08fdba
MS
1886 if (DECL_CHAIN (fndecl) == NULL_TREE)
1887 {
8251199e 1888 warning ("methods cannot be converted to function pointers");
8d08fdba
MS
1889 return fndecl;
1890 }
1891 else
1892 {
8251199e 1893 error ("ambiguous request for method pointer `%s'",
8d08fdba
MS
1894 IDENTIFIER_POINTER (name));
1895 return error_mark_node;
1896 }
2c73f9f5 1897#endif
8d08fdba
MS
1898 }
1899 }
1900 if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name))
1901 {
1902 return IDENTIFIER_LABEL_VALUE (name);
1903 }
1904 return error_mark_node;
1905 }
1906
1907 type = TREE_TYPE (value);
1908 if (TREE_CODE (value) == FIELD_DECL)
1909 {
4ac14744 1910 if (current_class_ptr == NULL_TREE)
8d08fdba 1911 {
672476cb
MM
1912 if (current_function_decl
1913 && DECL_STATIC_FUNCTION_P (current_function_decl))
8251199e 1914 cp_error ("invalid use of member `%D' in static member function",
672476cb
MM
1915 value);
1916 else
1917 /* We can get here when processing a bad default
1918 argument, like:
1919 struct S { int a; void f(int i = a); } */
8251199e 1920 cp_error ("invalid use of member `%D'", value);
672476cb 1921
8d08fdba
MS
1922 return error_mark_node;
1923 }
4ac14744 1924 TREE_USED (current_class_ptr) = 1;
a5894242 1925
8d08fdba
MS
1926 /* Mark so that if we are in a constructor, and then find that
1927 this field was initialized by a base initializer,
1928 we can emit an error message. */
1929 TREE_USED (value) = 1;
4ac14744 1930 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
8d08fdba 1931 }
8f032717
MM
1932 else if ((TREE_CODE (value) == FUNCTION_DECL
1933 && DECL_FUNCTION_MEMBER_P (value))
1934 || (TREE_CODE (value) == OVERLOAD
1935 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
51924768
JM
1936 {
1937 tree decl;
1938
8f032717
MM
1939 if (TREE_CODE (value) == OVERLOAD)
1940 value = OVL_CURRENT (value);
1941
4f1c5b7d 1942 decl = maybe_dummy_object (DECL_CONTEXT (value), 0);
51924768
JM
1943 value = build_component_ref (decl, name, NULL_TREE, 1);
1944 }
6b5fbb55 1945 else if (really_overloaded_fn (value))
8f032717 1946 ;
2c73f9f5
ML
1947 else if (TREE_CODE (value) == OVERLOAD)
1948 /* not really overloaded function */
1949 mark_used (OVL_FUNCTION (value));
a5ef9010
JM
1950 else if (TREE_CODE (value) == TREE_LIST)
1951 {
72b7eeff 1952 /* Ambiguous reference to base members, possibly other cases?. */
a5ef9010
JM
1953 tree t = value;
1954 while (t && TREE_CODE (t) == TREE_LIST)
1955 {
72b7eeff 1956 mark_used (TREE_VALUE (t));
a5ef9010
JM
1957 t = TREE_CHAIN (t);
1958 }
1959 }
2c73f9f5 1960 else if (TREE_CODE (value) == NAMESPACE_DECL)
0e607f34 1961 {
8251199e 1962 cp_error ("use of namespace `%D' as expression", value);
0e607f34
JM
1963 return error_mark_node;
1964 }
1965 else if (DECL_CLASS_TEMPLATE_P (value))
1966 {
8251199e 1967 cp_error ("use of class template `%T' as expression", value);
0e607f34
JM
1968 return error_mark_node;
1969 }
8d08fdba 1970 else
72b7eeff 1971 mark_used (value);
8d08fdba 1972
c6882a35
JM
1973 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
1974 || TREE_CODE (value) == RESULT_DECL)
5566b478
MS
1975 {
1976 tree context = decl_function_context (value);
1977 if (context != NULL_TREE && context != current_function_decl
1978 && ! TREE_STATIC (value))
1979 {
8251199e 1980 cp_error ("use of %s from containing function",
5566b478
MS
1981 (TREE_CODE (value) == VAR_DECL
1982 ? "`auto' variable" : "parameter"));
8251199e 1983 cp_error_at (" `%#D' declared here", value);
e76a2646 1984 value = error_mark_node;
5566b478
MS
1985 }
1986 }
1987
2f939d94 1988 if (DECL_P (value) && DECL_NONLOCAL (value))
8d08fdba 1989 {
70adf8a9 1990 if (DECL_CLASS_SCOPE_P (value)
4f1c5b7d 1991 && DECL_CONTEXT (value) != current_class_type)
8d08fdba 1992 {
d6479fe7 1993 tree path;
4f1c5b7d 1994 path = currently_open_derived_class (DECL_CONTEXT (value));
70adf8a9 1995 enforce_access (path, value);
8d08fdba 1996 }
8d08fdba 1997 }
280f9385
MM
1998 else if (TREE_CODE (value) == TREE_LIST
1999 && TREE_TYPE (value) == error_mark_node)
8d08fdba 2000 {
0cfdd854
ML
2001 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
2002 IDENTIFIER_POINTER (name));
66543169 2003 print_candidates (value);
0cfdd854 2004 return error_mark_node;
8d08fdba
MS
2005 }
2006
75d587eb 2007 if (! processing_template_decl)
6b5fbb55 2008 value = convert_from_reference (value);
8d08fdba
MS
2009 return value;
2010}
2011
8926095f 2012\f
8926095f 2013tree
c0bbf652 2014make_thunk (function, delta, vcall_index)
8926095f
MS
2015 tree function;
2016 int delta;
c0bbf652 2017 int vcall_index;
8926095f 2018{
b87692e5 2019 tree thunk_id;
8926095f 2020 tree thunk;
8926095f 2021 tree func_decl;
cc600f33 2022
8926095f
MS
2023 if (TREE_CODE (function) != ADDR_EXPR)
2024 abort ();
2025 func_decl = TREE_OPERAND (function, 0);
2026 if (TREE_CODE (func_decl) != FUNCTION_DECL)
2027 abort ();
cc600f33
JM
2028
2029 OB_INIT ();
2030 OB_PUTS ("__thunk_");
2031 if (delta > 0)
2032 {
2033 OB_PUTC ('n');
2034 icat (delta);
2035 }
5edb8b93 2036 else
cc600f33
JM
2037 icat (-delta);
2038 OB_PUTC ('_');
2039 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl));
c0bbf652
MM
2040 if (vcall_index)
2041 {
2042 OB_PUTC ('_');
2043 icat (vcall_index);
2044 }
cc600f33
JM
2045 OB_FINISH ();
2046 thunk_id = get_identifier (obstack_base (&scratch_obstack));
2047
a0a33927
MS
2048 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
2049 if (thunk && TREE_CODE (thunk) != THUNK_DECL)
2050 {
8251199e 2051 cp_error ("implementation-reserved name `%D' used", thunk_id);
2c73f9f5
ML
2052 thunk = NULL_TREE;
2053 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
a0a33927
MS
2054 }
2055 if (thunk == NULL_TREE)
2056 {
eb448459
MS
2057 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
2058 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
2059 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
7fcdf4c2 2060 comdat_linkage (thunk);
72b7eeff 2061 TREE_SET_CODE (thunk, THUNK_DECL);
a0a33927
MS
2062 DECL_INITIAL (thunk) = function;
2063 THUNK_DELTA (thunk) = delta;
c0bbf652
MM
2064 THUNK_VCALL_OFFSET (thunk)
2065 = vcall_index * TREE_INT_CST_LOW (TYPE_SIZE (vtable_entry_type));
72b7eeff 2066 DECL_EXTERNAL (thunk) = 1;
eb448459 2067 DECL_ARTIFICIAL (thunk) = 1;
a0a33927
MS
2068 /* So that finish_file can write out any thunks that need to be: */
2069 pushdecl_top_level (thunk);
2070 }
8926095f
MS
2071 return thunk;
2072}
2073
eb448459
MS
2074/* Emit the definition of a C++ multiple inheritance vtable thunk. */
2075
8926095f
MS
2076void
2077emit_thunk (thunk_fndecl)
824b9a4c 2078 tree thunk_fndecl;
8926095f 2079{
8926095f
MS
2080 tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0);
2081 int delta = THUNK_DELTA (thunk_fndecl);
8926095f
MS
2082
2083 if (TREE_ASM_WRITTEN (thunk_fndecl))
2084 return;
2085
a0a33927
MS
2086 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
2087
809c8c30
JM
2088 TREE_ADDRESSABLE (function) = 1;
2089 mark_used (function);
2090
8926095f
MS
2091 if (current_function_decl)
2092 abort ();
a0128b67
MS
2093
2094 TREE_SET_CODE (thunk_fndecl, FUNCTION_DECL);
eb66be0e 2095
a80e4195 2096#ifdef ASM_OUTPUT_MI_THUNK
3b62f224
MM
2097 if (!flag_syntax_only)
2098 {
3cce094d 2099 const char *fnname;
3b62f224
MM
2100 current_function_decl = thunk_fndecl;
2101 /* Make sure we build up its RTL before we go onto the
2102 temporary obstack. */
2103 make_function_rtl (thunk_fndecl);
3b62f224
MM
2104 DECL_RESULT (thunk_fndecl)
2105 = build_decl (RESULT_DECL, 0, integer_type_node);
2106 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
2107 init_function_start (thunk_fndecl, input_filename, lineno);
2108 current_function_is_thunk = 1;
2109 assemble_start_function (thunk_fndecl, fnname);
2110 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
2111 assemble_end_function (thunk_fndecl, fnname);
3b62f224 2112 current_function_decl = 0;
01d939e8 2113 cfun = 0;
3b62f224 2114 }
eb66be0e 2115#else /* ASM_OUTPUT_MI_THUNK */
3b62f224 2116 {
eb448459
MS
2117 /* If we don't have the necessary macro for efficient thunks, generate a
2118 thunk function that just makes a call to the real function.
2119 Unfortunately, this doesn't work for varargs. */
2120
eb66be0e 2121 tree a, t;
8926095f 2122
eb448459 2123 if (varargs_function_p (function))
8251199e 2124 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
eb448459
MS
2125 function);
2126
eb66be0e
MS
2127 /* Set up clone argument trees for the thunk. */
2128 t = NULL_TREE;
2129 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
2130 {
2131 tree x = copy_node (a);
2132 TREE_CHAIN (x) = t;
2133 DECL_CONTEXT (x) = thunk_fndecl;
2134 t = x;
2135 }
2136 a = nreverse (t);
2137 DECL_ARGUMENTS (thunk_fndecl) = a;
2138 DECL_RESULT (thunk_fndecl) = NULL_TREE;
eb448459
MS
2139 DECL_LANG_SPECIFIC (thunk_fndecl) = DECL_LANG_SPECIFIC (function);
2140 copy_lang_decl (thunk_fndecl);
2141 DECL_INTERFACE_KNOWN (thunk_fndecl) = 1;
2142 DECL_NOT_REALLY_EXTERN (thunk_fndecl) = 1;
eb66be0e 2143
a8f73d4b
MM
2144 start_function (NULL_TREE, thunk_fndecl, NULL_TREE,
2145 SF_DEFAULT | SF_PRE_PARSED);
eb66be0e 2146 store_parm_decls ();
eb448459 2147 current_function_is_thunk = 1;
eb66be0e
MS
2148
2149 /* Build up the call to the real function. */
2150 t = build_int_2 (delta, -1 * (delta < 0));
2151 TREE_TYPE (t) = signed_type (sizetype);
2152 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
e1b3e07d 2153 t = tree_cons (NULL_TREE, t, NULL_TREE);
eb66be0e 2154 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
e1b3e07d 2155 t = tree_cons (NULL_TREE, a, t);
eb66be0e 2156 t = nreverse (t);
0c11ada6 2157 t = build_call (function, t);
62409b39 2158 finish_return_stmt (t);
eb66be0e 2159
b35d4555 2160 expand_body (finish_function (lineno, 0));
4d6efa25
JM
2161
2162 /* Don't let the backend defer this function. */
2163 if (DECL_DEFER_OUTPUT (thunk_fndecl))
cd9f6678 2164 output_inline_function (thunk_fndecl);
eb448459 2165 }
3b62f224 2166#endif /* ASM_OUTPUT_MI_THUNK */
8926095f 2167
eb66be0e 2168 TREE_SET_CODE (thunk_fndecl, THUNK_DECL);
8926095f 2169}
f376e137
MS
2170\f
2171/* Code for synthesizing methods which have default semantics defined. */
2172
f376e137 2173/* Generate code for default X(X&) constructor. */
e92cc029 2174
824b9a4c 2175static void
db5ae43f 2176do_build_copy_constructor (fndecl)
f376e137
MS
2177 tree fndecl;
2178{
2179 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
2180 tree t;
2181
f376e137
MS
2182 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
2183 parm = TREE_CHAIN (parm);
2184 parm = convert_from_reference (parm);
2185
a59ca936
JM
2186 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
2187 && is_empty_class (current_class_type))
2188 /* Don't copy the padding byte; it might not have been allocated
2189 if *this is a base subobject. */;
2190 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
f376e137 2191 {
4ac14744 2192 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
f1dedc31 2193 finish_expr_stmt (t);
f376e137
MS
2194 }
2195 else
2196 {
2197 tree fields = TYPE_FIELDS (current_class_type);
2198 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2199 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2200 int i;
2201
1b5f5f76 2202 /* Initialize all the base-classes. */
f376e137
MS
2203 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
2204 t = TREE_CHAIN (t))
1b5f5f76
MM
2205 current_base_init_list
2206 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
f376e137
MS
2207 for (i = 0; i < n_bases; ++i)
2208 {
1b5f5f76
MM
2209 t = TREE_VEC_ELT (binfos, i);
2210 if (TREE_VIA_VIRTUAL (t))
8ccc31eb 2211 continue;
f376e137 2212
1b5f5f76
MM
2213 current_base_init_list
2214 = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
f376e137 2215 }
1b5f5f76 2216
f376e137
MS
2217 for (; fields; fields = TREE_CHAIN (fields))
2218 {
de22184b 2219 tree init, t;
a5894242
MS
2220 tree field = fields;
2221
2222 if (TREE_CODE (field) != FIELD_DECL)
f376e137 2223 continue;
8dff1027
MS
2224
2225 init = parm;
a5894242 2226 if (DECL_NAME (field))
f376e137 2227 {
a5894242 2228 if (VFIELD_NAME_P (DECL_NAME (field)))
f376e137 2229 continue;
a5894242 2230 if (VBASE_NAME_P (DECL_NAME (field)))
f376e137
MS
2231 continue;
2232
2233 /* True for duplicate members. */
a5894242 2234 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
f376e137
MS
2235 continue;
2236 }
a5894242 2237 else if ((t = TREE_TYPE (field)) != NULL_TREE
6bdb8141 2238 && ANON_AGGR_TYPE_P (t)
0171aeab 2239 && TYPE_FIELDS (t) != NULL_TREE)
6bdb8141
JM
2240 /* Just use the field; anonymous types can't have
2241 nontrivial copy ctors or assignment ops. */;
0171aeab
JM
2242 else
2243 continue;
f376e137 2244
8dff1027 2245 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
f376e137
MS
2246 init = build_tree_list (NULL_TREE, init);
2247
2248 current_member_init_list
6bdb8141 2249 = tree_cons (field, init, current_member_init_list);
f376e137
MS
2250 }
2251 current_member_init_list = nreverse (current_member_init_list);
faae18ab 2252 current_base_init_list = nreverse (current_base_init_list);
f376e137
MS
2253 setup_vtbl_ptr ();
2254 }
f376e137
MS
2255}
2256
824b9a4c 2257static void
db5ae43f 2258do_build_assign_ref (fndecl)
f376e137
MS
2259 tree fndecl;
2260{
2261 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
f1dedc31 2262 tree compound_stmt;
f376e137 2263
f1dedc31 2264 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
f376e137
MS
2265 parm = convert_from_reference (parm);
2266
a59ca936
JM
2267 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
2268 && is_empty_class (current_class_type))
2269 /* Don't copy the padding byte; it might not have been allocated
2270 if *this is a base subobject. */;
2271 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
f376e137 2272 {
4ac14744 2273 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
f1dedc31 2274 finish_expr_stmt (t);
f376e137
MS
2275 }
2276 else
2277 {
2278 tree fields = TYPE_FIELDS (current_class_type);
2279 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
2280 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
2281 int i;
2282
2283 for (i = 0; i < n_bases; ++i)
2284 {
2285 tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
e349ee73
MS
2286 tree p = convert_to_reference
2287 (build_reference_type (basetype), parm,
2288 CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
2289 p = convert_from_reference (p);
2290 p = build_member_call (basetype, ansi_opname [MODIFY_EXPR],
051e6fd7 2291 build_tree_list (NULL_TREE, p));
62409b39 2292 finish_expr_stmt (p);
f376e137
MS
2293 }
2294 for (; fields; fields = TREE_CHAIN (fields))
2295 {
0171aeab 2296 tree comp, init, t;
a5894242
MS
2297 tree field = fields;
2298
2299 if (TREE_CODE (field) != FIELD_DECL)
f376e137 2300 continue;
e349ee73 2301
1b8899d1 2302 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
e349ee73
MS
2303 {
2304 if (DECL_NAME (field))
8251199e 2305 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
e349ee73 2306 else
8251199e 2307 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type);
e349ee73
MS
2308 continue;
2309 }
2310 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
2311 {
2312 if (DECL_NAME (field))
8251199e 2313 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
e349ee73 2314 else
8251199e 2315 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type);
e349ee73
MS
2316 continue;
2317 }
2318
8dff1027
MS
2319 comp = current_class_ref;
2320 init = parm;
2321
a5894242 2322 if (DECL_NAME (field))
f376e137 2323 {
a5894242 2324 if (VFIELD_NAME_P (DECL_NAME (field)))
f376e137 2325 continue;
a5894242 2326 if (VBASE_NAME_P (DECL_NAME (field)))
f376e137
MS
2327 continue;
2328
2329 /* True for duplicate members. */
a5894242 2330 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
f376e137
MS
2331 continue;
2332 }
a5894242 2333 else if ((t = TREE_TYPE (field)) != NULL_TREE
6bdb8141 2334 && ANON_AGGR_TYPE_P (t)
0171aeab 2335 && TYPE_FIELDS (t) != NULL_TREE)
6bdb8141
JM
2336 /* Just use the field; anonymous types can't have
2337 nontrivial copy ctors or assignment ops. */;
0171aeab
JM
2338 else
2339 continue;
f376e137 2340
8dff1027
MS
2341 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
2342 init = build (COMPONENT_REF, TREE_TYPE (field), init, field);
f376e137 2343
62409b39 2344 finish_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
f376e137
MS
2345 }
2346 }
62409b39 2347 finish_return_stmt (current_class_ref);
f1dedc31 2348 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
f376e137
MS
2349}
2350
2351void
db5ae43f 2352synthesize_method (fndecl)
f376e137
MS
2353 tree fndecl;
2354{
db5ae43f 2355 int nested = (current_function_decl != NULL_TREE);
4f1c5b7d 2356 tree context = decl_function_context (fndecl);
62409b39 2357 int need_body = 1;
db5ae43f 2358
b7067a12
JM
2359 if (at_eof)
2360 import_export_decl (fndecl);
2361
9a3b49ac
MS
2362 if (! context)
2363 push_to_top_level ();
2364 else if (nested)
99dccabc 2365 push_function_context_to (context);
db5ae43f 2366
62409b39
MM
2367 /* Put the function definition at the position where it is needed,
2368 rather than within the body of the class. That way, an error
2369 during the generation of the implicit body points at the place
2370 where the attempt to generate the function occurs, giving the
2371 user a hint as to why we are attempting to generate the
2372 function. */
2373 DECL_SOURCE_LINE (fndecl) = lineno;
2374 DECL_SOURCE_FILE (fndecl) = input_filename;
2375
e76a2646 2376 interface_unknown = 1;
a8f73d4b 2377 start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
f376e137 2378 store_parm_decls ();
f1dedc31 2379 clear_last_expr ();
db5ae43f
MS
2380
2381 if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR])
62409b39
MM
2382 {
2383 do_build_assign_ref (fndecl);
2384 need_body = 0;
2385 }
9eb71d8c 2386 else if (DECL_DESTRUCTOR_P (fndecl))
018fc244 2387 setup_vtbl_ptr ();
db5ae43f
MS
2388 else
2389 {
2390 tree arg_chain = FUNCTION_ARG_CHAIN (fndecl);
2391 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl))
2392 arg_chain = TREE_CHAIN (arg_chain);
2393 if (arg_chain != void_list_node)
2394 do_build_copy_constructor (fndecl);
2395 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
62409b39
MM
2396 setup_vtbl_ptr ();
2397 }
f18a14bc 2398
62409b39
MM
2399 /* If we haven't yet generated the body of the function, just
2400 generate an empty compound statement. */
2401 if (need_body)
2402 {
2403 tree compound_stmt;
2404 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
2405 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
db5ae43f
MS
2406 }
2407
b35d4555 2408 expand_body (finish_function (lineno, 0));
28cbf42c 2409
db5ae43f 2410 extract_interface_info ();
9a3b49ac
MS
2411 if (! context)
2412 pop_from_top_level ();
2413 else if (nested)
99dccabc 2414 pop_function_context_from (context);
f376e137 2415}
9eb71d8c
MM
2416
2417/* Implicitly declare the special function indicated by KIND, as a
2418 member of TYPE. For copy constructors and assignment operators,
2419 CONST_P indicates whether these functions should take a const
2420 reference argument or a non-const reference. */
2421
2422tree
2423implicitly_declare_fn (kind, type, const_p)
2424 special_function_kind kind;
2425 tree type;
2426 int const_p;
2427{
2428 tree declspecs = NULL_TREE;
2429 tree fn, args = NULL_TREE;
2430 tree argtype;
2431 int retref = 0;
2432 tree name = constructor_name (TYPE_IDENTIFIER (type));
2433
2434 switch (kind)
2435 {
2436 /* Destructors. */
2437 case sfk_destructor:
2438 name = build_parse_node (BIT_NOT_EXPR, name);
2439 args = void_list_node;
2440 break;
2441
2442 case sfk_constructor:
2443 /* Default constructor. */
2444 args = void_list_node;
2445 break;
2446
2447 case sfk_copy_constructor:
2448 if (const_p)
2449 type = build_qualified_type (type, TYPE_QUAL_CONST);
2450 argtype = build_reference_type (type);
2451 args = tree_cons (NULL_TREE,
2452 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2453 get_identifier ("_ctor_arg")),
2454 void_list_node);
2455 break;
2456
2457 case sfk_assignment_operator:
2458 retref = 1;
2459 declspecs = build_decl_list (NULL_TREE, type);
2460
2461 if (const_p)
2462 type = build_qualified_type (type, TYPE_QUAL_CONST);
2463
2464 name = ansi_opname [(int) MODIFY_EXPR];
2465
2466 argtype = build_reference_type (type);
2467 args = tree_cons (NULL_TREE,
2468 build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2469 get_identifier ("_ctor_arg")),
2470 void_list_node);
2471 break;
2472
2473 default:
2474 my_friendly_abort (59);
2475 }
2476
2477 TREE_PARMLIST (args) = 1;
2478
2479 {
2480 tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE);
2481 if (retref)
2482 declarator = build_parse_node (ADDR_EXPR, declarator);
2483
2484 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
2485 }
2486
2487 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 20000408);
2488
2489 if (kind != sfk_constructor && kind != sfk_destructor)
2490 SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn)));
2491 SET_DECL_ARTIFICIAL (fn);
2492 DECL_NOT_REALLY_EXTERN (fn) = 1;
2493 DECL_THIS_INLINE (fn) = 1;
2494 DECL_INLINE (fn) = 1;
2495 defer_fn (fn);
2496
2497 return fn;
2498}
This page took 0.944815 seconds and 5 git commands to generate.