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 D8F2A385B50C for ; Thu, 23 Feb 2023 22:20:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8F2A385B50C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com Received: from smarchi-efficios.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (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 ESMTPSA id 5FA7C1E221; Thu, 23 Feb 2023 17:20:33 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 9/9] gdb: make-target-delegates.py: add type annotations Date: Thu, 23 Feb 2023 17:18:30 -0500 Message-Id: <20230223221830.499934-10-simon.marchi@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230223221830.499934-1-simon.marchi@efficios.com> References: <20230223221830.499934-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3497.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP,T_FILL_THIS_FORM_SHORT 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: From: Simon Marchi Fixes all warnings given by pyright. Change-Id: I480521bfc62960c4eccd9d32c886392b05a1ddaa --- gdb/make-target-delegates.py | 50 +++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/gdb/make-target-delegates.py b/gdb/make-target-delegates.py index aa0919e51b13..eb6c5de7cbc1 100755 --- a/gdb/make-target-delegates.py +++ b/gdb/make-target-delegates.py @@ -22,6 +22,7 @@ import re import gdbcopyright +import typing # The line we search for in target.h that marks where we should start @@ -121,7 +122,7 @@ def scan_target_h(): line = re.split("//", line)[0] all_the_text = all_the_text + " " + line if not found_trigger: - raise "Could not find trigger line" + raise RuntimeError("Could not find trigger line") # Now strip out the C comments. all_the_text = re.sub(r"/\*(.*?)\*/", "", all_the_text) # Replace sequences whitespace with a single space character. @@ -142,10 +143,10 @@ def scan_target_h(): # Parse arguments into a list. -def parse_argtypes(typestr): +def parse_argtypes(typestr: str): # Remove the outer parens. typestr = re.sub(r"^\((.*)\)$", r"\1", typestr) - result = [] + result: list[str] = [] for item in re.split(r",\s*", typestr): if item == "void" or item == "": continue @@ -163,7 +164,9 @@ def parse_argtypes(typestr): # Write function header given name, return type, and argtypes. # Returns a list of actual argument names. -def write_function_header(f, decl, name, return_type, argtypes): +def write_function_header( + f: typing.TextIO, decl: bool, name: str, return_type: str, argtypes: list[str] +): print(return_type, file=f, end="") if decl: if not return_type.endswith("*"): @@ -171,8 +174,8 @@ def write_function_header(f, decl, name, return_type, argtypes): else: print("", file=f) print(name + " (", file=f, end="") - argdecls = [] - actuals = [] + argdecls: list[str] = [] + actuals: list[str] = [] for i in range(len(argtypes)): val = re.sub(TARGET_DEBUG_PRINTER, "", argtypes[i]) if not val.endswith("*") and not val.endswith("&"): @@ -190,12 +193,14 @@ def write_function_header(f, decl, name, return_type, argtypes): # Write out a declaration. -def write_declaration(f, name, return_type, argtypes): +def write_declaration( + f: typing.TextIO, name: str, return_type: str, argtypes: list[str] +): write_function_header(f, True, name, return_type, argtypes) # Write out a delegation function. -def write_delegator(f, name, return_type, argtypes): +def write_delegator(f: typing.TextIO, name: str, return_type: str, argtypes: list[str]): names = write_function_header( f, False, "target_ops::" + name, return_type, argtypes ) @@ -209,7 +214,14 @@ def write_delegator(f, name, return_type, argtypes): # Write out a default function. -def write_tdefault(f, content, style, name, return_type, argtypes): +def write_tdefault( + f: typing.TextIO, + content: str, + style: str, + name: str, + return_type: str, + argtypes: list[str], +): name = "dummy_target::" + name names = write_function_header(f, False, name, return_type, argtypes) if style == "FUNC": @@ -227,11 +239,11 @@ def write_tdefault(f, content, style, name, return_type, argtypes): # Nothing. pass else: - raise "unrecognized style: " + style + raise RuntimeError("unrecognized style: " + style) print("}\n", file=f) -def munge_type(typename): +def munge_type(typename: str): m = re.search(TARGET_DEBUG_PRINTER, typename) if m: return m.group("arg") @@ -250,7 +262,9 @@ def munge_type(typename): # Write out a debug method. -def write_debugmethod(f, content, name, return_type, argtypes): +def write_debugmethod( + f: typing.TextIO, content: str, name: str, return_type: str, argtypes: list[str] +): debugname = "debug_target::" + name names = write_function_header(f, False, debugname, return_type, argtypes) if return_type != "void": @@ -296,7 +310,12 @@ def write_debugmethod(f, content, name, return_type, argtypes): print("}\n", file=f) -def print_class(f, class_name, delegators, entries): +def print_class( + f: typing.TextIO, + class_name: str, + delegators: list[str], + entries: dict[str, Entry], +): print("struct " + class_name + " : public target_ops", file=f) print("{", file=f) print(" const target_info &info () const override;", file=f) @@ -312,8 +331,9 @@ def print_class(f, class_name, delegators, entries): print("};\n", file=f) -delegators = [] -entries = {} +delegators: list[str] = [] +entries: dict[str, Entry] = {} + for current_line in scan_target_h(): # See comments in scan_target_h. Here we strip away the leading # and trailing whitespace. -- 2.39.2