gdb: make-target-delegates.py: add type annotations

Fixes all warnings given by pyright.

Change-Id: I480521bfc62960c4eccd9d32c886392b05a1ddaa
Reviewed-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
Simon Marchi
2023-02-26 20:14:03 -05:00
committed by Simon Marchi
parent c6cf3ced97
commit 13ee541070

View File

@ -21,7 +21,7 @@
# make-target-delegates.py # make-target-delegates.py
import re import re
from typing import List from typing import Dict, List, TextIO
import gdbcopyright import gdbcopyright
@ -122,7 +122,7 @@ def scan_target_h():
line = re.split("//", line)[0] line = re.split("//", line)[0]
all_the_text = all_the_text + " " + line all_the_text = all_the_text + " " + line
if not found_trigger: if not found_trigger:
raise "Could not find trigger line" raise RuntimeError("Could not find trigger line")
# Now strip out the C comments. # Now strip out the C comments.
all_the_text = re.sub(r"/\*(.*?)\*/", "", all_the_text) all_the_text = re.sub(r"/\*(.*?)\*/", "", all_the_text)
# Replace sequences whitespace with a single space character. # Replace sequences whitespace with a single space character.
@ -143,10 +143,10 @@ def scan_target_h():
# Parse arguments into a list. # Parse arguments into a list.
def parse_argtypes(typestr): def parse_argtypes(typestr: str):
# Remove the outer parens. # Remove the outer parens.
typestr = re.sub(r"^\((.*)\)$", r"\1", typestr) typestr = re.sub(r"^\((.*)\)$", r"\1", typestr)
result = [] result: list[str] = []
for item in re.split(r",\s*", typestr): for item in re.split(r",\s*", typestr):
if item == "void" or item == "": if item == "void" or item == "":
continue continue
@ -164,7 +164,9 @@ def parse_argtypes(typestr):
# Write function header given name, return type, and argtypes. # Write function header given name, return type, and argtypes.
# Returns a list of actual argument names. # 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="") print(return_type, file=f, end="")
if decl: if decl:
if not return_type.endswith("*"): if not return_type.endswith("*"):
@ -172,8 +174,8 @@ def write_function_header(f, decl, name, return_type, argtypes):
else: else:
print("", file=f) print("", file=f)
print(name + " (", file=f, end="") print(name + " (", file=f, end="")
argdecls = [] argdecls: list[str] = []
actuals = [] actuals: list[str] = []
for i in range(len(argtypes)): for i in range(len(argtypes)):
val = re.sub(TARGET_DEBUG_PRINTER, "", argtypes[i]) val = re.sub(TARGET_DEBUG_PRINTER, "", argtypes[i])
if not val.endswith("*") and not val.endswith("&"): 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. # 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_function_header(f, True, name, return_type, argtypes)
# Write out a delegation function. # 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( names = write_function_header(
f, False, "target_ops::" + name, return_type, argtypes 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. # 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 name = "dummy_target::" + name
names = write_function_header(f, False, name, return_type, argtypes) names = write_function_header(f, False, name, return_type, argtypes)
if style == "FUNC": if style == "FUNC":
@ -228,11 +237,11 @@ def write_tdefault(f, content, style, name, return_type, argtypes):
# Nothing. # Nothing.
pass pass
else: else:
raise "unrecognized style: " + style raise RuntimeError("unrecognized style: " + style)
print("}\n", file=f) print("}\n", file=f)
def munge_type(typename): def munge_type(typename: str):
m = re.search(TARGET_DEBUG_PRINTER, typename) m = re.search(TARGET_DEBUG_PRINTER, typename)
if m: if m:
return m.group("arg") return m.group("arg")
@ -251,7 +260,9 @@ def munge_type(typename):
# Write out a debug method. # 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 debugname = "debug_target::" + name
names = write_function_header(f, False, debugname, return_type, argtypes) names = write_function_header(f, False, debugname, return_type, argtypes)
if return_type != "void": if return_type != "void":
@ -297,7 +308,12 @@ def write_debugmethod(f, content, name, return_type, argtypes):
print("}\n", file=f) 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("struct " + class_name + " : public target_ops", file=f)
print("{", file=f) print("{", file=f)
print(" const target_info &info () const override;", 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) print("};\n", file=f)
delegators = [] delegators: List[str] = []
entries = {} entries: Dict[str, Entry] = {}
for current_line in scan_target_h(): for current_line in scan_target_h():
# See comments in scan_target_h. Here we strip away the leading # See comments in scan_target_h. Here we strip away the leading
# and trailing whitespace. # and trailing whitespace.