Skip to content

Commit

Permalink
Mark abstract and non-abstract Handle types
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbarrett committed Sep 24, 2021
1 parent b56d887 commit edc8e3c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion cocotb/handle.py
Expand Up @@ -32,6 +32,7 @@
import ctypes
import warnings
import enum
from abc import ABC, abstractmethod
from functools import lru_cache
from typing import Optional

Expand Down Expand Up @@ -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.
Expand All @@ -84,6 +85,7 @@ class SimHandleBase:
"name" : "_name",
}

@abstractmethod
def __init__(self, handle, path):
"""
.. Constructor. This RST comment works around sphinx-doc/sphinx#6885
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(())

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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*.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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*.
Expand Down Expand Up @@ -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*.
Expand Down Expand Up @@ -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*.
Expand Down

0 comments on commit edc8e3c

Please sign in to comment.