Skip to content
Snippets Groups Projects
Commit 703755da authored by pycsham's avatar pycsham
Browse files

Fixed issues with return statements in methods and also an AST building issue at if Nodes

parent 08e2af84
No related branches found
No related tags found
No related merge requests found
......@@ -179,7 +179,7 @@ class IfNode(ASTNode):
self.ifConditional = makeNodeFromExpr(parseTree.children[2], typeName)
self.ifBody = makeNodeFromAllStatement(parseTree.children[4], typeName)
if parseTree.name == 'ifElseStatement':
if parseTree.name == 'ifElseStatement' or parseTree.name == "ifElseStatementNoShortIf":
self.elseBody = makeNodeFromAllStatement(parseTree.children[6], typeName)
self.children.append(self.ifConditional)
......
......@@ -150,17 +150,10 @@ class MethodNode(ASTNode):
# With method body
returnNodes = getASTNode(["ReturnNode"], self.body)
# Checking for cases where there are no return statements
if not returnNodes:
# Either a constructor or the function has type Void
if not self.methodType or self.myType.name == "void":
return
raise Exception("ERROR: no return statement at function {}".format(self.name))
# Checking for cases where there are return statements
for n in returnNodes:
# Checking for functions of type void
# Only valid if either the function doesn't have a return statement(checked above), or the return statement is a semicolon (return;)
# Only valid if either the function doesn't have a return statement, or the return statement is a semicolon (return;)
if self.myType and self.myType.name == "void":
if n.myType:
raise Exception("ERROR: return type of function {} doesn't match with return statement.".format(self.name))
......@@ -174,11 +167,9 @@ class MethodNode(ASTNode):
self.outMaybe = False
# Check reachability of method body
# No need to check for empty function body, since the check is done in checkType
if self.body:
self.body.reachCheck(True) # For method bodies, in[L] = maybe by default
self.outMaybe = self.body.outMaybe
# Check if out[method body] is a maybe for non-void methods
if not self.methodType or self.myType.name == "void": # Omitting the check for constructors and void functions
......
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