From d622e05fb22bb01e517b3f05a527b832775104ba Mon Sep 17 00:00:00 2001
From: Nicholas Wesley Robinson <nwrobinson@uwaterloo.ca>
Date: Sun, 12 Apr 2020 23:46:08 -0400
Subject: [PATCH] finishing concat strings expr

---
 ExprPrimaryNodes.py | 27 +++++++++++++++++++++------
 UnitNodes.py        |  8 ++++----
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/ExprPrimaryNodes.py b/ExprPrimaryNodes.py
index 07860ef..960587e 100644
--- a/ExprPrimaryNodes.py
+++ b/ExprPrimaryNodes.py
@@ -586,11 +586,11 @@ class ExprNode(ASTNode):
             leftArg = ArgsNode(self.parseTree, self.typeName, [self.left])
             rightArg = ArgsNode(self.parseTree, self.typeName, [self.right])
             # 3. Put it all together
-            self.valueOfMethodInvLeft = MethodInvNode(self.parseTree, self.typeName, valueOfNameNode, leftArg)
-            self.valueOfMethodInvRight = MethodInvNode(self.parseTree, self.typeName, valueOfNameNode, rightArg)
+            valueOfMethodInvLeft = MethodInvNode(self.parseTree, self.typeName, valueOfNameNode, leftArg)
+            valueOfMethodInvRight = MethodInvNode(self.parseTree, self.typeName, valueOfNameNode, rightArg)
             # 4. Check type to be safe
-            self.valueOfMethodInvLeft.checkType()
-            self.valueOfMethodInvRight.checkType()
+            # valueOfMethodInvLeft.checkType()
+            # valueOfMethodInvRight.checkType()
 
             
             # methodInvoc primary PERIOD ID LPAREN args RPAREN
@@ -604,9 +604,10 @@ class ExprNode(ASTNode):
             # create MethodInvNode to call left.concat(right)
             # 1. Make NameNode for String.concat (name = "concat")
             concatNameNode = NameNode(self.parseTree, True, self.typeName, "concat")
-            # 2. Make ArgsNode for right (already have from above!)
+            # 2. Make ArgsNode for right
+            rightArgMethodInv = ArgsNode(self.parseTree, self.typeName, [valueOfMethodInvRight])
             # 3. Put it all together
-            self.concatMethodInv = MethodInvNode(self.parseTree, self.typeName, concatNameNode, rightArg, self.left)
+            self.concatMethodInv = MethodInvNode(self.parseTree, self.typeName, concatNameNode, rightArgMethodInv, valueOfMethodInvLeft)
             # 4. Check type to be safe
             self.concatMethodInv.checkType()
             
@@ -729,6 +730,20 @@ class ExprNode(ASTNode):
         # String Add TODO
         if (self.left.myType.name =='java.lang.String' or self.right.myType.name =='java.lang.String') \
         and self.op == '+':
+            # String.valueOf(left)
+            # if not hasattr(self.valueOfMethodInvLeft, "code"):
+            #     self.valueOfMethodInvLeft.codeGen()
+            # self.code += self.valueOfMethodInvLeft.code
+
+            # String.valueOf(right)
+            # if not hasattr(self.valueOfMethodInvLeft, "code"):
+            #     self.valueOfMethodInvLeft.codeGen()
+            # self.code += self.valueOfMethodInvLeft.code
+
+            # ( String.valueOf(right) ).concat( left )
+            if not hasattr(self.concatMethodInv, "code"):
+                self.concatMethodInv.codeGen()
+            self.code += self.concatMethodInv.code
             return
         # Number Add, Subtract, Multiply
         if self.op in ['+', '-', '*']:
diff --git a/UnitNodes.py b/UnitNodes.py
index 88b3200..f036b9b 100644
--- a/UnitNodes.py
+++ b/UnitNodes.py
@@ -57,10 +57,10 @@ class LiteralNode(ASTNode):
 
         # char
         if self.name == 'char':
-            self.code += p("mov", "eax", str(self.getConstant()), " set to literal char")
+            self.code += p("mov", "eax", str("dword " + self.getConstant()), " set to literal char")
             return
 
-        # string TODO
+        # string
         if self.name == 'java.lang.String':
             self.code += ";Start of String Literal Creation for class " + self.typeName + "\n"
             # generate array of characters
@@ -69,7 +69,7 @@ class LiteralNode(ASTNode):
             # remove quotation marks
             value = self.value[1:-1]
 
-            # FIRST: create char array for this string TODO figure out how to populate this array
+            # FIRST: create char array for this string
             # 1. Allocating space for the char array in heap
             # Note: uses ecx to temporarily store the array length
             self.code += ";Start of char array creation\n" + \
@@ -98,7 +98,7 @@ class LiteralNode(ASTNode):
             for i in range(len(value)):
                 if i != 0:
                     self.code += p(instruction="add", arg1="eax", arg2=4, comment="eax points at a["+str(i)+"]")
-                self.code += p(instruction="mov", arg1="[eax]", arg2=str("dword \""+value[i]+"\""), comment="a["+str(i)+"]="+str(value[i]))
+                self.code += p(instruction="mov", arg1="[eax]", arg2=str("dword '"+value[i]+"'"), comment="a["+str(i)+"]="+str(value[i]))
             # 4.4. restore array pointer
             self.code += p(instruction="pop", arg1="eax", comment="eax is pointer to array")
             self.code += ";End of populating char array\n"
-- 
GitLab