From d28b89d96693de8e64ddc490902d4be956d032d0 Mon Sep 17 00:00:00 2001 From: jzhou Date: Thu, 27 Jan 2011 00:51:49 +0000 Subject: [PATCH] Basic implementation of array initialization for mgc: local array declaration with array initialization is OK now. Need more work to enable array field declaration with initialization and array creation with initialization. Also fix a bug: previously do not support static fields that are object/array. --- Robust/src/IR/Flat/BuildCode.java | 20 +++++- Robust/src/IR/Flat/BuildFlat.java | 71 ++++++++++---------- Robust/src/IR/Tree/ArrayInitializerNode.java | 10 +-- Robust/src/IR/Tree/BuildIR.java | 17 +++-- Robust/src/IR/Tree/CreateObjectNode.java | 20 +++++- Robust/src/IR/Tree/SemanticCheck.java | 2 +- Robust/src/Tests/ArrayInitializerTest.java | 11 +++ 7 files changed, 93 insertions(+), 58 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 2fb5e3bf..dffb65c9 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1621,9 +1621,25 @@ public class BuildCode { if (state.MGC && fd.getType().isClass() && fd.getType().getClassDesc().isEnum()) { classdefout.println(" int " + fd.getSafeSymbol() + ";"); - } else if (fd.getType().isClass()||fd.getType().isArray()) + } else if (fd.getType().isClass()||fd.getType().isArray()) { + if ((state.MGC) && (fd.isStatic())) { + // TODO add version for normal Java later + // static field + if(fd.isVolatile()) { + globaldefout.println(" volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";"); + } else { + globaldefout.println(" struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";"); + } + classdefout.println(" struct "+fd.getType().getSafeSymbol()+" ** "+fd.getSafeSymbol()+";"); + } else if ((state.MGC) && (fd.isVolatile())) { + // TODO add version for normal Java later + // static field + globaldefout.println(" volatile struct "+fd.getType().getSafeSymbol()+ " * "+cn.getSafeSymbol()+fd.getSafeSymbol()+";"); + classdefout.println(" struct"+fd.getType().getSafeSymbol()+" ** "+fd.getSafeSymbol()+";"); + } else { classdefout.println(" struct "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";"); - else if ((state.MGC) && (fd.isStatic())) { + } + } else if ((state.MGC) && (fd.isStatic())) { // TODO add version for normal Java later // static field if(fd.isVolatile()) { diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index 97b697b7..f5347897 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -1387,43 +1387,44 @@ public class BuildFlat { } private NodePair flattenArrayInitializerNode(ArrayInitializerNode ain, TempDescriptor out_temp) { - /* - TempDescriptor expr_temp=TempDescriptor.tempFactory("arry_init",ain.getType()); + boolean isGlobal = false; + String disjointId = null; + // get the type the array to be initialized + TypeDescriptor td = out_temp.getType(); // create a new array of size equal to the array initializer - //FlatNode first=null; - //FlatNode last=null; - TempDescriptor[] temps=new TempDescriptor[ain.numVarInitializers()]; - - for (int i=0; i