From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 833A638930F4 for ; Sat, 20 Jun 2020 19:26:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 833A638930F4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2D0E01E5F9; Sat, 20 Jun 2020 15:26:19 -0400 (EDT) Subject: Re: [RFAv7 1/3] default-args: allow to define default arguments for aliases To: Philippe Waroquiers , gdb-patches@sourceware.org References: <20200614163942.19176-1-philippe.waroquiers@skynet.be> <20200614163942.19176-2-philippe.waroquiers@skynet.be> From: Simon Marchi Message-ID: <68f3d112-c3dd-8572-c181-48506fee7636@simark.ca> Date: Sat, 20 Jun 2020 15:26:18 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200614163942.19176-2-philippe.waroquiers@skynet.be> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, 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 Jun 2020 19:26:20 -0000 Some random comments I noted before I thought about the "set default-args" problem which I talked about in my response to [0/3]. I got: Applying: default-args: allow to define default arguments for aliases .git/rebase-apply/patch:680: trailing whitespace. if DEFAULT_ARGS is not null, *DEFAULT_ARGS is set to the found command warning: 1 line adds whitespace errors. > @@ -1046,6 +1046,32 @@ fput_command_name_styled (struct cmd_list_element *c, struct ui_file *stream) > If one or more names are printed, POSTFIX is printed after the last name. > */ > > +/* Print the definition of alias C using title style for alias > + and aliased command. */ The comment just above this (we see the end in this hunk) should stay with function fput_command_names_styled. > + > +static void > +fput_alias_definition_styled (struct cmd_list_element *c, struct ui_file *stream) > +{ > + gdb_assert (c->cmd_pointer != nullptr); > + fputs_filtered (" alias ", stream); > + fput_command_name_styled (c, stream); > + fprintf_filtered (stream, " = "); > + fput_command_name_styled (c->cmd_pointer, stream); > + fprintf_filtered (stream, " %s\n", c->default_args.c_str ()); > +} > + > +/* Print the definition of the aliases of CMD that have default args. */ > + > +static void > +fput_aliases_definition_styled (struct cmd_list_element *cmd, struct ui_file *stream) > +{ > + if (cmd->aliases != nullptr) > + for (cmd_list_element *iter = cmd->aliases; iter; iter = iter->alias_chain) > + if (!iter->default_args.empty ()) > + fput_alias_definition_styled (iter, stream); When we have nested control structures, the GNU coding style recommends to use braces for the outer ones: https://www.gnu.org/prep/standards/html_node/Syntactic-Conventions.html#Syntactic-Conventions I'd suggest following it, so: if (...) { for (...) { if (...) .. } } > @@ -1205,9 +1240,43 @@ help_cmd (const char *command, struct ui_file *stream) > /* If the user asked 'help somecommand' and there is no alias, > the false indicates to not output the (single) command name. */ > fput_command_names_styled (c, false, "\n", stream); > + fput_aliases_definition_styled (c, stream); > fputs_filtered (c->doc, stream); > fputs_filtered ("\n", stream); > > + if (c->func != nullptr) > + { > + /* Print the default args of the command if it has some. Use the > + lookup_cmd_composition result to find if help was requested for an > + alias. In this case, rather print the alias default_args. */ > + > + const char *name; > + std::string default_args; Use pointer to std::string to avoid an unnecessary copy? Simon