From b07fcbcc0de6542ea1ffc4629ad3e22567651df6 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Mon, 25 Jul 2016 17:39:11 +0200 Subject: [PATCH] Cleanup is_class and is_compatible_with_class_type There was two overloads of is_class, one for types and one for decls. Now that we have type_or_decl_base which is a common base type for both, having just one is_class function that takes a type_or_decl_base is more compact and easier to maintain. This patch does that. It also cleans up the declaration of the is_compatible_with_class_type function. * include/abg-fwd.h (is_class): Remove the overloads that take a decl_base or a type_base. Add one that takes a type_or_decl_base. (is_compatible_with_class_type): Make this take a reference to smart pointer, not just the smart pointer. * src/abg-ir.cc (is_class): Do the same as in the header file. (is_compatible_with_class_type): Likewise. Signed-off-by: Dodji Seketeli --- include/abg-fwd.h | 14 ++++---------- src/abg-ir.cc | 38 ++++++-------------------------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/include/abg-fwd.h b/include/abg-fwd.h index 8cbe1dc1..a07c03e8 100644 --- a/include/abg-fwd.h +++ b/include/abg-fwd.h @@ -237,22 +237,16 @@ shared_ptr is_enum_type(const shared_ptr&); class_decl* -is_class_type(const decl_base*); - -class_decl* -is_class_type(const type_base*); +is_class_type(const type_or_decl_base*); shared_ptr -is_class_type(const shared_ptr); +is_class_type(const shared_ptr&); shared_ptr -is_class_type(const shared_ptr); +is_compatible_with_class_type(const shared_ptr&); shared_ptr -is_compatible_with_class_type(const shared_ptr); - -shared_ptr -is_compatible_with_class_type(const shared_ptr); +is_compatible_with_class_type(const shared_ptr&); pointer_type_def* is_pointer_type(type_base*); diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 2032f074..3b3573ab 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -5660,7 +5660,7 @@ is_enum_type(const type_base_sptr& t) /// /// @return the class_decl if @p t is a class_decl or null otherwise. class_decl_sptr -is_compatible_with_class_type(const type_base_sptr t) +is_compatible_with_class_type(const type_base_sptr& t) { if (!t) return class_decl_sptr(); @@ -5674,7 +5674,7 @@ is_compatible_with_class_type(const type_base_sptr t) /// /// @return the class_decl if @p t is a class_decl or null otherwise. class_decl_sptr -is_compatible_with_class_type(const decl_base_sptr t) +is_compatible_with_class_type(const decl_base_sptr& t) {return is_compatible_with_class_type(is_type(t));} /// Test whether a type is a class. @@ -5683,8 +5683,8 @@ is_compatible_with_class_type(const decl_base_sptr t) /// /// @return the class_decl if @p t is a class_decl or null otherwise. class_decl* -is_class_type(const type_base* t) -{return dynamic_cast(const_cast(t));} +is_class_type(const type_or_decl_base* t) +{return dynamic_cast(const_cast(t));} /// Test whether a type is a class. /// @@ -5692,34 +5692,8 @@ is_class_type(const type_base* t) /// /// @return the class_decl if @p t is a class_decl or null otherwise. class_decl_sptr -is_class_type(const type_base_sptr t) -{ - if (!t) - return class_decl_sptr(); - return dynamic_pointer_cast(t); -} - -/// Test if a the declaration of a type is a class. -/// -/// This function looks through typedefs. -/// -/// @parm d the declaration of the type to consider. -/// -/// @return the class_decl if @p t is a class_decl or null otherwise. -class_decl* -is_class_type(const decl_base *d) -{return dynamic_cast(const_cast(d));} - -/// Test whether a type is a class. -/// -/// This function looks through typedefs. -/// -/// @parm d the declaration of the type to consider. -/// -/// @return the class_decl if @p d is a class_decl or null otherwise. -class_decl_sptr -is_class_type(const decl_base_sptr d) -{return is_class_type(is_type(d));} +is_class_type(const type_or_decl_base_sptr& d) +{return dynamic_pointer_cast(d);} /// Test whether a type is a pointer_type_def. ///