From 10185c2a562eb40582635c5803ab1c5e31891c76 Mon Sep 17 00:00:00 2001 From: Nicholas Robinson <nwrobins@edu.uwaterloo.ca> Date: Fri, 28 Feb 2020 20:28:09 -0500 Subject: [PATCH] hierarchy acyclic fixes & Test.py fixes - added package name to hierarchy - made sure hierarchy was appended correctly in recursion - fixed Test.py to test single files, and to produce total result --- CompNode.py | 4 ++-- Test.py | 27 ++++++++++++++++++++------- TypeNodes.py | 19 +++++++++++-------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/CompNode.py b/CompNode.py index 738e743..37faddf 100644 --- a/CompNode.py +++ b/CompNode.py @@ -26,9 +26,9 @@ class CompNode(ASTNode): typeNode = getParseTreeNodes('classDcl', node) if not typeNode: typeNode = getParseTreeNodes('interfaceDcl', node) - self.typeDcl = InterNode(typeNode[0]) + self.typeDcl = InterNode(typeNode[0], self.packageName) else: - self.typeDcl = ClassNode(typeNode[0]) + self.typeDcl = ClassNode(typeNode[0], self.packageName) # always populate the children list self.children.append(self.typeDcl) diff --git a/Test.py b/Test.py index 18fd00a..7a52152 100644 --- a/Test.py +++ b/Test.py @@ -38,29 +38,42 @@ def a2Multiple(): # All files in the test directory testDirectory = "./Tests/A2/" testCases = [f.path for f in scandir(testDirectory) if f.is_dir()] + testCases += [f.path for f in scandir(testDirectory) if not f.is_dir()] + + total = 0 + correct = 0 for c in testCases: - # print("**********************************************************") - # print("DIRECTORY") - # print(c) - # print("**********************************************************") # get all files from stdlib folder testFiles = [join(dp, f) for dp, dn, filenames in walk('stdlib/2.0/java/') for f in filenames] - # get all files in the folder recursively - testFiles += [join(dp, f) for dp, dn, filenames in walk(c) for f in filenames] + + if '.java' in c: + # add this one file + testFiles.append(c) + else: + # get all files in the folder recursively + testFiles += [join(dp, f) for dp, dn, filenames in walk(c) for f in filenames] + ret = run(testFiles) + total += 1 + if ret == "": # print(c) if 'Je_' in c: print(c) print("JE Passed without error") print("**********************************************************") + else: + correct += 1 else: if not 'Je_' in c: print(c) print(ret) print("**********************************************************") - # print("\n \n\n ") + else: + correct += 1 + + print("\nSCORE: {} / {} -> {}%".format(correct, total, (correct/total)*100)) diff --git a/TypeNodes.py b/TypeNodes.py index 05bb041..ad3ab35 100644 --- a/TypeNodes.py +++ b/TypeNodes.py @@ -31,15 +31,15 @@ class ClassInterNode(ASTNode): def getContains(self, hierarchy): # check if not acyclic - if self.name in hierarchy: - raise Exception("ERROR: The hierarchy is not acyclic '{}', saw '{}'".format(hierarchy, self.name)) - hierarchy.append(self.name) + canonName = self.packageName + '.' + self.name + if canonName in hierarchy: + raise Exception("ERROR: The hierarchy is not acyclic '{}', saw '{}'".format(hierarchy, canonName)) # get contains contains = self.methods for inter in self.superInter: - superContains = inter.getContains(hierarchy) + superContains = inter.getContains(hierarchy + [canonName]) for con in superContains: conOverwritten = False for method in self.methods: @@ -54,14 +54,15 @@ class ClassInterNode(ASTNode): break if not conOverwritten: contains.append(con) - + return contains # class class ClassNode(ClassInterNode): # always list all fields in the init method to show the class structure - def __init__(self, parseTree): + def __init__(self, parseTree, packageName): self.parseTree = parseTree + self.packageName = packageName self.name = '' self.fields = [] self.methods = [] @@ -163,11 +164,12 @@ class ClassNode(ClassInterNode): def getContains(self, hierarchy): # centralized logic contains = super().getContains(hierarchy) + canonName = self.packageName + '.' + self.name # get contains from extends class if self.superClass: addToContains = [] - superContains = self.superClass.getContains(hierarchy) + superContains = self.superClass.getContains(hierarchy + [canonName]) for con in superContains: conOverwritten = False for method in contains: @@ -200,8 +202,9 @@ class ClassNode(ClassInterNode): # interface class InterNode(ClassInterNode): # always list all fields in the init method to show the class structure - def __init__(self, parseTree): + def __init__(self, parseTree, packageName): self.parseTree = parseTree + self.packageName = packageName self.name = '' self.methods = [] self.superInter = [] # list of strings of extendInterface's name, then stores a pointer to the node after type linking -- GitLab