Skip to content

Commit

Permalink
Fixed issue with instrumentations of in and is
Browse files Browse the repository at this point in the history
  • Loading branch information
AryazE committed Mar 5, 2024
1 parent 055933a commit 5b98c59
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/dynapyt/utils/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
from .runtimeUtils import load_analyses


def get_name(s):
if (s in dir(builtins)) or (keyword.iskeyword(s)):
return "_" + s
return s


def snake(x):
res = ""
for i in range(len(x) - 1):
res += x[i]
if ("a" <= x[i] <= "z") and ("A" <= x[i + 1] <= "Z"):
res += "_"
res += x[-1]
return res.lower()


def get_name(s):
if (s in dir(builtins)) or (keyword.iskeyword(s)):
return "_" + s
return s
return get_name(res.lower())


def all_leaves(root):
Expand Down
12 changes: 12 additions & 0 deletions tests/trace_single_hook/comparison/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dynapyt.analyses.BaseAnalysis import BaseAnalysis


class TestAnalysis(BaseAnalysis):
def begin_execution(self):
print("begin execution")

def end_execution(self):
print("end execution")

def comparison(self, dyn_ast, iid, left, op, right, result):
print(f"Comparing {left} {op} {right} = {result}")
5 changes: 5 additions & 0 deletions tests/trace_single_hook/comparison/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
begin execution
Comparing 10 Is 10 = True
Comparing 10 In [1, 10, 100] = True
Comparing 10 NotIn [1, 2, 3] = True
end execution
7 changes: 7 additions & 0 deletions tests/trace_single_hook/comparison/program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
a = 10
b = 10
a is b
c = [1, 10, 100]
a in c
d = [1, 2, 3]
b not in d

0 comments on commit 5b98c59

Please sign in to comment.