gcc/gcc/is-a.h
David Malcolm 5e20cdc96e Automated part of renaming of symtab_node_base to symtab_node.
gcc/

	Patch autogenerated by rename_symtab.py from
	https://github.com/davidmalcolm/gcc-refactoring-scripts
	revision 58bb219cc090b2f4516a9297d868c245495ee622
	with ChangeLog entry fixed up by hand.

	* cgraph.c (x_cgraph_nodes_queue): Rename symtab_node_base to
	symtab_node.
	(cgraph_node_for_asm): Likewise.
	* cgraph.h (symtab_node_base): Likewise.
	(cgraph_node): Likewise.
	(varpool_node): Likewise.
	(is_a_helper <cgraph_node>::test): Likewise.
	(is_a_helper <varpool_node>::test): Likewise.
	(symtab_nodes): Likewise.
	(symtab_register_node): Likewise.
	(symtab_unregister_node): Likewise.
	(symtab_remove_node): Likewise.
	(symtab_get_node): Likewise.
	(symtab_node_for_asm): Likewise.
	(symtab_node_asm_name): Likewise.
	(symtab_node_name): Likewise.
	(symtab_insert_node_to_hashtable): Likewise.
	(symtab_add_to_same_comdat_group): Likewise.
	(symtab_dissolve_same_comdat_group_list): Likewise.
	(dump_symtab_node): Likewise.
	(debug_symtab_node): Likewise.
	(dump_symtab_base): Likewise.
	(verify_symtab_node): Likewise.
	(verify_symtab_base): Likewise.
	(symtab_used_from_object_file_p): Likewise.
	(symtab_alias_ultimate_target): Likewise.
	(symtab_resolve_alias): Likewise.
	(fixup_same_cpp_alias_visibility): Likewise.
	(symtab_for_node_and_aliases): Likewise.
	(symtab_nonoverwritable_alias): Likewise.
	(availability symtab_node_availability): Likewise.
	(symtab_semantically_equivalent_p): Likewise.
	(fixup_same_cpp_alias_visibility): Likewise.
	(symtab_prevail_in_asm_name_hash): Likewise.
	(cgraph): Likewise.
	(varpool): Likewise.
	(varpool_first_variable): Likewise.
	(varpool_next_variable): Likewise.
	(varpool_first_static_initializer): Likewise.
	(varpool_next_static_initializer): Likewise.
	(varpool_first_defined_variable): Likewise.
	(varpool_next_defined_variable): Likewise.
	(cgraph_first_defined_function): Likewise.
	(cgraph_next_defined_function): Likewise.
	(cgraph_first_function): Likewise.
	(cgraph_next_function): Likewise.
	(cgraph_first_function_with_gimple_body): Likewise.
	(cgraph_next_function_with_gimple_body): Likewise.
	(symtab_alias_target): Likewise.
	(symtab_real_symbol_p): Likewise.
	(symtab_can_be_discarded): Likewise.
	* cgraphbuild.c (mark_address): Likewise.
	(mark_load): Likewise.
	(mark_store): Likewise.
	* cgraphunit.c (decide_is_symbol_needed): Likewise.
	(first): Likewise.
	(enqueue_node): Likewise.
	(referred_to_p): Likewise.
	(cgraph_process_same_body_aliases): Likewise.
	(analyze_functions): Likewise.
	(handle_alias_pairs): Likewise.
	(output_weakrefs): Likewise.
	(compile): Likewise.
	* gimple-fold.c (can_refer_decl_in_current_unit_p): Likewise.
	* ipa-inline-analysis.c (inline_write_summary): Likewise.
	* ipa-prop.c (remove_described_reference): Likewise.
	(try_decrement_rdesc_refcount): Likewise.
	(ipa_edge_duplication_hook): Likewise.
	* ipa-ref.c (ipa_record_reference): Likewise.
	(ipa_maybe_record_reference): Likewise.
	(ipa_clone_ref): Likewise.
	(ipa_clone_references): Likewise.
	(ipa_clone_referring): Likewise.
	(ipa_find_reference): Likewise.
	(ipa_remove_stmt_references): Likewise.
	(ipa_clear_stmts_in_references): Likewise.
	* ipa-ref.h (symtab_node_base): Likewise.
	(ipa_ref): Likewise.
	(ipa_record_reference): Likewise.
	(ipa_maybe_record_reference): Likewise.
	(ipa_clone_references): Likewise.
	(ipa_clone_referring): Likewise.
	(ipa_clone_ref): Likewise.
	(ipa_find_reference): Likewise.
	(ipa_remove_stmt_references): Likewise.
	(ipa_clear_stmts_in_references): Likewise.
	* ipa-reference.c (ipa_reference_write_optimization_summary):
	Likewise.
	* ipa.c (enqueue_node): Likewise.
	(process_references): Likewise.
	(walk_polymorphic_call_targets): Likewise.
	(symtab_remove_unreachable_nodes): Likewise.
	(address_taken_from_non_vtable_p): Likewise.
	(comdat_can_be_unshared_p_1): Likewise.
	(comdat_can_be_unshared_p): Likewise.
	(can_replace_by_local_alias): Likewise.
	(function_and_variable_visibility): Likewise.
	* is-a.h: Likewise (within example in comment).
	* lto-cgraph.c (input_cgraph_opt_summary): Likewise.
	(lto_symtab_encoder_encode): Likewise.
	(lto_symtab_encoder_delete_node): Likewise.
	(lto_symtab_encoder_in_partition_p): Likewise.
	(lto_set_symtab_encoder_in_partition): Likewise.
	(output_refs): Likewise.
	(compute_ltrans_boundary): Likewise.
	(output_symtab): Likewise.
	(input_node): Likewise.
	(input_ref): Likewise.
	(input_edge): Likewise.
	(input_cgraph_1): Likewise.
	(input_refs): Likewise.
	(output_cgraph_opt_summary): Likewise.
	(input_node_opt_summary): Likewise.
	(input_cgraph_opt_section): Likewise.
	* lto-section-in.c (lto_free_function_in_decl_state_for_node):
	Likewise.
	* lto-streamer-out.c (lto_output): Likewise.
	(output_symbol_p): Likewise.
	(produce_symtab): Likewise.
	* lto-streamer.h (lto_encoder_entry): Likewise.
	(lto_free_function_in_decl_state_for_node): Likewise.
	(lto_symtab_encoder_encode): Likewise.
	(lto_symtab_encoder_delete_node): Likewise.
	(lto_symtab_encoder_in_partition_p): Likewise.
	(lto_set_symtab_encoder_in_partition): Likewise.
	(lto_symtab_encoder_lookup): Likewise.
	(lsei_node): Likewise.
	(lto_symtab_encoder_deref): Likewise.
	* symtab.c (symtab_hash): Likewise.
	(assembler_name_hash): Likewise.
	(symtab_nodes): Likewise.
	(hash_node): Likewise.
	(eq_node): Likewise.
	(hash_node_by_assembler_name): Likewise.
	(eq_assembler_name): Likewise.
	(insert_to_assembler_name_hash): Likewise.
	(unlink_from_assembler_name_hash): Likewise.
	(symtab_prevail_in_asm_name_hash): Likewise.
	(symtab_register_node): Likewise.
	(symtab_insert_node_to_hashtable): Likewise.
	(symtab_unregister_node): Likewise.
	(symtab_get_node): Likewise.
	(symtab_remove_node): Likewise.
	(symtab_initialize_asm_name_hash): Likewise.
	(symtab_node_for_asm): Likewise.
	(symtab_add_to_same_comdat_group): Likewise.
	(symtab_dissolve_same_comdat_group_list): Likewise.
	(symtab_node_asm_name): Likewise.
	(symtab_node_name): Likewise.
	(dump_symtab_base): Likewise.
	(dump_symtab_node): Likewise.
	(dump_symtab): Likewise.
	(debug_symtab_node): Likewise.
	(verify_symtab_base): Likewise.
	(verify_symtab_node): Likewise.
	(verify_symtab): Likewise.
	(symtab_used_from_object_file_p): Likewise.
	(symtab_node_availability): Likewise.
	(symtab_alias_ultimate_target): Likewise.
	(fixup_same_cpp_alias_visibility): Likewise.
	(symtab_resolve_alias): Likewise.
	(symtab_for_node_and_aliases): Likewise.
	(symtab_for_node_and_aliases): Likewise.
	(symtab_nonoverwritable_alias_1): Likewise.
	(symtab_nonoverwritable_alias): Likewise.
	(symtab_semantically_equivalent_p): Likewise.
	* value-prof.c (init_node_map): Likewise.
	* varasm.c (find_decl): Likewise.
	* varpool.c (varpool_node_for_asm): Likewise.
	(varpool_remove_unreferenced_decls): Likewise.

gcc/c-family/

	Patch autogenerated by rename_symtab.py from
	https://github.com/davidmalcolm/gcc-refactoring-scripts
	revision 58bb219cc090b2f4516a9297d868c245495ee622

	* c-pragma.c (maybe_apply_pending_pragma_weaks): Rename
	symtab_node_base to symtab_node.

gcc/lto/

	Patch autogenerated by rename_symtab.py from
	https://github.com/davidmalcolm/gcc-refactoring-scripts
	revision 58bb219cc090b2f4516a9297d868c245495ee622

	* lto-partition.c (add_symbol_to_partition): Rename
	symtab_node_base to symtab_node.
	(get_symbol_class): Likewise.
	(symbol_partitioned_p): Likewise.
	(add_references_to_partition): Likewise.
	(add_symbol_to_partition_1): Likewise.
	(contained_in_symbol): Likewise.
	(add_symbol_to_partition): Likewise.
	(lto_1_to_1_map): Likewise.
	(lto_max_map): Likewise.
	(lto_balanced_map): Likewise.
	(privatize_symbol_name): Likewise.
	(promote_symbol): Likewise.
	(may_need_named_section_p): Likewise.
	(rename_statics): Likewise.
	(lto_promote_statics_nonwpa): Likewise.
	* lto-symtab.c (lto_symtab_merge): Likewise.
	(lto_symtab_resolve_replaceable_p): Likewise.
	(lto_symtab_symbol_p): Likewise.
	(lto_symtab_resolve_can_prevail_p): Likewise.
	(lto_symtab_resolve_symbols): Likewise.
	(lto_symtab_merge_decls_2): Likewise.
	(lto_symtab_merge_decls_1): Likewise.
	(lto_symtab_merge_decls): Likewise.
	(lto_symtab_merge_symbols_1): Likewise.
	(lto_symtab_merge_symbols): Likewise.
	(lto_symtab_prevailing_decl): Likewise.
	* lto.c (lto_wpa_write_files): Likewise.
	(read_cgraph_and_symbols): Likewise.
	(do_whole_program_analysis): Likewise.

From-SVN: r204279
2013-10-31 21:26:14 +00:00

202 lines
5.4 KiB
C++

/* Dynamic testing for abstract is-a relationships.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
Contributed by Lawrence Crowl.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/* This header generic type query and conversion functions.
USING THE GENERIC TYPE FACILITY
The user functions are:
bool is_a <TYPE> (pointer)
Tests whether the pointer actually points to a more derived TYPE.
Suppose you have a symtab_node *ptr, AKA symtab_node *ptr. You can test
whether it points to a 'derived' cgraph_node as follows.
if (is_a <cgraph_node> (ptr))
....
TYPE *as_a <TYPE> (pointer)
Converts pointer to a TYPE*.
You can just assume that it is such a node.
do_something_with (as_a <cgraph_node> *ptr);
TYPE *dyn_cast <TYPE> (pointer)
Converts pointer to TYPE* if and only if "is_a <TYPE> pointer". Otherwise,
returns NULL. This function is essentially a checked down cast.
This functions reduce compile time and increase type safety when treating a
generic item as a more specific item.
You can test and obtain a pointer to the 'derived' type in one indivisible
operation.
if (cgraph_node *cptr = dyn_cast <cgraph_node> (ptr))
....
As an example, the code change is from
if (symtab_function_p (node))
{
struct cgraph_node *cnode = cgraph (node);
....
}
to
if (cgraph_node *cnode = dyn_cast <cgraph_node> (node))
{
....
}
The necessary conditional test defines a variable that holds a known good
pointer to the specific item and avoids subsequent conversion calls and
the assertion checks that may come with them.
When, the property test is embedded within a larger condition, the
variable declaration gets pulled out of the condition. (This approach
leaves some room for using the variable inappropriately.)
if (symtab_variable_p (node) && varpool (node)->finalized)
varpool_analyze_node (varpool (node));
becomes
varpool_node *vnode = dyn_cast <varpool_node> (node);
if (vnode && vnode->finalized)
varpool_analyze_node (vnode);
Note that we have converted two sets of assertions in the calls to varpool
into safe and efficient use of a variable.
If you use these functions and get a 'inline function not defined' or a
'missing symbol' error message for 'is_a_helper<....>::test', it means that
the connection between the types has not been made. See below.
EXTENDING THE GENERIC TYPE FACILITY
Each connection between types must be made by defining a specialization of the
template member function 'test' of the template class 'is_a_helper'. For
example,
template <>
template <>
inline bool
is_a_helper <cgraph_node>::test (symtab_node *p)
{
return p->type == SYMTAB_FUNCTION;
}
If a simple reinterpret_cast between the pointer types is incorrect, then you
must also specialize the template member function 'cast'. Failure to do so
when needed may result in a crash. For example,
template <>
template <>
inline bool
is_a_helper <cgraph_node>::cast (symtab_node *p)
{
return &p->x_function;
}
*/
#ifndef GCC_IS_A_H
#define GCC_IS_A_H
/* A generic type conversion internal helper class. */
template <typename T>
struct is_a_helper
{
template <typename U>
static inline bool test (U *p);
template <typename U>
static inline T *cast (U *p);
};
/* Note that we deliberately do not define the 'test' member template. Not
doing so will result in a build-time error for type relationships that have
not been defined, rather than a run-time error. See the discussion above
for when to define this member. */
/* This is the generic implementation for casting from one type to another.
Do not use this routine directly; it is an internal function. See the
discussion above for when to define this member. */
template <typename T>
template <typename U>
inline T *
is_a_helper <T>::cast (U *p)
{
return reinterpret_cast <T *> (p);
}
/* The public interface. */
/* A generic test for a type relationship. See the discussion above for when
to use this function. The question answered is "Is type T a derived type of
type U?". */
template <typename T, typename U>
inline bool
is_a (U *p)
{
return is_a_helper<T>::test (p);
}
/* A generic conversion from a base type U to a derived type T. See the
discussion above for when to use this function. */
template <typename T, typename U>
inline T *
as_a (U *p)
{
gcc_checking_assert (is_a <T> (p));
return is_a_helper <T>::cast (p);
}
/* A generic checked conversion from a base type U to a derived type T. See
the discussion above for when to use this function. */
template <typename T, typename U>
inline T *
dyn_cast (U *p)
{
if (is_a <T> (p))
return is_a_helper <T>::cast (p);
else
return static_cast <T *> (0);
}
#endif /* GCC_IS_A_H */