mirror of
git://sourceware.org/git/libabigail.git
synced 2025-02-08 17:47:13 +00:00
Add missing deep equality operator for pointer and reference types
I noticed that abigail::ir::pointer_type_def_sptr and abigail::ir::reference_type_def_sptr did not have any free form operator '==' defined. So writing a == b with a and b being either pointer_type_def_sptr or reference_type_def_sptr was using pointer value comparison, as opposed to deeply comparing the pointer and reference instances. This patch adds those two missing operators. * include/abg-ir.h (pointer_type_def::operator==): Add an overload for pointer_type_def. (reference_type_def::operator==) Add an overload for reference_type_def. (operator==): Add an overload for pointer_type_def_sptr and reference_type_def_sptr. * src/abg-ir.cc (pointer_type_def::operator==): Make the overload for type_base& use the overload for decl_base&. Add a new overload for pointer_type_def& and make is use the overload for decl_base& too. (operator==): Add free form overloads for pointer_type_def& and reference_type_def&. (reference_type_def::operator==): Add comments. Add an overload for reference_type_def&. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
parent
db02f0bdb4
commit
da4aaf467a
@ -1485,6 +1485,9 @@ public:
|
||||
virtual bool
|
||||
operator==(const type_base&) const;
|
||||
|
||||
bool
|
||||
operator==(const pointer_type_def&) const;
|
||||
|
||||
const type_base_sptr
|
||||
get_pointed_to_type() const;
|
||||
|
||||
@ -1500,6 +1503,9 @@ public:
|
||||
virtual ~pointer_type_def();
|
||||
}; // end class pointer_type_def
|
||||
|
||||
bool
|
||||
operator==(const pointer_type_def_sptr&, const pointer_type_def_sptr&);
|
||||
|
||||
bool
|
||||
equals(const reference_type_def&, const reference_type_def&, change_kind*);
|
||||
|
||||
@ -1530,6 +1536,9 @@ public:
|
||||
virtual bool
|
||||
operator==(const type_base&) const;
|
||||
|
||||
bool
|
||||
operator==(const reference_type_def&) const;
|
||||
|
||||
type_base_sptr
|
||||
get_pointed_to_type() const;
|
||||
|
||||
@ -1548,6 +1557,9 @@ public:
|
||||
virtual ~reference_type_def();
|
||||
}; // end class reference_type_def
|
||||
|
||||
bool
|
||||
operator==(const reference_type_def_sptr&, const reference_type_def_sptr&);
|
||||
|
||||
bool
|
||||
equals(const array_type_def&, const array_type_def&, change_kind*);
|
||||
|
||||
|
102
src/abg-ir.cc
102
src/abg-ir.cc
@ -6612,18 +6612,34 @@ pointer_type_def::operator==(const decl_base& o) const
|
||||
|
||||
/// Return true iff both instances of pointer_type_def are equal.
|
||||
///
|
||||
/// Note that this function does not check for the scopes of the this
|
||||
/// Note that this function does not check for the scopes of the
|
||||
/// types.
|
||||
///
|
||||
/// @param other the other type to compare against.
|
||||
///
|
||||
/// @return true iff @p other equals the current instance.
|
||||
bool
|
||||
pointer_type_def::operator==(const type_base& o) const
|
||||
pointer_type_def::operator==(const type_base& other) const
|
||||
{
|
||||
if (get_canonical_type() && o.get_canonical_type())
|
||||
return get_canonical_type().get() == o.get_canonical_type().get();
|
||||
|
||||
const pointer_type_def* other = dynamic_cast<const pointer_type_def*>(&o);
|
||||
if (!other)
|
||||
const decl_base* o = dynamic_cast<const decl_base*>(&other);
|
||||
if (!o)
|
||||
return false;
|
||||
return get_pointed_to_type() == other->get_pointed_to_type();
|
||||
return *this == *o;
|
||||
}
|
||||
|
||||
/// Return true iff both instances of pointer_type_def are equal.
|
||||
///
|
||||
/// Note that this function does not check for the scopes of the
|
||||
/// types.
|
||||
///
|
||||
/// @param other the other type to compare against.
|
||||
///
|
||||
/// @return true iff @p other equals the current instance.
|
||||
bool
|
||||
pointer_type_def::operator==(const pointer_type_def& other) const
|
||||
{
|
||||
const decl_base& o = other;
|
||||
return *this == o;
|
||||
}
|
||||
|
||||
const type_base_sptr
|
||||
@ -6686,6 +6702,28 @@ pointer_type_def::traverse(ir_node_visitor& v)
|
||||
pointer_type_def::~pointer_type_def()
|
||||
{}
|
||||
|
||||
/// Turn equality of shared_ptr of @ref pointer_type_def into a deep
|
||||
/// equality; that is, make it compare the pointed to objects too.
|
||||
///
|
||||
/// @param l the shared_ptr of @ref pointer_type_def on left-hand-side
|
||||
/// of the equality.
|
||||
///
|
||||
/// @param r the shared_ptr of @ref pointer_type_def on
|
||||
/// right-hand-side of the equality.
|
||||
///
|
||||
/// @return true if the @ref pointer_type_def pointed to by the
|
||||
/// shared_ptrs are equal, false otherwise.
|
||||
bool
|
||||
operator==(const pointer_type_def_sptr& l, const pointer_type_def_sptr& r)
|
||||
{
|
||||
if (l.get() == r.get())
|
||||
return true;
|
||||
if (!!l != !!r)
|
||||
return false;
|
||||
|
||||
return *l == *r;
|
||||
}
|
||||
|
||||
// </pointer_type_def definitions>
|
||||
|
||||
// <reference_type_def definitions>
|
||||
@ -6758,6 +6796,12 @@ equals(const reference_type_def& l, const reference_type_def& r, change_kind* k)
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Equality operator of the @ref reference_type_def type.
|
||||
///
|
||||
/// @param o the other instance of @ref reference_type_def to compare
|
||||
/// against.
|
||||
///
|
||||
/// @return true iff the two instances are equal.
|
||||
bool
|
||||
reference_type_def::operator==(const decl_base& o) const
|
||||
{
|
||||
@ -6772,6 +6816,12 @@ reference_type_def::operator==(const decl_base& o) const
|
||||
return equals(*this, *other, 0);
|
||||
}
|
||||
|
||||
/// Equality operator of the @ref reference_type_def type.
|
||||
///
|
||||
/// @param o the other instance of @ref reference_type_def to compare
|
||||
/// against.
|
||||
///
|
||||
/// @return true iff the two instances are equal.
|
||||
bool
|
||||
reference_type_def::operator==(const type_base& o) const
|
||||
{
|
||||
@ -6781,6 +6831,21 @@ reference_type_def::operator==(const type_base& o) const
|
||||
return *this == *other;
|
||||
}
|
||||
|
||||
/// Equality operator of the @ref reference_type_def type.
|
||||
///
|
||||
/// @param o the other instance of @ref reference_type_def to compare
|
||||
/// against.
|
||||
///
|
||||
/// @return true iff the two instances are equal.
|
||||
bool
|
||||
reference_type_def::operator==(const reference_type_def& o) const
|
||||
{
|
||||
const decl_base* other = dynamic_cast<const decl_base*>(&o);
|
||||
if (!other)
|
||||
return false;
|
||||
return *this == *other;
|
||||
}
|
||||
|
||||
type_base_sptr
|
||||
reference_type_def::get_pointed_to_type() const
|
||||
{
|
||||
@ -6850,6 +6915,27 @@ reference_type_def::traverse(ir_node_visitor& v)
|
||||
reference_type_def::~reference_type_def()
|
||||
{}
|
||||
|
||||
/// Turn equality of shared_ptr of @ref reference_type_def into a deep
|
||||
/// equality; that is, make it compare the pointed to objects too.
|
||||
///
|
||||
/// @param l the shared_ptr of @ref reference_type_def on left-hand-side
|
||||
/// of the equality.
|
||||
///
|
||||
/// @param r the shared_ptr of @ref reference_type_def on
|
||||
/// right-hand-side of the equality.
|
||||
///
|
||||
/// @return true if the @ref reference_type_def pointed to by the
|
||||
/// shared_ptrs are equal, false otherwise.
|
||||
bool
|
||||
operator==(const reference_type_def_sptr& l, const reference_type_def_sptr& r)
|
||||
{
|
||||
if (l.get() == r.get())
|
||||
return true;
|
||||
if (!!l != !!r)
|
||||
return false;
|
||||
|
||||
return *l == *r;
|
||||
}
|
||||
// </reference_type_def definitions>
|
||||
|
||||
// <array_type_def definitions>
|
||||
|
Loading…
Reference in New Issue
Block a user