1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading.
3 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 /* Handle method declarations. */
39 /* Various flags to control the mangling process. */
45 /* The thing we are presently mangling is part of a template type,
46 rather than a fully instantiated type. Therefore, we may see
47 complex expressions where we would normally expect to see a
48 simple integer constant. */
49 mf_maybe_uninstantiated = 1,
50 /* When mangling a numeric value, use the form `_XX_' (instead of
51 just `XX') if the value has more than one digit. */
52 mf_use_underscores_around_value = 2,
55 typedef enum mangling_flags mangling_flags;
57 #define obstack_chunk_alloc xmalloc
58 #define obstack_chunk_free free
60 static void do_build_assign_ref PARAMS ((tree));
61 static void do_build_copy_constructor PARAMS ((tree));
62 static tree synthesize_exception_spec PARAMS ((tree, tree (*) (tree, void *), void *));
63 static tree locate_dtor PARAMS ((tree, void *));
64 static tree locate_ctor PARAMS ((tree, void *));
65 static tree locate_copy PARAMS ((tree, void *));
67 /* Called once to initialize method.c. */
76 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
79 set_mangled_name_for_decl (decl)
82 if (processing_template_decl)
83 /* There's no need to mangle the name of a template function. */
90 /* Given a tree_code CODE, and some arguments (at least one),
91 attempt to use an overloaded operator on the arguments.
93 For unary operators, only the first argument need be checked.
94 For binary operators, both arguments may need to be checked.
96 Member functions can convert class references to class pointers,
97 for one-level deep indirection. More than that is not supported.
98 Operators [](), ()(), and ->() must be member functions.
100 We call function call building calls with LOOKUP_COMPLAIN if they
101 are our only hope. This is true when we see a vanilla operator
102 applied to something of aggregate type. If this fails, we are free
103 to return `error_mark_node', because we will have reported the
106 Operators NEW and DELETE overload in funny ways: operator new takes
107 a single `size' parameter, and operator delete takes a pointer to the
108 storage being deleted. When overloading these operators, success is
109 assumed. If there is a failure, report an error message and return
110 `error_mark_node'. */
114 build_opfncall (code, flags, xarg1, xarg2, arg3)
117 tree xarg1, xarg2, arg3;
119 return build_new_op (code, flags, xarg1, xarg2, arg3);
122 /* This function takes an identifier, ID, and attempts to figure out what
123 it means. There are a number of possible scenarios, presented in increasing
126 1) not in a class's scope
127 2) in class's scope, member name of the class's method
128 3) in class's scope, but not a member name of the class
129 4) in class's scope, member name of a class's variable
131 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
132 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
134 As a last ditch, try to look up the name as a label and return that
137 Values which are declared as being of REFERENCE_TYPE are
138 automatically dereferenced here (as a hack to make the
142 hack_identifier (value, name)
147 if (value == error_mark_node)
149 if (current_class_name)
151 tree fields = lookup_fnfields (TYPE_BINFO (current_class_type),
153 if (fields == error_mark_node)
154 return error_mark_node;
159 fndecl = TREE_VALUE (fields);
160 my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251);
161 /* I could not trigger this code. MvL */
162 my_friendly_abort (980325);
164 if (DECL_CHAIN (fndecl) == NULL_TREE)
166 warning ("methods cannot be converted to function pointers");
171 error ("ambiguous request for method pointer `%s'",
172 IDENTIFIER_POINTER (name));
173 return error_mark_node;
178 return error_mark_node;
181 type = TREE_TYPE (value);
182 if (TREE_CODE (value) == FIELD_DECL)
184 if (current_class_ptr == NULL_TREE)
186 if (current_function_decl
187 && DECL_STATIC_FUNCTION_P (current_function_decl))
188 cp_error ("invalid use of member `%D' in static member function",
191 /* We can get here when processing a bad default
193 struct S { int a; void f(int i = a); } */
194 cp_error ("invalid use of member `%D'", value);
196 return error_mark_node;
198 TREE_USED (current_class_ptr) = 1;
200 /* Mark so that if we are in a constructor, and then find that
201 this field was initialized by a base initializer,
202 we can emit an error message. */
203 TREE_USED (value) = 1;
204 value = build_component_ref (current_class_ref, name, NULL_TREE, 1);
206 else if ((TREE_CODE (value) == FUNCTION_DECL
207 && DECL_FUNCTION_MEMBER_P (value))
208 || (TREE_CODE (value) == OVERLOAD
209 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
213 if (TREE_CODE (value) == OVERLOAD)
214 value = OVL_CURRENT (value);
216 decl = maybe_dummy_object (DECL_CONTEXT (value), 0);
217 value = build_component_ref (decl, name, NULL_TREE, 1);
219 else if (really_overloaded_fn (value))
221 else if (TREE_CODE (value) == OVERLOAD)
222 /* not really overloaded function */
223 mark_used (OVL_FUNCTION (value));
224 else if (TREE_CODE (value) == TREE_LIST)
226 /* Ambiguous reference to base members, possibly other cases?. */
228 while (t && TREE_CODE (t) == TREE_LIST)
230 mark_used (TREE_VALUE (t));
234 else if (TREE_CODE (value) == NAMESPACE_DECL)
236 cp_error ("use of namespace `%D' as expression", value);
237 return error_mark_node;
239 else if (DECL_CLASS_TEMPLATE_P (value))
241 cp_error ("use of class template `%T' as expression", value);
242 return error_mark_node;
247 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
248 || TREE_CODE (value) == RESULT_DECL)
250 tree context = decl_function_context (value);
251 if (context != NULL_TREE && context != current_function_decl
252 && ! TREE_STATIC (value))
254 cp_error ("use of %s from containing function",
255 (TREE_CODE (value) == VAR_DECL
256 ? "`auto' variable" : "parameter"));
257 cp_error_at (" `%#D' declared here", value);
258 value = error_mark_node;
262 if (DECL_P (value) && DECL_NONLOCAL (value))
264 if (DECL_CLASS_SCOPE_P (value)
265 && DECL_CONTEXT (value) != current_class_type)
268 path = currently_open_derived_class (DECL_CONTEXT (value));
269 enforce_access (path, value);
272 else if (TREE_CODE (value) == TREE_LIST
273 && TREE_TYPE (value) == error_mark_node)
276 request for member `%D' is ambiguous in multiple inheritance lattice",
278 print_candidates (value);
279 return error_mark_node;
282 if (! processing_template_decl)
283 value = convert_from_reference (value);
288 /* Return a thunk to FUNCTION. For a virtual thunk, DELTA is the
289 offset to this used to locate the vptr, and VCALL_INDEX is used to
290 look up the eventual subobject location. For a non-virtual thunk,
291 DELTA is the offset to this and VCALL_INDEX is NULL. */
294 make_thunk (function, delta, vcall_index)
305 /* Scale the VCALL_INDEX to be in terms of bytes. */
308 = size_binop (MULT_EXPR,
311 TYPE_SIZE_UNIT (vtable_entry_type)));
313 vcall_offset = NULL_TREE;
315 d = tree_low_cst (delta, 0);
317 if (TREE_CODE (function) != ADDR_EXPR)
319 func_decl = TREE_OPERAND (function, 0);
320 if (TREE_CODE (func_decl) != FUNCTION_DECL)
323 thunk_id = mangle_thunk (TREE_OPERAND (function, 0),
324 delta, vcall_offset);
325 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
326 if (thunk && !DECL_THUNK_P (thunk))
328 cp_error ("implementation-reserved name `%D' used", thunk_id);
330 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
332 if (thunk == NULL_TREE)
334 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
335 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (func_decl);
336 copy_lang_decl (func_decl);
337 SET_DECL_ASSEMBLER_NAME (thunk, thunk_id);
338 DECL_CONTEXT (thunk) = DECL_CONTEXT (func_decl);
339 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
340 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
341 comdat_linkage (thunk);
342 SET_DECL_THUNK_P (thunk);
343 DECL_INITIAL (thunk) = function;
344 THUNK_DELTA (thunk) = d;
345 THUNK_VCALL_OFFSET (thunk) = vcall_offset;
346 /* The thunk itself is not a constructor or destructor, even if
347 the thing it is thunking to is. */
348 DECL_INTERFACE_KNOWN (thunk) = 1;
349 DECL_NOT_REALLY_EXTERN (thunk) = 1;
350 DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
351 DECL_DESTRUCTOR_P (thunk) = 0;
352 DECL_CONSTRUCTOR_P (thunk) = 0;
353 /* And neither is it a clone. */
354 DECL_CLONED_FUNCTION (thunk) = NULL_TREE;
355 DECL_EXTERNAL (thunk) = 1;
356 DECL_ARTIFICIAL (thunk) = 1;
357 /* Even if this thunk is a member of a local class, we don't
358 need a static chain. */
359 DECL_NO_STATIC_CHAIN (thunk) = 1;
360 /* The THUNK is not a pending inline, even if the FUNC_DECL is. */
361 DECL_PENDING_INLINE_P (thunk) = 0;
362 /* Nor has it been deferred. */
363 DECL_DEFERRED_FN (thunk) = 0;
364 /* So that finish_file can write out any thunks that need to be: */
365 pushdecl_top_level (thunk);
366 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
371 /* Emit the definition of a C++ multiple inheritance vtable thunk. If
372 EMIT_P is non-zero, the thunk is emitted immediately. */
375 use_thunk (thunk_fndecl, emit_p)
384 if (TREE_ASM_WRITTEN (thunk_fndecl))
387 fnaddr = DECL_INITIAL (thunk_fndecl);
388 if (TREE_CODE (DECL_INITIAL (thunk_fndecl)) != ADDR_EXPR)
389 /* We already turned this thunk into an ordinary function.
390 There's no need to process this thunk again. */
393 /* Thunks are always addressable; they only appear in vtables. */
394 TREE_ADDRESSABLE (thunk_fndecl) = 1;
396 /* Figure out what function is being thunked to. It's referenced in
397 this translation unit. */
398 function = TREE_OPERAND (fnaddr, 0);
399 TREE_ADDRESSABLE (function) = 1;
400 mark_used (function);
401 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (function)) = 1;
405 delta = THUNK_DELTA (thunk_fndecl);
406 vcall_offset = THUNK_VCALL_OFFSET (thunk_fndecl);
408 /* And, if we need to emit the thunk, it's used. */
409 mark_used (thunk_fndecl);
410 /* This thunk is actually defined. */
411 DECL_EXTERNAL (thunk_fndecl) = 0;
413 if (flag_syntax_only)
415 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
419 push_to_top_level ();
421 #ifdef ASM_OUTPUT_MI_THUNK
425 current_function_decl = thunk_fndecl;
426 DECL_RESULT (thunk_fndecl)
427 = build_decl (RESULT_DECL, 0, integer_type_node);
428 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
429 init_function_start (thunk_fndecl, input_filename, lineno);
430 current_function_is_thunk = 1;
431 assemble_start_function (thunk_fndecl, fnname);
432 ASM_OUTPUT_MI_THUNK (asm_out_file, thunk_fndecl, delta, function);
433 assemble_end_function (thunk_fndecl, fnname);
434 current_function_decl = 0;
436 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
439 #endif /* ASM_OUTPUT_MI_THUNK */
441 /* If we don't have the necessary macro for efficient thunks, generate a
442 thunk function that just makes a call to the real function.
443 Unfortunately, this doesn't work for varargs. */
447 if (varargs_function_p (function))
448 cp_error ("generic thunk code fails for method `%#D' which uses `...'",
451 /* Set up clone argument trees for the thunk. */
453 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
455 tree x = copy_node (a);
457 DECL_CONTEXT (x) = thunk_fndecl;
461 DECL_ARGUMENTS (thunk_fndecl) = a;
462 DECL_RESULT (thunk_fndecl) = NULL_TREE;
464 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, SF_PRE_PARSED);
465 /* We don't bother with a body block for thunks. */
467 /* Adjust the this pointer by the constant. */
468 t = ssize_int (delta);
469 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
470 /* If there's a vcall offset, look up that value in the vtable and
471 adjust the `this' pointer again. */
472 if (vcall_offset && !integer_zerop (vcall_offset))
478 /* The vptr is always at offset zero in the object. */
479 t = build1 (NOP_EXPR,
480 build_pointer_type (build_pointer_type
481 (vtable_entry_type)),
483 /* Form the vtable address. */
484 t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
485 /* Find the entry with the vcall offset. */
486 t = build (PLUS_EXPR, TREE_TYPE (t), t, vcall_offset);
487 /* Calculate the offset itself. */
488 t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
489 /* Adjust the `this' pointer. */
490 t = fold (build (PLUS_EXPR,
491 TREE_TYPE (orig_this),
496 /* Build up the call to the real function. */
497 t = tree_cons (NULL_TREE, t, NULL_TREE);
498 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
499 t = tree_cons (NULL_TREE, a, t);
501 t = build_call (function, t);
502 if (VOID_TYPE_P (TREE_TYPE (t)))
503 finish_expr_stmt (t);
505 finish_return_stmt (t);
507 /* The back-end expects DECL_INITIAL to contain a BLOCK, so we
509 DECL_INITIAL (thunk_fndecl) = make_node (BLOCK);
510 BLOCK_VARS (DECL_INITIAL (thunk_fndecl))
511 = DECL_ARGUMENTS (thunk_fndecl);
513 /* Since we want to emit the thunk, we explicitly mark its name as
515 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (thunk_fndecl)) = 1;
517 /* But we don't want debugging information about it. */
518 DECL_IGNORED_P (thunk_fndecl) = 1;
520 expand_body (finish_function (0));
523 pop_from_top_level ();
526 /* Code for synthesizing methods which have default semantics defined. */
528 /* Generate code for default X(X&) constructor. */
531 do_build_copy_constructor (fndecl)
534 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
537 parm = convert_from_reference (parm);
539 if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)
540 && is_empty_class (current_class_type))
541 /* Don't copy the padding byte; it might not have been allocated
542 if *this is a base subobject. */;
543 else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type))
545 t = build (INIT_EXPR, void_type_node, current_class_ref, parm);
546 finish_expr_stmt (t);
550 tree fields = TYPE_FIELDS (current_class_type);
551 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
552 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
553 tree member_init_list = NULL_TREE;
554 tree base_init_list = NULL_TREE;
555 int cvquals = cp_type_quals (TREE_TYPE (parm));
558 /* Initialize all the base-classes with the parameter converted
559 to their type so that we get their copy constructor and not
560 another constructor that takes current_class_type. We must
561 deal with the binfo's directly as a direct base might be
562 inaccessible due to ambiguity. */
563 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
566 tree binfo = TREE_VALUE (t);
568 base_init_list = tree_cons (binfo,
569 build_base_path (PLUS_EXPR, parm,
574 for (i = 0; i < n_bases; ++i)
576 tree binfo = TREE_VEC_ELT (binfos, i);
577 if (TREE_VIA_VIRTUAL (binfo))
580 base_init_list = tree_cons (binfo,
581 build_base_path (PLUS_EXPR, parm,
586 for (; fields; fields = TREE_CHAIN (fields))
591 if (TREE_CODE (field) != FIELD_DECL)
595 if (DECL_NAME (field))
597 if (VFIELD_NAME_P (DECL_NAME (field)))
600 /* True for duplicate members. */
601 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
604 else if ((t = TREE_TYPE (field)) != NULL_TREE
605 && ANON_AGGR_TYPE_P (t)
606 && TYPE_FIELDS (t) != NULL_TREE)
607 /* Just use the field; anonymous types can't have
608 nontrivial copy ctors or assignment ops. */;
612 init = build (COMPONENT_REF,
613 build_qualified_type (TREE_TYPE (field), cvquals),
615 init = build_tree_list (NULL_TREE, init);
618 = tree_cons (field, init, member_init_list);
620 member_init_list = nreverse (member_init_list);
621 base_init_list = nreverse (base_init_list);
622 setup_vtbl_ptr (member_init_list, base_init_list);
627 do_build_assign_ref (fndecl)
630 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
633 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
634 parm = convert_from_reference (parm);
636 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
637 && is_empty_class (current_class_type))
638 /* Don't copy the padding byte; it might not have been allocated
639 if *this is a base subobject. */;
640 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
642 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
643 finish_expr_stmt (t);
647 tree fields = TYPE_FIELDS (current_class_type);
648 int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type);
649 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
650 int cvquals = cp_type_quals (TREE_TYPE (parm));
653 for (i = 0; i < n_bases; ++i)
655 /* We must deal with the binfo's directly as a direct base
656 might be inaccessible due to ambiguity. */
657 tree binfo = TREE_VEC_ELT (binfos, i);
658 tree src = build_base_path (PLUS_EXPR, parm, binfo, 1);
659 tree dst = build_base_path (PLUS_EXPR, current_class_ref, binfo, 1);
661 tree expr = build_method_call (dst,
662 ansi_assopname (NOP_EXPR),
663 build_tree_list (NULL_TREE, src),
665 LOOKUP_NORMAL | LOOKUP_NONVIRTUAL);
666 finish_expr_stmt (expr);
668 for (; fields; fields = TREE_CHAIN (fields))
673 if (TREE_CODE (field) != FIELD_DECL)
676 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
678 cp_error ("non-static const member `%#D', can't use default assignment operator", field);
681 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
683 cp_error ("non-static reference member `%#D', can't use default assignment operator", field);
687 comp = current_class_ref;
690 if (DECL_NAME (field))
692 if (VFIELD_NAME_P (DECL_NAME (field)))
695 /* True for duplicate members. */
696 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
699 else if ((t = TREE_TYPE (field)) != NULL_TREE
700 && ANON_AGGR_TYPE_P (t)
701 && TYPE_FIELDS (t) != NULL_TREE)
702 /* Just use the field; anonymous types can't have
703 nontrivial copy ctors or assignment ops. */;
707 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
708 init = build (COMPONENT_REF,
709 build_qualified_type (TREE_TYPE (field), cvquals),
712 if (DECL_NAME (field))
713 finish_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
715 finish_expr_stmt (build (MODIFY_EXPR, TREE_TYPE (comp), comp,
719 finish_return_stmt (current_class_ref);
720 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
724 synthesize_method (fndecl)
727 int nested = (current_function_decl != NULL_TREE);
728 tree context = decl_function_context (fndecl);
732 import_export_decl (fndecl);
734 /* If we've been asked to synthesize a clone, just synthesize the
735 cloned function instead. Doing so will automatically fill in the
736 body for the clone. */
737 if (DECL_CLONED_FUNCTION_P (fndecl))
739 synthesize_method (DECL_CLONED_FUNCTION (fndecl));
744 push_to_top_level ();
746 push_function_context_to (context);
748 /* Put the function definition at the position where it is needed,
749 rather than within the body of the class. That way, an error
750 during the generation of the implicit body points at the place
751 where the attempt to generate the function occurs, giving the
752 user a hint as to why we are attempting to generate the
754 DECL_SOURCE_LINE (fndecl) = lineno;
755 DECL_SOURCE_FILE (fndecl) = input_filename;
757 interface_unknown = 1;
758 start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
761 if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
763 do_build_assign_ref (fndecl);
766 else if (DECL_DESTRUCTOR_P (fndecl))
767 setup_vtbl_ptr (NULL_TREE, NULL_TREE);
770 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
771 if (arg_chain != void_list_node)
772 do_build_copy_constructor (fndecl);
773 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
774 setup_vtbl_ptr (NULL_TREE, NULL_TREE);
777 /* If we haven't yet generated the body of the function, just
778 generate an empty compound statement. */
782 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
783 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
786 expand_body (finish_function (0));
788 extract_interface_info ();
790 pop_from_top_level ();
792 pop_function_context_from (context);
795 /* Use EXTRACTOR to locate the relevant function called for each base &
796 class field of TYPE. CLIENT allows additional information to be passed
797 to EXTRACTOR. Generates the union of all exceptions generated by
801 synthesize_exception_spec (type, extractor, client)
803 tree (*extractor) (tree, void *);
806 tree raises = empty_except_spec;
807 tree fields = TYPE_FIELDS (type);
808 int i, n_bases = CLASSTYPE_N_BASECLASSES (type);
809 tree binfos = TYPE_BINFO_BASETYPES (type);
811 for (i = 0; i != n_bases; i++)
813 tree base = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
814 tree fn = (*extractor) (base, client);
817 tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
819 raises = merge_exception_specifiers (raises, fn_raises);
822 for (; fields; fields = TREE_CHAIN (fields))
824 tree type = TREE_TYPE (fields);
827 if (TREE_CODE (fields) != FIELD_DECL)
829 while (TREE_CODE (type) == ARRAY_TYPE)
830 type = TREE_TYPE (type);
831 if (TREE_CODE (type) != RECORD_TYPE)
834 fn = (*extractor) (type, client);
837 tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
839 raises = merge_exception_specifiers (raises, fn_raises);
845 /* Locate the dtor of TYPE. */
848 locate_dtor (type, client)
850 void *client ATTRIBUTE_UNUSED;
854 if (!TYPE_HAS_DESTRUCTOR (type))
856 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type),
857 CLASSTYPE_DESTRUCTOR_SLOT);
861 /* Locate the default ctor of TYPE. */
864 locate_ctor (type, client)
866 void *client ATTRIBUTE_UNUSED;
870 if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
873 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type),
874 CLASSTYPE_CONSTRUCTOR_SLOT);
875 for (; fns; fns = OVL_NEXT (fns))
877 tree fn = OVL_CURRENT (fns);
878 tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
880 if (sufficient_parms_p (TREE_CHAIN (parms)))
892 /* Locate the copy ctor or copy assignment of TYPE. CLIENT_
893 points to a COPY_DATA holding the name (NULL for the ctor)
894 and desired qualifiers of the source operand. */
897 locate_copy (type, client_)
901 struct copy_data *client = (struct copy_data *)client_;
904 tree best = NULL_TREE;
909 if (TYPE_HAS_ASSIGN_REF (type))
910 ix = lookup_fnfields_1 (type, client->name);
912 else if (TYPE_HAS_INIT_REF (type))
913 ix = CLASSTYPE_CONSTRUCTOR_SLOT;
916 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), ix);
918 for (; fns; fns = OVL_NEXT (fns))
920 tree fn = OVL_CURRENT (fns);
921 tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
926 parms = TREE_CHAIN (parms);
929 src_type = TREE_VALUE (parms);
930 if (TREE_CODE (src_type) == REFERENCE_TYPE)
931 src_type = TREE_TYPE (src_type);
932 if (!same_type_ignoring_top_level_qualifiers_p (src_type, type))
934 if (!sufficient_parms_p (TREE_CHAIN (parms)))
936 quals = cp_type_quals (src_type);
937 if (client->quals & ~quals)
939 excess = quals & ~client->quals;
940 if (!best || (excess_p && !excess))
952 /* Implicitly declare the special function indicated by KIND, as a
953 member of TYPE. For copy constructors and assignment operators,
954 CONST_P indicates whether these functions should take a const
955 reference argument or a non-const reference. */
958 implicitly_declare_fn (kind, type, const_p)
959 special_function_kind kind;
963 tree declspecs = NULL_TREE;
964 tree fn, args = NULL_TREE;
965 tree raises = empty_except_spec;
968 tree name = constructor_name (TYPE_IDENTIFIER (type));
974 name = build_nt (BIT_NOT_EXPR, name);
975 args = void_list_node;
976 raises = synthesize_exception_spec (type, &locate_dtor, 0);
979 case sfk_constructor:
980 /* Default constructor. */
981 args = void_list_node;
982 raises = synthesize_exception_spec (type, &locate_ctor, 0);
985 case sfk_copy_constructor:
986 case sfk_assignment_operator:
988 struct copy_data data;
994 if (kind == sfk_assignment_operator)
997 declspecs = build_tree_list (NULL_TREE, type);
999 name = ansi_assopname (NOP_EXPR);
1004 data.quals = TYPE_QUAL_CONST;
1005 type = build_qualified_type (type, TYPE_QUAL_CONST);
1008 argtype = build_reference_type (type);
1009 args = build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1010 get_identifier ("_ctor_arg"));
1011 args = tree_cons (NULL_TREE, args, void_list_node);
1013 raises = synthesize_exception_spec (type, &locate_copy, &data);
1017 my_friendly_abort (59);
1020 TREE_PARMLIST (args) = 1;
1023 tree declarator = make_call_declarator (name, args, NULL_TREE, raises);
1026 declarator = build_nt (ADDR_EXPR, declarator);
1028 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
1030 TREE_USED (FUNCTION_FIRST_USER_PARM (fn)) = 1;
1033 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 20000408);
1035 DECL_ARTIFICIAL (fn) = 1;
1036 DECL_NOT_REALLY_EXTERN (fn) = 1;
1037 DECL_DECLARED_INLINE_P (fn) = 1;
1038 DECL_INLINE (fn) = 1;
1044 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
1045 as there are artificial parms in FN. */
1048 skip_artificial_parms_for (fn, list)
1051 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1052 list = TREE_CHAIN (list);
1056 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1057 list = TREE_CHAIN (list);
1058 if (DECL_HAS_VTT_PARM_P (fn))
1059 list = TREE_CHAIN (list);