From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AIPOHOyY71/aTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:32 -0500 Received: by simark.ca (Postfix, from userid 112) id D2DCD1F0BE; Fri, 1 Jan 2021 16:49:29 -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 E3FD91F0B8 for ; Fri, 1 Jan 2021 16:49:28 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF83E3938C2A; Fri, 1 Jan 2021 21:48:55 +0000 (GMT) Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.187.5]) by sourceware.org (Postfix) with ESMTPS id 549683938C17 for ; Fri, 1 Jan 2021 21:48:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 549683938C17 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 cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway36.websitewelcome.com (Postfix) with ESMTP id F4127400C8F64 for ; Fri, 1 Jan 2021 15:48:52 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSI0kyOc9svw9vSI0kLucg; Fri, 01 Jan 2021 15:48:52 -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=xRQCe0EjOffrH7v4JzMWMXE3r4bg2iXgN8kpK2aPl+U=; b=sn5vQ0VHwpOYh6zvM+RxM4YL0R 22XrWgiPcv2mZMrspT+YqJNqKkmkNfav1Apo3prYxjEKmKTG06hNdS4drc/yGMCH2/UfYRDu+bzf3 xjEJHCD9bbzdZi9OKV7PSJyIz; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60424 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 1kvSI0-0029vv-OJ for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:52 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 173/203] Add completion for operations Date: Fri, 1 Jan 2021 14:46:53 -0700 Message-Id: <20210101214723.1784144-174-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: 1kvSI0-0029vv-OJ X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60424 X-Source-Auth: tom+tromey.com X-Email-Count: 174 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 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-01-01 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 | 10 ++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/gdb/parse.c b/gdb/parse.c index 4c8eb14549b..24258eb2c27 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); @@ -1251,6 +1265,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 9f1925d463a..f4cce3dfb91 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -93,6 +93,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 +161,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