Skip to content
Snippets Groups Projects
Commit 10185c2a authored by Nicholas Robinson's avatar Nicholas Robinson
Browse files

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
parent 078bc3da
No related branches found
No related tags found
No related merge requests found
...@@ -26,9 +26,9 @@ class CompNode(ASTNode): ...@@ -26,9 +26,9 @@ class CompNode(ASTNode):
typeNode = getParseTreeNodes('classDcl', node) typeNode = getParseTreeNodes('classDcl', node)
if not typeNode: if not typeNode:
typeNode = getParseTreeNodes('interfaceDcl', node) typeNode = getParseTreeNodes('interfaceDcl', node)
self.typeDcl = InterNode(typeNode[0]) self.typeDcl = InterNode(typeNode[0], self.packageName)
else: else:
self.typeDcl = ClassNode(typeNode[0]) self.typeDcl = ClassNode(typeNode[0], self.packageName)
# always populate the children list # always populate the children list
self.children.append(self.typeDcl) self.children.append(self.typeDcl)
......
...@@ -38,29 +38,42 @@ def a2Multiple(): ...@@ -38,29 +38,42 @@ def a2Multiple():
# All files in the test directory # All files in the test directory
testDirectory = "./Tests/A2/" testDirectory = "./Tests/A2/"
testCases = [f.path for f in scandir(testDirectory) if f.is_dir()] 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: for c in testCases:
# print("**********************************************************")
# print("DIRECTORY")
# print(c)
# print("**********************************************************")
# get all files from stdlib folder # get all files from stdlib folder
testFiles = [join(dp, f) for dp, dn, filenames in walk('stdlib/2.0/java/') for f in filenames] 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) ret = run(testFiles)
total += 1
if ret == "": if ret == "":
# print(c) # print(c)
if 'Je_' in c: if 'Je_' in c:
print(c) print(c)
print("JE Passed without error") print("JE Passed without error")
print("**********************************************************") print("**********************************************************")
else:
correct += 1
else: else:
if not 'Je_' in c: if not 'Je_' in c:
print(c) print(c)
print(ret) print(ret)
print("**********************************************************") print("**********************************************************")
# print("\n \n\n ") else:
correct += 1
print("\nSCORE: {} / {} -> {}%".format(correct, total, (correct/total)*100))
......
...@@ -31,15 +31,15 @@ class ClassInterNode(ASTNode): ...@@ -31,15 +31,15 @@ class ClassInterNode(ASTNode):
def getContains(self, hierarchy): def getContains(self, hierarchy):
# check if not acyclic # check if not acyclic
if self.name in hierarchy: canonName = self.packageName + '.' + self.name
raise Exception("ERROR: The hierarchy is not acyclic '{}', saw '{}'".format(hierarchy, self.name)) if canonName in hierarchy:
hierarchy.append(self.name) raise Exception("ERROR: The hierarchy is not acyclic '{}', saw '{}'".format(hierarchy, canonName))
# get contains # get contains
contains = self.methods contains = self.methods
for inter in self.superInter: for inter in self.superInter:
superContains = inter.getContains(hierarchy) superContains = inter.getContains(hierarchy + [canonName])
for con in superContains: for con in superContains:
conOverwritten = False conOverwritten = False
for method in self.methods: for method in self.methods:
...@@ -54,14 +54,15 @@ class ClassInterNode(ASTNode): ...@@ -54,14 +54,15 @@ class ClassInterNode(ASTNode):
break break
if not conOverwritten: if not conOverwritten:
contains.append(con) contains.append(con)
return contains return contains
# class # class
class ClassNode(ClassInterNode): class ClassNode(ClassInterNode):
# always list all fields in the init method to show the class structure # 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.parseTree = parseTree
self.packageName = packageName
self.name = '' self.name = ''
self.fields = [] self.fields = []
self.methods = [] self.methods = []
...@@ -163,11 +164,12 @@ class ClassNode(ClassInterNode): ...@@ -163,11 +164,12 @@ class ClassNode(ClassInterNode):
def getContains(self, hierarchy): def getContains(self, hierarchy):
# centralized logic # centralized logic
contains = super().getContains(hierarchy) contains = super().getContains(hierarchy)
canonName = self.packageName + '.' + self.name
# get contains from extends class # get contains from extends class
if self.superClass: if self.superClass:
addToContains = [] addToContains = []
superContains = self.superClass.getContains(hierarchy) superContains = self.superClass.getContains(hierarchy + [canonName])
for con in superContains: for con in superContains:
conOverwritten = False conOverwritten = False
for method in contains: for method in contains:
...@@ -200,8 +202,9 @@ class ClassNode(ClassInterNode): ...@@ -200,8 +202,9 @@ class ClassNode(ClassInterNode):
# interface # interface
class InterNode(ClassInterNode): class InterNode(ClassInterNode):
# always list all fields in the init method to show the class structure # 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.parseTree = parseTree
self.packageName = packageName
self.name = '' self.name = ''
self.methods = [] self.methods = []
self.superInter = [] # list of strings of extendInterface's name, then stores a pointer to the node after type linking self.superInter = [] # list of strings of extendInterface's name, then stores a pointer to the node after type linking
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment