Skip to content
Snippets Groups Projects
Commit 971b226e authored by pycsham's avatar pycsham
Browse files

fixing the issue of ifConditional (could be methodInv, arrayAccess or fieldAccess)

parent c625d5b8
No related branches found
No related tags found
2 merge requests!26Array subtype,!20Master
......@@ -17,6 +17,8 @@ class ASTNode():
# reachability: None = not set, True = maybe, False = no
self.outMaybe = None # either None or True/False
def getConstant(self):
return None
# Do certains actions on every node of the AST tree
# call the same method in each class and its children recursively
......
......@@ -96,6 +96,7 @@ def genMethodInvoke(method):
# generates shorter code for constant value conditionals and comparison conditionals
# cond is either literalNode or ExprNode or NameNode
# cond could also be methodInvNode, arrayAccessNode or fieldAccessNode
def iffalse(cond, label):
result = ""
if cond.__class__.__name__ == "NameNode":
......
......@@ -163,6 +163,10 @@ class ArrayAccessNode(ASTNode):
if not self.index.myType.isNum():
raise Exception("ERROR: Array index must be a number.")
self.myType = TypeStruct(self.array.myType.name, self.array.myType.typePointer)
def getIfFalse(self, label):
self.codeGen()
return self.code + p("cmp", "eax", "[G__Zero]") + p("je", label)
def addr(self):
result = "; Start of calculating address for array access\n" + \
......@@ -872,6 +876,10 @@ class FieldAccessNode(ASTNode):
checkProtected(self.ID.prefixLink, self)
except: # where there are no mods
return
def getIfFalse(self, label):
self.codeGen()
return self.code + p("cmp", "eax", "[G__Zero]") + p("je", label)
# generates code that evaluates the address of field access
# result stored in eax (address)
......@@ -1005,6 +1013,10 @@ class MethodInvNode(ASTNode):
self.args.codeGen()
self.code += self.args.code
def getIfFalse(self, label):
self.codeGen()
return self.code + p("cmp", "eax", "[G__Zero]") + p("je", label)
def codeGen(self):
if hasattr(self, "code"):
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