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 7BC7B3858D33 for ; Fri, 2 Dec 2022 14:46:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BC7B3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (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 240E41E112; Fri, 2 Dec 2022 09:46:15 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1669992375; bh=wUESiKMZC/YhjwmVrlO3PW1W32zR09qjjmm1A9qDhpE=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Arlsq1jvbFe6yXn0zavr4FqM+Y4M+G+cssT884kQFLkBBm0jexfX38cN91kMnVidp a0zNyws/jpCE6y75wIqR0BD75Ol1ucZmqXcTcLO3CdnS7tTu47QcPRHCYQParkRqjO v3OS9rhYqA7LVCzNP5L+GR5XBI1MQpmSIw3dS7c0= Message-ID: <18711e08-f91c-3e56-fbf0-333bbca5e50f@simark.ca> Date: Fri, 2 Dec 2022 09:46:14 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH 2/2] gdbarch.py: Fix indentation in the generated set_gdbarch_* definitions Content-Language: en-US To: Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20221201223914.366184-1-thiago.bauermann@linaro.org> <20221201223914.366184-3-thiago.bauermann@linaro.org> From: Simon Marchi In-Reply-To: <20221201223914.366184-3-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py > index 7ac7140e1452..ce430318eb49 100755 > --- a/gdb/gdbarch.py > +++ b/gdb/gdbarch.py > @@ -479,10 +479,10 @@ with open("gdbarch.c", "w") as f: > print(file=f) > print("void", file=f) > print(f"set_gdbarch_{c.name} (struct gdbarch *gdbarch,", file=f) > - print( > - f" {' ' * len(c.name)} gdbarch_{c.name}_ftype {c.name})", > - file=f, > - ) > + total_indentation = len("set_gdbarch_") + len(c.name) + 2 > + tabs = '\t' * (total_indentation // 8) > + spaces = ' ' * (total_indentation % 8) > + print(f"{tabs}{spaces}gdbarch_{c.name}_ftype {c.name})", file=f) For clarity and to factor out the implementation, I think it would be worth putting the computation of the indentation characters in its own function (untested): def indentation(n_columns): return '\' * (n_columns // 8) + ' ' * (n_columns % 8) It can then be used directly in the format string: setter_name = f"set_gdbarch_{c.name}" ftype_name = f"gdbarch_{c.name}_ftype" print(f"{setter_name} (struct gdbarch *gdbarch,", file=f) indent_columns = len(f"{setter_name} (") print("f{indentation(indent_columns)}{ftype_name})", file=f) Simon