public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: make-target-delegates.py: add Entry type
@ 2023-02-27 18:29 Simon Marchi
  0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2023-02-27 18:29 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c6cf3ced973b8fea7d45c0f751cf9724a6a6e5b7

commit c6cf3ced973b8fea7d45c0f751cf9724a6a6e5b7
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Sun Feb 26 20:14:02 2023 -0500

    gdb: make-target-delegates.py: add Entry type
    
    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
    Reviewed-By: Tom Tromey <tom@tromey.com>
    Reviewed-By: Andrew Burgess <aburgess@redhat.com>

Diff:
---
 gdb/make-target-delegates.py | 55 +++++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/gdb/make-target-delegates.py b/gdb/make-target-delegates.py
index 2df84cd458c..1e2e741bc32 100755
--- a/gdb/make-target-delegates.py
+++ b/gdb/make-target-delegates.py
@@ -21,8 +21,9 @@
 #    make-target-delegates.py
 
 import re
-import gdbcopyright
+from typing import List
 
+import gdbcopyright
 
 # The line we search for in target.h that marks where we should start
 # looking for methods.
@@ -92,6 +93,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 +306,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 +323,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 +343,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,
+        )

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-27 18:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 18:29 [binutils-gdb] gdb: make-target-delegates.py: add Entry type Simon Marchi

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).