From: Dmitry Selyutin Date: Sat, 10 Jun 2023 19:32:52 +0000 (+0300) Subject: insndb/core: introduce Dict class X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b89e3e2f6693418758cbc82895dacef56eb89328;p=openpower-isa.git insndb/core: introduce Dict class --- diff --git a/src/openpower/insndb/core.py b/src/openpower/insndb/core.py index 23e68e39..7ec4788f 100644 --- a/src/openpower/insndb/core.py +++ b/src/openpower/insndb/core.py @@ -119,6 +119,24 @@ class Tuple(Node, tuple): yield (str(index), item) +class Dict(Node, dict): + def __init_subclass__(cls, datatype): + cls.__datatype = datatype + return super().__init_subclass__() + + @walkmethod + def walk(clsself, match=None): + if match is None: + match = lambda subnode: True + + if isinstance(clsself, type): + yield ("{}", clsself.__datatype) + else: + for (key, value) in clsself.items(): + if match(value): + yield (key, value) + + class VisitorMethod: def __init__(self, nodecls, method): self.__nodecls = nodecls diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index 291e1a61..c7788f8a 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -9,6 +9,7 @@ from openpower.decoder.power_enums import ( from openpower.insndb.core import ( Database, Dataclass, + Dict, Record, Records, Tuple, @@ -52,7 +53,7 @@ class TreeVisitor(Visitor): with super().__call__(path=path, node=node): self.__path.append(path) print("/".join(self.__path)) - if not isinstance(node, (Dataclass, Tuple)): + if not isinstance(node, (Dataclass, Tuple, Dict)): print(" ", repr(node), sep="") self.__depth += 1 yield node