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 static void do_build_assign_ref PARAMS ((tree));
58 static void do_build_copy_constructor PARAMS ((tree));
59 static tree synthesize_exception_spec PARAMS ((tree, tree (*) (tree, void *), void *));
60 static tree locate_dtor PARAMS ((tree, void *));
61 static tree locate_ctor PARAMS ((tree, void *));
62 static tree locate_copy PARAMS ((tree, void *));
64 /* Called once to initialize method.c. */
73 /* Set the mangled name (DECL_ASSEMBLER_NAME) for DECL. */
76 set_mangled_name_for_decl (decl)
79 if (processing_template_decl)
80 /* There's no need to mangle the name of a template function. */
87 /* Given a tree_code CODE, and some arguments (at least one),
88 attempt to use an overloaded operator on the arguments.
90 For unary operators, only the first argument need be checked.
91 For binary operators, both arguments may need to be checked.
93 Member functions can convert class references to class pointers,
94 for one-level deep indirection. More than that is not supported.
95 Operators [](), ()(), and ->() must be member functions.
97 We call function call building calls with LOOKUP_COMPLAIN if they
98 are our only hope. This is true when we see a vanilla operator
99 applied to something of aggregate type. If this fails, we are free
100 to return `error_mark_node', because we will have reported the
103 Operators NEW and DELETE overload in funny ways: operator new takes
104 a single `size' parameter, and operator delete takes a pointer to the
105 storage being deleted. When overloading these operators, success is
106 assumed. If there is a failure, report an error message and return
107 `error_mark_node'. */
111 build_opfncall (code, flags, xarg1, xarg2, arg3)
114 tree xarg1, xarg2, arg3;
116 return build_new_op (code, flags, xarg1, xarg2, arg3);
119 /* This function takes an identifier, ID, and attempts to figure out what
120 it means. There are a number of possible scenarios, presented in increasing
123 1) not in a class's scope
124 2) in class's scope, member name of the class's method
125 3) in class's scope, but not a member name of the class
126 4) in class's scope, member name of a class's variable
128 NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
129 VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
131 As a last ditch, try to look up the name as a label and return that
134 Values which are declared as being of REFERENCE_TYPE are
135 automatically dereferenced here (as a hack to make the
139 hack_identifier (value, name)
144 if (value == error_mark_node)
145 return error_mark_node;
147 type = TREE_TYPE (value);
148 if (TREE_CODE (value) == FIELD_DECL)
150 if (current_class_ptr == NULL_TREE)
152 if (current_function_decl
153 && DECL_STATIC_FUNCTION_P (current_function_decl))
154 error ("invalid use of member `%D' in static member function",
157 /* We can get here when processing a bad default
159 struct S { int a; void f(int i = a); } */
160 error ("invalid use of member `%D'", value);
162 return error_mark_node;
164 TREE_USED (current_class_ptr) = 1;
165 if (processing_template_decl)
166 value = build_min_nt (COMPONENT_REF, current_class_ref, name);
169 tree access_type = current_class_type;
171 while (!DERIVED_FROM_P (context_for_name_lookup (value),
174 access_type = TYPE_CONTEXT (access_type);
175 while (DECL_P (access_type))
176 access_type = DECL_CONTEXT (access_type);
179 enforce_access (access_type, value);
181 = build_class_member_access_expr (current_class_ref, value,
182 /*access_path=*/NULL_TREE,
183 /*preserve_reference=*/false);
186 else if ((TREE_CODE (value) == FUNCTION_DECL
187 && DECL_FUNCTION_MEMBER_P (value))
188 || (TREE_CODE (value) == OVERLOAD
189 && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
193 if (TREE_CODE (value) == OVERLOAD)
194 value = OVL_CURRENT (value);
196 decl = maybe_dummy_object (DECL_CONTEXT (value), 0);
197 value = finish_class_member_access_expr (decl, name);
199 else if (really_overloaded_fn (value))
201 else if (TREE_CODE (value) == OVERLOAD)
202 /* not really overloaded function */
203 mark_used (OVL_FUNCTION (value));
204 else if (TREE_CODE (value) == TREE_LIST)
206 /* Ambiguous reference to base members, possibly other cases?. */
208 while (t && TREE_CODE (t) == TREE_LIST)
210 mark_used (TREE_VALUE (t));
214 else if (TREE_CODE (value) == NAMESPACE_DECL)
216 error ("use of namespace `%D' as expression", value);
217 return error_mark_node;
219 else if (DECL_CLASS_TEMPLATE_P (value))
221 error ("use of class template `%T' as expression", value);
222 return error_mark_node;
227 if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
228 || TREE_CODE (value) == RESULT_DECL)
230 tree context = decl_function_context (value);
231 if (context != NULL_TREE && context != current_function_decl
232 && ! TREE_STATIC (value))
234 error ("use of %s from containing function",
235 (TREE_CODE (value) == VAR_DECL
236 ? "`auto' variable" : "parameter"));
237 cp_error_at (" `%#D' declared here", value);
238 value = error_mark_node;
242 if (DECL_P (value) && DECL_NONLOCAL (value))
244 if (DECL_CLASS_SCOPE_P (value)
245 && DECL_CONTEXT (value) != current_class_type)
248 path = currently_open_derived_class (DECL_CONTEXT (value));
249 enforce_access (path, value);
252 else if (TREE_CODE (value) == TREE_LIST
253 && TREE_TYPE (value) == error_mark_node)
256 request for member `%D' is ambiguous in multiple inheritance lattice",
258 print_candidates (value);
259 return error_mark_node;
262 if (! processing_template_decl)
263 value = convert_from_reference (value);
268 /* Return a thunk to FUNCTION. For a virtual thunk, DELTA is the
269 offset to this used to locate the vptr, and VCALL_INDEX is used to
270 look up the eventual subobject location. For a non-virtual thunk,
271 DELTA is the offset to this and VCALL_INDEX is NULL. */
274 make_thunk (function, delta, vcall_index)
285 /* Scale the VCALL_INDEX to be in terms of bytes. */
288 = size_binop (MULT_EXPR,
291 TYPE_SIZE_UNIT (vtable_entry_type)));
293 vcall_offset = NULL_TREE;
295 d = tree_low_cst (delta, 0);
297 if (TREE_CODE (function) != ADDR_EXPR)
299 func_decl = TREE_OPERAND (function, 0);
300 if (TREE_CODE (func_decl) != FUNCTION_DECL)
303 thunk_id = mangle_thunk (TREE_OPERAND (function, 0),
304 delta, vcall_offset);
305 thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id);
306 if (thunk && !DECL_THUNK_P (thunk))
308 error ("implementation-reserved name `%D' used", thunk_id);
310 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
312 if (thunk == NULL_TREE)
314 thunk = build_decl (FUNCTION_DECL, thunk_id, TREE_TYPE (func_decl));
315 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (func_decl);
316 cxx_dup_lang_specific_decl (func_decl);
317 SET_DECL_ASSEMBLER_NAME (thunk, thunk_id);
318 DECL_CONTEXT (thunk) = DECL_CONTEXT (func_decl);
319 TREE_READONLY (thunk) = TREE_READONLY (func_decl);
320 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (func_decl);
321 TREE_PUBLIC (thunk) = TREE_PUBLIC (func_decl);
323 comdat_linkage (thunk);
324 SET_DECL_THUNK_P (thunk);
325 DECL_INITIAL (thunk) = function;
326 THUNK_DELTA (thunk) = d;
327 THUNK_VCALL_OFFSET (thunk) = vcall_offset;
328 /* The thunk itself is not a constructor or destructor, even if
329 the thing it is thunking to is. */
330 DECL_INTERFACE_KNOWN (thunk) = 1;
331 DECL_NOT_REALLY_EXTERN (thunk) = 1;
332 DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
333 DECL_DESTRUCTOR_P (thunk) = 0;
334 DECL_CONSTRUCTOR_P (thunk) = 0;
335 /* And neither is it a clone. */
336 DECL_CLONED_FUNCTION (thunk) = NULL_TREE;
337 DECL_EXTERNAL (thunk) = 1;
338 DECL_ARTIFICIAL (thunk) = 1;
339 /* Even if this thunk is a member of a local class, we don't
340 need a static chain. */
341 DECL_NO_STATIC_CHAIN (thunk) = 1;
342 /* The THUNK is not a pending inline, even if the FUNC_DECL is. */
343 DECL_PENDING_INLINE_P (thunk) = 0;
344 /* Nor has it been deferred. */
345 DECL_DEFERRED_FN (thunk) = 0;
346 /* So that finish_file can write out any thunks that need to be: */
347 pushdecl_top_level (thunk);
348 SET_IDENTIFIER_GLOBAL_VALUE (thunk_id, thunk);
353 /* Emit the definition of a C++ multiple inheritance vtable thunk. If
354 EMIT_P is nonzero, the thunk is emitted immediately. */
357 use_thunk (thunk_fndecl, emit_p)
366 if (TREE_ASM_WRITTEN (thunk_fndecl))
369 fnaddr = DECL_INITIAL (thunk_fndecl);
370 if (TREE_CODE (DECL_INITIAL (thunk_fndecl)) != ADDR_EXPR)
371 /* We already turned this thunk into an ordinary function.
372 There's no need to process this thunk again. */
375 /* Thunks are always addressable; they only appear in vtables. */
376 TREE_ADDRESSABLE (thunk_fndecl) = 1;
378 /* Figure out what function is being thunked to. It's referenced in
379 this translation unit. */
380 function = TREE_OPERAND (fnaddr, 0);
381 TREE_ADDRESSABLE (function) = 1;
382 mark_used (function);
383 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (function)) = 1;
387 delta = THUNK_DELTA (thunk_fndecl);
388 vcall_offset = THUNK_VCALL_OFFSET (thunk_fndecl);
390 /* And, if we need to emit the thunk, it's used. */
391 mark_used (thunk_fndecl);
392 /* This thunk is actually defined. */
393 DECL_EXTERNAL (thunk_fndecl) = 0;
394 /* The linkage of the function may have changed. FIXME in linkage
396 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
398 if (flag_syntax_only)
400 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
404 push_to_top_level ();
406 /* The back-end expects DECL_INITIAL to contain a BLOCK, so we
408 DECL_INITIAL (thunk_fndecl) = make_node (BLOCK);
409 BLOCK_VARS (DECL_INITIAL (thunk_fndecl))
410 = DECL_ARGUMENTS (thunk_fndecl);
412 if (targetm.asm_out.output_mi_vcall_thunk
413 || (targetm.asm_out.output_mi_thunk && !vcall_offset))
416 current_function_decl = thunk_fndecl;
417 DECL_RESULT (thunk_fndecl)
418 = build_decl (RESULT_DECL, 0, integer_type_node);
419 fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0);
420 init_function_start (thunk_fndecl, input_filename, lineno);
421 current_function_is_thunk = 1;
422 assemble_start_function (thunk_fndecl, fnname);
423 if (targetm.asm_out.output_mi_vcall_thunk)
425 HOST_WIDE_INT vcall_value;
428 vcall_value = tree_low_cst (vcall_offset, /*pos=*/0);
431 targetm.asm_out.output_mi_vcall_thunk (asm_out_file,
437 targetm.asm_out.output_mi_thunk (asm_out_file, thunk_fndecl,
439 assemble_end_function (thunk_fndecl, fnname);
440 current_function_decl = 0;
442 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
446 /* If we don't have the necessary code for efficient thunks,
447 generate a thunk function that just makes a call to the real
448 function. Unfortunately, this doesn't work for varargs. */
452 if (varargs_function_p (function))
453 error ("generic thunk code fails for method `%#D' which uses `...'",
456 /* Set up clone argument trees for the thunk. */
458 for (a = DECL_ARGUMENTS (function); a; a = TREE_CHAIN (a))
460 tree x = copy_node (a);
462 DECL_CONTEXT (x) = thunk_fndecl;
466 DECL_ARGUMENTS (thunk_fndecl) = a;
467 DECL_RESULT (thunk_fndecl) = NULL_TREE;
469 start_function (NULL_TREE, thunk_fndecl, NULL_TREE, SF_PRE_PARSED);
470 /* We don't bother with a body block for thunks. */
472 /* Adjust the this pointer by the constant. */
473 t = ssize_int (delta);
474 t = fold (build (PLUS_EXPR, TREE_TYPE (a), a, t));
476 /* If there's a vcall offset, look up that value in the vtable and
477 adjust the `this' pointer again. */
478 if (vcall_offset && !integer_zerop (vcall_offset))
484 /* The vptr is always at offset zero in the object. */
485 t = build1 (NOP_EXPR,
486 build_pointer_type (build_pointer_type
487 (vtable_entry_type)),
489 /* Form the vtable address. */
490 t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
491 /* Find the entry with the vcall offset. */
492 t = build (PLUS_EXPR, TREE_TYPE (t), t, vcall_offset);
493 /* Calculate the offset itself. */
494 t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t);
495 /* Adjust the `this' pointer. */
496 t = fold (build (PLUS_EXPR,
497 TREE_TYPE (orig_this),
502 /* Build up the call to the real function. */
503 t = tree_cons (NULL_TREE, t, NULL_TREE);
504 for (a = TREE_CHAIN (a); a; a = TREE_CHAIN (a))
505 t = tree_cons (NULL_TREE, a, t);
507 t = build_call (function, t);
508 if (VOID_TYPE_P (TREE_TYPE (t)))
509 finish_expr_stmt (t);
511 finish_return_stmt (t);
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 int cvquals = cp_type_quals (TREE_TYPE (parm));
557 /* Initialize all the base-classes with the parameter converted
558 to their type so that we get their copy constructor and not
559 another constructor that takes current_class_type. We must
560 deal with the binfo's directly as a direct base might be
561 inaccessible due to ambiguity. */
562 for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
565 tree binfo = TREE_VALUE (t);
569 build_tree_list (NULL_TREE,
570 build_base_path (PLUS_EXPR, parm,
575 for (i = 0; i < n_bases; ++i)
577 tree binfo = TREE_VEC_ELT (binfos, i);
578 if (TREE_VIA_VIRTUAL (binfo))
583 build_tree_list (NULL_TREE,
584 build_base_path (PLUS_EXPR, parm,
589 for (; fields; fields = TREE_CHAIN (fields))
595 if (TREE_CODE (field) != FIELD_DECL)
599 if (DECL_NAME (field))
601 if (VFIELD_NAME_P (DECL_NAME (field)))
604 /* True for duplicate members. */
605 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
608 else if ((t = TREE_TYPE (field)) != NULL_TREE
609 && ANON_AGGR_TYPE_P (t)
610 && TYPE_FIELDS (t) != NULL_TREE)
611 /* Just use the field; anonymous types can't have
612 nontrivial copy ctors or assignment ops. */;
616 /* Compute the type of "init->field". If the copy-constructor
617 parameter is, for example, "const S&", and the type of
618 the field is "T", then the type will usually be "const
619 T". (There are no cv-qualified variants of reference
621 expr_type = TREE_TYPE (field);
622 if (TREE_CODE (expr_type) != REFERENCE_TYPE)
623 expr_type = cp_build_qualified_type (expr_type, cvquals);
624 init = build (COMPONENT_REF, expr_type, init, field);
625 init = build_tree_list (NULL_TREE, init);
628 = tree_cons (field, init, member_init_list);
630 finish_mem_initializers (member_init_list);
635 do_build_assign_ref (fndecl)
638 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
641 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
642 parm = convert_from_reference (parm);
644 if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)
645 && is_empty_class (current_class_type))
646 /* Don't copy the padding byte; it might not have been allocated
647 if *this is a base subobject. */;
648 else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type))
650 tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm);
651 finish_expr_stmt (t);
656 int cvquals = cp_type_quals (TREE_TYPE (parm));
659 /* Assign to each of thedirect base classes. */
660 for (i = 0; i < CLASSTYPE_N_BASECLASSES (current_class_type); ++i)
665 binfo = BINFO_BASETYPE (TYPE_BINFO (current_class_type), i);
666 /* We must convert PARM directly to the base class
667 explicitly since the base class may be ambiguous. */
668 converted_parm = build_base_path (PLUS_EXPR, parm, binfo, 1);
669 /* Call the base class assignment operator. */
671 (build_special_member_call (current_class_ref,
672 ansi_assopname (NOP_EXPR),
673 build_tree_list (NULL_TREE,
676 LOOKUP_NORMAL | LOOKUP_NONVIRTUAL));
679 /* Assign to each of the non-static data members. */
680 for (fields = TYPE_FIELDS (current_class_type);
682 fields = TREE_CHAIN (fields))
687 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
690 if (CP_TYPE_CONST_P (TREE_TYPE (field)))
692 error ("non-static const member `%#D', can't use default assignment operator", field);
695 else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE)
697 error ("non-static reference member `%#D', can't use default assignment operator", field);
701 comp = current_class_ref;
704 if (DECL_NAME (field))
706 if (VFIELD_NAME_P (DECL_NAME (field)))
709 /* True for duplicate members. */
710 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field)
713 else if ((t = TREE_TYPE (field)) != NULL_TREE
714 && ANON_AGGR_TYPE_P (t)
715 && TYPE_FIELDS (t) != NULL_TREE)
716 /* Just use the field; anonymous types can't have
717 nontrivial copy ctors or assignment ops. */;
721 comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field);
722 init = build (COMPONENT_REF,
723 cp_build_qualified_type (TREE_TYPE (field), cvquals),
726 if (DECL_NAME (field))
727 finish_expr_stmt (build_modify_expr (comp, NOP_EXPR, init));
729 finish_expr_stmt (build (MODIFY_EXPR, TREE_TYPE (comp), comp,
733 finish_return_stmt (current_class_ref);
734 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
738 synthesize_method (fndecl)
741 int nested = (current_function_decl != NULL_TREE);
742 tree context = decl_function_context (fndecl);
747 import_export_decl (fndecl);
749 /* If we've been asked to synthesize a clone, just synthesize the
750 cloned function instead. Doing so will automatically fill in the
751 body for the clone. */
752 if (DECL_CLONED_FUNCTION_P (fndecl))
754 synthesize_method (DECL_CLONED_FUNCTION (fndecl));
759 push_to_top_level ();
761 push_function_context_to (context);
763 /* Put the function definition at the position where it is needed,
764 rather than within the body of the class. That way, an error
765 during the generation of the implicit body points at the place
766 where the attempt to generate the function occurs, giving the
767 user a hint as to why we are attempting to generate the
769 DECL_SOURCE_LINE (fndecl) = lineno;
770 DECL_SOURCE_FILE (fndecl) = input_filename;
772 interface_unknown = 1;
773 start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
775 stmt = begin_function_body ();
777 if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR)
779 do_build_assign_ref (fndecl);
782 else if (DECL_CONSTRUCTOR_P (fndecl))
784 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
785 if (arg_chain != void_list_node)
786 do_build_copy_constructor (fndecl);
787 else if (TYPE_NEEDS_CONSTRUCTING (current_class_type))
788 finish_mem_initializers (NULL_TREE);
791 /* If we haven't yet generated the body of the function, just
792 generate an empty compound statement. */
796 compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
797 finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
800 finish_function_body (stmt);
801 expand_body (finish_function (0));
803 extract_interface_info ();
805 pop_from_top_level ();
807 pop_function_context_from (context);
810 /* Use EXTRACTOR to locate the relevant function called for each base &
811 class field of TYPE. CLIENT allows additional information to be passed
812 to EXTRACTOR. Generates the union of all exceptions generated by those
813 functions. Note that we haven't updated TYPE_FIELDS and such of any
814 variants yet, so we need to look at the main one. */
817 synthesize_exception_spec (type, extractor, client)
819 tree (*extractor) (tree, void *);
822 tree raises = empty_except_spec;
823 tree fields = TYPE_FIELDS (type);
824 int i, n_bases = CLASSTYPE_N_BASECLASSES (type);
825 tree binfos = TYPE_BINFO_BASETYPES (type);
827 for (i = 0; i != n_bases; i++)
829 tree base = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
830 tree fn = (*extractor) (base, client);
833 tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
835 raises = merge_exception_specifiers (raises, fn_raises);
838 for (; fields; fields = TREE_CHAIN (fields))
840 tree type = TREE_TYPE (fields);
843 if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields))
845 while (TREE_CODE (type) == ARRAY_TYPE)
846 type = TREE_TYPE (type);
847 if (TREE_CODE (type) != RECORD_TYPE)
850 fn = (*extractor) (type, client);
853 tree fn_raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
855 raises = merge_exception_specifiers (raises, fn_raises);
861 /* Locate the dtor of TYPE. */
864 locate_dtor (type, client)
866 void *client ATTRIBUTE_UNUSED;
870 if (!TYPE_HAS_DESTRUCTOR (type))
872 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type),
873 CLASSTYPE_DESTRUCTOR_SLOT);
877 /* Locate the default ctor of TYPE. */
880 locate_ctor (type, client)
882 void *client ATTRIBUTE_UNUSED;
886 if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
889 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type),
890 CLASSTYPE_CONSTRUCTOR_SLOT);
891 for (; fns; fns = OVL_NEXT (fns))
893 tree fn = OVL_CURRENT (fns);
894 tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
896 if (sufficient_parms_p (TREE_CHAIN (parms)))
908 /* Locate the copy ctor or copy assignment of TYPE. CLIENT_
909 points to a COPY_DATA holding the name (NULL for the ctor)
910 and desired qualifiers of the source operand. */
913 locate_copy (type, client_)
917 struct copy_data *client = (struct copy_data *)client_;
920 tree best = NULL_TREE;
925 if (TYPE_HAS_ASSIGN_REF (type))
926 ix = lookup_fnfields_1 (type, client->name);
928 else if (TYPE_HAS_INIT_REF (type))
929 ix = CLASSTYPE_CONSTRUCTOR_SLOT;
932 fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), ix);
934 for (; fns; fns = OVL_NEXT (fns))
936 tree fn = OVL_CURRENT (fns);
937 tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
942 parms = TREE_CHAIN (parms);
945 src_type = TREE_VALUE (parms);
946 if (TREE_CODE (src_type) == REFERENCE_TYPE)
947 src_type = TREE_TYPE (src_type);
948 if (!same_type_ignoring_top_level_qualifiers_p (src_type, type))
950 if (!sufficient_parms_p (TREE_CHAIN (parms)))
952 quals = cp_type_quals (src_type);
953 if (client->quals & ~quals)
955 excess = quals & ~client->quals;
956 if (!best || (excess_p && !excess))
968 /* Implicitly declare the special function indicated by KIND, as a
969 member of TYPE. For copy constructors and assignment operators,
970 CONST_P indicates whether these functions should take a const
971 reference argument or a non-const reference. */
974 implicitly_declare_fn (kind, type, const_p)
975 special_function_kind kind;
979 tree declspecs = NULL_TREE;
980 tree fn, args = NULL_TREE;
981 tree raises = empty_except_spec;
984 tree name = constructor_name (TYPE_IDENTIFIER (type));
990 name = build_nt (BIT_NOT_EXPR, name);
991 args = void_list_node;
992 raises = synthesize_exception_spec (type, &locate_dtor, 0);
995 case sfk_constructor:
996 /* Default constructor. */
997 args = void_list_node;
998 raises = synthesize_exception_spec (type, &locate_ctor, 0);
1001 case sfk_copy_constructor:
1002 case sfk_assignment_operator:
1004 struct copy_data data;
1005 tree argtype = type;
1010 if (kind == sfk_assignment_operator)
1013 declspecs = build_tree_list (NULL_TREE, type);
1015 name = ansi_assopname (NOP_EXPR);
1020 data.quals = TYPE_QUAL_CONST;
1021 argtype = build_qualified_type (argtype, TYPE_QUAL_CONST);
1024 argtype = build_reference_type (argtype);
1025 args = build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1026 get_identifier ("_ctor_arg"));
1027 args = tree_cons (NULL_TREE, args, void_list_node);
1029 raises = synthesize_exception_spec (type, &locate_copy, &data);
1036 TREE_PARMLIST (args) = 1;
1039 tree declarator = make_call_declarator (name, args, NULL_TREE, raises);
1042 declarator = build_nt (ADDR_EXPR, declarator);
1044 fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
1046 TREE_USED (FUNCTION_FIRST_USER_PARM (fn)) = 1;
1049 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 20000408);
1051 DECL_ARTIFICIAL (fn) = 1;
1052 DECL_NOT_REALLY_EXTERN (fn) = 1;
1053 DECL_DECLARED_INLINE_P (fn) = 1;
1054 DECL_INLINE (fn) = 1;
1060 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
1061 as there are artificial parms in FN. */
1064 skip_artificial_parms_for (fn, list)
1067 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1068 list = TREE_CHAIN (list);
1072 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
1073 list = TREE_CHAIN (list);
1074 if (DECL_HAS_VTT_PARM_P (fn))
1075 list = TREE_CHAIN (list);