summaryrefslogtreecommitdiff
path: root/gdb/gdbarch_types.py
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2023-02-26 20:14:00 -0500
committerSimon Marchi <simon.marchi@efficios.com>2023-02-27 13:28:32 -0500
commit116e3492f2945d46db44d921f0b5eb03c58d5c93 (patch)
tree8c709212c7658170414c503b009a7991fae6d56a /gdb/gdbarch_types.py
parent05e4e893736c870ad5d2fd4e7ea8d95a94cdff3c (diff)
downloadbinutils-gdb-116e3492f2945d46db44d921f0b5eb03c58d5c93.tar.gz
gdb: gdbarch*.py, copyright.py: add type annotations
Add type annotations to gdbarch*.py to fix all errors shown by pyright. There is one change in copyright.py too, to fix this one: /home/simark/src/binutils-gdb/gdb/gdbarch.py /home/simark/src/binutils-gdb/gdb/gdbarch.py:206:13 - error: Type of "copyright" is partially unknown Type of "copyright" is "(tool: Unknown, description: Unknown) -> str" (reportUnknownMemberType) Change-Id: Ia109b53e267f6e2f5bd79a1288d0d5c9508c9ac4 Reviewed-By: Tom Tromey <tom@tromey.com> Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/gdbarch_types.py')
-rwxr-xr-xgdb/gdbarch_types.py85
1 files changed, 43 insertions, 42 deletions
diff --git a/gdb/gdbarch_types.py b/gdb/gdbarch_types.py
index 3a3cbbf8891..988da80dd7c 100755
--- a/gdb/gdbarch_types.py
+++ b/gdb/gdbarch_types.py
@@ -17,8 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from typing import List, Optional, Tuple, Union
-def join_type_and_name(t, n):
+
+def join_type_and_name(t: str, n: str):
"Combine the type T and the name N into a C declaration."
if t.endswith("*") or t.endswith("&"):
return t + n
@@ -26,30 +28,29 @@ def join_type_and_name(t, n):
return t + " " + n
-def join_params(params):
+def join_params(params: List[Tuple[str, str]]):
"""Given a sequence of (TYPE, NAME) pairs, generate a comma-separated
list of declarations."""
- params = [join_type_and_name(p[0], p[1]) for p in params]
- return ", ".join(params)
+ return ", ".join([join_type_and_name(p[0], p[1]) for p in params])
-class _Component:
+class Component:
"Base class for all components."
def __init__(
self,
- name,
- type,
- printer=None,
- comment=None,
- predicate=False,
- predefault=None,
- postdefault=None,
- invalid=None,
- params=None,
- param_checks=None,
- result_checks=None,
- implement=True,
+ name: str,
+ type: str,
+ printer: Optional[str] = None,
+ comment: Optional[str] = None,
+ predicate: bool = False,
+ predefault: Optional[str] = None,
+ postdefault: Optional[str] = None,
+ invalid: Optional[Union[bool, str]] = None,
+ params: Optional[List[Tuple[str, str]]] = None,
+ param_checks: Optional[List[str]] = None,
+ result_checks: Optional[List[str]] = None,
+ implement: bool = True,
):
self.name = name
self.type = type
@@ -59,7 +60,7 @@ class _Component:
self.predefault = predefault
self.postdefault = postdefault
self.invalid = invalid
- self.params = params
+ self.params = params or []
self.param_checks = param_checks
self.result_checks = result_checks
self.implement = implement
@@ -81,24 +82,24 @@ class _Component:
return predicate
-class Info(_Component):
+class Info(Component):
"An Info component is copied from the gdbarch_info."
-class Value(_Component):
+class Value(Component):
"A Value component is just a data member."
def __init__(
self,
*,
- name,
- type,
- comment=None,
- predicate=False,
- predefault=None,
- postdefault=None,
- invalid=None,
- printer=None,
+ name: str,
+ type: str,
+ comment: Optional[str] = None,
+ predicate: bool = False,
+ predefault: Optional[str] = None,
+ postdefault: Optional[str] = None,
+ invalid: Optional[Union[bool, str]] = None,
+ printer: Optional[str] = None,
):
super().__init__(
comment=comment,
@@ -112,24 +113,24 @@ class Value(_Component):
)
-class Function(_Component):
+class Function(Component):
"A Function component is a function pointer member."
def __init__(
self,
*,
- name,
- type,
- params,
- comment=None,
- predicate=False,
- predefault=None,
- postdefault=None,
- invalid=None,
- printer=None,
- param_checks=None,
- result_checks=None,
- implement=True,
+ name: str,
+ type: str,
+ params: List[Tuple[str, str]],
+ comment: Optional[str] = None,
+ predicate: bool = False,
+ predefault: Optional[str] = None,
+ postdefault: Optional[str] = None,
+ invalid: Optional[Union[bool, str]] = None,
+ printer: Optional[str] = None,
+ param_checks: Optional[List[str]] = None,
+ result_checks: Optional[List[str]] = None,
+ implement: bool = True,
):
super().__init__(
comment=comment,
@@ -180,4 +181,4 @@ class Method(Function):
# All the components created in gdbarch-components.py.
-components = []
+components: List[Component] = []