From: Dmitry Selyutin Date: Tue, 19 Apr 2022 22:25:10 +0000 (+0000) Subject: sv_binutils: inherit metaclasses correctly X-Git-Tag: sv_maxu_works-initial~485 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8bcb6a19923a324f6a59c6da674a88e11675ebfa;p=openpower-isa.git sv_binutils: inherit metaclasses correctly --- diff --git a/src/openpower/sv/sv_binutils.py b/src/openpower/sv/sv_binutils.py index faadbbd3..3f3692ea 100644 --- a/src/openpower/sv/sv_binutils.py +++ b/src/openpower/sv/sv_binutils.py @@ -32,23 +32,23 @@ def indent(strings): return map(lambda string: (" " + string), strings) -class CType: - @classmethod +class CTypeMeta(type): @_abc.abstractmethod - def c_decl(cls, name): + def c_decl(cls): pass @_abc.abstractmethod - def c_value(self, prefix="", suffix=""): + def c_var(cls, name): pass - @classmethod + +class CType(metaclass=CTypeMeta): @_abc.abstractmethod - def c_var(cls, name): + def c_value(self, prefix="", suffix=""): pass -class EnumMeta(_enum.EnumMeta): +class EnumMeta(_enum.EnumMeta, CTypeMeta): def __call__(metacls, name, entries, tag=None, **kwargs): if isinstance(entries, type) and issubclass(entries, _enum.Enum): entries = dict(entries.__members__) @@ -109,7 +109,7 @@ class Constant(CType, _enum.Enum, metaclass=EnumMeta): Mode = Constant("Mode", _SVP64MODE) -class StructMeta(type): +class StructMeta(CTypeMeta): def __new__(metacls, name, bases, attrs, tag=None): if tag is None: tag = f"svp64_{name.lower()}" @@ -134,7 +134,7 @@ class StructMeta(type): @_dataclasses.dataclass(eq=True, frozen=True) -class Struct(metaclass=StructMeta): +class Struct(CType, metaclass=StructMeta): def c_value(self, prefix="", suffix=""): yield f"{prefix}{{" for field in _dataclasses.fields(self):