From ef72f207533fe0e9d972fbac1438e0e485be395e Mon Sep 17 00:00:00 2001 From: Aryaz Eghbali Date: Sat, 9 Sep 2023 16:34:28 +0200 Subject: [PATCH] Fixed solution analyses --- tutorial/solution-analyses/CallGraphAnalysis.py | 12 +----------- .../solution-analyses/SlowStringConcatAnalysis.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tutorial/solution-analyses/CallGraphAnalysis.py b/tutorial/solution-analyses/CallGraphAnalysis.py index ce0f320..4bea315 100644 --- a/tutorial/solution-analyses/CallGraphAnalysis.py +++ b/tutorial/solution-analyses/CallGraphAnalysis.py @@ -75,14 +75,4 @@ def end_execution(self): DynaPyt hook for end of execution """ # to avoid serialization failures in converting dict to json - try: - logging.info(json.dumps(self.graph)) - except Exception: - logging.info("{") - for idx, key in enumerate(self.graph): - values = ['"{}"'.format(x) for x in self.graph[key]] - if not idx == (len(self.graph.keys()) - 1): - logging.info('"{}" : {}, '.format(key, values)) - else: - logging.info('"{}" : {}'.format(key, values)) - logging.info("}") + print(self.graph) diff --git a/tutorial/solution-analyses/SlowStringConcatAnalysis.py b/tutorial/solution-analyses/SlowStringConcatAnalysis.py index 9b6c9e1..dcd9d56 100644 --- a/tutorial/solution-analyses/SlowStringConcatAnalysis.py +++ b/tutorial/solution-analyses/SlowStringConcatAnalysis.py @@ -10,8 +10,15 @@ def __init__(self): self.threshold = 5 def enter_for(self, dyn_ast: str, iid: int, next_value, iterable: Iterable): - self.in_loop.append((dyn_ast, iid)) - self.concat_count.append(0) + if ( + self.in_loop + and self.in_loop[-1][0] == dyn_ast + and self.in_loop[-1][1] == iid + ): + pass + else: + self.in_loop.append((dyn_ast, iid)) + self.concat_count.append(0) def exit_for(self, dyn_ast: str, iid: int): curr = self.in_loop.pop() @@ -21,7 +28,7 @@ def exit_for(self, dyn_ast: str, iid: int): def add_assign(self, dyn_ast: str, iid: int, lhs, rhs): if self.in_loop: - if isinstance(lhs, str) and isinstance(rhs, str): + if isinstance(rhs, str): self.concat_count[-1] += 1 if self.concat_count[-1] >= self.threshold: print(f"Possible slow string concatenation in {dyn_ast} at {iid}")