Skip to content
Snippets Groups Projects
Commit eae4a5e3 authored by pycsham's avatar pycsham
Browse files

fixed paramNode bug. still working on bug for disambig called twice

parent c014e22b
No related branches found
No related tags found
1 merge request!5Name disambig
......@@ -51,10 +51,11 @@ def disamiguateAndTypeChecking(ASTs):
# disambiguate namesapce: figuring out the meaning of the shortest prefix of names
for t in ASTs:
try:
t[1].recurseAction("disambigName")
except Exception as e:
raise e
# try:
# t[1].recurseAction("disambigName")
# except Exception as e:
# raise e
t[1].recurseAction("disambigName")
# type checking
......
......@@ -6,7 +6,8 @@ class Env:
'InterNode': 'type',
'ClassNode': 'type',
'MethodNode': 'method',
'VarDclNode': 'expr'
'VarDclNode': 'expr',
'ParamNode': 'expr'
})
......
......@@ -29,7 +29,7 @@ def makeNodeFromExpr(parseTree, typeName):
if c.name == 'primaryAndArray':
return makeNodeFromAllPrimary(c, typeName)
elif c.name == 'ID' or c.name == 'COMPID':
return NameNode(c, typeName, False)
return NameNode(c, typeName, typeName)
elif c.name == 'assignment':
return AssignNode(c, typeName)
elif len(c.children) == 1:
......@@ -73,7 +73,7 @@ def makeNodeFromAllPrimary(parseTree, typeName):
# helper methods
###########################################################
def helperDisambigName(node):
if node and node.__class.__name__ == "NameNode":
if node and node.__class__.__name__ == "NameNode":
try:
node.disambigName()
except Exception as e:
......
......@@ -27,6 +27,7 @@ class NameNode(ASTNode):
self.methodInvoke = methodInvoke # Bool: true if the last ID in the name is a method invokation
self.env = None
self.typeName = typeName # the name of the class or interface that this node belongs under
self.children = []
self.name = getParseTreeNodes(["ID", "COMPID"], parseTree)[0].lex
......@@ -59,16 +60,18 @@ class NameNode(ASTNode):
return True
return False
# Checks and updates prefix if the next ID in self.IDs is a local variable
# Checks and updates prefix if the next ID in self.IDs is a local variable or a parameter
def checkLocalVar(self):
if not self.IDs:
return True
print("checking local variable")
print(self.IDs)
ID = self.IDs[0]
localVarNode = self.env.findNode(ID, "expr")
if localVarNode:
self.addToPrefix(localVarNode)
return True
return False
# Checks and updates prefix if the next ID in self.IDs is in the contains set
......@@ -76,6 +79,8 @@ class NameNode(ASTNode):
def checkContains(self, update=False):
if not self.IDs:
return True
print("checking contains set")
print(self.IDs)
ID = self.IDs[0]
if self.env.findNode(ID, "fieldDcl") or self.env.findNode(ID, "method"):
......@@ -88,14 +93,14 @@ class NameNode(ASTNode):
def checkStatic(self):
if not self.IDs:
return True
currPrefix = ""
for index, ID in enumerate(self.IDs):
if currPrefix:
currPrefix += "."
currPrefix += ID
typeNode = self.env.getNode(currPrefix)
typeNode = self.env.getNode(currPrefix, "type")
if typeNode:
# checking if the next ID is a static field in the class/interface
......@@ -131,6 +136,8 @@ class NameNode(ASTNode):
# Checking if a1 is a local variable
if self.checkLocalVar():
print("local variable check is true")
print(self.IDs)
return
# TODO: Checking if a1 is in the contains set
......
......@@ -5,7 +5,7 @@ import traceback
from Scanning import scan
from Parsing import parse
from AstBuilding import astBuild, buildEnvAndLink
from AstBuilding import astBuild, buildEnvAndLink, disamiguateAndTypeChecking
import Weeding
......@@ -82,7 +82,7 @@ def run(testFiles):
parseTrees = []
for f in testFiles:
# print(f)
print(f)
if f.split("/")[-1] == ".DS_Store":
continue
content = open(f, "r").read()
......@@ -146,10 +146,10 @@ def run(testFiles):
ASTs = astBuild(parseTrees)
# for (n, t) in ASTs:
# print(n)
# print("--------------------")
# t.printTree()
# print("\n \n\n \n")
# print(n)
# print("--------------------")
# t.printTree()
# print("\n \n\n \n")
try:
buildEnvAndLink(ASTs)
......@@ -160,16 +160,17 @@ def run(testFiles):
return "buildEnvAndLink: " + e.args[0]
# print("<<<<------- after buildEnvAndLink -------->>>>>>")
# for (n, t) in ASTs:
# print(n)
# print("--------------------")
# t.printTree()
# print("\n \n\n \n")
for (n, t) in ASTs:
print(n)
print("--------------------")
t.printTree()
print("\n \n\n \n")
try:
disamiguateAndTypeChecking(ASTs)
except Exception as e:
return "Disambiguate and Type checking: " + e.args[0]
# try:
# disamiguateAndTypeChecking(ASTs)
# except Exception as e:
# return "Disambiguate and Type checking: " + e.args[0]
disamiguateAndTypeChecking(ASTs)
# print("Succeeded")
# print("**********************************************************")
return ""
......
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