From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [50.116.126.2]) by sourceware.org (Postfix) with ESMTPS id CCE6A395BC4B for ; Sat, 20 Feb 2021 20:16:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CCE6A395BC4B 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 cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 6DAA5400D001D for ; Sat, 20 Feb 2021 14:16:50 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id DYgMlmUGADT64DYgMlULrG; Sat, 20 Feb 2021 14:16:50 -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=YaNLQIMl2egoBy/oXDPBRFD9QhY0puPpF8M+Jvozu6M=; b=OBAw0Ipgoj2NGoh7iOn1EaTxl7 EScAHBSbgMmYYFP3p1vgiLtPMWf+DkbJF1HTytsZBMsSPSumAaNXsCkub1B1uNBJPWOvOG/OxiX5o TK9s50noZkqSw9UaaINybsUX1; Received: from 97-122-70-152.hlrn.qwest.net ([97.122.70.152]:52706 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 1lDYgM-000Gqq-8C for gdb-patches@sourceware.org; Sat, 20 Feb 2021 13:16:50 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH v3 176/206] Add completion for operations Date: Sat, 20 Feb 2021 13:15:39 -0700 Message-Id: <20210220201609.838264-177-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210220201609.838264-1-tom@tromey.com> References: <20210220201609.838264-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.70.152 X-Source-L: No X-Exim-ID: 1lDYgM-000Gqq-8C X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-152.hlrn.qwest.net (localhost.localdomain) [97.122.70.152]:52706 X-Source-Auth: tom+tromey.com X-Email-Count: 177 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3034.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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: 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: , X-List-Received-Date: Sat, 20 Feb 2021 20:17:10 -0000 This patch adds the necessary support for field name completion for expressions using class operation. This patch takes an approach similar to what is done today. It might be good, in the future, to change completion to be a method on the base class, to enable context-sensitive completion in more areas. gdb/ChangeLog 2021-02-20 Tom Tromey * parser-defs.h (struct expr_completion_state) : New member. (struct parser_state) : New method. * parse.c (parser_state::mark_struct_expression): Update assert. (parser_state::mark_struct_expression): New method. (parser_state::mark_completion_tag): Update assert. (parse_expression_for_completion): Handle expout_last_op. --- gdb/ChangeLog | 10 ++++++++++ gdb/parse.c | 26 ++++++++++++++++++++++++-- gdb/parser-defs.h | 11 +++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/gdb/parse.c b/gdb/parse.c index 68386f17bc5..79b1ca16121 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -507,10 +507,23 @@ parser_state::mark_struct_expression () { gdb_assert (parse_completion && (m_completion_state.expout_tag_completion_type - == TYPE_CODE_UNDEF)); + == TYPE_CODE_UNDEF) + && m_completion_state.expout_last_op == nullptr); m_completion_state.expout_last_struct = expout_ptr; } +/* See parser-defs.h. */ + +void +parser_state::mark_struct_expression (expr::structop_base_operation *op) +{ + gdb_assert (parse_completion + && (m_completion_state.expout_tag_completion_type + == TYPE_CODE_UNDEF) + && m_completion_state.expout_last_struct == -1); + m_completion_state.expout_last_op = op; +} + /* Indicate that the current parser invocation is completing a tag. TAG is the type code of the tag, and PTR and LENGTH represent the start of the tag name. */ @@ -523,7 +536,8 @@ parser_state::mark_completion_tag (enum type_code tag, const char *ptr, && (m_completion_state.expout_tag_completion_type == TYPE_CODE_UNDEF) && m_completion_state.expout_completion_name == NULL - && m_completion_state.expout_last_struct == -1); + && m_completion_state.expout_last_struct == -1 + && m_completion_state.expout_last_op == nullptr); gdb_assert (tag == TYPE_CODE_UNION || tag == TYPE_CODE_STRUCT || tag == TYPE_CODE_ENUM); @@ -1262,6 +1276,14 @@ parse_expression_for_completion (const char *string, return NULL; } + if (cstate.expout_last_op != nullptr) + { + expr::structop_base_operation *op = cstate.expout_last_op; + const std::string &fld = op->get_string (); + *name = make_unique_xstrdup (fld.c_str ()); + return value_type (op->evaluate_lhs (exp.get ())); + } + if (cstate.expout_last_struct == -1) return NULL; diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index a9ae198fab2..9f70ff9dca7 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -25,6 +25,7 @@ #include "expression.h" #include "symtab.h" +#include "expop.h" struct block; struct language_defn; @@ -93,6 +94,11 @@ struct expr_completion_state field name. It is -1 if no dereference operation was found. */ int expout_last_struct = -1; + /* The last struct expression directly before a '.' or '->'. This + is set when parsing and is only used when completing a field + name. It is nullptr if no dereference operation was found. */ + expr::structop_base_operation *expout_last_op = nullptr; + /* If we are completing a tagged type name, this will be nonzero. */ enum type_code expout_tag_completion_type = TYPE_CODE_UNDEF; @@ -156,6 +162,11 @@ struct parser_state : public expr_builder void mark_struct_expression (); + /* Mark the given operation as the starting location of a structure + expression. This is used when completing on field names. */ + + void mark_struct_expression (expr::structop_base_operation *op); + /* Indicate that the current parser invocation is completing a tag. TAG is the type code of the tag, and PTR and LENGTH represent the start of the tag name. */ -- 2.26.2