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