Skip to content

Commit

Permalink
fix: counter now counts correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
micah-0w0 authored Jul 18, 2024
1 parent 9c4b884 commit b114050
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b114050

Please sign in to comment.