From 6877880e219c06c005d126015039320b3032da5b Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Sat, 3 Jun 2023 13:41:42 +0300 Subject: [PATCH] insndb/db: refactor classes hierarchy --- src/openpower/insndb/db.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/openpower/insndb/db.py b/src/openpower/insndb/db.py index c66a07e7..d59595b4 100644 --- a/src/openpower/insndb/db.py +++ b/src/openpower/insndb/db.py @@ -11,31 +11,39 @@ from openpower.insndb.core import ( ) -class GenericVisitor(Visitor): +class BaseVisitor(Visitor): def __init__(self, **_): pass -class ListVisitor(GenericVisitor): +class ListVisitor(BaseVisitor): @contextlib.contextmanager def record(self, record): print(record.name) yield record -class OpcodesVisitor(GenericVisitor): +class ConcreteInstructionVisitor(BaseVisitor): def __init__(self, insn, **_): self.__insn = insn return super().__init__() + def handler(self, record): + raise NotImplementedError + @contextlib.contextmanager def record(self, record): if record.name == self.__insn: - for opcode in record.opcodes: - print(opcode) + self.handler(record=record) yield record +class OpcodesVisitor(ConcreteInstructionVisitor): + def handler(self, record): + for opcode in record.opcodes: + print(opcode) + + def main(): visitors = { "list": ListVisitor, -- 2.30.2