From edc8e3cb84c0cdd81edda4cbad3543ad9dc09b31 Mon Sep 17 00:00:00 2001 From: Kaleb Barrett Date: Sun, 5 Sep 2021 09:15:41 -0500 Subject: [PATCH] Mark abstract and non-abstract Handle types --- cocotb/handle.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/cocotb/handle.py b/cocotb/handle.py index 81ad0db210..659a00032f 100755 --- a/cocotb/handle.py +++ b/cocotb/handle.py @@ -32,6 +32,7 @@ import ctypes import warnings import enum +from abc import ABC, abstractmethod from functools import lru_cache from typing import Optional @@ -68,7 +69,7 @@ def _value_limits(n_bits, limits): return min_val, max_val -class SimHandleBase: +class SimHandleBase(ABC): """Base class for all simulation objects. We maintain a handle which we can use for GPI calls. @@ -84,6 +85,7 @@ class SimHandleBase: "name" : "_name", } + @abstractmethod def __init__(self, handle, path): """ .. Constructor. This RST comment works around sphinx-doc/sphinx#6885 @@ -213,6 +215,7 @@ class RegionObject(SimHandleBase): Region objects don't have values, they are effectively scopes or namespaces. """ + @abstractmethod def __init__(self, handle, path): SimHandleBase.__init__(self, handle, path) self._discovered = False # True if this object has already been discovered @@ -280,6 +283,9 @@ def __dir__(self): class HierarchyObject(RegionObject): """Hierarchy objects are namespace/scope objects.""" + def __init__(self, handle, path): + super().__init__(handle, path) + def __get_sub_handle_by_name(self, name): try: return self._sub_handles[name] @@ -368,6 +374,9 @@ def _id(self, name, extended: bool = True): class HierarchyArrayObject(RegionObject): """Hierarchy Arrays are containers of Hierarchy Objects.""" + def __init__(self, handle, path): + super().__init__(handle, path) + def _sub_handle_key(self, name): """Translate the handle name to a key to use in :any:`_sub_handles` dictionary.""" # This is slightly hacky, but we need to extract the index from the name @@ -439,6 +448,10 @@ def __bool__(self): class NonHierarchyObject(SimHandleBase): """Common base class for all non-hierarchy objects.""" + @abstractmethod + def __init__(self, handle, path): + super().__init__(handle, path) + def __iter__(self): return iter(()) @@ -661,6 +674,7 @@ def _as_gpi_args_for(self, hdl): class ModifiableObject(NonHierarchyObject): """Base class for simulator objects whose values can be modified.""" + @abstractmethod def __init__(self, handle, path): super().__init__(handle, path) self._range = self._handle.get_range() @@ -745,6 +759,9 @@ def __str__(self): class LogicObject(ModifiableObject): """Specific object handle for Verilog nets and regs and VHDL std_logic and std_logic_vectors""" + def __init__(self, handle, path): + super().__init__(handle, path) + def _set_value(self, value, call_sim): """Set the value of the underlying simulation object to *value*. @@ -842,6 +859,9 @@ def __int__(self): class RealObject(ModifiableObject): """Specific object handle for Real signals and variables.""" + def __init__(self, handle, path): + super().__init__(handle, path) + def _set_value(self, value, call_sim): """Set the value of the underlying simulation object to value. @@ -898,6 +918,9 @@ def __setitem__(self, item): class EnumObject(ModifiableObject): """Specific object handle for enumeration signals and variables.""" + def __init__(self, handle, path): + super().__init__(handle, path) + def _set_value(self, value, call_sim): """Set the value of the underlying simulation object to *value*. @@ -957,6 +980,9 @@ def __setitem__(self, item): class IntegerObject(ModifiableObject): """Specific object handle for integer and enumeration signals and variables.""" + def __init__(self, handle, path): + super().__init__(handle, path) + def _set_value(self, value, call_sim): """Set the value of the underlying simulation object to *value*. @@ -1019,6 +1045,9 @@ def __setitem__(self, item): class StringObject(ModifiableObject): """Specific object handle for String variables.""" + def __init__(self, handle, path): + super().__init__(handle, path) + def _set_value(self, value, call_sim): """Set the value of the underlying simulation object to *value*.