Add missing deep comparison operators for {function, method}_decl_sptr
authorDodji Seketeli <dodji@redhat.com>
Fri, 13 Jan 2017 12:11:45 +0000 (13:11 +0100)
committerDodji Seketeli <dodji@redhat.com>
Mon, 16 Jan 2017 20:00:54 +0000 (21:00 +0100)
It turned out we were missing deep comparison operators for smart
pointers to function_decl and method_decl.  Because of coming patches
that compare virtual member functions as part of comparing classes, we
need these deep comparison operators.

* include/abg-ir.h (operator==): Declare two new overloads for
function_decl_sptr an method_decl_sptr.
* src/abg-ir.cc (operator==): Define two new overloads for
function_decl_sptr an method_decl_sptr.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
include/abg-ir.h
src/abg-ir.cc

index 63e3e156af2cd7b855ab4b5d8f38560fa3ee8b83..5b1af5743090d4ab0515574264385d2f57a182ff 100644 (file)
@@ -2418,6 +2418,12 @@ public:
   virtual ~function_decl();
 }; // end class function_decl
 
+bool
+operator==(const function_decl_sptr& l, const function_decl_sptr& r);
+
+bool
+operator!=(const function_decl_sptr& l, const function_decl_sptr& r);
+
 bool
 function_decls_alias(const function_decl& f1, const function_decl& f2);
 
@@ -3158,6 +3164,12 @@ public:
   virtual ~method_decl();
 };// end class method_decl
 
+bool
+operator==(const method_decl_sptr& l, const method_decl_sptr& r);
+
+bool
+operator!=(const method_decl_sptr& l, const method_decl_sptr& r);
+
 /// The base type of @ref class_decl and @ref union_decl
 class class_or_union : public scope_type_decl
 {
index f7710190c53b5b1719c11ecf4bda7cb399602047..bd14badb5449692431a2575b71f63b976a2bcbe4 100644 (file)
@@ -13813,6 +13813,40 @@ function_decl::traverse(ir_node_visitor& v)
 function_decl::~function_decl()
 {delete priv_;}
 
+/// A deep comparison operator for a shared pointer to @ref function_decl
+///
+/// This function compares to shared pointers to @ref function_decl by
+/// looking at the pointed-to instances of @ref function_dec
+/// comparing them too.  If the two pointed-to objects are equal then
+/// this function returns true.
+///
+/// @param l the left-hand side argument of the equality operator.
+///
+/// @param r the right-hand side argument of the equality operator.
+///
+/// @return true iff @p l equals @p r.
+bool
+operator==(const function_decl_sptr& l, const function_decl_sptr& r)
+{
+  if (l.get() == r.get())
+    return true;
+  if (!!l != !!r)
+    return false;
+
+  return *l == *r;
+}
+
+/// A deep inequality operator for smart pointers to functions.
+///
+/// @param l the left-hand side argument of the inequality operator.
+///
+/// @pram r the right-hand side argument of the inequality operator.
+///
+/// @return true iff @p is not equal to @p r.
+bool
+operator!=(const function_decl_sptr& l, const function_decl_sptr& r)
+{return !operator==(l, r);}
+
 // <function_decl definitions>
 
 // <function_decl::parameter definitions>
@@ -16048,6 +16082,41 @@ method_decl::set_scope(scope_decl* scope)
     get_context_rel()->set_scope(scope);
 }
 
+/// Equality operator for @ref method_decl_sptr.
+///
+/// This is a deep equality operator, as it compares the @ref
+/// method_decl that is pointed-to by the smart pointer.
+///
+/// @param l the left-hand side argument of the equality operator.
+///
+/// @param r the righ-hand side argument of the equality operator.
+///
+/// @return true iff @p l equals @p r.
+bool
+operator==(const method_decl_sptr& l, const method_decl_sptr& r)
+{
+  if (l.get() == r.get())
+    return true;
+  if (!!l != !!r)
+    return false;
+
+  return *l == *r;
+}
+
+/// Inequality operator for @ref method_decl_sptr.
+///
+/// This is a deep equality operator, as it compares the @ref
+/// method_decl that is pointed-to by the smart pointer.
+///
+/// @param l the left-hand side argument of the equality operator.
+///
+/// @param r the righ-hand side argument of the equality operator.
+///
+/// @return true iff @p l differs from @p r.
+bool
+operator!=(const method_decl_sptr& l, const method_decl_sptr& r)
+{return !operator==(l, r);}
+
 /// Test if a function_decl is actually a method_decl.
 ///
 ///@param d the @ref function_decl to consider.