From patchwork Wed Jul 8 09:53:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 39954 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA5AD3861841; Wed, 8 Jul 2020 09:53:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA5AD3861841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1594202012; bh=S+bdQLR7O1xny2qvOs5HyD3+faLEhFDEQp4+nZ/NAiI=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QIE1zwaCpMyjknnKGUvLiZrM70a5gN7xVZtYuMBPnte+kzRHEYaA8APSn0Rp0CGhX SKBFwfymdXwkPoZ4K5aUrMhAWnDXbwMtrcyxjJZjYykHgjKnKK16MHu7aylaBe7qdV VGMBNs9vKrT8OW/fqycan18dxZEW2SmZEsGyvegk= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by sourceware.org (Postfix) with ESMTPS id 233A9386180A for ; Wed, 8 Jul 2020 09:53:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 233A9386180A Received: by mail-qv1-xf4a.google.com with SMTP id m8so11431037qvv.10 for ; Wed, 08 Jul 2020 02:53:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=S+bdQLR7O1xny2qvOs5HyD3+faLEhFDEQp4+nZ/NAiI=; b=Jk6smIhWowrWEALF+GvVT/M3AFJqBZHzjxYPCoAG4fbslIbffrh1EWdj2YtY/W3xjz hiy7vsOhz5rRSkBfJQYj1HA4E8ev2epFA4CdLQj/KptolfbVaD6DMu0TPzbeMaiNzMq5 e/OZ9tkYHQtG9t61LURuo88fEJ0rbdCx8LmGbDq5YIwfTl3OL8xy0ZV7e5kYFX2/FuWM SNbGixmLb8zaWeVO3liPBuG29aN8zwiXND0HCFHPIBHgqhhiMFuaciuPmqGZojVUbggg c6rW9GGgySDOSWEnpqq4ciL0FDjLerBh/Pt/s97cUycil/UxblUI0L+Rq5dMJ2aSLFLR Yyaw== X-Gm-Message-State: AOAM533NZRHih4XkPa36e14VP0xeVh5gnTMO3ImOVNCpaPT60cOHzY9d hQt2o6G+edV+rm48aL5jjyuXSrnGeTWmNv0JESGOYz15A2wayMJfUaKp6fMHgxWpASbOwlSrIe7 fJh1Mlz99SBePGMlGfgT1hXvfZzBVggTIwkXRH873Z+3T/KVO1uDyGO/GUuBWxmmdOhCe47E= X-Google-Smtp-Source: ABdhPJwW9hw4W90KTD+m8MoPWI7JZebSil3faO3mYF/VZp93pQgoH3IRFu1srJq/YImLIS3MyVFNH/xSsSWU3w== X-Received: by 2002:a05:6214:a85:: with SMTP id ev5mr54273635qvb.153.1594202008590; Wed, 08 Jul 2020 02:53:28 -0700 (PDT) Date: Wed, 8 Jul 2020 10:53:14 +0100 In-Reply-To: <20200708095315.948634-1-gprocida@google.com> Message-Id: <20200708095315.948634-3-gprocida@google.com> Mime-Version: 1.0 References: <20200708095315.948634-1-gprocida@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH 2/3] abg-ir.cc: Refactor operator== methods with helper To: libabigail@sourceware.org X-Spam-Status: No, score=-23.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" Many of the operator== definitions in this source file follow the same pattern: - the address of the argument is dynamic_cast to type of 'this' - naked canonical type pointers are compared, if both present - the types are compared structurally with 'equals' In a couple of cases extra work is done to fetch the canonical type of the definition of a declaration. This commit refactors all the common logic into a couple of templated helper functions. There are no behavioural changes. * src/abg-ir.cc (equality_helper): Add an overloaded function to perform the common actions needed for operator==. The first overload takes two extra canonical type pointer arguments while the second obtains these from the types being compared. (type_decl::operator==): Call equality_helper to perform canonical type pointer and 'equals' comparisons. (scope_type_decl::operator==): Likewise. (qualified_type_def::operator==): Likewise. (pointer_type_def::operator==): Likewise. (reference_type_def::operator==): Likewise. (array_type_def::subrange_type::operator==): Likewise. (array_type_def::operator==): Likewise. (enum_type_decl::operator==): Likewise. (typedef_decl::operator==): Likewise. (function_type::operator==): Likewise. (class_or_union::operator==): Likewise. (class_decl::operator==): Likewise. (union_decl::operator==): Likewise. Signed-off-by: Giuliano Procida --- src/abg-ir.cc | 104 ++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 75 deletions(-) diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 41e2f00e..4b7e180d 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -651,6 +651,22 @@ struct type_name_comp {return operator()(type_base_sptr(l), type_base_sptr(r));} }; // end struct type_name_comp +template +bool equality_helper(const T* lptr, const T* rptr, + const type_base* lcanon, + const type_base* rcanon) +{ + return lcanon && rcanon ? lcanon == rcanon : equals(*lptr, *rptr, 0); +} + +template +bool equality_helper(const T* lptr, const T* rptr) +{ + return equality_helper(lptr, rptr, + lptr->get_naked_canonical_type(), + rptr->get_naked_canonical_type()); +} + /// Getter of all types types sorted by their pretty representation. /// /// @return a sorted vector of all types sorted by their pretty @@ -12690,11 +12706,7 @@ type_decl::operator==(const decl_base& o) const const type_decl* other = dynamic_cast(&o); if (!other) return false; - - if (get_naked_canonical_type() && other->get_naked_canonical_type()) - return get_naked_canonical_type() == other->get_naked_canonical_type(); - - return equals(*this, *other, 0); + return equality_helper(this, other); } /// Return true if both types equals. @@ -12871,11 +12883,7 @@ scope_type_decl::operator==(const decl_base& o) const const scope_type_decl* other = dynamic_cast(&o); if (!other) return false; - - if (get_naked_canonical_type() && other->get_naked_canonical_type()) - return get_naked_canonical_type() == other->get_naked_canonical_type(); - - return equals(*this, *other, 0); + return equality_helper(this, other); } /// Equality operator between two scope_type_decl. @@ -13239,11 +13247,7 @@ qualified_type_def::operator==(const decl_base& o) const dynamic_cast(&o); if (!other) return false; - - if (get_naked_canonical_type() && other->get_naked_canonical_type()) - return get_naked_canonical_type() == other->get_naked_canonical_type(); - - return equals(*this, *other, 0); + return equality_helper(this, other); } /// Equality operator for qualified types. @@ -13610,14 +13614,7 @@ pointer_type_def::operator==(const decl_base& o) const const pointer_type_def* other = is_pointer_type(&o); if (!other) return false; - - type_base* canonical_type = get_naked_canonical_type(); - type_base* other_canonical_type = other->get_naked_canonical_type(); - - if (canonical_type && other_canonical_type) - return canonical_type == other_canonical_type; - - return equals(*this, *other, 0); + return equality_helper(this, other); } /// Return true iff both instances of pointer_type_def are equal. @@ -13921,14 +13918,7 @@ reference_type_def::operator==(const decl_base& o) const dynamic_cast(&o); if (!other) return false; - - type_base* canonical_type = get_naked_canonical_type(); - type_base* other_canonical_type = other->get_naked_canonical_type(); - - if (canonical_type && other_canonical_type) - return canonical_type == other_canonical_type; - - return equals(*this, *other, 0); + return equality_helper(this, other); } /// Equality operator of the @ref reference_type_def type. @@ -14470,11 +14460,7 @@ array_type_def::subrange_type::operator==(const decl_base& o) const dynamic_cast(&o); if (!other) return false; - - if (get_naked_canonical_type() && other->get_naked_canonical_type()) - return get_naked_canonical_type() == other->get_naked_canonical_type(); - - return equals(*this, *other, 0); + return equality_helper(this, other); } /// Equality operator. @@ -14792,11 +14778,7 @@ array_type_def::operator==(const decl_base& o) const dynamic_cast(&o); if (!other) return false; - - if (get_naked_canonical_type() && other->get_naked_canonical_type()) - return get_naked_canonical_type() == other->get_naked_canonical_type(); - - return equals(*this, *other, 0); + return equality_helper(this, other); } bool @@ -15272,11 +15254,7 @@ enum_type_decl::operator==(const decl_base& o) const const enum_type_decl* op = dynamic_cast(&o); if (!op) return false; - - if (get_naked_canonical_type() && op->get_naked_canonical_type()) - return get_naked_canonical_type() == op->get_naked_canonical_type(); - - return equals(*this, *op, 0); + return equality_helper(this, op); } /// Equality operator. @@ -15626,11 +15604,7 @@ typedef_decl::operator==(const decl_base& o) const const typedef_decl* other = dynamic_cast(&o); if (!other) return false; - - if (get_naked_canonical_type() && other->get_naked_canonical_type()) - return get_naked_canonical_type() == other->get_naked_canonical_type(); - - return equals(*this, *other, 0); + return equality_helper(this, other); } /// Equality operator @@ -16725,14 +16699,7 @@ function_type::operator==(const type_base& other) const const function_type* o = dynamic_cast(&other); if (!o) return false; - - type_base* canonical_type = get_naked_canonical_type(); - type_base* other_canonical_type = other.get_naked_canonical_type(); - - if (canonical_type && other_canonical_type) - return canonical_type == other_canonical_type; - - return equals(*this, *o, 0); + return equality_helper(this, o); } /// Return a copy of the pretty representation of the current @ref @@ -19107,10 +19074,7 @@ class_or_union::operator==(const decl_base& other) const other_canonical_type = op->get_naked_definition_of_declaration()->get_naked_canonical_type(); - if (canonical_type && other_canonical_type) - return canonical_type == other_canonical_type; - - return equals(*this, *op, 0); + return equality_helper(this, op, canonical_type, other_canonical_type); } /// Equality operator. @@ -20961,10 +20925,7 @@ class_decl::operator==(const decl_base& other) const other_canonical_type = op->get_naked_definition_of_declaration()->get_naked_canonical_type(); - if (canonical_type && other_canonical_type) - return canonical_type == other_canonical_type; - - return equals(*this, *op, 0); + return equality_helper(this, op, canonical_type, other_canonical_type); } /// Equality operator for class_decl. @@ -21745,14 +21706,7 @@ union_decl::operator==(const decl_base& other) const const union_decl* op = dynamic_cast(&other); if (!op) return false; - - type_base *canonical_type = get_naked_canonical_type(), - *other_canonical_type = op->get_naked_canonical_type(); - - if (canonical_type && other_canonical_type) - return canonical_type == other_canonical_type; - - return equals(*this, *op, 0); + return equality_helper(this, op); } /// Equality operator for union_decl.