void synthesize_method (tree fndecl) { bool nested = (current_function_decl != NULL_TREE); tree context = decl_function_context (fndecl); bool need_body = true; tree stmt; location_t save_input_location = input_location; int error_count = errorcount; int warning_count = warningcount; /* Reset the source location, we might have been previously deferred, and thus have saved where we were first needed. */ DECL_SOURCE_LOCATION (fndecl) = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl))); /* If we've been asked to synthesize a clone, just synthesize the cloned function instead. Doing so will automatically fill in the body for the clone. */ if (DECL_CLONED_FUNCTION_P (fndecl)) fndecl = DECL_CLONED_FUNCTION (fndecl); /* We may be in the middle of deferred access check. Disable it now. */ push_deferring_access_checks (dk_no_deferred); if (! context) push_to_top_level (); else if (nested) push_function_context_to (context); input_location = DECL_SOURCE_LOCATION (fndecl); start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED); stmt = begin_function_body (); if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR) { do_build_assign_ref (fndecl); need_body = false; } else if (DECL_CONSTRUCTOR_P (fndecl)) { tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl); if (arg_chain != void_list_node) do_build_copy_constructor (fndecl); else finish_mem_initializers (NULL_TREE); } /* If we haven't yet generated the body of the function, just generate an empty compound statement. */ if (need_body) { tree compound_stmt; compound_stmt = begin_compound_stmt (BCS_FN_BODY); finish_compound_stmt (compound_stmt); } finish_function_body (stmt); expand_or_defer_fn (finish_function (0)); input_location = save_input_location; if (! context) pop_from_top_level (); else if (nested) pop_function_context_from (context); pop_deferring_access_checks (); if (error_count != errorcount || warning_count != warningcount) inform ("%Hsynthesized method %qD first required here ", &input_location, fndecl); }
void synthesize_method (tree fndecl) { bool nested = (current_function_decl != NULL_TREE); tree context = decl_function_context (fndecl); bool need_body = true; tree stmt; if (at_eof) import_export_decl (fndecl); /* If we've been asked to synthesize a clone, just synthesize the cloned function instead. Doing so will automatically fill in the body for the clone. */ if (DECL_CLONED_FUNCTION_P (fndecl)) { synthesize_method (DECL_CLONED_FUNCTION (fndecl)); return; } /* We may be in the middle of deferred access check. Disable it now. */ push_deferring_access_checks (dk_no_deferred); if (! context) push_to_top_level (); else if (nested) push_function_context_to (context); /* Put the function definition at the position where it is needed, rather than within the body of the class. That way, an error during the generation of the implicit body points at the place where the attempt to generate the function occurs, giving the user a hint as to why we are attempting to generate the function. */ DECL_SOURCE_LOCATION (fndecl) = input_location; interface_unknown = 1; start_function (NULL_TREE, fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED); clear_last_expr (); stmt = begin_function_body (); if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR) { do_build_assign_ref (fndecl); need_body = false; } else if (DECL_CONSTRUCTOR_P (fndecl)) { tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl); if (arg_chain != void_list_node) do_build_copy_constructor (fndecl); else if (TYPE_NEEDS_CONSTRUCTING (current_class_type)) finish_mem_initializers (NULL_TREE); } /* If we haven't yet generated the body of the function, just generate an empty compound statement. */ if (need_body) { tree compound_stmt; compound_stmt = begin_compound_stmt (/*has_no_scope=*/false); finish_compound_stmt (compound_stmt); } finish_function_body (stmt); expand_or_defer_fn (finish_function (0)); extract_interface_info (); if (! context) pop_from_top_level (); else if (nested) pop_function_context_from (context); pop_deferring_access_checks (); }