Skip to content
Snippets Groups Projects
Commit e637212c authored by Xun Yang's avatar Xun Yang
Browse files

Merge branch 'master' of git.uwaterloo.ca:x299yang/cs444

parents aa1b51a3 5aea5c77
No related branches found
No related tags found
No related merge requests found
......@@ -310,6 +310,15 @@ class ClassCreateNode(ASTNode):
else:
raise Exception("ERROR: Class {} doesn't have a constructor with given argument types.".format(classDef.name))
# check to make sure we are allowed to call this (protected?)
# if self.cons is protected, check that:
# - current class is in the same package
if 'protected' in self.cons.mods:
curClass = self.env.getNode(self.typeName, 'type')
if curClass.packageName != classDef.packageName:
raise Exception("ERROR: In class {0}, using a protected constructor, but class {1} is not in class {0}'s package ({2}).".format(curClass.name, classDef.name, curClass.packageName))
#################################################################################
# condOrExpr
......@@ -421,7 +430,10 @@ class FieldAccessNode(ASTNode):
def checkType(self):
self.primary.checkType()
self.ID.prefixLink = self.primary.myType.typePointer
if self.primary.myType.isArray or self.primary.myType.isPrimitive:
self.ID.prefixLink = self.primary
else:
self.ID.prefixLink = self.primary.myType.typePointer
self.ID.checkType()
self.myType = self.ID.myType
......
......@@ -66,6 +66,13 @@ class NameNode(ASTNode):
self.addToPrefix(typeNode)
return True
return False
def checkLength(self):
if not self.IDs:
return True
if self.IDs[0] == "length":
return True
return False
# Checks and updates prefix if the next ID in self.IDs is a local variable or a parameter
def checkLocalVar(self):
......@@ -157,6 +164,10 @@ class NameNode(ASTNode):
if self.checkThis():
self.pointToThis = True
return
# Checking if a1 is length
if self.checkLength():
return
# Checking if a1 is a local variable
if self.checkLocalVar():
......
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