From patchwork Mon Aug 18 15:30:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 2417 Received: (qmail 19669 invoked by alias); 18 Aug 2014 15:30:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19621 invoked by uid 89); 18 Aug 2014 15:30:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RP_MATCHES_RCVD, SPF_PASS, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 18 Aug 2014 15:30:53 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 11FDC116153 for ; Mon, 18 Aug 2014 11:30:52 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Cqr2lPpYhsgq for ; Mon, 18 Aug 2014 11:30:52 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id DB04111615E for ; Mon, 18 Aug 2014 11:30:51 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id B679C410E4; Mon, 18 Aug 2014 17:30:50 +0200 (CEST) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed/Ada 2/3] avoid "if ... else if ... else" logic in ada-lang.c::ada_evaluate_subexp Date: Mon, 18 Aug 2014 17:30:43 +0200 Message-Id: <1408375844-28020-3-git-send-email-brobecker@adacore.com> In-Reply-To: <1408375844-28020-1-git-send-email-brobecker@adacore.com> References: <1408375844-28020-1-git-send-email-brobecker@adacore.com> The OP_VAR_VALUE branch in ada_evaluate_subexp is written with multiple "if ... else if ... else if ... else ..." block. But in practice, these blocks all either goto out of that block of code, or return. This patch rewrites this code slightly by replacing the "else if"-s by simple "if"s. This should better reflect the ideal processing where we try to do a standard eval whenever possible, and only do something else when the standard eval does not work. On a pratical level, this patch makes it easier to fall through to the default processing when none of the special situations are detected, thus making it easier to add more handlers of those special situations; or to remove them as they no longer become necessary! gdb/ChangeLog: * ada-lang.c (ada_evaluate_subexp) : Slight code rewrite to avoid "else if" and "else" constructs. Should be a no-op in practice. --- gdb/ChangeLog | 6 ++++++ gdb/ada-lang.c | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8cb2f18..23bc214 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2014-08-18 Joel Brobecker + * ada-lang.c (ada_evaluate_subexp) : Slight code + rewrite to avoid "else if" and "else" constructs. Should be + a no-op in practice. + +2014-08-18 Joel Brobecker + * ada-lang.c (ada_evaluate_subexp) : Fix identation of lexical block. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 334df1f..a9b5e6f 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10121,13 +10121,15 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, *pos += 4; goto nosideret; } - else if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) + + if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) /* Only encountered when an unresolved symbol occurs in a context other than a function call, in which case, it is invalid. */ error (_("Unexpected unresolved symbol, %s, during evaluation"), SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); - else if (noside == EVAL_AVOID_SIDE_EFFECTS) + + if (noside == EVAL_AVOID_SIDE_EFFECTS) { type = static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol)); /* Check to see if this is a tagged type. We also need to handle @@ -10186,11 +10188,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, *pos += 4; return value_zero (to_static_fixed_type (type), not_lval); } - else - { - arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside); - return ada_to_fixed_value (arg1); - } + + arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside); + return ada_to_fixed_value (arg1); case OP_FUNCALL: (*pos) += 2;