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()) {
}
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<con.numArgs(); i++) {
- ExpressionNode en=con.getArg(i);
- TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
- temps[i]=tmp;
- NodePair np=flattenExpressionNode(en, tmp);
- if (first==null)
- first=np.getBegin();
- else
- last.addNext(np.getBegin());
- last=np.getEnd();
-
- TempDescriptor tmp2=(i==0) ?
- out_temp :
- TempDescriptor.tempFactory("arg",en.getType());
- }
- FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
- last.addNext(fn);
-
-
- // assign each element of the new array to the flattened expression
-
-
- FlatOpNode fonAssignArray=new FlatOpNode(out_temp, newarry_temp, null, new Operation(Operation.ASSIGN));
- */
- //return new NodePair( , fonAssignArray );
- ain.printNode(0);
- System.out.println( "Array initializers not implemented yet." );
- System.exit( -1 );
- return null;
+ FlatNode first=null;
+ FlatNode last=null;
+ TempDescriptor tmp=TempDescriptor.tempFactory("arg", new TypeDescriptor(TypeDescriptor.INT));
+ FlatLiteralNode fln_tmp=new FlatLiteralNode(tmp.getType(), new Integer(ain.numVarInitializers()), tmp);
+ first = last=fln_tmp;
+
+ // create the new array
+ FlatNew fn=new FlatNew(td, out_temp, tmp, isGlobal, disjointId);
+ last.addNext(fn);
+ last = fn;
+
+ // initialize the new array
+ for(int i = 0; i < ain.numVarInitializers(); i++) {
+ ExpressionNode var_init_node = ain.getVarInitializer(i);
+ TempDescriptor tmp_toinit = out_temp;
+ TempDescriptor tmp_init=TempDescriptor.tempFactory("array_init", td.dereference());
+ // index=i
+ TempDescriptor index=TempDescriptor.tempFactory("index", new TypeDescriptor(TypeDescriptor.INT));
+ FlatLiteralNode fln=new FlatLiteralNode(index.getType(), new Integer(i), index);
+ // calculate the initial value
+ NodePair np_init = flattenExpressionNode(var_init_node, tmp_init);
+ // TODO wrapper class process is missing now
+ /*if(td.isArray() && td.dereference().iswrapper()) {
+ }*/
+ FlatSetElementNode fsen=new FlatSetElementNode(tmp_toinit, index, tmp_init);
+ last.addNext(fln);
+ fln.addNext(np_init.getBegin());
+ np_init.getEnd().addNext(fsen);
+ last = fsen;
+ }
+
+ return new NodePair(first, last);
}
private NodePair flattenTertiaryNode(TertiaryNode tn, TempDescriptor out_temp) {
package IR.Tree;
import java.util.Vector;
-import IR.TypeDescriptor;
-import IR.MethodDescriptor;
public class ArrayInitializerNode extends ExpressionNode {
- TypeDescriptor td;
Vector varInitList;
- public ArrayInitializerNode(TypeDescriptor type, Vector vil) {
- td=type;
+ public ArrayInitializerNode(Vector vil) {
varInitList=vil;
}
- public TypeDescriptor getType() {
- return td;
- }
-
public int numVarInitializers() {
return varInitList.size();
}
td=td.makeArray(state);
CreateObjectNode con=new CreateObjectNode(td, false, null);
// TODO array initializers
- pn.getChild("initializer");
+ ParseNode ipn = pn.getChild("initializer");
+ Vector initializers=parseVariableInitializerList(ipn);
+ ArrayInitializerNode ain = new ArrayInitializerNode(initializers);
+ con.addArrayInitializer(ain);
return con;
} else if (isNode(pn,"name")) {
NameDescriptor nd=parseName(pn);
ExpressionNode exp=parseExpression(pn.getChild("exp").getFirstChild());
TypeDescriptor t=parseTypeDescriptor(pn);
return new InstanceOfNode(exp,t);
- } else if (isNode(pn, "array_initializer")) {
- System.out.println( "Array initializers not implemented yet." );
- return null; // TODO MGC
- //throw new Error();
- //TypeDescriptor td=parseTypeDescriptor(pn);
- //Vector initializers=parseVariableInitializerList(pn);
- //return new ArrayInitializerNode(td, initializers);
+ } else if (isNode(pn, "array_initializer")) {
+ Vector initializers=parseVariableInitializerList(pn);
+ return new ArrayInitializerNode(initializers);
} else if (isNode(pn, "class_type") && state.MGC) {
TypeDescriptor td=parseTypeDescriptor(pn);
return new ClassTypeNode(td);
private Vector parseVariableInitializerList(ParseNode pn) {
Vector varInitList=new Vector();
- ParseNode vin=pn.getChild("variable_init_list");
+ ParseNode vin=pn.getChild("var_init_list");
if (vin==null) /* No argument list */
return varInitList;
ParseNodeVector vinv=vin.getChildren();
FlagEffects fe;
boolean isglobal;
String disjointId;
+ ArrayInitializerNode ain;
public CreateObjectNode(TypeDescriptor type, boolean isglobal, String disjointId) {
td=type;
argumentlist=new Vector();
this.isglobal=isglobal;
this.disjointId=disjointId;
+ this.ain = null;
}
public boolean isGlobal() {
public ExpressionNode getArg(int i) {
return (ExpressionNode) argumentlist.get(i);
}
+
+ public void addArrayInitializer(ArrayInitializerNode ain) {
+ this.ain = ain;
+ }
+
+ public ArrayInitializerNode getArrayInitializer() {
+ return this.ain;
+ }
public String printNode(int indent) {
String st;
}
}
if (isarray)
- return st+"]";
+ st += "]";
else
- return st+")";
+ st += ")";
+ if(isarray && this.ain != null) {
+ st += "{";
+ st += this.ain.printNode(indent);
+ st += "}";
+ }
+ return st;
}
public int kind() {
void checkArrayInitializerNode(Descriptor md, SymbolTable nametable, ArrayInitializerNode ain, TypeDescriptor td) {
for( int i = 0; i < ain.numVarInitializers(); ++i ) {
- checkExpressionNode(md, nametable, ain.getVarInitializer(i), td);
+ checkExpressionNode(md, nametable, ain.getVarInitializer(i), td.dereference());
}
}
int[] a = { 1, 2, 3 };
System.out.println( "a[2] should be 3: "+a[2] );
+
+ int ia[][] = { {1, 2}, null };
+ for (int i = 0; i < 2; i++) {
+ if(ia[i] != null) {
+ for (int j = 0; j < 2; j++) {
+ System.out.println(ia[i][j]);
+ }
+ } else {
+ System.out.println("ia[" + i + "] is null");
+ }
+ }
}
}
\ No newline at end of file