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

check static

parent 69a84e4c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
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