bool emit_tinfo_decl (tree decl) { tree type = TREE_TYPE (DECL_NAME (decl)); int in_library = typeinfo_in_lib_p (type); tree var_desc, var_init; gcc_assert (DECL_TINFO_P (decl)); if (in_library) { if (doing_runtime) DECL_EXTERNAL (decl) = 0; else { /* If we're not in the runtime, then DECL (which is already DECL_EXTERNAL) will not be defined here. */ DECL_INTERFACE_KNOWN (decl) = 1; return false; } } else if (involves_incomplete_p (type)) { if (!decl_needed_p (decl)) return false; /* If TYPE involves an incomplete class type, then the typeinfo object will be emitted with internal linkage. There is no way to know whether or not types are incomplete until the end of the compilation, so this determination must be deferred until this point. */ TREE_PUBLIC (decl) = 0; DECL_EXTERNAL (decl) = 0; DECL_INTERFACE_KNOWN (decl) = 1; } import_export_decl (decl); if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl)) { DECL_EXTERNAL (decl) = 0; var_desc = get_pseudo_ti_desc (type); var_init = get_pseudo_ti_init (type, var_desc); DECL_INITIAL (decl) = var_init; mark_used (decl); cp_finish_decl (decl, var_init, NULL_TREE, 0); return true; } else return false; }
static tree tinfo_base_init (tree desc, tree target) { tree init = NULL_TREE; tree name_decl; tree vtable_ptr; { tree name_name; /* Generate the NTBS array variable. */ tree name_type = build_cplus_array_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST), NULL_TREE); tree name_string = tinfo_name (target); /* Determine the name of the variable -- and remember with which type it is associated. */ name_name = mangle_typeinfo_string_for_type (target); TREE_TYPE (name_name) = target; name_decl = build_lang_decl (VAR_DECL, name_name, name_type); SET_DECL_ASSEMBLER_NAME (name_decl, name_name); DECL_ARTIFICIAL (name_decl) = 1; DECL_IGNORED_P (name_decl) = 1; TREE_READONLY (name_decl) = 1; TREE_STATIC (name_decl) = 1; DECL_EXTERNAL (name_decl) = 0; DECL_TINFO_P (name_decl) = 1; if (involves_incomplete_p (target)) { TREE_PUBLIC (name_decl) = 0; DECL_INTERFACE_KNOWN (name_decl) = 1; } else set_linkage_according_to_type (target, name_decl); import_export_decl (name_decl); DECL_INITIAL (name_decl) = name_string; mark_used (name_decl); pushdecl_top_level_and_finish (name_decl, name_string); } vtable_ptr = TINFO_VTABLE_DECL (desc); if (!vtable_ptr) { tree real_type; push_nested_namespace (abi_node); real_type = xref_tag (class_type, TINFO_REAL_NAME (desc), /* APPLE LOCAL 4184203 */ /*tag_scope=*/ts_global, false); pop_nested_namespace (abi_node); if (!COMPLETE_TYPE_P (real_type)) { /* We never saw a definition of this type, so we need to tell the compiler that this is an exported class, as indeed all of the __*_type_info classes are. */ SET_CLASSTYPE_INTERFACE_KNOWN (real_type); CLASSTYPE_INTERFACE_ONLY (real_type) = 1; } vtable_ptr = get_vtable_decl (real_type, /*complete=*/1); vtable_ptr = build_unary_op (ADDR_EXPR, vtable_ptr, 0); /* We need to point into the middle of the vtable. */ vtable_ptr = build2 (PLUS_EXPR, TREE_TYPE (vtable_ptr), vtable_ptr, size_binop (MULT_EXPR, size_int (2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE), TYPE_SIZE_UNIT (vtable_entry_type))); TINFO_VTABLE_DECL (desc) = vtable_ptr; } init = tree_cons (NULL_TREE, vtable_ptr, init); init = tree_cons (NULL_TREE, decay_conversion (name_decl), init); init = build_constructor (NULL_TREE, nreverse (init)); TREE_CONSTANT (init) = 1; TREE_INVARIANT (init) = 1; TREE_STATIC (init) = 1; init = tree_cons (NULL_TREE, init, NULL_TREE); return init; }
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 (); }