From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 8/9] gdb: make-target-delegates.py: add Entry type
Date: Thu, 23 Feb 2023 17:18:29 -0500 [thread overview]
Message-ID: <20230223221830.499934-9-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230223221830.499934-1-simon.marchi@efficios.com>
From: Simon Marchi <simon.marchi@polymtl.ca>
Add the Entry type and use it in the `entries` map, rather than using an
ad-hoc str -> str map that comes from the re.match. This will make it
easier to make typing work in a subsequent patch, but it also helps
readers know what attributes exist for entries, which is not clear
currently.
Change-Id: I5b58dee1ed7ae85987b99bd417e641ede718624c
---
gdb/make-target-delegates.py | 52 +++++++++++++++++++++++++-----------
1 file changed, 37 insertions(+), 15 deletions(-)
diff --git a/gdb/make-target-delegates.py b/gdb/make-target-delegates.py
index 2df84cd458c6..aa0919e51b13 100755
--- a/gdb/make-target-delegates.py
+++ b/gdb/make-target-delegates.py
@@ -92,6 +92,16 @@ ARGTYPES = re.compile(
TARGET_DEBUG_PRINTER = r"\s*TARGET_DEBUG_PRINTER\s*\((?P<arg>[^)]*)\)\s*"
+class Entry:
+ def __init__(
+ self, argtypes: list[str], return_type: str, style: str, default_arg: str
+ ):
+ self.argtypes = argtypes
+ self.return_type = return_type
+ self.style = style
+ self.default_arg = default_arg
+
+
def scan_target_h():
found_trigger = False
all_the_text = ""
@@ -295,10 +305,9 @@ def print_class(f, class_name, delegators, entries):
print("", file=f)
for name in delegators:
- return_type = entries[name]["return_type"]
- argtypes = entries[name]["argtypes"]
print(" ", file=f, end="")
- write_declaration(f, name, return_type, argtypes)
+ entry = entries[name]
+ write_declaration(f, name, entry.return_type, entry.argtypes)
print("};\n", file=f)
@@ -313,11 +322,14 @@ for current_line in scan_target_h():
if not m:
continue
data = m.groupdict()
- data["argtypes"] = parse_argtypes(data["args"])
- data["return_type"] = data["return_type"].strip()
- entries[data["name"]] = data
+ name = data["name"]
+ argtypes = parse_argtypes(data["args"])
+ return_type = data["return_type"].strip()
+ style = data["style"]
+ default_arg = data["default_arg"]
+ entries[name] = Entry(argtypes, return_type, style, default_arg)
- delegators.append(data["name"])
+ delegators.append(name)
with open("target-delegates.c", "w") as f:
print(
@@ -330,11 +342,21 @@ with open("target-delegates.c", "w") as f:
print_class(f, "debug_target", delegators, entries)
for name in delegators:
- tdefault = entries[name]["default_arg"]
- return_type = entries[name]["return_type"]
- style = entries[name]["style"]
- argtypes = entries[name]["argtypes"]
-
- write_delegator(f, name, return_type, argtypes)
- write_tdefault(f, tdefault, style, name, return_type, argtypes)
- write_debugmethod(f, tdefault, name, return_type, argtypes)
+ entry = entries[name]
+
+ write_delegator(f, name, entry.return_type, entry.argtypes)
+ write_tdefault(
+ f,
+ entry.default_arg,
+ entry.style,
+ name,
+ entry.return_type,
+ entry.argtypes,
+ )
+ write_debugmethod(
+ f,
+ entry.default_arg,
+ name,
+ entry.return_type,
+ entry.argtypes,
+ )
--
2.39.2
next prev parent reply other threads:[~2023-02-23 22:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 22:18 [PATCH 0/9] Add typing annotations to gdbarch*.py and make-target-delegates.py Simon Marchi
2023-02-23 22:18 ` [PATCH 1/9] gdb: remove invalid / dead code from gdbarch.py Simon Marchi
2023-02-23 22:18 ` [PATCH 2/9] gdb: reformat Python files with black 23.1.0 Simon Marchi
2023-02-23 22:18 ` [PATCH 3/9] gdb: gdbarch.py: spell out parameters of _Component.__init__ Simon Marchi
2023-02-24 19:51 ` Tom Tromey
2023-02-24 20:31 ` Simon Marchi
2023-02-24 22:07 ` Tom Tromey
2023-02-23 22:18 ` [PATCH 4/9] gdb: pyproject.toml: set pyright typeCheckingMode = "strict" Simon Marchi
2023-02-23 22:18 ` [PATCH 5/9] gdb: split gdbarch component types to gdbarch_types.py Simon Marchi
2023-02-23 22:18 ` [PATCH 6/9] gdb: gdbarch*.py, copyright.py: add type annotations Simon Marchi
2023-02-23 22:18 ` [PATCH 7/9] gdb: make-target-delegates.py: make one string raw Simon Marchi
2023-02-23 22:18 ` Simon Marchi [this message]
2023-02-23 22:18 ` [PATCH 9/9] gdb: make-target-delegates.py: add type annotations Simon Marchi
2023-02-24 19:54 ` [PATCH 0/9] Add typing annotations to gdbarch*.py and make-target-delegates.py Tom Tromey
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=20230223221830.499934-9-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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).