From patchwork Mon Feb 27 01:14:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 65662 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C3D5385840D for ; Mon, 27 Feb 2023 01:17:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0C3D5385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677460631; bh=a5nE4X29VzCFXQcrlBQ86NkrGWTraGJyjs5C0htXBok=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=RRnOZRM1egm5Cy3wWFsPytl1d6J/WcYqCaXE4Xg1pahgHG9KM/aKQzgPBOde5xsn6 DhdgsN4EMMIQMlbhx3+RcohxM+VUoRLG5Ga8l52r7WIb0K51U3MnP5q8pu0jCZZUEc UyEZ4QfuG43vsTbEzmuENTO/9WvIQWH02x9ZqQMw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 4DC823858D32 for ; Mon, 27 Feb 2023 01:16:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DC823858D32 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 31R1G9H0026741 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 26 Feb 2023 20:16:14 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 31R1G9H0026741 Received: from simark.localdomain (unknown [217.28.27.60]) (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 20F9F1E222; Sun, 26 Feb 2023 20:16:09 -0500 (EST) To: gdb-patches@sourceware.org Cc: Simon Marchi , Tom Tromey Subject: [PATCH v3 10/10] gdb: make-target-delegates.py: add type annotations Date: Sun, 26 Feb 2023 20:14:03 -0500 Message-Id: <20230227011403.612304-11-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230227011403.612304-1-simon.marchi@polymtl.ca> References: <20230227011403.612304-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 27 Feb 2023 01:16:09 +0000 X-Spam-Status: No, score=-3189.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, 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 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-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Fixes all warnings given by pyright. Change-Id: I480521bfc62960c4eccd9d32c886392b05a1ddaa Reviewed-By: Tom Tromey --- gdb/make-target-delegates.py | 49 ++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/gdb/make-target-delegates.py b/gdb/make-target-delegates.py index 1e2e741bc320..6226e5843836 100755 --- a/gdb/make-target-delegates.py +++ b/gdb/make-target-delegates.py @@ -21,7 +21,7 @@ # make-target-delegates.py import re -from typing import List +from typing import Dict, List, TextIO import gdbcopyright @@ -122,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. @@ -143,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 @@ -164,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: TextIO, decl: bool, name: str, return_type: str, argtypes: List[str] +): print(return_type, file=f, end="") if decl: if not return_type.endswith("*"): @@ -172,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("&"): @@ -191,12 +193,12 @@ 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: 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: TextIO, name: str, return_type: str, argtypes: List[str]): names = write_function_header( f, False, "target_ops::" + name, return_type, argtypes ) @@ -210,7 +212,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: 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": @@ -228,11 +237,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") @@ -251,7 +260,9 @@ def munge_type(typename): # Write out a debug method. -def write_debugmethod(f, content, name, return_type, argtypes): +def write_debugmethod( + f: 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": @@ -297,7 +308,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: 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) @@ -313,8 +329,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.