From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AE/ABNSY71/aTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:08 -0500 Received: by simark.ca (Postfix, from userid 112) id EE3C91F0C5; Fri, 1 Jan 2021 16:49:06 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,MAILING_LIST_MULTI, RDNS_NONE,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 91CA01F0BE for ; Fri, 1 Jan 2021 16:49:03 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CDEAA389367C; Fri, 1 Jan 2021 21:48:38 +0000 (GMT) Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.130]) by sourceware.org (Postfix) with ESMTPS id 0E2A43896C0C for ; Fri, 1 Jan 2021 21:48:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0E2A43896C0C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway33.websitewelcome.com (Postfix) with ESMTP id A2A5C10BE63E for ; Fri, 1 Jan 2021 15:48:33 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHhka1hfnPrxvSHhkle8z; Fri, 01 Jan 2021 15:48:33 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wU32L4voKeLuyCQI7M/WX7cnNlSvdE7UbjyefbMXWMM=; b=gsSjjlLoKF5Er90daXcdnbAzuN 3VTf/BSrfdV4A8nhB/5kan7zVGQzaS7P+VHvatuB2q23/i6u8aBlgkHcS/CuuLTaMK9c90aPmuEOR URxuLsgaFcK7FRl3w69bCqBDj; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60414 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kvSHh-0029lU-FS for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:33 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 137/203] Implement the "&&" and "||" operators Date: Fri, 1 Jan 2021 14:46:17 -0700 Message-Id: <20210101214723.1784144-138-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210101214723.1784144-1-tom@tromey.com> References: <20210101214723.1784144-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.81.39 X-Source-L: No X-Exim-ID: 1kvSHh-0029lU-FS X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60414 X-Source-Auth: tom+tromey.com X-Email-Count: 138 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This implements the "&&" and "||" operators. gdb/ChangeLog 2021-01-01 Tom Tromey * expop.h (class logical_and_operation) (class logical_or_operation): New. * eval.c (logical_and_operation::evaluate) (logical_or_operation::evaluate): New methods. * ax-gdb.c (logical_and_operation::do_generate_ax) (logical_or_operation::do_generate_ax): New methods. --- gdb/ChangeLog | 9 ++++++++ gdb/ax-gdb.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ gdb/eval.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/expop.h | 48 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 176 insertions(+) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index bdf4a6dc39a..8ec3dd7cc3d 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2693,6 +2693,62 @@ var_value_operation::do_generate_ax (struct expression *exp, } } +void +logical_and_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + struct axs_value value1, value2; + int if1, go1, if2, go2, end; + + /* Generate the obvious sequence of tests and jumps. */ + std::get<0> (m_storage)->generate_ax (exp, ax, &value1); + gen_usual_unary (ax, &value1); + if1 = ax_goto (ax, aop_if_goto); + go1 = ax_goto (ax, aop_goto); + ax_label (ax, if1, ax->len); + std::get<1> (m_storage)->generate_ax (exp, ax, &value2); + gen_usual_unary (ax, &value2); + if2 = ax_goto (ax, aop_if_goto); + go2 = ax_goto (ax, aop_goto); + ax_label (ax, if2, ax->len); + ax_const_l (ax, 1); + end = ax_goto (ax, aop_goto); + ax_label (ax, go1, ax->len); + ax_label (ax, go2, ax->len); + ax_const_l (ax, 0); + ax_label (ax, end, ax->len); + value->kind = axs_rvalue; + value->type = builtin_type (ax->gdbarch)->builtin_int; +} + +void +logical_or_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + struct axs_value value1, value2; + int if1, if2, end; + + /* Generate the obvious sequence of tests and jumps. */ + std::get<0> (m_storage)->generate_ax (exp, ax, &value1); + gen_usual_unary (ax, &value1); + if1 = ax_goto (ax, aop_if_goto); + std::get<1> (m_storage)->generate_ax (exp, ax, &value2); + gen_usual_unary (ax, &value2); + if2 = ax_goto (ax, aop_if_goto); + ax_const_l (ax, 0); + end = ax_goto (ax, aop_goto); + ax_label (ax, if1, ax->len); + ax_label (ax, if2, ax->len); + ax_const_l (ax, 1); + ax_label (ax, end, ax->len); + value->kind = axs_rvalue; + value->type = builtin_type (ax->gdbarch)->builtin_int; +} + } /* This handles the middle-to-right-side of code generation for binary diff --git a/gdb/eval.c b/gdb/eval.c index b1087d1329d..495cd4b26a3 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2461,6 +2461,69 @@ multi_subscript_operation::evaluate (struct type *expect_type, gdb::make_array_view (argvec, values.size ())); } +value * +logical_and_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + + value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, + EVAL_AVOID_SIDE_EFFECTS); + + if (binop_user_defined_p (BINOP_LOGICAL_AND, arg1, arg2)) + { + arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + return value_x_binop (arg1, arg2, BINOP_LOGICAL_AND, OP_NULL, noside); + } + else + { + int tem = value_logical_not (arg1); + if (!tem) + { + arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + tem = value_logical_not (arg2); + } + struct type *type = language_bool_type (exp->language_defn, + exp->gdbarch); + return value_from_longest (type, !tem); + } +} + +value * +logical_or_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + + value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, + EVAL_AVOID_SIDE_EFFECTS); + + if (binop_user_defined_p (BINOP_LOGICAL_OR, arg1, arg2)) + { + arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + return value_x_binop (arg1, arg2, BINOP_LOGICAL_OR, OP_NULL, noside); + } + else + { + int tem = value_logical_not (arg1); + if (tem) + { + arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside); + tem = value_logical_not (arg2); + } + + struct type *type = language_bool_type (exp->language_defn, + exp->gdbarch); + return value_from_longest (type, !tem); + } +} + } struct value * diff --git a/gdb/expop.h b/gdb/expop.h index 21c7b9e25da..f858f591baf 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -1979,6 +1979,54 @@ class multi_subscript_operation { return MULTI_SUBSCRIPT; } }; +/* The "&&" operator. */ +class logical_and_operation + : public maybe_constant_operation +{ +public: + + using maybe_constant_operation::maybe_constant_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + + enum exp_opcode opcode () const override + { return BINOP_LOGICAL_AND; } + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override; +}; + +/* The "||" operator. */ +class logical_or_operation + : public maybe_constant_operation +{ +public: + + using maybe_constant_operation::maybe_constant_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + + enum exp_opcode opcode () const override + { return BINOP_LOGICAL_OR; } + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override; +}; + } /* namespace expr */ #endif /* EXPOP_H */ -- 2.26.2