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 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 #ifndef PARM_CAN_BE_ARRAY_TYPE
29 #define PARM_CAN_BE_ARRAY_TYPE 1
32 /* Handle method declarations. */
41 #include "hard-reg-set.h"
45 /* TREE_LIST of the current inline functions that need to be
47 struct pending_inline
*pending_inlines
;
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
54 /* Obstack where we build text strings for overloading, etc. */
55 static struct obstack scratch_obstack
;
56 static char *scratch_firstobj
;
58 static void icat
PROTO((HOST_WIDE_INT
));
59 static void dicat
PROTO((HOST_WIDE_INT
, HOST_WIDE_INT
));
60 static void flush_repeats
PROTO((int, tree
));
61 static void build_overload_identifier
PROTO((tree
));
62 static void build_overload_nested_name
PROTO((tree
));
63 static void build_overload_int
PROTO((tree
, int));
64 static void build_overload_identifier
PROTO((tree
));
65 static void build_qualified_name
PROTO((tree
));
66 static void build_overload_value
PROTO((tree
, tree
, int));
67 static void issue_nrepeats
PROTO((int, tree
));
68 static char *build_mangled_name
PROTO((tree
,int,int));
69 static void process_modifiers
PROTO((tree
));
70 static void process_overload_item
PROTO((tree
,int));
71 static void do_build_assign_ref
PROTO((tree
));
72 static void do_build_copy_constructor
PROTO((tree
));
73 static tree largest_union_member
PROTO((tree
));
74 static void build_template_template_parm_names
PROTO((tree
));
75 static void build_template_parm_names
PROTO((tree
, tree
));
76 static void build_underscore_int
PROTO((int));
77 static void start_squangling
PROTO((void));
78 static void end_squangling
PROTO((void));
79 static int check_ktype
PROTO((tree
, int));
80 static int issue_ktype
PROTO((tree
));
81 static void build_overload_scope_ref
PROTO((tree
));
82 static void build_mangled_template_parm_index
PROTO((char *, tree
));
83 static int is_back_referenceable_type
PROTO((tree
));
84 static int check_btype
PROTO((tree
));
85 static void build_mangled_name_for_type
PROTO((tree
));
86 static void build_mangled_name_for_type_with_Gcode
PROTO((tree
, int));
88 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
89 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
90 # define OB_PUTC2(C1,C2) \
91 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
92 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
93 # define OB_PUTID(ID) \
94 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
95 IDENTIFIER_LENGTH (ID)))
96 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
97 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
98 # define OB_LAST() (obstack_next_free (&scratch_obstack)[-1])
103 gcc_obstack_init (&scratch_obstack
);
104 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
107 /* This must be large enough to hold any printed integer or floating-point
109 static char digit_buffer
[128];
111 /* Move inline function definitions out of structure so that they
112 can be processed normally. CNAME is the name of the class
113 we are working from, METHOD_LIST is the list of method lists
114 of the structure. We delete friend methods here, after
115 saving away their inline function definitions (if any). */
118 do_inline_function_hair (type
, friend_list
)
119 tree type
, friend_list
;
121 tree method
= TYPE_METHODS (type
);
123 if (method
&& TREE_CODE (method
) == TREE_VEC
)
125 if (TREE_VEC_ELT (method
, 1))
126 method
= TREE_VEC_ELT (method
, 1);
127 else if (TREE_VEC_ELT (method
, 0))
128 method
= TREE_VEC_ELT (method
, 0);
130 method
= TREE_VEC_ELT (method
, 2);
135 /* Do inline member functions. */
136 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (method
);
141 my_friendly_assert (info
->fndecl
== method
, 238);
142 args
= DECL_ARGUMENTS (method
);
145 DECL_CONTEXT (args
) = method
;
146 args
= TREE_CHAIN (args
);
149 method
= TREE_CHAIN (method
);
153 tree fndecl
= TREE_VALUE (friend_list
);
154 struct pending_inline
*info
= DECL_PENDING_INLINE_INFO (fndecl
);
159 my_friendly_assert (info
->fndecl
== fndecl
, 239);
160 args
= DECL_ARGUMENTS (fndecl
);
163 DECL_CONTEXT (args
) = fndecl
;
164 args
= TREE_CHAIN (args
);
168 friend_list
= TREE_CHAIN (friend_list
);
172 /* Here is where overload code starts. */
174 /* type tables for K and B type compression */
175 static tree
*btypelist
= NULL
;
176 static tree
*ktypelist
= NULL
;
177 static int maxbsize
= 0;
178 static int maxksize
= 0;
180 /* number of each type seen */
181 static int maxbtype
= 0;
182 static int maxktype
= 0;
184 /* Array of types seen so far in top-level call to `build_mangled_name'.
185 Allocated and deallocated by caller. */
186 static tree
*typevec
= NULL
;
187 static int typevec_size
;
189 /* Number of types interned by `build_mangled_name' so far. */
190 static int maxtype
= 0;
192 /* Nonzero if we should not try folding parameter types. */
195 /* This appears to be set to true if an underscore is required to be
196 comcatenated before another number can be outputed. */
197 static int numeric_output_need_bar
;
202 if (flag_do_squangling
)
209 btypelist
= (tree
*)xmalloc (sizeof (tree
) * maxbsize
);
210 ktypelist
= (tree
*)xmalloc (sizeof (tree
) * maxksize
);
217 if (flag_do_squangling
)
232 /* Code to concatenate an asciified integer to a string. */
238 unsigned HOST_WIDE_INT ui
;
240 /* Handle this case first, to go really quickly. For many common values,
241 the result of ui/10 below is 1. */
259 OB_PUTC ('0' + (ui
% 10));
264 HOST_WIDE_INT lo
, hi
;
266 unsigned HOST_WIDE_INT ulo
, uhi
, qlo
, qhi
;
275 uhi
= (lo
== 0 ? -hi
: -hi
-1);
279 && ulo
< ((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)))
284 /* Divide 2^HOST_WIDE_INT*uhi+ulo by 10. */
287 qlo
= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) / 5);
290 ulo
+= uhi
* (((unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
- 1)) % 5)
294 /* Quotient is 2^HOST_WIDE_INT*qhi+qlo, remainder is ulo. */
300 flush_repeats (nrepeats
, type
)
306 while (typevec
[tindex
] != type
)
323 /* Returns nonzero iff this is a type to which we will want to make
324 back-references (using the `B' code). */
327 is_back_referenceable_type (type
)
330 if (btypelist
== NULL
)
331 /* We're not generating any back-references. */
334 switch (TREE_CODE (type
))
340 /* These types have single-character manglings, so there's no
341 point in generating back-references. */
344 case TEMPLATE_TYPE_PARM
:
345 /* It would be a bit complex to demangle signatures correctly if
346 we generated back-references to these, and the manglings of
347 type parameters are short. */
355 /* Issue the squangling code indicating NREPEATS repetitions of TYPE,
356 which was the last parameter type output. */
359 issue_nrepeats (nrepeats
, type
)
363 if (nrepeats
== 1 && !is_back_referenceable_type (type
))
364 /* For types whose manglings are short, don't bother using the
365 repetition code if there's only one repetition, since the
366 repetition code will be about as long as the ordinary mangling. */
367 build_mangled_name_for_type (type
);
377 /* Check to see if a tree node has been entered into the Kcode typelist */
378 /* if not, add it. Return -1 if it isn't found, otherwise return the index */
380 check_ktype (node
, add
)
385 tree localnode
= node
;
387 if (ktypelist
== NULL
)
390 if (TREE_CODE (node
) == TYPE_DECL
)
391 localnode
= TREE_TYPE (node
);
393 for (x
=0; x
< maxktype
; x
++)
395 if (localnode
== ktypelist
[x
])
398 /* Didn't find it, so add it here */
401 if (maxksize
<= maxktype
)
403 maxksize
= maxksize
* 3 / 2;
404 ktypelist
= (tree
*)xrealloc (ktypelist
, sizeof (tree
) * maxksize
);
406 ktypelist
[maxktype
++] = localnode
;
417 kindex
= check_ktype (decl
, FALSE
);
429 /* Build a representation for DECL, which may be an entity not at
430 global scope. If so, a marker indicating that the name is
431 qualified has already been output, but the qualifying context has
435 build_overload_nested_name (decl
)
440 if (ktypelist
&& issue_ktype (decl
))
443 if (decl
== global_namespace
)
446 context
= CP_DECL_CONTEXT (decl
);
448 /* try to issue a K type, and if we can't continue the normal path */
449 if (!(ktypelist
&& issue_ktype (context
)))
451 /* For a template type parameter, we want to output an 'Xn'
452 rather than 'T' or some such. */
453 if (TREE_CODE (context
) == TEMPLATE_TYPE_PARM
454 || TREE_CODE (context
) == TEMPLATE_TEMPLATE_PARM
)
455 build_mangled_name_for_type (context
);
458 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
459 context
= TYPE_NAME (context
);
460 build_overload_nested_name (context
);
464 if (TREE_CODE (decl
) == FUNCTION_DECL
)
466 tree name
= DECL_ASSEMBLER_NAME (decl
);
469 ASM_FORMAT_PRIVATE_NAME (label
, IDENTIFIER_POINTER (name
), static_labelno
);
472 if (numeric_output_need_bar
)
474 icat (strlen (label
));
476 numeric_output_need_bar
= 1;
478 else if (TREE_CODE (decl
) == NAMESPACE_DECL
)
479 build_overload_identifier (DECL_NAME (decl
));
481 build_overload_identifier (decl
);
484 /* Output the decimal representation of I. If I > 9, the decimal
485 representation is preceeded and followed by an underscore. */
488 build_underscore_int (i
)
499 build_overload_scope_ref (value
)
503 numeric_output_need_bar
= 0;
504 build_mangled_name_for_type (TREE_OPERAND (value
, 0));
505 build_overload_identifier (TREE_OPERAND (value
, 1));
508 /* Encoding for an INTEGER_CST value. */
511 build_overload_int (value
, in_template
)
515 if (in_template
&& TREE_CODE (value
) != INTEGER_CST
)
517 if (TREE_CODE (value
) == SCOPE_REF
)
519 build_overload_scope_ref (value
);
524 numeric_output_need_bar
= 0;
526 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (value
))))
529 int operands
= tree_code_length
[(int) TREE_CODE (value
)];
533 id
= ansi_opname
[(int) TREE_CODE (value
)];
534 my_friendly_assert (id
!= NULL_TREE
, 0);
535 name
= IDENTIFIER_POINTER (id
);
536 if (name
[0] != '_' || name
[1] != '_')
537 /* On some erroneous inputs, we can get here with VALUE a
538 LOOKUP_EXPR. In that case, the NAME will be the
539 identifier for "<invalid operator>". We must survive
540 this routine in order to issue a sensible error
541 message, so we fall through to the case below. */
544 for (i
= 0; i
< operands
; ++i
)
549 /* We just outputted either the `E' or the name of the
551 numeric_output_need_bar
= 0;
554 /* Skip the leading underscores. */
557 operand
= TREE_OPERAND (value
, i
);
558 tc
= TREE_CODE (operand
);
560 if (TREE_CODE_CLASS (tc
) == 't')
561 /* We can get here with sizeof, e.g.:
563 template <class T> void f(A<sizeof(T)>); */
564 build_mangled_name_for_type (operand
);
565 else if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (tc
)))
566 build_overload_int (operand
, in_template
);
568 build_overload_value (TREE_TYPE (operand
),
575 /* We don't ever want this output, but it's
576 inconvenient not to be able to build the string.
577 This should cause assembler errors we'll notice. */
581 sprintf (digit_buffer
, " *%d", n
++);
582 OB_PUTCP (digit_buffer
);
586 numeric_output_need_bar
= 0;
590 my_friendly_assert (TREE_CODE (value
) == INTEGER_CST
, 243);
591 if (TYPE_PRECISION (TREE_TYPE (value
)) == 2 * HOST_BITS_PER_WIDE_INT
)
593 if (TREE_INT_CST_HIGH (value
)
594 != (TREE_INT_CST_LOW (value
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
596 /* need to print a DImode value in decimal */
597 dicat (TREE_INT_CST_LOW (value
), TREE_INT_CST_HIGH (value
));
598 numeric_output_need_bar
= 1;
601 /* else fall through to print in smaller mode */
603 /* Wordsize or smaller */
604 icat (TREE_INT_CST_LOW (value
));
605 numeric_output_need_bar
= 1;
609 /* Output S followed by a representation of the TEMPLATE_PARM_INDEX
610 supplied in INDEX. */
613 build_mangled_template_parm_index (s
, index
)
618 build_underscore_int (TEMPLATE_PARM_IDX (index
));
619 /* We use the LEVEL, not the ORIG_LEVEL, because the mangling is a
620 representation of the function from the point of view of its
622 build_underscore_int (TEMPLATE_PARM_LEVEL (index
));
627 build_overload_value (type
, value
, in_template
)
631 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (type
)) == 't', 0);
633 while (TREE_CODE (value
) == NON_LVALUE_EXPR
634 || TREE_CODE (value
) == NOP_EXPR
)
635 value
= TREE_OPERAND (value
, 0);
637 if (numeric_output_need_bar
)
640 numeric_output_need_bar
= 0;
643 if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
645 build_mangled_template_parm_index ("Y", value
);
649 if (TYPE_PTRMEM_P (type
))
651 if (TREE_CODE (value
) != PTRMEM_CST
)
652 /* We should have already rejected this pointer to member,
653 since it is not a constant. */
654 my_friendly_abort (0);
656 /* Get the actual FIELD_DECL. */
657 value
= PTRMEM_CST_MEMBER (value
);
658 my_friendly_assert (TREE_CODE (value
) == FIELD_DECL
, 0);
660 /* Output the name of the field. */
661 build_overload_identifier (DECL_NAME (value
));
665 if (TYPE_PTRMEMFUNC_P (type
))
666 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
668 switch (TREE_CODE (type
))
674 build_overload_int (value
, in_template
);
680 char *bufp
= digit_buffer
;
682 pedwarn ("ANSI C++ forbids floating-point template arguments");
684 my_friendly_assert (TREE_CODE (value
) == REAL_CST
, 244);
685 val
= TREE_REAL_CST (value
);
686 if (REAL_VALUE_ISNAN (val
))
688 sprintf (bufp
, "NaN");
692 if (REAL_VALUE_NEGATIVE (val
))
694 val
= REAL_VALUE_NEGATE (val
);
697 if (REAL_VALUE_ISINF (val
))
699 sprintf (bufp
, "Infinity");
703 REAL_VALUE_TO_DECIMAL (val
, "%.20e", bufp
);
704 bufp
= (char *) index (bufp
, 'e');
706 strcat (digit_buffer
, "e0");
732 #ifdef NO_DOT_IN_LABEL
733 bufp
= (char *) index (bufp
, '.');
739 OB_PUTCP (digit_buffer
);
740 numeric_output_need_bar
= 1;
744 if (TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
745 && TREE_CODE (value
) != ADDR_EXPR
)
747 if (TREE_CODE (value
) == CONSTRUCTOR
)
749 /* This is dangerous code, crack built up pointer to members. */
750 tree args
= CONSTRUCTOR_ELTS (value
);
751 tree a1
= TREE_VALUE (args
);
752 tree a2
= TREE_VALUE (TREE_CHAIN (args
));
753 tree a3
= CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
))));
754 a3
= TREE_VALUE (a3
);
756 if (TREE_CODE (a1
) == INTEGER_CST
757 && TREE_CODE (a2
) == INTEGER_CST
)
759 build_overload_int (a1
, in_template
);
761 build_overload_int (a2
, in_template
);
763 if (TREE_CODE (a3
) == ADDR_EXPR
)
765 a3
= TREE_OPERAND (a3
, 0);
766 if (TREE_CODE (a3
) == FUNCTION_DECL
)
768 numeric_output_need_bar
= 0;
769 build_overload_identifier (DECL_ASSEMBLER_NAME (a3
));
773 else if (TREE_CODE (a3
) == INTEGER_CST
)
776 build_overload_int (a3
, in_template
);
781 sorry ("template instantiation with pointer to method that is too complex");
784 if (TREE_CODE (value
) == INTEGER_CST
)
786 build_overload_int (value
, in_template
);
789 else if (TREE_CODE (value
) == TEMPLATE_PARM_INDEX
)
791 build_mangled_template_parm_index ("", value
);
792 numeric_output_need_bar
= 1;
796 value
= TREE_OPERAND (value
, 0);
797 if (TREE_CODE (value
) == VAR_DECL
)
799 my_friendly_assert (DECL_NAME (value
) != 0, 245);
800 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
803 else if (TREE_CODE (value
) == FUNCTION_DECL
)
805 my_friendly_assert (DECL_NAME (value
) != 0, 246);
806 build_overload_identifier (DECL_ASSEMBLER_NAME (value
));
809 else if (TREE_CODE (value
) == SCOPE_REF
)
810 build_overload_scope_ref (value
);
812 my_friendly_abort (71);
813 break; /* not really needed */
816 sorry ("conversion of %s as template parameter",
817 tree_code_name
[(int) TREE_CODE (type
)]);
818 my_friendly_abort (72);
823 /* Add encodings for the declaration of template template parameters.
824 PARMLIST must be a TREE_VEC */
827 build_template_template_parm_names (parmlist
)
832 my_friendly_assert (TREE_CODE (parmlist
) == TREE_VEC
, 246.5);
833 nparms
= TREE_VEC_LENGTH (parmlist
);
835 for (i
= 0; i
< nparms
; i
++)
837 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
838 if (TREE_CODE (parm
) == TYPE_DECL
)
840 /* This parameter is a type. */
843 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
845 /* This parameter is a template. */
847 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
850 /* It's a PARM_DECL. */
851 build_mangled_name_for_type (TREE_TYPE (parm
));
856 /* Add encodings for the vector of template parameters in PARMLIST,
857 given the vector of arguments to be substituted in ARGLIST. */
860 build_template_parm_names (parmlist
, arglist
)
865 tree inner_args
= innermost_args (arglist
);
867 nparms
= TREE_VEC_LENGTH (parmlist
);
869 for (i
= 0; i
< nparms
; i
++)
871 tree parm
= TREE_VALUE (TREE_VEC_ELT (parmlist
, i
));
872 tree arg
= TREE_VEC_ELT (inner_args
, i
);
873 if (TREE_CODE (parm
) == TYPE_DECL
)
875 /* This parameter is a type. */
877 build_mangled_name_for_type (arg
);
879 else if (TREE_CODE (parm
) == TEMPLATE_DECL
)
881 /* This parameter is a template. */
882 if (TREE_CODE (arg
) == TEMPLATE_TEMPLATE_PARM
)
883 /* Output parameter declaration, argument index and level */
884 build_mangled_name_for_type (arg
);
887 /* A TEMPLATE_DECL node, output the parameter declaration
891 build_template_template_parm_names (DECL_INNERMOST_TEMPLATE_PARMS (parm
));
892 icat (IDENTIFIER_LENGTH (DECL_NAME (arg
)));
893 OB_PUTID (DECL_NAME (arg
));
898 parm
= tsubst (parm
, arglist
, NULL_TREE
);
899 /* It's a PARM_DECL. */
900 build_mangled_name_for_type (TREE_TYPE (parm
));
901 build_overload_value (TREE_TYPE (parm
), arg
,
902 uses_template_parms (arglist
));
907 /* Output the representation for NAME, which is either a TYPE_DECL or
911 build_overload_identifier (name
)
914 if (TREE_CODE (name
) == TYPE_DECL
915 && IS_AGGR_TYPE (TREE_TYPE (name
))
916 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (name
))
917 && (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
)))
918 || (TREE_CODE (DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE
922 /* NAME is the TYPE_DECL for a template specialization. */
923 tree
template, parmlist
, arglist
, tname
;
924 template = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (name
));
925 arglist
= CLASSTYPE_TI_ARGS (TREE_TYPE (name
));
926 tname
= DECL_NAME (template);
927 parmlist
= DECL_INNERMOST_TEMPLATE_PARMS (template);
929 icat (IDENTIFIER_LENGTH (tname
));
931 build_template_parm_names (parmlist
, arglist
);
935 if (TREE_CODE (name
) == TYPE_DECL
)
936 name
= DECL_NAME (name
);
937 if (numeric_output_need_bar
)
940 numeric_output_need_bar
= 0;
942 icat (IDENTIFIER_LENGTH (name
));
947 /* Given DECL, either a class TYPE, TYPE_DECL or FUNCTION_DECL, produce
948 the mangling for it. Used by build_mangled_name and build_static_name. */
951 build_qualified_name (decl
)
957 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 't')
958 decl
= TYPE_NAME (decl
);
960 /* If DECL_ASSEMBLER_NAME has been set properly, use it. */
961 if (TREE_CODE (decl
) == TYPE_DECL
962 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
) && !flag_do_squangling
)
964 tree id
= DECL_ASSEMBLER_NAME (decl
);
966 if (ISDIGIT (IDENTIFIER_POINTER (id
) [IDENTIFIER_LENGTH (id
) - 1]))
967 numeric_output_need_bar
= 1;
972 /* if we can't find a Ktype, do it the hard way */
973 if (check_ktype (context
, FALSE
) == -1)
975 /* count type and namespace scopes */
976 while (DECL_CONTEXT (context
) && DECL_CONTEXT (context
) != global_namespace
)
979 context
= DECL_CONTEXT (context
);
980 if (check_ktype (context
, FALSE
) != -1) /* found it! */
982 if (TREE_CODE_CLASS (TREE_CODE (context
)) == 't')
983 context
= TYPE_NAME (context
);
990 build_underscore_int (i
);
991 numeric_output_need_bar
= 0;
993 build_overload_nested_name (decl
);
996 /* Output the mangled representation for TYPE. If EXTRA_GCODE is
997 non-zero, mangled names for structure/union types are intentionally
998 mangled differently from the method described in the ARM. */
1001 build_mangled_name_for_type_with_Gcode (type
, extra_Gcode
)
1005 if (TYPE_PTRMEMFUNC_P (type
))
1006 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
1007 type
= canonical_type_variant (type
);
1008 process_modifiers (type
);
1009 process_overload_item (type
, extra_Gcode
);
1012 /* Like build_mangled_name_for_type_with_Gcode, but never outputs the
1016 build_mangled_name_for_type (type
)
1019 build_mangled_name_for_type_with_Gcode (type
, 0);
1022 /* Given a list of parameters in PARMTYPES, create an unambiguous
1023 overload string. Should distinguish any type that C (or C++) can
1024 distinguish. I.e., pointers to functions are treated correctly.
1026 Caller must deal with whether a final `e' goes on the end or not.
1028 Any default conversions must take place before this function
1031 BEGIN and END control initialization and finalization of the
1032 obstack where we build the string. */
1035 build_overload_name (parmtypes
, begin
, end
)
1040 start_squangling ();
1041 ret
= build_mangled_name (parmtypes
, begin
, end
);
1046 /* Output the mangled representation for PARMTYPES. If PARMTYPES is a
1047 TREE_LIST, then it is a list of parameter types. Otherwise,
1048 PARMTYPES must be a single type. */
1051 build_mangled_name (parmtypes
, begin
, end
)
1058 if (TREE_CODE (parmtypes
) != TREE_LIST
)
1059 /* There is only one type. */
1060 build_mangled_name_for_type (parmtypes
);
1063 /* There are several types in a parameter list. */
1065 int old_style_repeats
= !flag_do_squangling
&& !nofold
&& typevec
;
1066 tree last_type
= NULL_TREE
;
1068 for (; parmtypes
&& parmtypes
!= void_list_node
;
1069 parmtypes
= TREE_CHAIN (parmtypes
))
1071 tree parmtype
= canonical_type_variant (TREE_VALUE (parmtypes
));
1073 if (old_style_repeats
)
1075 /* Every argument gets counted. */
1076 my_friendly_assert (maxtype
< typevec_size
, 387);
1077 typevec
[maxtype
++] = parmtype
;
1080 if (parmtype
== last_type
)
1082 if (flag_do_squangling
1083 || (old_style_repeats
&& TREE_USED (parmtype
)
1084 && !TYPE_FOR_JAVA (parmtype
)))
1086 /* The next type is the same as this one. Keep
1087 track of the repetition, and output the repeat
1093 else if (nrepeats
!= 0)
1095 /* Indicate how many times the previous parameter was
1097 if (old_style_repeats
)
1098 flush_repeats (nrepeats
, last_type
);
1100 issue_nrepeats (nrepeats
, last_type
);
1104 last_type
= parmtype
;
1106 if (old_style_repeats
)
1110 flush_repeats (nrepeats
, last_type
);
1114 if (TREE_USED (parmtype
))
1117 /* We can turn this on at some point when we want
1118 improved symbol mangling. */
1121 /* This is bug compatible with 2.7.x */
1122 flush_repeats (nrepeats
, parmtype
);
1128 /* Only cache types which take more than one character. */
1129 if ((parmtype
!= TYPE_MAIN_VARIANT (parmtype
)
1130 || (TREE_CODE (parmtype
) != INTEGER_TYPE
1131 && TREE_CODE (parmtype
) != REAL_TYPE
))
1132 && ! TYPE_FOR_JAVA (parmtype
))
1133 TREE_USED (parmtype
) = 1;
1136 /* Output the PARMTYPE. */
1137 build_mangled_name_for_type_with_Gcode (parmtype
, 1);
1140 /* Output the repeat count for the last parameter, if
1144 if (old_style_repeats
)
1145 flush_repeats (nrepeats
, last_type
);
1147 issue_nrepeats (nrepeats
, last_type
);
1152 /* The parameter list ends in an ellipsis. */
1158 return (char *)obstack_base (&scratch_obstack
);
1161 /* handles emitting modifiers such as Constant, read-only, and volatile */
1163 process_modifiers (parmtype
)
1166 /* Note that here we do not use CP_TYPE_CONST_P and friends because
1167 we describe types recursively; we will get the `const' in
1168 `const int ()[10]' when processing the `const int' part. */
1169 if (TYPE_READONLY (parmtype
))
1171 if (TREE_CODE (parmtype
) == INTEGER_TYPE
1172 && (TYPE_MAIN_VARIANT (parmtype
)
1173 == unsigned_type (TYPE_MAIN_VARIANT (parmtype
)))
1174 && ! TYPE_FOR_JAVA (parmtype
))
1176 if (TYPE_VOLATILE (parmtype
))
1178 /* It would be better to use `R' for `restrict', but that's already
1179 used for reference types. And `r' is used for `long double'. */
1180 if (TYPE_RESTRICT (parmtype
))
1184 /* Check to see if TYPE has been entered into the Bcode typelist. If
1185 so, return 1 and emit a backreference to TYPE. Otherwise, add TYPE
1186 to the list of back-referenceable types and return 0. */
1194 if (btypelist
== NULL
)
1197 if (!is_back_referenceable_type (type
))
1200 /* We assume that our caller has put out any necessary
1202 type
= TYPE_MAIN_VARIANT (type
);
1204 for (x
= 0; x
< maxbtype
; x
++)
1205 if (type
== btypelist
[x
])
1214 if (maxbsize
<= maxbtype
)
1216 /* Enlarge the table. */
1217 maxbsize
= maxbsize
* 3 / 2;
1218 btypelist
= (tree
*)xrealloc (btypelist
, sizeof (tree
) * maxbsize
);
1221 /* Register the TYPE. */
1222 btypelist
[maxbtype
++] = type
;
1227 /* handle emitting the correct code for various node types */
1229 process_overload_item (parmtype
, extra_Gcode
)
1233 numeric_output_need_bar
= 0;
1235 /* These tree types are considered modifiers for B code squangling , */
1236 /* and therefore should not get entries in the Btypelist */
1237 /* they are, however, repeatable types */
1239 switch (TREE_CODE (parmtype
))
1241 case REFERENCE_TYPE
:
1246 #if PARM_CAN_BE_ARRAY_TYPE
1249 if (TYPE_DOMAIN (parmtype
) == NULL_TREE
)
1253 tree length
= array_type_nelts (parmtype
);
1254 if (TREE_CODE (length
) != INTEGER_CST
|| flag_do_squangling
)
1256 length
= fold (build (PLUS_EXPR
, TREE_TYPE (length
),
1257 length
, integer_one_node
));
1258 STRIP_NOPS (length
);
1260 build_overload_value (sizetype
, length
, 1);
1262 if (numeric_output_need_bar
&& ! flag_do_squangling
)
1274 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1282 if (flag_do_squangling
&& check_btype (parmtype
))
1283 /* If PARMTYPE is already in the list of back-referenceable types,
1284 then check_btype will output the appropriate reference, and
1285 there's nothing more to do. */
1288 switch (TREE_CODE (parmtype
))
1292 build_mangled_name_for_type (TYPE_OFFSET_BASETYPE (parmtype
));
1294 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1300 tree parms
= TYPE_ARG_TYPES (parmtype
);
1302 /* Rather than implementing a reentrant TYPEVEC, we turn off
1303 repeat codes here, unless we're squangling. Squangling
1304 doesn't make use of the TYPEVEC, so there's no reentrancy
1306 int old_nofold
= nofold
;
1307 if (!flag_do_squangling
)
1310 if (TREE_CODE (parmtype
) == METHOD_TYPE
)
1312 /* Mark this as a method. */
1314 /* Output the class of which this method is a member. */
1315 build_mangled_name_for_type (TYPE_METHOD_BASETYPE (parmtype
));
1316 /* Output any qualifiers for the `this' parameter. */
1317 process_modifiers (TREE_TYPE (TREE_VALUE (parms
)));
1320 /* Output the parameter types. */
1322 if (parms
== NULL_TREE
)
1324 else if (parms
== void_list_node
)
1327 build_mangled_name (parms
, 0, 0);
1329 /* Output the return type. */
1331 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1333 nofold
= old_nofold
;
1338 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1339 if (parmtype
== integer_type_node
1340 || parmtype
== unsigned_type_node
1341 || parmtype
== java_int_type_node
)
1343 else if (parmtype
== long_integer_type_node
1344 || parmtype
== long_unsigned_type_node
)
1346 else if (parmtype
== short_integer_type_node
1347 || parmtype
== short_unsigned_type_node
1348 || parmtype
== java_short_type_node
)
1350 else if (parmtype
== signed_char_type_node
)
1355 else if (parmtype
== char_type_node
1356 || parmtype
== unsigned_char_type_node
1357 || parmtype
== java_byte_type_node
)
1359 else if (parmtype
== wchar_type_node
1360 || parmtype
== java_char_type_node
)
1362 else if (parmtype
== long_long_integer_type_node
1363 || parmtype
== long_long_unsigned_type_node
1364 || parmtype
== java_long_type_node
)
1367 /* it would seem there is no way to enter these in source code,
1369 else if (parmtype
== long_long_long_integer_type_node
1370 || parmtype
== long_long_long_unsigned_type_node
)
1373 else if (parmtype
== java_boolean_type_node
)
1376 my_friendly_abort (73);
1384 parmtype
= TYPE_MAIN_VARIANT (parmtype
);
1385 if (parmtype
== long_double_type_node
)
1387 else if (parmtype
== double_type_node
1388 || parmtype
== java_double_type_node
)
1390 else if (parmtype
== float_type_node
1391 || parmtype
== java_float_type_node
)
1393 else my_friendly_abort (74);
1398 build_mangled_name_for_type (TREE_TYPE (parmtype
));
1405 case ERROR_MARK
: /* not right, but nothing is anyway */
1408 /* have to do these */
1413 OB_PUTC ('G'); /* make it look incompatible with AT&T */
1414 /* drop through into next case */
1418 tree name
= TYPE_NAME (parmtype
);
1420 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 248);
1422 build_qualified_name (name
);
1427 /* This will take some work. */
1431 case TEMPLATE_TEMPLATE_PARM
:
1432 /* Find and output the original template parameter
1434 if (CLASSTYPE_TEMPLATE_INFO (parmtype
))
1436 build_mangled_template_parm_index ("tzX",
1437 TEMPLATE_TYPE_PARM_INDEX
1439 build_template_parm_names
1440 (DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (parmtype
)),
1441 CLASSTYPE_TI_ARGS (parmtype
));
1445 build_mangled_template_parm_index ("ZzX",
1446 TEMPLATE_TYPE_PARM_INDEX
1448 build_template_template_parm_names
1449 (DECL_INNERMOST_TEMPLATE_PARMS (TYPE_STUB_DECL (parmtype
)));
1453 case TEMPLATE_TYPE_PARM
:
1454 build_mangled_template_parm_index ("X",
1455 TEMPLATE_TYPE_PARM_INDEX
1460 /* When mangling the type of a function template whose
1461 declaration looks like:
1463 template <class T> void foo(typename T::U)
1465 we have to mangle these. */
1466 build_qualified_name (parmtype
);
1470 my_friendly_abort (75);
1475 /* Produce the mangling for a variable named NAME in CONTEXT, which can
1476 be either a class TYPE or a FUNCTION_DECL. */
1479 build_static_name (context
, name
)
1483 numeric_output_need_bar
= 0;
1484 start_squangling ();
1487 build_qualified_name (context
);
1490 OB_PUTS ("__static_");
1491 build_qualified_name (context
);
1498 return get_identifier ((char *)obstack_base (&scratch_obstack
));
1501 /* FOR_METHOD should be 1 if the declaration in question is for a member
1502 of a class (including a static member) and 2 if the declaration is
1503 for a constructor. */
1505 build_decl_overload_real (dname
, parms
, ret_type
, tparms
, targs
,
1514 char *name
= IDENTIFIER_POINTER (dname
);
1516 /* member operators new and delete look like methods at this point. */
1517 if (! for_method
&& parms
!= NULL_TREE
&& TREE_CODE (parms
) == TREE_LIST
1518 && TREE_CHAIN (parms
) == void_list_node
)
1520 if (dname
== ansi_opname
[(int) DELETE_EXPR
])
1521 return get_identifier ("__builtin_delete");
1522 else if (dname
== ansi_opname
[(int) VEC_DELETE_EXPR
])
1523 return get_identifier ("__builtin_vec_delete");
1524 if (dname
== ansi_opname
[(int) NEW_EXPR
])
1525 return get_identifier ("__builtin_new");
1526 else if (dname
== ansi_opname
[(int) VEC_NEW_EXPR
])
1527 return get_identifier ("__builtin_vec_new");
1530 start_squangling ();
1532 if (for_method
!= 2)
1534 /* Otherwise, we can divine that this is a constructor,
1535 and figure out its name without any extra encoding. */
1537 OB_PUTC2 ('_', '_');
1538 numeric_output_need_bar
= 0;
1543 build_template_parm_names (tparms
, targs
);
1546 else if (!for_method
&& current_namespace
== global_namespace
)
1547 /* XXX this works only if we call this in the same namespace
1548 as the declaration. Unfortunately, we don't have the _DECL,
1552 if (!for_method
&& current_namespace
!= global_namespace
)
1553 /* qualify with namespace */
1554 build_qualified_name (current_namespace
);
1556 if (parms
== NULL_TREE
)
1558 else if (parms
== void_list_node
)
1562 if (!flag_do_squangling
) /* Allocate typevec array. */
1565 typevec_size
= list_length (parms
);
1566 if (!for_method
&& current_namespace
!= global_namespace
)
1567 /* the namespace of a global function needs one slot */
1569 typevec
= (tree
*)alloca (typevec_size
* sizeof (tree
));
1575 tree this_type
= TREE_VALUE (parms
);
1577 if (TREE_CODE (this_type
) == RECORD_TYPE
) /* a signature pointer */
1578 this_type
= SIGNATURE_TYPE (this_type
);
1580 this_type
= TREE_TYPE (this_type
);
1582 build_mangled_name_for_type (this_type
);
1584 if (!flag_do_squangling
)
1586 my_friendly_assert (maxtype
< typevec_size
, 387);
1587 typevec
[maxtype
++] = this_type
;
1588 TREE_USED (this_type
) = 1;
1590 /* By setting up PARMS in this way, the loop below will
1591 automatically clear TREE_USED on THIS_TYPE. */
1592 parms
= temp_tree_cons (NULL_TREE
, this_type
,
1593 TREE_CHAIN (parms
));
1596 if (TREE_CHAIN (parms
))
1597 build_mangled_name (TREE_CHAIN (parms
), 0, 0);
1603 /* the namespace qualifier for a global function
1604 will count as type */
1605 if (current_namespace
!= global_namespace
1606 && !flag_do_squangling
)
1608 my_friendly_assert (maxtype
< typevec_size
, 387);
1609 typevec
[maxtype
++] = current_namespace
;
1611 build_mangled_name (parms
, 0, 0);
1614 if (!flag_do_squangling
) /* Deallocate typevec array */
1620 tree temp
= TREE_VALUE (t
);
1621 TREE_USED (temp
) = 0;
1622 /* clear out the type variant in case we used it */
1623 temp
= canonical_type_variant (temp
);
1624 TREE_USED (temp
) = 0;
1630 if (ret_type
!= NULL_TREE
&& for_method
!= 2)
1632 /* Add the return type. */
1634 build_mangled_name_for_type (ret_type
);
1640 tree n
= get_identifier (obstack_base (&scratch_obstack
));
1641 if (IDENTIFIER_OPNAME_P (dname
))
1642 IDENTIFIER_OPNAME_P (n
) = 1;
1647 /* Change the name of a function definition so that it may be
1648 overloaded. NAME is the name of the function to overload,
1649 PARMS is the parameter list (which determines what name the
1650 final function obtains).
1652 FOR_METHOD is 1 if this overload is being performed
1653 for a method, rather than a function type. It is 2 if
1654 this overload is being performed for a constructor. */
1657 build_decl_overload (dname
, parms
, for_method
)
1662 return build_decl_overload_real (dname
, parms
, NULL_TREE
, NULL_TREE
,
1663 NULL_TREE
, for_method
);
1666 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
1669 set_mangled_name_for_decl (decl
)
1674 if (processing_template_decl
)
1675 /* There's no need to mangle the name of a template function. */
1678 parm_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
1680 if (DECL_STATIC_FUNCTION_P (decl
))
1682 hash_tree_chain (build_pointer_type (DECL_CLASS_CONTEXT (decl
)),
1685 /* The only member functions whose type is a FUNCTION_TYPE, rather
1686 than a METHOD_TYPE, should be static members. */
1687 my_friendly_assert (!DECL_CONTEXT (decl
)
1688 || !IS_AGGR_TYPE_CODE (TREE_CODE (DECL_CONTEXT (decl
)))
1689 || TREE_CODE (TREE_TYPE (decl
)) != FUNCTION_TYPE
,
1692 DECL_ASSEMBLER_NAME (decl
)
1693 = build_decl_overload (DECL_NAME (decl
), parm_types
,
1694 DECL_FUNCTION_MEMBER_P (decl
)
1695 + DECL_CONSTRUCTOR_P (decl
));
1698 /* Build an overload name for the type expression TYPE. */
1701 build_typename_overload (type
)
1707 OB_PUTID (ansi_opname
[(int) TYPE_EXPR
]);
1709 start_squangling ();
1710 build_mangled_name (type
, 0, 1);
1711 id
= get_identifier (obstack_base (&scratch_obstack
));
1712 IDENTIFIER_OPNAME_P (id
) = 1;
1714 IDENTIFIER_GLOBAL_VALUE (id
) = TYPE_MAIN_DECL (type
);
1716 TREE_TYPE (id
) = type
;
1722 build_overload_with_type (name
, type
)
1729 start_squangling ();
1730 build_mangled_name (type
, 0, 1);
1732 return get_identifier (obstack_base (&scratch_obstack
));
1736 get_id_2 (name
, name2
)
1744 return get_identifier (obstack_base (&scratch_obstack
));
1747 /* Returns a DECL_ASSEMBLER_NAME for the destructor of type TYPE. */
1750 build_destructor_name (type
)
1753 return build_overload_with_type (get_identifier (DESTRUCTOR_DECL_PREFIX
),
1757 /* Given a tree_code CODE, and some arguments (at least one),
1758 attempt to use an overloaded operator on the arguments.
1760 For unary operators, only the first argument need be checked.
1761 For binary operators, both arguments may need to be checked.
1763 Member functions can convert class references to class pointers,
1764 for one-level deep indirection. More than that is not supported.
1765 Operators [](), ()(), and ->() must be member functions.
1767 We call function call building calls with LOOKUP_COMPLAIN if they
1768 are our only hope. This is true when we see a vanilla operator
1769 applied to something of aggregate type. If this fails, we are free
1770 to return `error_mark_node', because we will have reported the
1773 Operators NEW and DELETE overload in funny ways: operator new takes
1774 a single `size' parameter, and operator delete takes a pointer to the
1775 storage being deleted. When overloading these operators, success is
1776 assumed. If there is a failure, report an error message and return
1777 `error_mark_node'. */
1781 build_opfncall (code
, flags
, xarg1
, xarg2
, arg3
)
1782 enum tree_code code
;
1784 tree xarg1
, xarg2
, arg3
;
1786 return build_new_op (code
, flags
, xarg1
, xarg2
, arg3
);
1789 /* This function takes an identifier, ID, and attempts to figure out what
1790 it means. There are a number of possible scenarios, presented in increasing
1793 1) not in a class's scope
1794 2) in class's scope, member name of the class's method
1795 3) in class's scope, but not a member name of the class
1796 4) in class's scope, member name of a class's variable
1798 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
1799 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
1801 As a last ditch, try to look up the name as a label and return that
1804 Values which are declared as being of REFERENCE_TYPE are
1805 automatically dereferenced here (as a hack to make the
1806 compiler faster). */
1809 hack_identifier (value
, name
)
1814 if (value
== error_mark_node
)
1816 if (current_class_name
)
1818 tree fields
= lookup_fnfields (TYPE_BINFO (current_class_type
), name
, 1);
1819 if (fields
== error_mark_node
)
1820 return error_mark_node
;
1825 fndecl
= TREE_VALUE (fields
);
1826 my_friendly_assert (TREE_CODE (fndecl
) == FUNCTION_DECL
, 251);
1827 /* I could not trigger this code. MvL */
1828 my_friendly_abort (980325);
1830 if (DECL_CHAIN (fndecl
) == NULL_TREE
)
1832 warning ("methods cannot be converted to function pointers");
1837 error ("ambiguous request for method pointer `%s'",
1838 IDENTIFIER_POINTER (name
));
1839 return error_mark_node
;
1844 if (flag_labels_ok
&& IDENTIFIER_LABEL_VALUE (name
))
1846 return IDENTIFIER_LABEL_VALUE (name
);
1848 return error_mark_node
;
1851 type
= TREE_TYPE (value
);
1852 if (TREE_CODE (value
) == FIELD_DECL
)
1854 if (current_class_ptr
== NULL_TREE
)
1856 if (current_function_decl
1857 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1858 cp_error ("invalid use of member `%D' in static member function",
1861 /* We can get here when processing a bad default
1863 struct S { int a; void f(int i = a); } */
1864 cp_error ("invalid use of member `%D'", value
);
1866 return error_mark_node
;
1868 TREE_USED (current_class_ptr
) = 1;
1870 /* Mark so that if we are in a constructor, and then find that
1871 this field was initialized by a base initializer,
1872 we can emit an error message. */
1873 TREE_USED (value
) = 1;
1874 value
= build_component_ref (current_class_ref
, name
, NULL_TREE
, 1);
1876 else if (TREE_CODE (value
) == FUNCTION_DECL
1877 && DECL_FUNCTION_MEMBER_P (value
))
1881 if (IS_SIGNATURE (DECL_CLASS_CONTEXT (value
)))
1884 decl
= maybe_dummy_object (DECL_CLASS_CONTEXT (value
), 0);
1885 value
= build_component_ref (decl
, name
, NULL_TREE
, 1);
1887 else if (really_overloaded_fn (value
))
1890 tree t
= get_first_fn (value
);
1891 for (; t
; t
= DECL_CHAIN (t
))
1893 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1896 assemble_external (t
);
1901 else if (TREE_CODE (value
) == OVERLOAD
)
1902 /* not really overloaded function */
1903 mark_used (OVL_FUNCTION (value
));
1904 else if (TREE_CODE (value
) == TREE_LIST
)
1906 /* Ambiguous reference to base members, possibly other cases?. */
1908 while (t
&& TREE_CODE (t
) == TREE_LIST
)
1910 mark_used (TREE_VALUE (t
));
1914 else if (TREE_CODE (value
) == NAMESPACE_DECL
)
1916 cp_error ("use of namespace `%D' as expression", value
);
1917 return error_mark_node
;
1919 else if (DECL_CLASS_TEMPLATE_P (value
))
1921 cp_error ("use of class template `%T' as expression", value
);
1922 return error_mark_node
;
1927 if (TREE_CODE (value
) == VAR_DECL
|| TREE_CODE (value
) == PARM_DECL
)
1929 tree context
= decl_function_context (value
);
1930 if (context
!= NULL_TREE
&& context
!= current_function_decl
1931 && ! TREE_STATIC (value
))
1933 cp_error ("use of %s from containing function",
1934 (TREE_CODE (value
) == VAR_DECL
1935 ? "`auto' variable" : "parameter"));
1936 cp_error_at (" `%#D' declared here", value
);
1937 value
= error_mark_node
;
1941 if (TREE_CODE_CLASS (TREE_CODE (value
)) == 'd' && DECL_NONLOCAL (value
))
1943 if (DECL_LANG_SPECIFIC (value
)
1944 && DECL_CLASS_CONTEXT (value
) != current_class_type
)
1947 register tree context
1948 = (TREE_CODE (value
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (value
))
1949 ? DECL_CLASS_CONTEXT (value
)
1950 : DECL_CONTEXT (value
);
1952 get_base_distance (context
, current_class_type
, 0, &path
);
1955 access
= compute_access (path
, value
);
1956 if (access
!= access_public_node
)
1958 if (TREE_CODE (value
) == VAR_DECL
)
1959 error ("static member `%s' is %s",
1960 IDENTIFIER_POINTER (name
),
1961 TREE_PRIVATE (value
) ? "private"
1962 : "from a private base class");
1964 error ("enum `%s' is from private base class",
1965 IDENTIFIER_POINTER (name
));
1966 return error_mark_node
;
1971 else if (TREE_CODE (value
) == TREE_LIST
&& TREE_NONLOCAL_FLAG (value
))
1973 error ("request for member `%s' is ambiguous in multiple inheritance lattice",
1974 IDENTIFIER_POINTER (name
));
1975 return error_mark_node
;
1978 if (! processing_template_decl
)
1979 value
= convert_from_reference (value
);
1985 make_thunk (function
, delta
)
1993 if (TREE_CODE (function
) != ADDR_EXPR
)
1995 func_decl
= TREE_OPERAND (function
, 0);
1996 if (TREE_CODE (func_decl
) != FUNCTION_DECL
)
2000 OB_PUTS ("__thunk_");
2009 OB_PUTID (DECL_ASSEMBLER_NAME (func_decl
));
2011 thunk_id
= get_identifier (obstack_base (&scratch_obstack
));
2013 thunk
= IDENTIFIER_GLOBAL_VALUE (thunk_id
);
2014 if (thunk
&& TREE_CODE (thunk
) != THUNK_DECL
)
2016 cp_error ("implementation-reserved name `%D' used", thunk_id
);
2018 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id
, thunk
);
2020 if (thunk
== NULL_TREE
)
2022 thunk
= build_decl (FUNCTION_DECL
, thunk_id
, TREE_TYPE (func_decl
));
2023 TREE_READONLY (thunk
) = TREE_READONLY (func_decl
);
2024 TREE_THIS_VOLATILE (thunk
) = TREE_THIS_VOLATILE (func_decl
);
2025 comdat_linkage (thunk
);
2026 TREE_SET_CODE (thunk
, THUNK_DECL
);
2027 DECL_INITIAL (thunk
) = function
;
2028 THUNK_DELTA (thunk
) = delta
;
2029 DECL_EXTERNAL (thunk
) = 1;
2030 DECL_ARTIFICIAL (thunk
) = 1;
2031 /* So that finish_file can write out any thunks that need to be: */
2032 pushdecl_top_level (thunk
);
2037 /* Emit the definition of a C++ multiple inheritance vtable thunk. */
2040 emit_thunk (thunk_fndecl
)
2043 tree function
= TREE_OPERAND (DECL_INITIAL (thunk_fndecl
), 0);
2044 int delta
= THUNK_DELTA (thunk_fndecl
);
2046 if (TREE_ASM_WRITTEN (thunk_fndecl
))
2049 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
2051 TREE_ADDRESSABLE (function
) = 1;
2052 mark_used (function
);
2054 if (current_function_decl
)
2057 TREE_SET_CODE (thunk_fndecl
, FUNCTION_DECL
);
2060 #ifdef ASM_OUTPUT_MI_THUNK
2062 current_function_decl
= thunk_fndecl
;
2063 /* Make sure we build up its RTL before we go onto the
2064 temporary obstack. */
2065 make_function_rtl (thunk_fndecl
);
2066 temporary_allocation ();
2067 DECL_RESULT (thunk_fndecl
)
2068 = build_decl (RESULT_DECL
, 0, integer_type_node
);
2069 fnname
= XSTR (XEXP (DECL_RTL (thunk_fndecl
), 0), 0);
2070 init_function_start (thunk_fndecl
, input_filename
, lineno
);
2071 current_function_is_thunk
= 1;
2072 assemble_start_function (thunk_fndecl
, fnname
);
2073 ASM_OUTPUT_MI_THUNK (asm_out_file
, thunk_fndecl
, delta
, function
);
2074 assemble_end_function (thunk_fndecl
, fnname
);
2075 permanent_allocation (1);
2076 current_function_decl
= 0;
2077 #else /* ASM_OUTPUT_MI_THUNK */
2078 /* If we don't have the necessary macro for efficient thunks, generate a
2079 thunk function that just makes a call to the real function.
2080 Unfortunately, this doesn't work for varargs. */
2084 if (varargs_function_p (function
))
2085 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
2088 /* Set up clone argument trees for the thunk. */
2090 for (a
= DECL_ARGUMENTS (function
); a
; a
= TREE_CHAIN (a
))
2092 tree x
= copy_node (a
);
2094 DECL_CONTEXT (x
) = thunk_fndecl
;
2098 DECL_ARGUMENTS (thunk_fndecl
) = a
;
2099 DECL_RESULT (thunk_fndecl
) = NULL_TREE
;
2100 DECL_LANG_SPECIFIC (thunk_fndecl
) = DECL_LANG_SPECIFIC (function
);
2101 copy_lang_decl (thunk_fndecl
);
2102 DECL_INTERFACE_KNOWN (thunk_fndecl
) = 1;
2103 DECL_NOT_REALLY_EXTERN (thunk_fndecl
) = 1;
2105 start_function (NULL_TREE
, thunk_fndecl
, NULL_TREE
, 1);
2106 store_parm_decls ();
2107 current_function_is_thunk
= 1;
2109 /* Build up the call to the real function. */
2110 t
= build_int_2 (delta
, -1 * (delta
< 0));
2111 TREE_TYPE (t
) = signed_type (sizetype
);
2112 t
= fold (build (PLUS_EXPR
, TREE_TYPE (a
), a
, t
));
2113 t
= expr_tree_cons (NULL_TREE
, t
, NULL_TREE
);
2114 for (a
= TREE_CHAIN (a
); a
; a
= TREE_CHAIN (a
))
2115 t
= expr_tree_cons (NULL_TREE
, a
, t
);
2117 t
= build_call (function
, TREE_TYPE (TREE_TYPE (function
)), t
);
2118 c_expand_return (t
);
2120 finish_function (lineno
, 0, 0);
2122 /* Don't let the backend defer this function. */
2123 if (DECL_DEFER_OUTPUT (thunk_fndecl
))
2125 output_inline_function (thunk_fndecl
);
2126 permanent_allocation (1);
2128 #endif /* ASM_OUTPUT_MI_THUNK */
2131 TREE_SET_CODE (thunk_fndecl
, THUNK_DECL
);
2134 /* Code for synthesizing methods which have default semantics defined. */
2136 /* For the anonymous union in TYPE, return the member that is at least as
2137 large as the rest of the members, so we can copy it. */
2140 largest_union_member (type
)
2143 tree f
, type_size
= TYPE_SIZE (type
);
2145 for (f
= TYPE_FIELDS (type
); f
; f
= TREE_CHAIN (f
))
2146 if (simple_cst_equal (DECL_SIZE (f
), type_size
) == 1)
2149 /* We should always find one. */
2150 my_friendly_abort (323);
2154 /* Generate code for default X(X&) constructor. */
2157 do_build_copy_constructor (fndecl
)
2160 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2166 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
2167 parm
= TREE_CHAIN (parm
);
2168 parm
= convert_from_reference (parm
);
2170 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
)
2171 && is_empty_class (current_class_type
))
2172 /* Don't copy the padding byte; it might not have been allocated
2173 if *this is a base subobject. */;
2174 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type
))
2176 t
= build (INIT_EXPR
, void_type_node
, current_class_ref
, parm
);
2177 TREE_SIDE_EFFECTS (t
) = 1;
2178 cplus_expand_expr_stmt (t
);
2182 tree fields
= TYPE_FIELDS (current_class_type
);
2183 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2184 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2187 for (t
= CLASSTYPE_VBASECLASSES (current_class_type
); t
;
2190 tree basetype
= BINFO_TYPE (t
);
2191 tree p
= convert_to_reference
2192 (build_reference_type (basetype
), parm
,
2193 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2194 p
= convert_from_reference (p
);
2196 if (p
== error_mark_node
)
2197 cp_error ("in default copy constructor");
2199 current_base_init_list
= tree_cons (basetype
,
2200 p
, current_base_init_list
);
2203 for (i
= 0; i
< n_bases
; ++i
)
2205 tree p
, basetype
= TREE_VEC_ELT (binfos
, i
);
2206 if (TREE_VIA_VIRTUAL (basetype
))
2209 basetype
= BINFO_TYPE (basetype
);
2210 p
= convert_to_reference
2211 (build_reference_type (basetype
), parm
,
2212 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2214 if (p
== error_mark_node
)
2215 cp_error ("in default copy constructor");
2218 p
= convert_from_reference (p
);
2219 current_base_init_list
= tree_cons (basetype
,
2220 p
, current_base_init_list
);
2223 for (; fields
; fields
= TREE_CHAIN (fields
))
2226 tree field
= fields
;
2228 if (TREE_CODE (field
) != FIELD_DECL
)
2232 if (DECL_NAME (field
))
2234 if (VFIELD_NAME_P (DECL_NAME (field
)))
2236 if (VBASE_NAME_P (DECL_NAME (field
)))
2239 /* True for duplicate members. */
2240 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2243 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2244 && ANON_UNION_TYPE_P (t
)
2245 && TYPE_FIELDS (t
) != NULL_TREE
)
2249 init
= build (COMPONENT_REF
, t
, init
, field
);
2250 field
= largest_union_member (t
);
2252 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2253 && ANON_UNION_TYPE_P (t
)
2254 && TYPE_FIELDS (t
) != NULL_TREE
);
2259 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2260 init
= build_tree_list (NULL_TREE
, init
);
2262 current_member_init_list
2263 = tree_cons (DECL_NAME (field
), init
, current_member_init_list
);
2265 current_member_init_list
= nreverse (current_member_init_list
);
2266 current_base_init_list
= nreverse (current_base_init_list
);
2274 do_build_assign_ref (fndecl
)
2277 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
2282 parm
= convert_from_reference (parm
);
2284 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
)
2285 && is_empty_class (current_class_type
))
2286 /* Don't copy the padding byte; it might not have been allocated
2287 if *this is a base subobject. */;
2288 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type
))
2290 tree t
= build (MODIFY_EXPR
, void_type_node
, current_class_ref
, parm
);
2291 TREE_SIDE_EFFECTS (t
) = 1;
2292 cplus_expand_expr_stmt (t
);
2296 tree fields
= TYPE_FIELDS (current_class_type
);
2297 int n_bases
= CLASSTYPE_N_BASECLASSES (current_class_type
);
2298 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
2301 for (i
= 0; i
< n_bases
; ++i
)
2303 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2304 tree p
= convert_to_reference
2305 (build_reference_type (basetype
), parm
,
2306 CONV_IMPLICIT
|CONV_CONST
, LOOKUP_COMPLAIN
, NULL_TREE
);
2307 p
= convert_from_reference (p
);
2308 p
= build_member_call (basetype
, ansi_opname
[MODIFY_EXPR
],
2309 build_expr_list (NULL_TREE
, p
));
2310 expand_expr_stmt (p
);
2312 for (; fields
; fields
= TREE_CHAIN (fields
))
2315 tree field
= fields
;
2317 if (TREE_CODE (field
) != FIELD_DECL
)
2320 if (TREE_READONLY (field
))
2322 if (DECL_NAME (field
))
2323 cp_error ("non-static const member `%#D', can't use default assignment operator", field
);
2325 cp_error ("non-static const member in type `%T', can't use default assignment operator", current_class_type
);
2328 else if (TREE_CODE (TREE_TYPE (field
)) == REFERENCE_TYPE
)
2330 if (DECL_NAME (field
))
2331 cp_error ("non-static reference member `%#D', can't use default assignment operator", field
);
2333 cp_error ("non-static reference member in type `%T', can't use default assignment operator", current_class_type
);
2337 comp
= current_class_ref
;
2340 if (DECL_NAME (field
))
2342 if (VFIELD_NAME_P (DECL_NAME (field
)))
2344 if (VBASE_NAME_P (DECL_NAME (field
)))
2347 /* True for duplicate members. */
2348 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field
)) != field
)
2351 else if ((t
= TREE_TYPE (field
)) != NULL_TREE
2352 && ANON_UNION_TYPE_P (t
)
2353 && TYPE_FIELDS (t
) != NULL_TREE
)
2357 comp
= build (COMPONENT_REF
, t
, comp
, field
);
2358 init
= build (COMPONENT_REF
, t
, init
, field
);
2359 field
= largest_union_member (t
);
2361 while ((t
= TREE_TYPE (field
)) != NULL_TREE
2362 && ANON_UNION_TYPE_P (t
)
2363 && TYPE_FIELDS (t
) != NULL_TREE
);
2368 comp
= build (COMPONENT_REF
, TREE_TYPE (field
), comp
, field
);
2369 init
= build (COMPONENT_REF
, TREE_TYPE (field
), init
, field
);
2371 expand_expr_stmt (build_modify_expr (comp
, NOP_EXPR
, init
));
2374 c_expand_return (current_class_ref
);
2379 synthesize_method (fndecl
)
2382 int nested
= (current_function_decl
!= NULL_TREE
);
2383 tree context
= hack_decl_function_context (fndecl
);
2386 import_export_decl (fndecl
);
2389 push_to_top_level ();
2391 push_cp_function_context (context
);
2393 interface_unknown
= 1;
2394 start_function (NULL_TREE
, fndecl
, NULL_TREE
, 1);
2395 store_parm_decls ();
2397 if (DECL_NAME (fndecl
) == ansi_opname
[MODIFY_EXPR
])
2398 do_build_assign_ref (fndecl
);
2399 else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2403 tree arg_chain
= FUNCTION_ARG_CHAIN (fndecl
);
2404 if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl
))
2405 arg_chain
= TREE_CHAIN (arg_chain
);
2406 if (arg_chain
!= void_list_node
)
2407 do_build_copy_constructor (fndecl
);
2408 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type
))
2412 finish_function (lineno
, 0, nested
);
2414 extract_interface_info ();
2416 pop_from_top_level ();
2418 pop_cp_function_context (context
);