diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py index d1dba9a91fdde384cf37338fe35a068ee0090ed5..812bb1789e4fc50cb87062b7ffc7fd329c33c7b5 100644 --- a/ExprPrimaryNodes.py +++ b/ExprPrimaryNodes.py @@ -484,6 +484,11 @@ class MethodInvNode(ASTNode): from pprint import pprint if m: + if self.ID.shouldBeStatic and (not 'static' in m.mods): + raise Exception("ERROR: Static access of non-static method {}.".format(m.name)) + if (not self.ID.shouldBeStatic) and 'static' in m.mods: + raise Exception("ERROR: Non-static access of static method {}.".format(m.name)) + self.method = m self.myType = m.methodType.myType return diff --git a/NameNode.py b/NameNode.py index 141b789454f2bf8c26b4ad99c1ef0ad5429a7fe9..3401352672bf9ce9da052cd9e5c362d7d9adf4da 100644 --- a/NameNode.py +++ b/NameNode.py @@ -33,6 +33,7 @@ class NameNode(ASTNode): self.typeName = typeName # the name of the class or interface that this node belongs under self.children = [] self.myType = None # will become TypeStruct to tell us what the whole is/returns + self.shouldBeStatic = False self.name = getParseTreeNodes(["ID", "COMPID"], parseTree)[0].lex @@ -119,11 +120,11 @@ class NameNode(ASTNode): typeFieldNode = typeNode.env.getNode(staticFieldName, "fieldDcl") if "static" in typeFieldNode.mods: self.prefixLink = typeFieldNode.variableDcl - + # if it is primitive, then we leave it as a VarDclNode if not self.prefixLink.dclType.myType.isPrimitive: self.prefixLink = self.prefixLink.dclType.myType.typePointer - + self.prefix = currPrefix + "." + staticFieldName self.IDs = self.IDs[index+2:] return True @@ -160,6 +161,7 @@ class NameNode(ASTNode): # Checking if the shortest prefix is a static field if self.checkStatic(): + self.shouldBeStatic = True return raise Exception("ERROR at disambiguating namespace: no prefix of name {} is found in environment.".format(self.name)) @@ -193,6 +195,10 @@ class NameNode(ASTNode): else: curType = curType.env.getNode(self.IDs[0], 'fieldDcl') + # at this stage, all newly resolved field should be non static: + if curType.__class__.__name__ == 'FieldNode' and 'static' in curType.mods: + raise Exception("ERROR: Non-static access of static field {}".format(curType.name)) + self.prefix = self.prefix + "." + self.IDs[0] self.IDs.pop(0)