public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>, Tom Tromey <tom@tromey.com>
Subject: [PATCH v3 10/10] gdb: make-target-delegates.py: add type annotations
Date: Sun, 26 Feb 2023 20:14:03 -0500	[thread overview]
Message-ID: <20230227011403.612304-11-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20230227011403.612304-1-simon.marchi@polymtl.ca>

Fixes all warnings given by pyright.

Change-Id: I480521bfc62960c4eccd9d32c886392b05a1ddaa
Reviewed-By: Tom Tromey <tom@tromey.com>
---
 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.
-- 
2.39.2


  parent reply	other threads:[~2023-02-27  1:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27  1:13 [PATCH v3 00/10] Add typing annotations to gdbarch*.py and make-target-delegates.py Simon Marchi
2023-02-27  1:13 ` [PATCH v3 01/10] gdb: remove invalid / dead code from gdbarch.py Simon Marchi
2023-02-27  1:13 ` [PATCH v3 02/10] gdb: reformat Python files with black 23.1.0 Simon Marchi
2023-02-27  1:13 ` [PATCH v3 03/10] gdb: gdbarch.py: spell out parameters of _Component.__init__ Simon Marchi
2023-02-27  1:13 ` [PATCH v3 04/10] gdb: gdbarch.py: remove Info.__init__ Simon Marchi
2023-02-27  1:13 ` [PATCH v3 05/10] gdb: pyproject.toml: set pyright typeCheckingMode = "strict" Simon Marchi
2023-02-27  1:13 ` [PATCH v3 06/10] gdb: split gdbarch component types to gdbarch_types.py Simon Marchi
2023-02-27  1:14 ` [PATCH v3 07/10] gdb: gdbarch*.py, copyright.py: add type annotations Simon Marchi
2023-02-27  1:14 ` [PATCH v3 08/10] gdb: make-target-delegates.py: make one string raw Simon Marchi
2023-02-27  1:14 ` [PATCH v3 09/10] gdb: make-target-delegates.py: add Entry type Simon Marchi
2023-02-27  1:14 ` Simon Marchi [this message]
2023-02-27 17:38 ` [PATCH v3 00/10] Add typing annotations to gdbarch*.py and make-target-delegates.py Andrew Burgess
2023-02-27 18:27   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230227011403.612304-11-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).