From: jzhou Date: Thu, 27 Jan 2011 19:26:16 +0000 (+0000) Subject: Enable array creation with initialization for MGC. Now array initialization is fully... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=004fbc9789c7bc547ed38f7085c784558233d730;p=IRC.git Enable array creation with initialization for MGC. Now array initialization is fully supported in MGC. --- diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index d8e4442e..48b07b78 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -360,6 +360,7 @@ public class BuildFlat { } return new NodePair(fn,last); } else { + if(con.getArrayInitializer() == null) { FlatNode first=null; FlatNode last=null; TempDescriptor[] temps=new TempDescriptor[con.numArgs()]; @@ -390,6 +391,11 @@ public class BuildFlat { return new NodePair(first,np.getEnd()); } else return new NodePair(first, fn); + } else if(state.MGC) { + // array creation with initializers + return flattenArrayInitializerNode(con.getArrayInitializer(), out_temp); + } + return null; } } diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index ddc0dc5a..be2e490a 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -900,6 +900,11 @@ public class SemanticCheck { if (td!=null&&!typeutil.isSuperorType(td, typetolookin)) throw new Error(typetolookin + " isn't a "+td); + + /* Check Array Initializers */ + if(state.MGC && (con.getArrayInitializer() != null)) { + checkArrayInitializerNode(md, nametable, con.getArrayInitializer(), td); + } /* Check flag effects */ if (con.getFlagEffects()!=null) { diff --git a/Robust/src/Tests/ArrayInitializerTest.java b/Robust/src/Tests/ArrayInitializerTest.java index f7d664d6..c14db846 100644 --- a/Robust/src/Tests/ArrayInitializerTest.java +++ b/Robust/src/Tests/ArrayInitializerTest.java @@ -25,5 +25,16 @@ public class ArrayInitializerTest { for(int i = 0; i < ait.sa.length; i++) { System.out.println(ait.sa[i]); } + + int[][] ja = new int[][]{null, {3,4}}; + for (int i = 0; i < 2; i++) { + if(ja[i] != null) { + for (int j = 0; j < 2; j++) { + System.out.println(ja[i][j]); + } + } else { + System.out.println("ja[" + i + "] is null"); + } + } } } \ No newline at end of file