From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 067073858C50; Mon, 27 Feb 2023 18:29:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 067073858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677522591; bh=QumPmABIttOrrtqIr/L5FBHUxXrDKMdAMTdt+JDBTrI=; h=From:To:Subject:Date:From; b=wFEJBok3gxPh3gxyB4easHJfEPKdLRlk/7SmSBoQrrHw8SuYSUulEDuDyUAuY2Lx7 bS9lNQOkUJTELB5tJLNqM4puMuhWYLXE/ajL/wPTlS6SSPHdgoBAdp28f0m74Rfrsu l0YF3dq5ZeTXfkkaN33buU7zpc16JVxbXQxI1cdU= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: make-target-delegates.py: add type annotations X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: c6cf3ced973b8fea7d45c0f751cf9724a6a6e5b7 X-Git-Newrev: 13ee5410707d0487fbd97c91b83280d169b5a654 Message-Id: <20230227182951.067073858C50@sourceware.org> Date: Mon, 27 Feb 2023 18:29:51 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D13ee5410707d= 0487fbd97c91b83280d169b5a654 commit 13ee5410707d0487fbd97c91b83280d169b5a654 Author: Simon Marchi Date: Sun Feb 26 20:14:03 2023 -0500 gdb: make-target-delegates.py: add type annotations =20 Fixes all warnings given by pyright. =20 Change-Id: I480521bfc62960c4eccd9d32c886392b05a1ddaa Reviewed-By: Tom Tromey Reviewed-By: Andrew Burgess Diff: --- 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 1e2e741bc32..6226e584383 100755 --- a/gdb/make-target-delegates.py +++ b/gdb/make-target-delegates.py @@ -21,7 +21,7 @@ # make-target-delegates.py =20 import re -from typing import List +from typing import Dict, List, TextIO =20 import gdbcopyright =20 @@ -122,7 +122,7 @@ def scan_target_h(): line =3D re.split("//", line)[0] all_the_text =3D 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 =3D re.sub(r"/\*(.*?)\*/", "", all_the_text) # Replace sequences whitespace with a single space character. @@ -143,10 +143,10 @@ def scan_target_h(): =20 =20 # Parse arguments into a list. -def parse_argtypes(typestr): +def parse_argtypes(typestr: str): # Remove the outer parens. typestr =3D re.sub(r"^\((.*)\)$", r"\1", typestr) - result =3D [] + result: list[str] =3D [] for item in re.split(r",\s*", typestr): if item =3D=3D "void" or item =3D=3D "": continue @@ -164,7 +164,9 @@ def parse_argtypes(typestr): =20 # 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=3Df, end=3D"") if decl: if not return_type.endswith("*"): @@ -172,8 +174,8 @@ def write_function_header(f, decl, name, return_type, a= rgtypes): else: print("", file=3Df) print(name + " (", file=3Df, end=3D"") - argdecls =3D [] - actuals =3D [] + argdecls: list[str] =3D [] + actuals: list[str] =3D [] for i in range(len(argtypes)): val =3D 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): =20 =20 # Write out a declaration. -def write_declaration(f, name, return_type, argtypes): +def write_declaration(f: TextIO, name: str, return_type: str, argtypes: Li= st[str]): write_function_header(f, True, name, return_type, argtypes) =20 =20 # 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 =3D write_function_header( f, False, "target_ops::" + name, return_type, argtypes ) @@ -210,7 +212,14 @@ def write_delegator(f, name, return_type, argtypes): =20 =20 # 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 =3D "dummy_target::" + name names =3D write_function_header(f, False, name, return_type, argtypes) if style =3D=3D "FUNC": @@ -228,11 +237,11 @@ def write_tdefault(f, content, style, name, return_ty= pe, argtypes): # Nothing. pass else: - raise "unrecognized style: " + style + raise RuntimeError("unrecognized style: " + style) print("}\n", file=3Df) =20 =20 -def munge_type(typename): +def munge_type(typename: str): m =3D re.search(TARGET_DEBUG_PRINTER, typename) if m: return m.group("arg") @@ -251,7 +260,9 @@ def munge_type(typename): =20 =20 # 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[s= tr] +): debugname =3D "debug_target::" + name names =3D write_function_header(f, False, debugname, return_type, argt= ypes) if return_type !=3D "void": @@ -297,7 +308,12 @@ def write_debugmethod(f, content, name, return_type, a= rgtypes): print("}\n", file=3Df) =20 =20 -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=3Df) print("{", file=3Df) print(" const target_info &info () const override;", file=3Df) @@ -313,8 +329,9 @@ def print_class(f, class_name, delegators, entries): print("};\n", file=3Df) =20 =20 -delegators =3D [] -entries =3D {} +delegators: List[str] =3D [] +entries: Dict[str, Entry] =3D {} + for current_line in scan_target_h(): # See comments in scan_target_h. Here we strip away the leading # and trailing whitespace.