From 45be4d7fdd3b51344d42961c57cb1b30dfda9fdb Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Fri, 21 Aug 2015 12:09:22 +0200 Subject: [PATCH] Make get_pretty_representation work on method types Until now, get_pretty_representation() considered method types just as function types. This patch makes it know about them specifically. This useful for debugging, at least. * include/abg-fwd.h (is_method_type): Declare new overloads for naked pointers. (get_method_type_name): Declare new functions. (get_pretty_representation): Declare new overloads for method_type. * src/abg-ir.cc (get_function_type_name): If the function type is a method type, handle it as such. (get_method_type_name): Define new functions. (get_pretty_representation): If the function type is a method type, handle it as such. (get_pretty_representation): Define new overloads for method_type and pointer/reference to method_type. (is_method_type): Add overloads for naked pointers. Signed-off-by: Dodji Seketeli --- include/abg-fwd.h | 25 ++++++++++ src/abg-ir.cc | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) diff --git a/include/abg-fwd.h b/include/abg-fwd.h index 9607b14c..0d254473 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -267,6 +267,12 @@ is_function_type(const type_base*); shared_ptr is_method_type(const shared_ptr); +const method_type* +is_method_type(const type_base*); + +method_type* +is_method_type(type_base*); + shared_ptr look_through_decl_only_class(shared_ptr); @@ -496,6 +502,15 @@ get_function_type_name(const function_type*); string get_function_type_name(const function_type&); +string +get_method_type_name(const shared_ptr& +); +string +get_method_type_name(const method_type*); + +string +get_method_type_name(const method_type&); + string get_pretty_representation(const decl_base*); @@ -523,6 +538,16 @@ get_pretty_representation(const function_type*); string get_pretty_representation(const shared_ptr&); +string +get_pretty_representation(const method_type&); + +string +get_pretty_representation(const method_type*); + +string +get_pretty_representation(const shared_ptr&); + + const decl_base* get_type_declaration(const type_base*); diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 65d753e5..b1b7b8d4 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -3765,6 +3765,10 @@ get_function_type_name(const function_type* fn_type) { if (!fn_type) return ""; + + if (const method_type* method = is_method_type(fn_type)) + return get_method_type_name(method); + return get_function_type_name(*fn_type); } @@ -3795,6 +3799,61 @@ get_function_type_name(const function_type& fn_type) return o.str(); } +/// Get the name of a given method type and return a copy of it. +/// +/// @param fn_type the function type to consider. +/// +/// @return a copy of the function type name +string +get_method_type_name(const method_type_sptr fn_type) +{return get_method_type_name(fn_type.get());} + +/// Get the name of a given method type and return a copy of it. +/// +/// @param fn_type the function type to consider. +/// +/// @return a copy of the function type name +string +get_method_type_name(const method_type* fn_type) +{ + if (fn_type) + get_method_type_name(*fn_type); + + return ""; +} + +/// Get the name of a given method type and return a copy of it. +/// +/// @param fn_type the function type to consider. +/// +/// @return a copy of the function type name +string +get_method_type_name(const method_type& fn_type) +{ + std::ostringstream o; + type_base_sptr return_type= fn_type.get_return_type(); + + o << get_pretty_representation(return_type); + + class_decl_sptr class_type = fn_type.get_class_type(); + assert(class_type); + + o << " (" << class_type->get_qualified_name() << "::*)" + << " ("; + + for (function_type::parameters::const_iterator i = + fn_type.get_parameters().begin(); + i != fn_type.get_parameters().end(); + ++i) + { + if (i != fn_type.get_parameters().begin()) + o << ", "; + o << get_pretty_representation((*i)->get_type()); + } + o <<")"; + return o.str(); +} + /// Build and return a copy of the pretty representation of an ABI /// artifact that could be either a type of a decl. /// @@ -3899,6 +3958,10 @@ get_pretty_representation(const function_type* fn_type) { if (!fn_type) return "void"; + + if (const method_type* method = is_method_type(fn_type)) + return get_pretty_representation(method); + return get_pretty_representation(*fn_type); } @@ -3915,6 +3978,40 @@ get_pretty_representation(const function_type& fn_type) return o.str(); } +/// Get the pretty representation of a method type. +/// +/// @param method the method type to consider. +/// +/// @return the string represenation of the method type. +string +get_pretty_representation(const method_type& method) +{ + std::ostringstream o; + o << "method type " << get_method_type_name(method); + return o.str(); +} +/// Get the pretty representation of a method type. +/// +/// @param method the method type to consider. +/// +/// @return the string represenation of the method type. +string +get_pretty_representation(const method_type* method) +{ + if (!method) + return "void"; + return get_pretty_representation(*method); +} + +/// Get the pretty representation of a method type. +/// +/// @param method the method type to consider. +/// +/// @return the string represenation of the method type. +string +get_pretty_representation(const method_type_sptr method) +{return get_pretty_representation(method.get());} + /// Get the declaration for a given type. /// /// @param t the type to consider. @@ -4448,6 +4545,26 @@ shared_ptr is_method_type(const shared_ptr t) {return dynamic_pointer_cast(t);} +/// Test whether a type is a method_type. +/// +/// @param t the type to test. +/// +/// @return the @ref method_type_sptr if @p t is a +/// method_type, null otherwise. +const method_type* +is_method_type(const type_base* t) +{return dynamic_cast(t);} + +/// Test whether a type is a method_type. +/// +/// @param t the type to test. +/// +/// @return the @ref method_type_sptr if @p t is a +/// method_type, null otherwise. +method_type* +is_method_type(type_base* t) +{return dynamic_cast(t);} + /// If a class is a decl-only class, get its definition. Otherwise, /// just return the initial class. ///