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

fix array access

parent b5da1cb6
No related branches found
No related tags found
No related merge requests found
...@@ -135,11 +135,13 @@ class ArrayAccessNode(ASTNode): ...@@ -135,11 +135,13 @@ class ArrayAccessNode(ASTNode):
def disambigName(self): def disambigName(self):
self.array.disambigName() self.array.disambigName()
self.index.disambigName() self.index.disambigName()
# helperDisambigName(self.array)
# helperDisambigName(self.index)
def checkType(self): def checkType(self):
self.array.disambigName() # hacky fix, not sure why disambigName wasn't called before
self.array.checkType() self.array.checkType()
self.index.checkType() self.index.checkType()
if not self.array.myType.isArray:
raise Exception("ERROR: Cannot perform array access on non-array {}".format(self.array.name))
if not self.index.myType.isNum(): if not self.index.myType.isNum():
raise Exception("ERROR: Array index must be a number.") raise Exception("ERROR: Array index must be a number.")
self.myType = TypeStruct(self.array.myType.name, self.array.myType.typePointer) self.myType = TypeStruct(self.array.myType.name, self.array.myType.typePointer)
...@@ -410,7 +412,7 @@ class FieldAccessNode(ASTNode): ...@@ -410,7 +412,7 @@ class FieldAccessNode(ASTNode):
self.children.append(self.primary) self.children.append(self.primary)
self.children.append(self.ID) self.children.append(self.ID)
def disambigName(self): def disambigName(self):
if not self.primary: # this implies that the ID has nothing that comes before it if not self.primary: # this implies that the ID has nothing that comes before it
# helperDisambigName(self.ID) # helperDisambigName(self.ID)
self.ID.disambigName() self.ID.disambigName()
......
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