diff --git a/AstBuilding.py b/AstBuilding.py index 177b623cc98260a8686862ff177e63ff86d1bd16..17c97e799c79686ba1ea1fb2edb68c9c1c8715ac 100644 --- a/AstBuilding.py +++ b/AstBuilding.py @@ -65,6 +65,7 @@ def arrayClassMemory(types): # TODO: add subtype testing table methods = ["M_Object_Object_", "M_Object_equals_Object", "M_Object_toString_", "M_Object_hashCode_", "M_Object_clone_", "M_Object_getClass_"] typeDict = {} + primTypes = ['boolean', 'byte', 'char', 'int', 'short'] # All possible types for t in types: # Class memory layout # Label: "A_type" @@ -95,8 +96,10 @@ def arrayClassMemory(types): p(instruction="mov", arg1="[eax]", arg2="dword "+m, comment="points to method implementation") code += p(instruction="ret", arg1="") code += "; End of function to initialize class memory layout\n" - - typeDict[t] = code + if t in primTypes: + typeDict[('P', t)] = code # primitive types (for file name) + else: + typeDict[('T', t)] = code # non primitive types return typeDict @@ -179,11 +182,11 @@ def startGen(ASTs, output, arrayClassMemory): callArrayInit = "; Start of calling each array type's arrayMemoryInitialize\n" for t, code in arrayClassMemory.items(): - label = "H_" + t + "_arrayMemoryInitialize" + label = "H_" + t[1] + "_arrayMemoryInitialize" callArrayInit += p(instruction="extern", arg1=label) + \ p(instruction="call", arg1=label) # Creating .s files for each array type to store the class memory layout - fileName = output + "/" + t + "_arrayClass" + ".s" + fileName = output + "/" + t[0] + '_' + t[1] + "_arrayClass" + ".s" f = open(fileName, "w") f.write(code) f.close() diff --git a/Scanning.py b/Scanning.py index 290553105fff6f45d2771d787689d652f9f69f24..55d7f718f788307995804e9ca859bd867f46d8cc 100644 --- a/Scanning.py +++ b/Scanning.py @@ -524,8 +524,6 @@ def scan(input): for i, t in enumerate(temp): if i == 0 and t in wrongJavaKeyWordDict: return (None, "wrong keyword in comp id") - if i is not 0 and (t == 'Class' or t == 'class'): - return (None, "wrong keyword in comp id") if i is not 0 and t == 'this': return (None, "this cannot be in the middle of a compid") diff --git a/Tests/A5/J1_01_SIT_methodInv/Main.java b/Tests/A5/J1_01_SIT_methodInv/Main.java index aab2790afe3c386c42457271396c027609e2399a..b9f859045d1dc445888723e1a3148755b6f56177 100644 --- a/Tests/A5/J1_01_SIT_methodInv/Main.java +++ b/Tests/A5/J1_01_SIT_methodInv/Main.java @@ -7,7 +7,7 @@ public class Main { public int j = 5; public static int test() { - Interface a = new pkg.Class1(); + Interface a = new pkg.Class(); Object o = a.clone(); return o.hashCode() + a.k(2); } diff --git a/Tests/A5/J1_01_SIT_methodInv/pkg/Class1.java b/Tests/A5/J1_01_SIT_methodInv/pkg/Class.java similarity index 64% rename from Tests/A5/J1_01_SIT_methodInv/pkg/Class1.java rename to Tests/A5/J1_01_SIT_methodInv/pkg/Class.java index 46aae13f366fbe1b6dc9121e36adfec4981b7dd4..fbdb8374b9268f3e152405c0ef66f684d23c77d7 100644 --- a/Tests/A5/J1_01_SIT_methodInv/pkg/Class1.java +++ b/Tests/A5/J1_01_SIT_methodInv/pkg/Class.java @@ -1,8 +1,8 @@ // CODE_GENERATION package pkg; -public class Class1 implements Interface { - public Class1() {} +public class Class implements Interface { + public Class() {} public Object clone() { return this; } public int k(int i) {return i + 42;} }