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

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

parents 8f2b5dcc 8c9f9e70
No related branches found
No related tags found
No related merge requests found
......@@ -139,6 +139,13 @@ class MethodNode(ASTNode):
if not self.body:
return
# check no use of this in static method
if 'static' in self.mods:
names = getNameNodes(self.body)
for n in names:
if 'this' in n.name or (n.pointToThis and n.prefixLink.__class__.__name__ == ['MethodNode', 'FieldNode'] and 'static' not in n.prefixLink.mods):
raise Exception("ERROR: Cannot use non-static member {} in static method {} in class {}".format(n.name, self.name, self.typeName))
# With method body
returnNodes = getASTNode(["ReturnNode"], self.body)
......@@ -177,3 +184,18 @@ def getForwardRefNames(node):
result.extend(getForwardRefNames(c))
return result
# Input: AST Node
# Output: A list of names to be check
def getNameNodes(node):
if not node:
return []
if node.__class__.__name__ == 'NameNode':
return [node]
result = []
for c in node.children:
result.extend(getNameNodes(c))
return result
......@@ -34,6 +34,7 @@ class NameNode(ASTNode):
self.children = []
self.myType = None # will become TypeStruct to tell us what the whole is/returns
self.shouldBeStatic = False
self.pointToThis = False
self.name = getParseTreeNodes(["ID", "COMPID"], parseTree)[0].lex
......@@ -170,6 +171,7 @@ class NameNode(ASTNode):
def disambigName(self):
# Checking if a1 is "this"
if self.checkThis():
self.pointToThis = True
return
# Checking if a1 is length
......@@ -182,6 +184,7 @@ class NameNode(ASTNode):
# Checking if a1 is in contains set
if self.checkContains():
self.pointToThis = True
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