From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by sourceware.org (Postfix) with ESMTPS id BBBBD3858D20 for ; Fri, 2 Dec 2022 19:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BBBBD3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-12c8312131fso6600107fac.4 for ; Fri, 02 Dec 2022 11:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=1mePL0t8008ESXjjzDzsRYkarpcRtArZml/K4siudV0=; b=vox6+y812foqGhBMOgzduANiOmszKje7TUm5BfI5nQARtlCte4bXIoNbDQBvoll4gi eWPshHu8xbICRqvtKHtERSAgznk2ire1feUzeeC6JHGxfgb5jjVT8T8XSE3/MRHD2Iru RK6ziJhoqqdiiD5jtwkDVrPP4eozJBqRaC+2xkPJew/SeD/QUxjK0JNCNk7ywDawyVSp 5WEXzt48BkJEyUDeCdKiSb6xfv351grUte+6StLxw5FkVVMEHyoFD70Gx6y0heBXJ+gM GurR2rbxZK9zRjn5WepfblnTKCsGuJsMHhgCNbhSP9ZVfvrAYjn9tHh8VyNOTQhT0ROf 14Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=1mePL0t8008ESXjjzDzsRYkarpcRtArZml/K4siudV0=; b=W+jnr8cimoaNKO1Xag1ZB4odgQNhhjcjI6JjBfYYrUXZRlVzim1T/wPVumsIPck9K2 8/RHNPMWt/2Pc2KgqZnrigbeB7obY5LzVKeoeXakCG/yZnyM4PdWCwQS91ZlvBLgBAZl HTGfueHKFiYaPFPIXc5Kr9hdr1Ht3Vy+KJrn+Pof9aUKCdY4+Z+/fD1NIVFyWyc3vmT6 t/ha/QkilKoohT0gIUDj1pn34t+S6mo+ocC1rE69jIJG9bSz+2BuZr+isMRYEfUifBXI L1/7kyozc2aJ5XdAY93h1V7nFn0/UU+aNX3P7gVqknPaahXn0IwBr8vZ7XAPEteDA6YX 1wZw== X-Gm-Message-State: ANoB5pkkBTA70j6l1jnR4/5SZrYcwMMesRSthGiGlpqyaUONP7cQ/VDb PJ+SgwBfAeqCc5MHG/JxAN06N67vNwqOM7sV X-Google-Smtp-Source: AA0mqf7eYflfcP6QTzZSpjYphJwnBi58zmLO34T3VfaaTRvYJVu1sVDilL0IZFxuqDlw3DgN7e1swA== X-Received: by 2002:a05:6870:e90:b0:141:d8d1:2b2b with SMTP id mm16-20020a0568700e9000b00141d8d12b2bmr32600012oab.254.1670008252131; Fri, 02 Dec 2022 11:10:52 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:2982:38ed:93ad:52f1]) by smtp.gmail.com with ESMTPSA id p9-20020a4aa249000000b004a0783d7da6sm3215505ool.16.2022.12.02.11.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 11:10:51 -0800 (PST) References: <20221201223914.366184-1-thiago.bauermann@linaro.org> <20221201223914.366184-3-thiago.bauermann@linaro.org> <18711e08-f91c-3e56-fbf0-333bbca5e50f@simark.ca> User-agent: mu4e 1.8.11; emacs 28.2 From: Thiago Jung Bauermann To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] gdbarch.py: Fix indentation in the generated set_gdbarch_* definitions In-reply-to: <18711e08-f91c-3e56-fbf0-333bbca5e50f@simark.ca> Date: Fri, 02 Dec 2022 19:10:42 +0000 Message-ID: <87ilitfwp9.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: Simon Marchi writes: >> 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=3Df) >> print("void", file=3Df) >> print(f"set_gdbarch_{c.name} (struct gdbarch *gdbarch,", fi= le=3Df) >> - print( >> - f" {' ' * len(c.name)} gdbarch_{c.name}_ftype {c.name})", >> - file=3Df, >> - ) >> + total_indentation =3D len("set_gdbarch_") + len(c.name) + 2 >> + tabs =3D '\t' * (total_indentation // 8) >> + spaces =3D ' ' * (total_indentation % 8) >> + print(f"{tabs}{spaces}gdbarch_{c.name}_ftype {c.name})", fi= le=3Df) > > 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 =3D f"set_gdbarch_{c.name}" > ftype_name =3D f"gdbarch_{c.name}_ftype" > print(f"{setter_name} (struct gdbarch *gdbarch,", file=3Df) > indent_columns =3D len(f"{setter_name} (") > print("f{indentation(indent_columns)}{ftype_name})", file=3Df) Good idea, I adopted your version. I just added a doc string to the indentation function. Since a big part of the patch is now your code, I added a =E2=80=9CCo-developed-by: Simon Marchi = =E2=80=9D to it, hope you don't mind. --=20 Thiago