diff --git a/utils/metrics.py b/utils/metrics.py index 5ac2f57..a493558 100644 --- a/utils/metrics.py +++ b/utils/metrics.py @@ -3,34 +3,45 @@ from parser.ast import VarExpr, NotExpr, ParenExpr, AndExpr, OrExpr from parser.visitor import Visitor + class OpCounter(Visitor): - def __init__(self) -> None: + _count = 0 + + def __init__(self): self._count: int = 0 @override def visitVarExpr(self, vex: VarExpr) -> None: - OpCounter._count += 1 + vex.first.accept(self) + if vex.second: + vex.second.accept(self) @override def visitNotExpr(self, nex: NotExpr) -> None: - OpCounter._count += 1 + self.updateCount() + nex.first.accept(self) @override def visitParenExpr(self, pex: ParenExpr) -> None: - OpCounter._count += 1 + pex.first.accept(self) @override def visitAndExpr(self, aex: AndExpr) -> None: - OpCounter._count += 1 + self.updateCount() + aex.first.accept(self) @override def visitOrExpr(self, oex: OrExpr) -> None: - OpCounter._count += 1 + self.updateCount() + oex.first.accept(self) @override def visitVar(self, _) -> None: - OpCounter._count += 1 + pass + + def updateCount(self) -> None: + self._count += 1 def getCount(self) -> None: return self._count