+ src_tmp=tmp;
+ last.addNext(fc1);
+ last=fc;
+ } else {
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ fon.setNumLine(an.getNumLine());
+ src_tmp=tmp;
+ last.addNext(fon);
+ last=fon;
+ }
+ }
+
+
+ FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
+ fsfn.setNumLine(en.getNumLine());
+ addMapNode2FlatNodeSet(an,fsfn);
+ last.addNext(fsfn);
+ last=fsfn;
+ if (pre) {
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fon2.setNumLine(an.getNumLine());
+ fsfn.addNext(fon2);
+ last=fon2;
+ }
+ return new NodePair(first, last);
+ } else {
+ if (nn.getField()!=null) {
+ //It is a field
+ //Get src value
+
+ //See if we need to perform an operation
+ if (base!=null) {
+ //If it is a preinc we need to store the initial value
+ TempDescriptor src_tmp2=pre?TempDescriptor.tempFactory("src",an.getDest().getType()):out_temp;
+ TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
+
+ TempDescriptor ftmp= null;
+ if((nn.getClassDesc() != null)) {
+ // this is a static field
+ ftmp = new TempDescriptor(nn.getClassDesc().getSymbol(), nn.getClassType());
+
+ } else {
+ ftmp=getTempforVar(nn.getVar());
+ }
+ FlatFieldNode ffn=new FlatFieldNode(nn.getField(), ftmp, src_tmp2);
+ ffn.setNumLine(an.getNumLine());
+
+ if (first==null)
+ first=ffn;
+ else {
+ last.addNext(ffn);
+ }
+ last=ffn;
+
+
+ if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+ TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+ MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+ FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {src_tmp2});
+ fc1.setNumLine(an.getNumLine());
+
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, tmp, src_tmp3, new TempDescriptor[] {src_tmp});
+ fc.setNumLine(an.getNumLine());
+ src_tmp=tmp;
+ last.addNext(fc1);
+ fc1.addNext(fc);
+ last=fc;
+ } else {
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ fon.setNumLine(an.getNumLine());
+ src_tmp=tmp;
+ last.addNext(fon);
+ last=fon;
+ }
+ }
+
+ FlatSetFieldNode fsfn=null;
+ if(nn.getClassDesc()!=null) {
+ // this is a static field access inside of a static block
+ fsfn=new FlatSetFieldNode(new TempDescriptor("sfsb", nn.getClassType()), nn.getField(), src_tmp);
+ fsfn.setNumLine(nn.getNumLine());
+ } else {
+ fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
+ fsfn.setNumLine(nn.getNumLine());
+ }
+ addMapNode2FlatNodeSet(an,fsfn);
+ if (first==null) {
+ first=fsfn;
+ } else {
+ last.addNext(fsfn);
+ }
+ last=fsfn;
+ if (pre) {
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fon2.setNumLine(an.getNumLine());
+ fsfn.addNext(fon2);
+ last=fon2;
+ }
+ return new NodePair(first, last);
+ } else {
+ //It is a variable
+ //See if we need to perform an operation
+
+ if (base!=null) {
+ //If it is a preinc we need to store the initial value
+ TempDescriptor src_tmp2=getTempforVar(nn.getVar());
+ TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
+ if (!pre) {
+ FlatOpNode fon=new FlatOpNode(out_temp, src_tmp2, null, new Operation(Operation.ASSIGN));
+ fon.setNumLine(an.getNumLine());
+ if (first==null)
+ first=fon;
+ else
+ last.addNext(fon);
+ last=fon;
+ }
+
+
+ if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+ TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+ MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+ FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {src_tmp2});
+ fc1.setNumLine(an.getNumLine());
+
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, tmp, src_tmp3, new TempDescriptor[] {src_tmp});
+ fc.setNumLine(an.getNumLine());
+ src_tmp=tmp;
+ fc1.addNext(fc);
+
+ if (first==null)
+ first=fc1;
+ else
+ last.addNext(fc1);
+ src_tmp=tmp;
+ last=fc;
+ } else {
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ fon.setNumLine(an.getNumLine());
+ if (first==null)
+ first=fon;
+ else
+ last.addNext(fon);
+ src_tmp=tmp;
+ last=fon;
+ }
+ }
+
+ FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
+ fon.setNumLine(an.getNumLine());
+ addMapNode2FlatNodeSet(an,fon);
+
+ last.addNext(fon);
+ last=fon;
+ if (pre) {
+ FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
+ fon2.setNumLine(an.getNumLine());
+ fon.addNext(fon2);
+ last=fon2;
+ }
+ return new NodePair(first, last);
+ } //end of else
+ }
+ }
+
+ throw new Error();
+ }
+
+ private NodePair flattenNameNode(NameNode nn,TempDescriptor out_temp) {
+ if (nn.getExpression()!=null) {
+ /* Hack - use subtree instead */
+ return flattenExpressionNode(nn.getExpression(),out_temp);
+ } else if (nn.getField()!=null) {
+ TempDescriptor tmp= null;
+ if((nn.getClassDesc() != null)) {
+ // this is a static field
+ tmp = new TempDescriptor(nn.getClassDesc().getSymbol(), nn.getClassType());
+
+ } else {
+ tmp=getTempforVar(nn.getVar());
+ }
+ FlatFieldNode ffn=new FlatFieldNode(nn.getField(), tmp, out_temp);
+ ffn.setNumLine(nn.getNumLine());
+ addMapNode2FlatNodeSet(nn,ffn);
+ return new NodePair(ffn,ffn);
+ } else {
+ TempDescriptor tmp=getTempforVar(nn.isTag()?nn.getTagVar():nn.getVar());
+ if (nn.isTag()) {
+ //propagate tag
+ out_temp.setTag(tmp.getTag());
+ }
+ FlatOpNode fon=new FlatOpNode(out_temp, tmp, null, new Operation(Operation.ASSIGN));
+ fon.setNumLine(nn.getNumLine());
+ addMapNode2FlatNodeSet(nn,fon);
+ return new NodePair(fon,fon);
+ }
+ }
+
+ private NodePair flattenOpNode(OpNode on,TempDescriptor out_temp) {
+ TempDescriptor temp_left=TempDescriptor.tempFactory("leftop",on.getLeft().getType());
+ TempDescriptor temp_right=null;
+
+ Operation op=on.getOp();
+
+ NodePair left=flattenExpressionNode(on.getLeft(),temp_left);
+ NodePair right;
+ if (on.getRight()!=null) {
+ temp_right=TempDescriptor.tempFactory("rightop",on.getRight().getType());
+ right=flattenExpressionNode(on.getRight(),temp_right);
+ } else {
+ FlatNop nop=new FlatNop();
+ right=new NodePair(nop,nop);
+ }
+
+ if (op.getOp()==Operation.LOGIC_OR) {
+ /* Need to do shortcircuiting */
+ FlatCondBranch fcb=new FlatCondBranch(temp_left);
+ fcb.setNumLine(on.getNumLine());
+ FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
+ fon1.setNumLine(on.getNumLine());
+ FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
+ fon2.setNumLine(on.getNumLine());
+ FlatNop fnop=new FlatNop();
+ left.getEnd().addNext(fcb);
+ fcb.addFalseNext(right.getBegin());
+ right.getEnd().addNext(fon2);
+ fon2.addNext(fnop);
+ fcb.addTrueNext(fon1);
+ fon1.addNext(fnop);
+ return new NodePair(left.getBegin(), fnop);
+ } else if (op.getOp()==Operation.LOGIC_AND) {
+ /* Need to do shortcircuiting */
+ FlatCondBranch fcb=new FlatCondBranch(temp_left);
+ fcb.setNumLine(on.getNumLine());
+ FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
+ fon1.setNumLine(on.getNumLine());
+ FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
+ fon2.setNumLine(on.getNumLine());
+ FlatNop fnop=new FlatNop();
+ left.getEnd().addNext(fcb);
+ fcb.addTrueNext(right.getBegin());
+ right.getEnd().addNext(fon2);
+ fon2.addNext(fnop);
+ fcb.addFalseNext(fon1);
+ fon1.addNext(fnop);
+ return new NodePair(left.getBegin(), fnop);
+ } else if (op.getOp()==Operation.ADD&&on.getLeft().getType().isString()) {
+ //We have a string concatenate
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
+ TempDescriptor src_tmp3=TempDescriptor.tempFactory("src", new TypeDescriptor(stringcd));
+ MethodDescriptor valueOfmd=typeutil.getMethod(stringcd, "valueOf", new TypeDescriptor[] {new TypeDescriptor(objectcd)});
+ FlatCall fc1=new FlatCall(valueOfmd, src_tmp3, null, new TempDescriptor[] {temp_left});
+ fc1.setNumLine(on.getNumLine());
+
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, out_temp, src_tmp3, new TempDescriptor[] {temp_right});
+ fc.setNumLine(on.getNumLine());
+ left.getEnd().addNext(right.getBegin());
+ right.getEnd().addNext(fc1);
+ fc1.addNext(fc);
+ return new NodePair(left.getBegin(), fc);
+ }
+
+ FlatOpNode fon=new FlatOpNode(out_temp,temp_left,temp_right,op);
+ fon.setNumLine(on.getNumLine());
+ left.getEnd().addNext(right.getBegin());
+ right.getEnd().addNext(fon);
+ return new NodePair(left.getBegin(),fon);
+ }
+
+ private NodePair flattenExpressionNode(ExpressionNode en, TempDescriptor out_temp) {
+ switch(en.kind()) {
+ case Kind.AssignmentNode:
+ return flattenAssignmentNode((AssignmentNode)en,out_temp);
+
+ case Kind.CastNode:
+ return flattenCastNode((CastNode)en,out_temp);
+
+ case Kind.CreateObjectNode:
+ return flattenCreateObjectNode((CreateObjectNode)en,out_temp);
+
+ case Kind.FieldAccessNode:
+ return flattenFieldAccessNode((FieldAccessNode)en,out_temp);
+
+ case Kind.ArrayAccessNode:
+ return flattenArrayAccessNode((ArrayAccessNode)en,out_temp);
+
+ case Kind.LiteralNode:
+ return flattenLiteralNode((LiteralNode)en,out_temp);
+
+ case Kind.MethodInvokeNode:
+ return flattenMethodInvokeNode((MethodInvokeNode)en,out_temp);
+
+ case Kind.NameNode:
+ return flattenNameNode((NameNode)en,out_temp);
+
+ case Kind.OpNode:
+ return flattenOpNode((OpNode)en,out_temp);
+
+ case Kind.OffsetNode:
+ return flattenOffsetNode((OffsetNode)en,out_temp);
+
+ case Kind.TertiaryNode:
+ return flattenTertiaryNode((TertiaryNode)en,out_temp);
+
+ case Kind.InstanceOfNode:
+ return flattenInstanceOfNode((InstanceOfNode)en,out_temp);
+
+ case Kind.ArrayInitializerNode:
+ return flattenArrayInitializerNode((ArrayInitializerNode)en,out_temp);
+ }
+ throw new Error();
+ }
+
+ private NodePair flattenDeclarationNode(DeclarationNode dn) {
+ VarDescriptor vd=dn.getVarDescriptor();
+ TempDescriptor td=getTempforVar(vd);
+ if (dn.getExpression()!=null)
+ return flattenExpressionNode(dn.getExpression(),td);
+ else {
+ FlatNop fn=new FlatNop();
+ return new NodePair(fn,fn);
+ }
+ }
+
+ private NodePair flattenTagDeclarationNode(TagDeclarationNode dn) {
+ TagVarDescriptor tvd=dn.getTagVarDescriptor();
+ TagDescriptor tag=tvd.getTag();
+ TempDescriptor tmp=getTempforVar(tvd);
+ FlatTagDeclaration ftd=new FlatTagDeclaration(tag, tmp);
+ ftd.setNumLine(dn.getNumLine());
+ return new NodePair(ftd,ftd);
+ }
+
+ private TempDescriptor getTempforParam(Descriptor d) {
+ if (temptovar.containsKey(d))
+ return (TempDescriptor)temptovar.get(d);
+ else {
+ if (d instanceof VarDescriptor) {
+ VarDescriptor vd=(VarDescriptor)d;
+ TempDescriptor td=TempDescriptor.paramtempFactory(vd.getName(),vd.getType());
+ temptovar.put(vd,td);
+ return td;
+ } else if (d instanceof TagVarDescriptor) {
+ TagVarDescriptor tvd=(TagVarDescriptor)d;
+ TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
+ TempDescriptor td=TempDescriptor.paramtempFactory(tvd.getName(), tagtype, tvd.getTag());
+ temptovar.put(tvd,td);
+ return td;
+ } else throw new Error("Unreconized Descriptor");
+ }
+ }
+
+ private TempDescriptor getTempforVar(Descriptor d) {
+ if (temptovar.containsKey(d))
+ return (TempDescriptor)temptovar.get(d);
+ else {
+ if (d instanceof VarDescriptor) {
+ VarDescriptor vd=(VarDescriptor)d;
+ TempDescriptor td=TempDescriptor.tempFactory(vd.getName(), vd.getType());
+ temptovar.put(vd,td);
+ return td;
+ } else if (d instanceof TagVarDescriptor) {
+ TagVarDescriptor tvd=(TagVarDescriptor)d;
+ //BUGFIX TAGTYPE - add next line, modify following
+ //line to tag this new type descriptor, modify
+ //TempDescriptor constructor & factory to set type
+ //using this Type To test, use any program with tags
+ TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
+ TempDescriptor td=TempDescriptor.tempFactory(tvd.getName(),tagtype, tvd.getTag());
+ temptovar.put(tvd,td);
+ return td;
+ } else throw new Error("Unrecognized Descriptor");
+ }
+ }
+
+ private NodePair flattenIfStatementNode(IfStatementNode isn) {
+ TempDescriptor cond_temp=TempDescriptor.tempFactory("condition",new TypeDescriptor(TypeDescriptor.BOOLEAN));
+ NodePair cond=flattenExpressionNode(isn.getCondition(),cond_temp);
+ FlatCondBranch fcb=new FlatCondBranch(cond_temp);
+ fcb.setNumLine(isn.getNumLine());
+ NodePair true_np=flattenBlockNode(isn.getTrueBlock());
+ NodePair false_np;
+ FlatNop nopend=new FlatNop();
+
+ if (isn.getFalseBlock()!=null)
+ false_np=flattenBlockNode(isn.getFalseBlock());
+ else {
+ FlatNop nop=new FlatNop();
+ false_np=new NodePair(nop,nop);
+ }
+
+ cond.getEnd().addNext(fcb);
+ fcb.addTrueNext(true_np.getBegin());
+ fcb.addFalseNext(false_np.getBegin());
+ if (true_np.getEnd()!=null)
+ true_np.getEnd().addNext(nopend);
+ if (false_np.getEnd()!=null)
+ false_np.getEnd().addNext(nopend);
+ if (nopend.numPrev()==0)
+ return new NodePair(cond.getBegin(), null);
+
+ return new NodePair(cond.getBegin(), nopend);
+ }
+
+ private NodePair flattenSwitchStatementNode(SwitchStatementNode ssn) {
+ TempDescriptor cond_temp=TempDescriptor.tempFactory("condition",new TypeDescriptor(TypeDescriptor.INT));
+ NodePair cond=flattenExpressionNode(ssn.getCondition(),cond_temp);
+ NodePair sbody = flattenSwitchBodyNode(ssn.getSwitchBody(), cond_temp);
+
+ cond.getEnd().addNext(sbody.getBegin());
+
+ return new NodePair(cond.getBegin(), sbody.getEnd());
+ }
+
+ private NodePair flattenSwitchBodyNode(BlockNode bn, TempDescriptor cond_temp) {
+ FlatNode begin=null;
+ FlatNode end=null;
+ NodePair prev_true_branch = null;
+ NodePair prev_false_branch = null;
+ for(int i=0; i<bn.size(); i++) {
+ SwitchBlockNode sbn = (SwitchBlockNode)bn.get(i);
+ HashSet oldbs=breakset;
+ breakset=new HashSet();
+
+ NodePair body=flattenBlockNode(sbn.getSwitchBlockStatement());
+ Vector<SwitchLabelNode> slnv = sbn.getSwitchConditions();
+ FlatNode cond_begin = null;
+ NodePair prev_fnp = null;
+ for(int j = 0; j < slnv.size(); j++) {
+ SwitchLabelNode sln = slnv.elementAt(j);
+ NodePair left = null;
+ NodePair false_np = null;
+ if(sln.isDefault()) {
+ left = body;
+ } else {
+ TempDescriptor cond_tmp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
+ TempDescriptor temp_left=TempDescriptor.tempFactory("leftop", sln.getCondition().getType());
+ Operation op=new Operation(Operation.EQUAL);
+ left=flattenExpressionNode(sln.getCondition(), temp_left);
+ FlatOpNode fon=new FlatOpNode(cond_tmp, temp_left, cond_temp, op);
+ fon.setNumLine(sln.getNumLine());
+ left.getEnd().addNext(fon);
+
+ FlatCondBranch fcb=new FlatCondBranch(cond_tmp);
+ fcb.setNumLine(bn.getNumLine());
+ fcb.setTrueProb(State.TRUEPROB);
+
+ FlatNop nop=new FlatNop();
+ false_np=new NodePair(nop,nop);
+
+ fon.addNext(fcb);
+ fcb.addTrueNext(body.getBegin());
+ fcb.addFalseNext(false_np.getBegin());
+ }
+ if((prev_fnp != null) && (prev_fnp.getEnd() != null)) {
+ prev_fnp.getEnd().addNext(left.getBegin());
+ }
+ prev_fnp = false_np;
+
+ if (begin==null) {
+ begin = left.getBegin();
+ }
+ if(cond_begin == null) {
+ cond_begin = left.getBegin();
+ }
+ }
+ if((prev_false_branch != null) && (prev_false_branch.getEnd() != null)) {
+ prev_false_branch.getEnd().addNext(cond_begin);
+ }
+ prev_false_branch = prev_fnp;
+ if((prev_true_branch != null) && (prev_true_branch.getEnd() != null)) {
+ prev_true_branch.getEnd().addNext(body.getBegin());
+ }
+ prev_true_branch = body;
+ for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) {
+ FlatNode fn=(FlatNode)breakit.next();
+ breakit.remove();
+ if (end==null)
+ end=new FlatNop();
+ fn.addNext(end);
+ }
+ breakset=oldbs;
+ }
+ if((prev_true_branch != null) && (prev_true_branch.getEnd() != null)) {
+ if (end==null)
+ end=new FlatNop();
+ prev_true_branch.getEnd().addNext(end);
+ }
+ if((prev_false_branch != null) && (prev_false_branch.getEnd() != null)) {
+ if (end==null)
+ end=new FlatNop();
+ prev_false_branch.getEnd().addNext(end);
+ }
+ if(begin == null) {
+ end=begin=new FlatNop();
+ }
+ return new NodePair(begin,end);
+ }
+
+ private NodePair flattenLoopNode(LoopNode ln) {
+
+ HashSet oldbs=breakset;
+ HashSet oldcs=continueset;
+ breakset=new HashSet();
+ continueset=new HashSet();
+
+ if (ln.getType()==LoopNode.FORLOOP) {
+ NodePair initializer=flattenBlockNode(ln.getInitializer());
+ TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
+ NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
+ NodePair update=flattenBlockNode(ln.getUpdate());
+ NodePair body=flattenBlockNode(ln.getBody());
+ FlatNode begin=initializer.getBegin();
+ FlatCondBranch fcb=new FlatCondBranch(cond_temp);
+ fcb.setNumLine(ln.getNumLine());
+ fcb.setTrueProb(State.TRUEPROB);
+ fcb.setLoop();
+ fcb.setLoopEntrance(condition.getBegin());
+ FlatNop nopend=new FlatNop();
+ FlatBackEdge backedge=new FlatBackEdge();
+
+ FlatNop nop2=new FlatNop();
+ initializer.getEnd().addNext(nop2);
+ nop2.addNext(condition.getBegin());
+ if (body.getEnd()!=null)
+ body.getEnd().addNext(update.getBegin());
+ update.getEnd().addNext(backedge);
+ backedge.addNext(condition.getBegin());
+ condition.getEnd().addNext(fcb);
+ fcb.addFalseNext(nopend);
+ fcb.addTrueNext(body.getBegin());
+ for(Iterator contit=continueset.iterator(); contit.hasNext(); ) {
+ FlatNode fn=(FlatNode)contit.next();
+ contit.remove();
+ fn.addNext(update.getBegin());
+ }
+ for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) {
+ FlatNode fn=(FlatNode)breakit.next();
+ breakit.remove();
+ fn.addNext(nopend);
+ }
+ breakset=oldbs;
+ continueset=oldcs;
+ if(ln.getLabel()!=null){
+ state.fn2labelMap.put(condition.getBegin(), ln.getLabel());
+ }
+ return new NodePair(begin,nopend);
+ } else if (ln.getType()==LoopNode.WHILELOOP) {
+ TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
+ NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
+ NodePair body=flattenBlockNode(ln.getBody());
+ FlatNode begin=condition.getBegin();
+ FlatCondBranch fcb=new FlatCondBranch(cond_temp);
+ fcb.setNumLine(ln.getNumLine());
+ fcb.setTrueProb(State.TRUEPROB);
+ fcb.setLoop();
+ fcb.setLoopEntrance(begin);
+ FlatNop nopend=new FlatNop();
+ FlatBackEdge backedge=new FlatBackEdge();
+
+ if (body.getEnd()!=null)
+ body.getEnd().addNext(backedge);
+ backedge.addNext(condition.getBegin());
+
+ condition.getEnd().addNext(fcb);
+ fcb.addFalseNext(nopend);
+ fcb.addTrueNext(body.getBegin());
+
+ for(Iterator contit=continueset.iterator(); contit.hasNext(); ) {
+ FlatNode fn=(FlatNode)contit.next();
+ contit.remove();
+ fn.addNext(backedge);
+ }
+ for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) {
+ FlatNode fn=(FlatNode)breakit.next();
+ breakit.remove();
+ fn.addNext(nopend);
+ }
+ breakset=oldbs;
+ continueset=oldcs;
+ if(ln.getLabel()!=null){
+ state.fn2labelMap.put(begin, ln.getLabel());
+ }
+ return new NodePair(begin,nopend);
+ } else if (ln.getType()==LoopNode.DOWHILELOOP) {
+ TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
+ NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
+ NodePair body=flattenBlockNode(ln.getBody());
+ FlatNode begin=body.getBegin();
+ FlatCondBranch fcb=new FlatCondBranch(cond_temp);
+ fcb.setNumLine(ln.getNumLine());
+ fcb.setTrueProb(State.TRUEPROB);
+ fcb.setLoop();
+ fcb.setLoopEntrance(begin);
+ FlatNop nopend=new FlatNop();
+ FlatBackEdge backedge=new FlatBackEdge();
+
+ if (body.getEnd()!=null)
+ body.getEnd().addNext(condition.getBegin());
+ condition.getEnd().addNext(fcb);
+ fcb.addFalseNext(nopend);
+ fcb.addTrueNext(backedge);
+ backedge.addNext(body.getBegin());
+
+ for(Iterator contit=continueset.iterator(); contit.hasNext(); ) {
+ FlatNode fn=(FlatNode)contit.next();
+ contit.remove();
+ fn.addNext(condition.getBegin());
+ }
+ for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) {
+ FlatNode fn=(FlatNode)breakit.next();
+ breakit.remove();
+ fn.addNext(nopend);
+ }
+ breakset=oldbs;
+ continueset=oldcs;
+ if(ln.getLabel()!=null){
+ state.fn2labelMap.put(begin, ln.getLabel());
+ }
+ return new NodePair(begin,nopend);
+ } else throw new Error();
+ }
+
+ private NodePair flattenReturnNode(ReturnNode rntree) {
+ TempDescriptor retval=null;
+ NodePair cond=null;
+ if (rntree.getReturnExpression()!=null) {
+ retval=TempDescriptor.tempFactory("ret_value", rntree.getReturnExpression().getType());
+ cond=flattenExpressionNode(rntree.getReturnExpression(),retval);
+ }
+
+ FlatReturnNode rnflat=new FlatReturnNode(retval);
+ rnflat.setNumLine(rntree.getNumLine());
+ rnflat.addNext(fe);
+ FlatNode ln=rnflat;
+ if ((state.THREAD||state.MGC)&&!this.lockStack.isEmpty()) {
+ if (state.JNI) {
+ //XXXXXXXXX: FIX THIS
+ } else {
+ FlatNode end = null;
+ MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
+ for(int j = this.lockStack.size(); j > 0; j--) {
+ TempDescriptor thistd = this.lockStack.elementAt(j-1);
+ FlatCall fcunlock = new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
+ fcunlock.setNumLine(rntree.getNumLine());
+ if(end != null) {
+ end.addNext(fcunlock);
+ }
+ end = fcunlock;