From: Dodji Seketeli Date: Thu, 21 Mar 2019 17:17:31 +0000 (+0100) Subject: Add ir::{lookup_data_member, get_function_parameter} X-Git-Tag: libabigail-1.6~6 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=782c3d8c429c383221e4cd5eb6cc9906c01aca11;p=libabigail.git Add ir::{lookup_data_member, get_function_parameter} While looking at something else, I figured it's useful, for debugging purposes, to be able to lookup a given data member of a union/class by name, as well as a function parameter by index. This patch adds both. * include/abg-ir.h (lookup_data_member, get_function_parameter): Declare new functions. * src/abg-ir.cc (lookup_data_member, get_function_parameter): Define them. Signed-off-by: Dodji Seketeli --- diff --git a/include/abg-ir.h b/include/abg-ir.h index f35cde67..be53b8d7 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -4149,6 +4149,14 @@ is_method_decl(const type_or_decl_base&); method_decl_sptr is_method_decl(const type_or_decl_base_sptr&); +const var_decl* +lookup_data_member(const type_base* type, + const char* dm_name); + +const function_decl::parameter* +get_function_parameter(const decl_base* fun, + unsigned parm_num); + /// Abstract a member function template. class member_function_template : public member_base, public virtual decl_base { diff --git a/src/abg-ir.cc b/src/abg-ir.cc index af6fc815..0dd180c5 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -21200,6 +21200,62 @@ types_have_similar_structure(const type_base* first, const type_base* second) return false; } +/// Look for a data member of a given class, struct or union type and +/// return it. +/// +/// The data member is designated by its name. +/// +/// @param type the class, struct or union type to consider. +/// +/// @param dm_name the name of the data member to lookup. +/// +/// @return the data member iff it was found in @type or NULL if no +/// data member with that name was found. +const var_decl* +lookup_data_member(const type_base* type, + const char* dm_name) + +{ + class_or_union *cou = is_class_or_union_type(type); + if (!cou) + return 0; + + for (class_or_union::data_members::const_iterator i = + cou->get_data_members().begin(); + i != cou->get_data_members().end(); + ++i) + { + if ((*i)->get_name() == dm_name) + return i->get(); + } + return 0; +} + +/// Get the function parameter designated by its index. +/// +/// Note that the first function parameter has index 0. +/// +/// @param fun the function to consider. +/// +/// @param parm_index the index of the function parameter to get. +/// +/// @return the function parameter designated by its index, of NULL if +/// no function parameter with that index was found. +const function_decl::parameter* +get_function_parameter(const decl_base* fun, + unsigned parm_index) +{ + function_decl* fn = is_function_decl(fun); + if (!fn) + return 0; + + const function_decl::parameters &parms = fn->get_type()->get_parameters(); + if (parms.size() <= parm_index) + return 0; + + return parms[parm_index].get(); +} + bool ir_traversable_base::traverse(ir_node_visitor&) {return true;}