insndb/db: refactor classes hierarchy
authorDmitry Selyutin <ghostmansd@gmail.com>
Sat, 3 Jun 2023 10:41:42 +0000 (13:41 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 22 Dec 2023 19:26:19 +0000 (19:26 +0000)
src/openpower/insndb/db.py

index c66a07e77f87734b360444dba5f030d6cc9765f0..d59595b447082792aa6ab188a4d6e87f569f092c 100644 (file)
@@ -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,