diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py index 163c0a22ea5a3185a482262767a6eaf295bc018a..a5194ae0b818ce2c92cb167d891fb1e0d2c92cf7 100644 --- a/ExprPrimaryNodes.py +++ b/ExprPrimaryNodes.py @@ -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 diff --git a/NameNode.py b/NameNode.py index 2d87cf3b10ca69480be378509c111ec4eaf7232c..e99fd9f337674e10e101014035d0e45055de4101 100644 --- a/NameNode.py +++ b/NameNode.py @@ -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():