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