From 19eb00f4e107110445c062df8870b70bc431114c Mon Sep 17 00:00:00 2001 From: pycsham <shampuiyanchloe@gmail.com> Date: Thu, 12 Mar 2020 20:02:31 -0400 Subject: [PATCH] Fixed remaining definitve assignemnt issues. Passing 80% on local --- AST.py | 1 + LineNodes.py | 9 +++++++-- Test.py | 13 +++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/AST.py b/AST.py index fbb2702..0793590 100644 --- a/AST.py +++ b/AST.py @@ -136,6 +136,7 @@ def getParseTreeNodes(names, tree, terminateList = []): result.extend(getParseTreeNodes(names, n, terminateList)) return result +# Getting a list of nodes with the provided list of names of the nodes def getASTNode(names, AST): result = [] if not AST: diff --git a/LineNodes.py b/LineNodes.py index ca29384..86464f9 100644 --- a/LineNodes.py +++ b/LineNodes.py @@ -1,4 +1,4 @@ -from AST import ASTNode, getParseTreeNodes +from AST import ASTNode, getParseTreeNodes, getASTNode from Environment import Env from ExprPrimaryNodes import makeNodeFromExpr, makeNodeFromAllPrimary, MethodInvNode, ClassCreateNode from TheTypeNode import TypeNode, TypeStruct @@ -113,7 +113,12 @@ class VarDclNode(ASTNode): # Checking for definite assignment if checkAssign: if not self.variableInit: - raise Exception("ERROR: local variable declaration not assigned") + raise Exception("ERROR: local variable declaration {} is not assigned".format(self.name)) + # Checking if the local variable appears in it's own intializer + nameNodes = getASTNode(["NameNode"], self.variableInit) + for node in nameNodes: + if self.name in node.IDs: + raise Exception("ERROR: local variable {} appears in it's own intialization".format(self.name)) self.myType = self.dclType.myType self.children.append(self.dclType) diff --git a/Test.py b/Test.py index e0dcfd6..34940af 100644 --- a/Test.py +++ b/Test.py @@ -134,7 +134,7 @@ def run(testFiles): parseTrees.append((f, tree)) # for (n, t) in parseTrees: - # if n == "Tests/A3/J1_accessstaticfield/Main.java": + # if n == "./Tests/A4/Je_8_DefiniteAssignment_InitToItself.java": # print(n) # print(t) try: @@ -142,11 +142,12 @@ def run(testFiles): except Exception as e: return "AST buidling: " + e.args[0] - # for (n, t) in ASTs: - # print(n) - # print("--------------------") - # t.printTree() - # print("\n \n\n \n") + for (n, t) in ASTs: + if n == "./Tests/A4/Je_8_DefiniteAssignment_ComplexInitializer.java": + print(n) + print("--------------------") + t.printTree() + print("\n \n\n \n") try: buildEnvAndLink(ASTs) -- GitLab