6 public class BuildFlat {
9 MethodDescriptor currmd;
16 public BuildFlat(State st, TypeUtil typeutil) {
18 temptovar=new Hashtable();
19 this.typeutil=typeutil;
20 this.breakset=new HashSet();
21 this.continueset=new HashSet();
24 public Hashtable getMap() {
28 public void buildFlat() {
29 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
31 ClassDescriptor cn=(ClassDescriptor)it.next();
35 Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator();
36 while(task_it.hasNext()) {
37 TaskDescriptor td=(TaskDescriptor)task_it.next();
42 private void flattenTask(TaskDescriptor td) {
43 BlockNode bn=state.getMethodBody(td);
44 NodePair np=flattenBlockNode(bn);
45 FlatNode fn=np.getBegin();
47 FlatNode fn2=np.getEnd();
49 if (fn2!=null&& fn2.kind()!=FKind.FlatReturnNode) {
50 FlatReturnNode rnflat=new FlatReturnNode(null);
55 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.PRE);
58 FlatMethod fm=new FlatMethod(td, fe);
61 Hashtable visitedset=new Hashtable();
63 for(int i=0; i<td.numParameters(); i++) {
64 VarDescriptor paramvd=td.getParameter(i);
65 fm.addParameterTemp(getTempforVar(paramvd));
66 TagExpressionList tel=td.getTag(paramvd);
67 //BUG added next line to fix...to test feed in any task program
69 for(int j=0; j<tel.numTags(); j++) {
70 TagVarDescriptor tvd=(TagVarDescriptor) td.getParameterTable().getFromSameScope(tel.getName(j));
71 TempDescriptor tagtmp=getTempforVar(tvd);
72 if (!visitedset.containsKey(tvd.getName())) {
73 visitedset.put(tvd.getName(),tvd.getTag());
74 fm.addTagTemp(tagtmp);
76 TagDescriptor tmptd=(TagDescriptor) visitedset.get(tvd.getName());
77 if (!tmptd.equals(tvd.getTag()))
78 throw new Error("Two different tag types with same name as parameters to:"+td);
80 tel.setTemp(j, tagtmp);
84 /* Flatten Vector of Flag Effects */
85 Vector flags=td.getFlagEffects();
86 updateFlagActionNode(ffan,flags);
88 state.addFlatCode(td,fm);
92 /* This method transforms a vector of FlagEffects into the FlatFlagActionNode */
93 private void updateFlagActionNode(FlatFlagActionNode ffan, Vector flags) {
94 if (flags==null) // Do nothing if the flag effects vector is empty
97 for(int i=0; i<flags.size(); i++) {
98 FlagEffects fes=(FlagEffects)flags.get(i);
99 TempDescriptor flagtemp=getTempforVar(fes.getVar());
101 for(int j=0; j<fes.numEffects(); j++) {
102 FlagEffect fe=fes.getEffect(j);
103 ffan.addFlagAction(flagtemp, fe.getFlag(), fe.getStatus());
106 for(int j=0; j<fes.numTagEffects(); j++) {
107 TagEffect te=fes.getTagEffect(j);
108 TempDescriptor tagtemp=getTempforVar(te.getTag());
110 ffan.addTagAction(flagtemp, te.getTag().getTag(), tagtemp, te.getStatus());
115 FlatAtomicEnterNode curran=null;
117 private void flattenClass(ClassDescriptor cn) {
118 Iterator methodit=cn.getMethods();
119 while(methodit.hasNext()) {
120 currmd=(MethodDescriptor)methodit.next();
122 // if MLP is on, splice a special SESE in to
123 // enclose the main method, and a special SESE
124 // in around every other method that statically
125 // represents the SESE instance that will call
126 // that method at runtime
127 FlatSESEEnterNode spliceSESE = null;
128 FlatSESEExitNode spliceExit = null;
130 if( currmd.equals( typeutil.getMain() ) ) {
131 SESENode mainTree = new SESENode( "main" );
132 spliceSESE = new FlatSESEEnterNode( mainTree );
133 spliceExit = new FlatSESEExitNode ( mainTree );
134 spliceSESE.setFlatExit ( spliceExit );
135 spliceExit.setFlatEnter( spliceSESE );
137 SESENode callerSESETree = new SESENode( "caller SESE placeholder" );
138 spliceSESE = new FlatSESEEnterNode( callerSESETree );
139 spliceSESE.setCallerSESEplaceholder();
140 spliceExit = new FlatSESEExitNode ( callerSESETree );
141 spliceSESE.setFlatExit ( spliceExit );
142 spliceExit.setFlatEnter( spliceSESE );
148 BlockNode bn=state.getMethodBody(currmd);
150 if (state.DSM&&currmd.getModifiers().isAtomic()) {
151 curran=new FlatAtomicEnterNode();
154 NodePair np=flattenBlockNode(bn);
155 FlatNode fn=np.getBegin();
156 if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
157 MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
158 TempDescriptor thistd=getTempforVar(currmd.getThis());
159 FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
162 if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
163 MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
164 FlatCall fcunlock=new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
165 np.getEnd().addNext(fcunlock);
166 FlatReturnNode rnflat=new FlatReturnNode(null);
167 fcunlock.addNext(rnflat);
170 } else if (state.DSM&&currmd.getModifiers().isAtomic()) {
173 if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
174 FlatAtomicExitNode aen=new FlatAtomicExitNode(curran);
175 np.getEnd().addNext(aen);
176 FlatReturnNode rnflat=new FlatReturnNode(null);
181 } else if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
182 FlatReturnNode rnflat=new FlatReturnNode(null);
183 // splice implicit SESE exit after method body
185 np.getEnd().addNext(spliceExit);
186 spliceExit.addNext(rnflat);
188 np.getEnd().addNext(rnflat);
192 } else if (np.getEnd()!=null) {
193 // splice implicit SESE exit after method body
195 FlatReturnNode rnflat=(FlatReturnNode)np.getEnd();
196 np.getEnd().addNext(spliceExit);
197 spliceExit.addNext(fe);
201 // splice an implicit SESE enter before method body
203 spliceSESE.addNext(fn);
207 FlatMethod fm=new FlatMethod(currmd, fe);
209 if (!currmd.isStatic())
210 fm.addParameterTemp(getTempforParam(currmd.getThis()));
211 for(int i=0; i<currmd.numParameters(); i++) {
212 fm.addParameterTemp(getTempforParam(currmd.getParameter(i)));
215 state.addFlatCode(currmd,fm);
219 private NodePair flattenBlockNode(BlockNode bn) {
222 for(int i=0; i<bn.size(); i++) {
223 NodePair np=flattenBlockStatementNode(bn.get(i));
224 FlatNode np_begin=np.getBegin();
225 FlatNode np_end=np.getEnd();
232 end.addNext(np_begin);
234 return new NodePair(begin, null);
240 end=begin=new FlatNop();
242 return new NodePair(begin,end);
245 private NodePair flattenBlockExpressionNode(BlockExpressionNode en) {
246 //System.out.println("DEBUG -> inside flattenBlockExpressionNode\n");
247 TempDescriptor tmp=TempDescriptor.tempFactory("neverused",en.getExpression().getType());
248 return flattenExpressionNode(en.getExpression(),tmp);
251 private NodePair flattenCastNode(CastNode cn,TempDescriptor out_temp) {
252 TempDescriptor tmp=TempDescriptor.tempFactory("tocast",cn.getExpression().getType());
253 NodePair np=flattenExpressionNode(cn.getExpression(), tmp);
254 FlatCastNode fcn=new FlatCastNode(cn.getType(), tmp, out_temp);
255 np.getEnd().addNext(fcn);
256 return new NodePair(np.getBegin(),fcn);
259 private NodePair flattenLiteralNode(LiteralNode ln,TempDescriptor out_temp) {
260 FlatLiteralNode fln=new FlatLiteralNode(ln.getType(), ln.getValue(), out_temp);
261 return new NodePair(fln,fln);
264 private NodePair flattenOffsetNode(OffsetNode ofn, TempDescriptor out_temp) {
265 FlatOffsetNode fln = new FlatOffsetNode(ofn.getClassType(), ofn.getField(), out_temp);
266 return new NodePair(fln, fln);
269 private NodePair flattenCreateObjectNode(CreateObjectNode con,TempDescriptor out_temp) {
270 TypeDescriptor td=con.getType();
272 FlatNode fn=new FlatNew(td, out_temp, con.isGlobal(), con.getDisjointId());
274 //handle wrapper fields
275 ClassDescriptor cd=td.getClassDesc();
276 for(Iterator fieldit=cd.getFields();fieldit.hasNext();) {
277 FieldDescriptor fd=(FieldDescriptor)fieldit.next();
278 if (fd.getType().iswrapper()) {
279 TempDescriptor wrap_tmp=TempDescriptor.tempFactory("wrapper_obj",fd.getType());
280 FlatNode fnwrapper=new FlatNew(fd.getType(), wrap_tmp, con.isGlobal());
281 FlatSetFieldNode fsfn=new FlatSetFieldNode(out_temp, fd, wrap_tmp);
282 last.addNext(fnwrapper);
283 fnwrapper.addNext(fsfn);
288 TempDescriptor[] temps=new TempDescriptor[con.numArgs()];
291 for(int i=0; i<con.numArgs(); i++) {
292 ExpressionNode en=con.getArg(i);
293 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
295 NodePair np=flattenExpressionNode(en, tmp);
296 last.addNext(np.getBegin());
299 MethodDescriptor md=con.getConstructor();
300 //Call to constructor
301 FlatCall fc=new FlatCall(md, null, out_temp, temps);
304 if (td.getClassDesc().hasFlags()) {
305 // if (con.getFlagEffects()!=null) {
306 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.NEWOBJECT);
307 FlagEffects fes=con.getFlagEffects();
308 TempDescriptor flagtemp=out_temp;
310 for(int j=0; j<fes.numEffects(); j++) {
311 FlagEffect fe=fes.getEffect(j);
312 ffan.addFlagAction(flagtemp, fe.getFlag(), fe.getStatus());
314 for(int j=0; j<fes.numTagEffects(); j++) {
315 TagEffect te=fes.getTagEffect(j);
316 TempDescriptor tagtemp=getTempforVar(te.getTag());
318 ffan.addTagAction(flagtemp, te.getTag().getTag(), tagtemp, te.getStatus());
321 ffan.addFlagAction(flagtemp, null, false);
326 return new NodePair(fn,last);
330 TempDescriptor[] temps=new TempDescriptor[con.numArgs()];
331 for (int i=0; i<con.numArgs(); i++) {
332 ExpressionNode en=con.getArg(i);
333 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
335 NodePair np=flattenExpressionNode(en, tmp);
339 last.addNext(np.getBegin());
342 TempDescriptor tmp2=(i==0) ?
344 TempDescriptor.tempFactory("arg",en.getType());
346 FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
348 if (temps.length>1) {
349 NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
350 fn.addNext(np.getBegin());
351 return new NodePair(first,np.getEnd());
352 } else if (td.isArray()&&td.dereference().iswrapper()) {
353 NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
354 fn.addNext(np.getBegin());
355 return new NodePair(first,np.getEnd());
357 return new NodePair(first, fn);
361 private NodePair generateNewArrayLoop(TempDescriptor[] temparray, TypeDescriptor td, TempDescriptor tmp, int i, boolean isglobal) {
362 TempDescriptor index=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT));
363 TempDescriptor tmpone=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT));
364 FlatNop fnop=new FlatNop(); //last node
367 FlatLiteralNode fln=new FlatLiteralNode(index.getType(),new Integer(0),index);
369 FlatLiteralNode fln2=new FlatLiteralNode(tmpone.getType(),new Integer(1),tmpone);
371 TempDescriptor tmpbool=TempDescriptor.tempFactory("comp",new TypeDescriptor(TypeDescriptor.BOOLEAN));
373 FlatOpNode fcomp=new FlatOpNode(tmpbool,index,temparray[i],new Operation(Operation.LT));
374 FlatCondBranch fcb=new FlatCondBranch(tmpbool);
375 fcb.setTrueProb(State.TRUEPROB);
378 TempDescriptor new_tmp=TempDescriptor.tempFactory("tmp",td);
379 FlatNew fn=td.iswrapper()?new FlatNew(td, new_tmp, isglobal):new FlatNew(td, new_tmp, temparray[i+1], isglobal);
380 FlatSetElementNode fsen=new FlatSetElementNode(tmp,index,new_tmp);
382 FlatOpNode fon=new FlatOpNode(index,index,tmpone,new Operation(Operation.ADD));
388 fcb.addFalseNext(fnop);
390 //Recursive call here
391 if ((i+2)<temparray.length) {
392 NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
393 fsen.addNext(np2.getBegin());
394 np2.getEnd().addNext(fon);
395 } else if (td.isArray()&&td.dereference().iswrapper()) {
396 NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
397 fsen.addNext(np2.getBegin());
398 np2.getEnd().addNext(fon);
403 return new NodePair(fln, fnop);
406 private NodePair flattenMethodInvokeNode(MethodInvokeNode min,TempDescriptor out_temp) {
407 TempDescriptor[] temps=new TempDescriptor[min.numArgs()];
410 TempDescriptor thisarg=null;
412 if (min.getExpression()!=null) {
413 thisarg=TempDescriptor.tempFactory("thisarg",min.getExpression().getType());
414 NodePair np=flattenExpressionNode(min.getExpression(),thisarg);
420 for(int i=0; i<min.numArgs(); i++) {
421 ExpressionNode en=min.getArg(i);
422 TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
424 NodePair np=flattenExpressionNode(en, td);
428 last.addNext(np.getBegin());
432 MethodDescriptor md=min.getMethod();
434 //Call to constructor
437 if(md.getReturnType()==null||md.getReturnType().isVoid())
438 fc=new FlatCall(md, null, thisarg, temps);
440 fc=new FlatCall(md, out_temp, thisarg, temps);
445 return new NodePair(first,fc);
448 private NodePair flattenFieldAccessNode(FieldAccessNode fan,TempDescriptor out_temp) {
449 TempDescriptor tmp=TempDescriptor.tempFactory("temp",fan.getExpression().getType());
450 NodePair npe=flattenExpressionNode(fan.getExpression(),tmp);
451 FlatFieldNode fn=new FlatFieldNode(fan.getField(),tmp,out_temp);
452 npe.getEnd().addNext(fn);
453 return new NodePair(npe.getBegin(),fn);
456 private NodePair flattenArrayAccessNode(ArrayAccessNode aan,TempDescriptor out_temp) {
457 TempDescriptor tmp=TempDescriptor.tempFactory("temp",aan.getExpression().getType());
458 TempDescriptor tmpindex=TempDescriptor.tempFactory("temp",aan.getIndex().getType());
459 NodePair npe=flattenExpressionNode(aan.getExpression(),tmp);
460 NodePair npi=flattenExpressionNode(aan.getIndex(),tmpindex);
461 TempDescriptor arraytmp=out_temp;
462 if (aan.iswrapper()) {
464 arraytmp=TempDescriptor.tempFactory("temp", aan.getExpression().getType().dereference());
466 FlatNode fn=new FlatElementNode(tmp,tmpindex,arraytmp);
467 npe.getEnd().addNext(npi.getBegin());
468 npi.getEnd().addNext(fn);
469 if (aan.iswrapper()) {
470 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)aan.getExpression().getType().dereference().getClassDesc().getFieldTable().get("value") ,arraytmp,out_temp);
474 return new NodePair(npe.getBegin(),fn);
477 private NodePair flattenAssignmentNode(AssignmentNode an,TempDescriptor out_temp) {
479 // left side is variable
480 // left side is field
481 // left side is array
483 Operation base=an.getOperation().getBaseOp();
484 boolean pre=base==null||(base.getOp()!=Operation.POSTINC&&base.getOp()!=Operation.POSTDEC);
487 //rewrite the base operation
488 base=base.getOp()==Operation.POSTINC ? new Operation(Operation.ADD) : new Operation(Operation.SUB);
492 TempDescriptor src_tmp = src_tmp=an.getSrc()==null ? TempDescriptor.tempFactory("srctmp",an.getDest().getType()) : TempDescriptor.tempFactory("srctmp",an.getSrc().getType());
495 if (an.getSrc()!=null) {
496 NodePair np_src=flattenExpressionNode(an.getSrc(),src_tmp);
497 first=np_src.getBegin();
498 last=np_src.getEnd();
500 FlatLiteralNode fln=new FlatLiteralNode(new TypeDescriptor(TypeDescriptor.INT),new Integer(1),src_tmp);
505 if (an.getDest().kind()==Kind.FieldAccessNode) {
506 //We are assigning an object field
508 FieldAccessNode fan=(FieldAccessNode)an.getDest();
509 ExpressionNode en=fan.getExpression();
510 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
511 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
513 first=np_baseexp.getBegin();
515 last.addNext(np_baseexp.getBegin());
516 last=np_baseexp.getEnd();
518 //See if we need to perform an operation
520 //If it is a preinc we need to store the initial value
521 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
522 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
523 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
527 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
528 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
529 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
530 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
535 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
542 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
546 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
550 return new NodePair(first, last);
551 } else if (an.getDest().kind()==Kind.ArrayAccessNode) {
552 //We are assigning an array element
554 ArrayAccessNode aan=(ArrayAccessNode)an.getDest();
555 ExpressionNode en=aan.getExpression();
556 ExpressionNode enindex=aan.getIndex();
557 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
558 TempDescriptor index_tmp=TempDescriptor.tempFactory("index",enindex.getType());
559 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
560 NodePair np_indexexp=flattenExpressionNode(enindex, index_tmp);
562 first=np_baseexp.getBegin();
564 last.addNext(np_baseexp.getBegin());
565 np_baseexp.getEnd().addNext(np_indexexp.getBegin());
566 last=np_indexexp.getEnd();
568 //See if we need to perform an operation
570 //If it is a preinc we need to store the initial value
571 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
572 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
574 if (aan.iswrapper()) {
575 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
576 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
577 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
578 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp3,src_tmp2);
583 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
587 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
588 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
589 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
590 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
595 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
602 if (aan.iswrapper()) {
603 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
604 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
605 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
606 FlatSetFieldNode fsfn=new FlatSetFieldNode(src_tmp3,(FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp);
611 FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
616 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
620 return new NodePair(first, last);
621 } else if (an.getDest().kind()==Kind.NameNode) {
622 //We could be assigning a field or variable
623 NameNode nn=(NameNode)an.getDest();
626 if (nn.getExpression()!=null) {
628 FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
629 ExpressionNode en=fan.getExpression();
630 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
631 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
633 first=np_baseexp.getBegin();
635 last.addNext(np_baseexp.getBegin());
636 last=np_baseexp.getEnd();
638 //See if we need to perform an operation
640 //If it is a preinc we need to store the initial value
641 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
642 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
644 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
649 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
650 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
651 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
652 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
657 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
665 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
669 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
673 return new NodePair(first, last);
675 if (nn.getField()!=null) {
679 //See if we need to perform an operation
681 //If it is a preinc we need to store the initial value
682 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
683 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
685 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), getTempforVar(nn.getVar()), src_tmp2);
694 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
695 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
696 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
697 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
702 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
709 FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
717 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
721 return new NodePair(first, last);
724 //See if we need to perform an operation
727 //If it is a preinc we need to store the initial value
728 TempDescriptor src_tmp2=getTempforVar(nn.getVar());
729 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
731 FlatOpNode fon=new FlatOpNode(out_temp, src_tmp2, null, new Operation(Operation.ASSIGN));
740 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
741 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
742 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
743 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
751 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
761 FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
766 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
770 return new NodePair(first, last);
778 private NodePair flattenNameNode(NameNode nn,TempDescriptor out_temp) {
779 if (nn.getExpression()!=null) {
780 /* Hack - use subtree instead */
781 return flattenExpressionNode(nn.getExpression(),out_temp);
782 } else if (nn.getField()!=null) {
783 TempDescriptor tmp=getTempforVar(nn.getVar());
784 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), tmp, out_temp);
785 return new NodePair(ffn,ffn);
787 TempDescriptor tmp=getTempforVar(nn.isTag() ? nn.getTagVar() : nn.getVar());
790 out_temp.setTag(tmp.getTag());
792 FlatOpNode fon=new FlatOpNode(out_temp, tmp, null, new Operation(Operation.ASSIGN));
793 return new NodePair(fon,fon);
797 private NodePair flattenOpNode(OpNode on,TempDescriptor out_temp) {
798 TempDescriptor temp_left=TempDescriptor.tempFactory("leftop",on.getLeft().getType());
799 TempDescriptor temp_right=null;
801 Operation op=on.getOp();
803 NodePair left=flattenExpressionNode(on.getLeft(),temp_left);
805 if (on.getRight()!=null) {
806 temp_right=TempDescriptor.tempFactory("rightop",on.getRight().getType());
807 right=flattenExpressionNode(on.getRight(),temp_right);
809 FlatNop nop=new FlatNop();
810 right=new NodePair(nop,nop);
813 if (op.getOp()==Operation.LOGIC_OR) {
814 /* Need to do shortcircuiting */
815 FlatCondBranch fcb=new FlatCondBranch(temp_left);
816 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
817 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
818 FlatNop fnop=new FlatNop();
819 left.getEnd().addNext(fcb);
820 fcb.addFalseNext(right.getBegin());
821 right.getEnd().addNext(fon2);
823 fcb.addTrueNext(fon1);
825 return new NodePair(left.getBegin(), fnop);
826 } else if (op.getOp()==Operation.LOGIC_AND) {
827 /* Need to do shortcircuiting */
828 FlatCondBranch fcb=new FlatCondBranch(temp_left);
829 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
830 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
831 FlatNop fnop=new FlatNop();
832 left.getEnd().addNext(fcb);
833 fcb.addTrueNext(right.getBegin());
834 right.getEnd().addNext(fon2);
836 fcb.addFalseNext(fon1);
838 return new NodePair(left.getBegin(), fnop);
839 } else if (op.getOp()==Operation.ADD&&on.getLeft().getType().isString()) {
840 //We have a string concatenate
841 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
842 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
843 FlatCall fc=new FlatCall(concatmd, out_temp, temp_left, new TempDescriptor[] {temp_right});
844 left.getEnd().addNext(right.getBegin());
845 right.getEnd().addNext(fc);
846 return new NodePair(left.getBegin(), fc);
849 FlatOpNode fon=new FlatOpNode(out_temp,temp_left,temp_right,op);
850 left.getEnd().addNext(right.getBegin());
851 right.getEnd().addNext(fon);
852 return new NodePair(left.getBegin(),fon);
855 private NodePair flattenExpressionNode(ExpressionNode en, TempDescriptor out_temp) {
857 case Kind.AssignmentNode:
858 return flattenAssignmentNode((AssignmentNode)en,out_temp);
861 return flattenCastNode((CastNode)en,out_temp);
863 case Kind.CreateObjectNode:
864 return flattenCreateObjectNode((CreateObjectNode)en,out_temp);
866 case Kind.FieldAccessNode:
867 return flattenFieldAccessNode((FieldAccessNode)en,out_temp);
869 case Kind.ArrayAccessNode:
870 return flattenArrayAccessNode((ArrayAccessNode)en,out_temp);
872 case Kind.LiteralNode:
873 return flattenLiteralNode((LiteralNode)en,out_temp);
875 case Kind.MethodInvokeNode:
876 return flattenMethodInvokeNode((MethodInvokeNode)en,out_temp);
879 return flattenNameNode((NameNode)en,out_temp);
882 return flattenOpNode((OpNode)en,out_temp);
884 case Kind.OffsetNode:
885 return flattenOffsetNode((OffsetNode)en,out_temp);
887 case Kind.TertiaryNode:
888 return flattenTertiaryNode((TertiaryNode)en,out_temp);
890 case Kind.InstanceOfNode:
891 return flattenInstanceOfNode((InstanceOfNode)en,out_temp);
893 case Kind.ArrayInitializerNode:
894 return flattenArrayInitializerNode((ArrayInitializerNode)en,out_temp);
899 private NodePair flattenDeclarationNode(DeclarationNode dn) {
900 VarDescriptor vd=dn.getVarDescriptor();
901 TempDescriptor td=getTempforVar(vd);
902 if (dn.getExpression()!=null)
903 return flattenExpressionNode(dn.getExpression(),td);
905 FlatNop fn=new FlatNop();
906 return new NodePair(fn,fn);
910 private NodePair flattenTagDeclarationNode(TagDeclarationNode dn) {
911 TagVarDescriptor tvd=dn.getTagVarDescriptor();
912 TagDescriptor tag=tvd.getTag();
913 TempDescriptor tmp=getTempforVar(tvd);
914 FlatTagDeclaration ftd=new FlatTagDeclaration(tag, tmp);
915 return new NodePair(ftd,ftd);
918 private TempDescriptor getTempforParam(Descriptor d) {
919 if (temptovar.containsKey(d))
920 return (TempDescriptor)temptovar.get(d);
922 if (d instanceof VarDescriptor) {
923 VarDescriptor vd=(VarDescriptor)d;
924 TempDescriptor td=TempDescriptor.paramtempFactory(vd.getName(),vd.getType());
925 temptovar.put(vd,td);
927 } else if (d instanceof TagVarDescriptor) {
928 TagVarDescriptor tvd=(TagVarDescriptor)d;
929 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
930 TempDescriptor td=TempDescriptor.paramtempFactory(tvd.getName(), tagtype, tvd.getTag());
931 temptovar.put(tvd,td);
933 } else throw new Error("Unreconized Descriptor");
937 private TempDescriptor getTempforVar(Descriptor d) {
938 if (temptovar.containsKey(d))
939 return (TempDescriptor)temptovar.get(d);
941 if (d instanceof VarDescriptor) {
942 VarDescriptor vd=(VarDescriptor)d;
943 TempDescriptor td=TempDescriptor.tempFactory(vd.getName(), vd.getType());
944 temptovar.put(vd,td);
946 } else if (d instanceof TagVarDescriptor) {
947 TagVarDescriptor tvd=(TagVarDescriptor)d;
948 //BUGFIX TAGTYPE - add next line, modify following
949 //line to tag this new type descriptor, modify
950 //TempDescriptor constructor & factory to set type
951 //using this Type To test, use any program with tags
952 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
953 TempDescriptor td=TempDescriptor.tempFactory(tvd.getName(),tagtype, tvd.getTag());
954 temptovar.put(tvd,td);
956 } else throw new Error("Unrecognized Descriptor");
960 private NodePair flattenIfStatementNode(IfStatementNode isn) {
961 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition",new TypeDescriptor(TypeDescriptor.BOOLEAN));
962 NodePair cond=flattenExpressionNode(isn.getCondition(),cond_temp);
963 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
964 NodePair true_np=flattenBlockNode(isn.getTrueBlock());
966 FlatNop nopend=new FlatNop();
968 if (isn.getFalseBlock()!=null)
969 false_np=flattenBlockNode(isn.getFalseBlock());
971 FlatNop nop=new FlatNop();
972 false_np=new NodePair(nop,nop);
975 cond.getEnd().addNext(fcb);
976 fcb.addTrueNext(true_np.getBegin());
977 fcb.addFalseNext(false_np.getBegin());
978 if (true_np.getEnd()!=null)
979 true_np.getEnd().addNext(nopend);
980 if (false_np.getEnd()!=null)
981 false_np.getEnd().addNext(nopend);
982 if (nopend.numPrev()==0)
983 return new NodePair(cond.getBegin(), null);
985 return new NodePair(cond.getBegin(), nopend);
988 private NodePair flattenLoopNode(LoopNode ln) {
989 HashSet oldbs=breakset;
990 HashSet oldcs=continueset;
991 breakset=new HashSet();
992 continueset=new HashSet();
994 if (ln.getType()==LoopNode.FORLOOP) {
995 NodePair initializer=flattenBlockNode(ln.getInitializer());
996 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
997 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
998 NodePair update=flattenBlockNode(ln.getUpdate());
999 NodePair body=flattenBlockNode(ln.getBody());
1000 FlatNode begin=initializer.getBegin();
1001 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1002 fcb.setTrueProb(State.TRUEPROB);
1004 FlatNop nopend=new FlatNop();
1005 FlatBackEdge backedge=new FlatBackEdge();
1007 FlatNop nop2=new FlatNop();
1008 initializer.getEnd().addNext(nop2);
1009 nop2.addNext(condition.getBegin());
1010 if (body.getEnd()!=null)
1011 body.getEnd().addNext(update.getBegin());
1012 update.getEnd().addNext(backedge);
1013 backedge.addNext(condition.getBegin());
1014 condition.getEnd().addNext(fcb);
1015 fcb.addFalseNext(nopend);
1016 fcb.addTrueNext(body.getBegin());
1017 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1018 FlatNode fn=(FlatNode)contit.next();
1020 fn.addNext(update.getBegin());
1022 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1023 FlatNode fn=(FlatNode)breakit.next();
1029 return new NodePair(begin,nopend);
1030 } else if (ln.getType()==LoopNode.WHILELOOP) {
1031 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1032 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1033 NodePair body=flattenBlockNode(ln.getBody());
1034 FlatNode begin=condition.getBegin();
1035 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1036 fcb.setTrueProb(State.TRUEPROB);
1038 FlatNop nopend=new FlatNop();
1039 FlatBackEdge backedge=new FlatBackEdge();
1041 if (body.getEnd()!=null)
1042 body.getEnd().addNext(backedge);
1043 backedge.addNext(condition.getBegin());
1045 condition.getEnd().addNext(fcb);
1046 fcb.addFalseNext(nopend);
1047 fcb.addTrueNext(body.getBegin());
1049 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1050 FlatNode fn=(FlatNode)contit.next();
1052 fn.addNext(backedge);
1054 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1055 FlatNode fn=(FlatNode)breakit.next();
1061 return new NodePair(begin,nopend);
1062 } else if (ln.getType()==LoopNode.DOWHILELOOP) {
1063 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1064 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1065 NodePair body=flattenBlockNode(ln.getBody());
1066 FlatNode begin=body.getBegin();
1067 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1068 fcb.setTrueProb(State.TRUEPROB);
1070 FlatNop nopend=new FlatNop();
1071 FlatBackEdge backedge=new FlatBackEdge();
1073 if (body.getEnd()!=null)
1074 body.getEnd().addNext(condition.getBegin());
1075 condition.getEnd().addNext(fcb);
1076 fcb.addFalseNext(nopend);
1077 fcb.addTrueNext(backedge);
1078 backedge.addNext(body.getBegin());
1080 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1081 FlatNode fn=(FlatNode)contit.next();
1083 fn.addNext(condition.getBegin());
1085 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1086 FlatNode fn=(FlatNode)breakit.next();
1092 return new NodePair(begin,nopend);
1093 } else throw new Error();
1096 private NodePair flattenReturnNode(ReturnNode rntree) {
1097 TempDescriptor retval=null;
1099 if (rntree.getReturnExpression()!=null) {
1100 retval=TempDescriptor.tempFactory("ret_value", rntree.getReturnExpression().getType());
1101 cond=flattenExpressionNode(rntree.getReturnExpression(),retval);
1104 FlatReturnNode rnflat=new FlatReturnNode(retval);
1107 if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
1108 MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1109 TempDescriptor thistd=getTempforVar(currmd.getThis());
1110 FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
1114 if (state.DSM&&currmd.getModifiers().isAtomic()) {
1115 FlatAtomicExitNode faen=new FlatAtomicExitNode(curran);
1121 cond.getEnd().addNext(ln);
1122 return new NodePair(cond.getBegin(),null);
1124 return new NodePair(ln,null);
1127 private NodePair flattenTaskExitNode(TaskExitNode ten) {
1128 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.TASKEXIT);
1129 ffan.setTaskExitIndex(ten.getTaskExitIndex());
1130 updateFlagActionNode(ffan, ten.getFlagEffects());
1131 NodePair fcn=flattenConstraintCheck(ten.getChecks());
1132 ffan.addNext(fcn.getBegin());
1133 FlatReturnNode rnflat=new FlatReturnNode(null);
1135 fcn.getEnd().addNext(rnflat);
1136 return new NodePair(ffan, null);
1139 private NodePair flattenConstraintCheck(Vector ccs) {
1140 FlatNode begin=new FlatNop();
1142 return new NodePair(begin,begin);
1143 FlatNode last=begin;
1144 for(int i=0; i<ccs.size(); i++) {
1145 ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
1146 /* Flatten the arguments */
1147 TempDescriptor[] temps=new TempDescriptor[cc.numArgs()];
1148 String[] vars=new String[cc.numArgs()];
1149 for(int j=0; j<cc.numArgs(); j++) {
1150 ExpressionNode en=cc.getArg(j);
1151 TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
1153 vars[j]=cc.getVar(j);
1154 NodePair np=flattenExpressionNode(en, td);
1155 last.addNext(np.getBegin());
1159 FlatCheckNode fcn=new FlatCheckNode(cc.getSpec(), vars, temps);
1163 return new NodePair(begin,last);
1166 private NodePair flattenSubBlockNode(SubBlockNode sbn) {
1167 return flattenBlockNode(sbn.getBlockNode());
1170 private NodePair flattenSynchronizedNode(SynchronizedNode sbn) {
1171 TempDescriptor montmp=TempDescriptor.tempFactory("monitor",sbn.getExpr().getType());
1172 NodePair npexp=flattenExpressionNode(sbn.getExpr(), montmp);
1173 NodePair npblock=flattenBlockNode(sbn.getBlockNode());
1175 MethodDescriptor menmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
1176 FlatCall fcen=new FlatCall(menmd, null, montmp, new TempDescriptor[0]);
1178 MethodDescriptor mexmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1179 FlatCall fcex=new FlatCall(mexmd, null, montmp, new TempDescriptor[0]);
1181 npexp.getEnd().addNext(fcen);
1182 fcen.addNext(npblock.getBegin());
1183 npblock.getEnd().addNext(fcex);
1184 return new NodePair(npexp.getBegin(), fcex);
1187 private NodePair flattenAtomicNode(AtomicNode sbn) {
1188 NodePair np=flattenBlockNode(sbn.getBlockNode());
1189 FlatAtomicEnterNode faen=new FlatAtomicEnterNode();
1190 FlatAtomicExitNode faexn=new FlatAtomicExitNode(faen);
1191 faen.addNext(np.getBegin());
1192 np.getEnd().addNext(faexn);
1193 return new NodePair(faen, faexn);
1196 private NodePair flattenSESENode(SESENode sn) {
1197 if( sn.isStart() ) {
1198 FlatSESEEnterNode fsen=new FlatSESEEnterNode(sn);
1199 sn.setFlatEnter(fsen);
1200 return new NodePair(fsen, fsen);
1203 FlatSESEExitNode fsexn=new FlatSESEExitNode(sn);
1204 sn.setFlatExit(fsexn);
1205 FlatSESEEnterNode fsen=sn.getStart().getFlatEnter();
1206 fsexn.setFlatEnter(fsen);
1207 sn.getStart().getFlatEnter().setFlatExit( fsexn );
1209 return new NodePair(fsexn, fsexn);
1212 private NodePair flattenContinueBreakNode(ContinueBreakNode cbn) {
1213 FlatNop fn=new FlatNop();
1217 continueset.add(fn);
1218 return new NodePair(fn,null);
1221 private NodePair flattenInstanceOfNode(InstanceOfNode tn, TempDescriptor out_temp) {
1222 TempDescriptor expr_temp=TempDescriptor.tempFactory("expr",tn.getExpr().getType());
1223 NodePair cond=flattenExpressionNode(tn.getExpr(), expr_temp);
1224 FlatInstanceOfNode fion=new FlatInstanceOfNode(tn.getExprType(), expr_temp, out_temp);
1225 cond.getEnd().addNext(fion);
1226 return new NodePair(cond.getBegin(),fion);
1229 private NodePair flattenArrayInitializerNode(ArrayInitializerNode ain, TempDescriptor out_temp) {
1231 TempDescriptor expr_temp=TempDescriptor.tempFactory("arry_init",ain.getType());
1233 // create a new array of size equal to the array initializer
1234 //FlatNode first=null;
1235 //FlatNode last=null;
1236 TempDescriptor[] temps=new TempDescriptor[ain.numVarInitializers()];
1238 for (int i=0; i<con.numArgs(); i++) {
1239 ExpressionNode en=con.getArg(i);
1240 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
1242 NodePair np=flattenExpressionNode(en, tmp);
1244 first=np.getBegin();
1246 last.addNext(np.getBegin());
1249 TempDescriptor tmp2=(i==0) ?
1251 TempDescriptor.tempFactory("arg",en.getType());
1253 FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
1257 // assign each element of the new array to the flattened expression
1260 FlatOpNode fonAssignArray=new FlatOpNode(out_temp, newarry_temp, null, new Operation(Operation.ASSIGN));
1262 //return new NodePair( , fonAssignArray );
1264 System.out.println( "Array initializers not implemented yet." );
1269 private NodePair flattenTertiaryNode(TertiaryNode tn, TempDescriptor out_temp) {
1270 TempDescriptor cond_temp=TempDescriptor.tempFactory("tert_cond",new TypeDescriptor(TypeDescriptor.BOOLEAN));
1271 TempDescriptor true_temp=TempDescriptor.tempFactory("tert_true",tn.getTrueExpr().getType());
1272 TempDescriptor fals_temp=TempDescriptor.tempFactory("tert_fals",tn.getFalseExpr().getType());
1274 NodePair cond=flattenExpressionNode(tn.getCond(),cond_temp);
1275 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1277 NodePair trueExpr=flattenExpressionNode(tn.getTrueExpr(),true_temp);
1278 FlatOpNode fonT=new FlatOpNode(out_temp, true_temp, null, new Operation(Operation.ASSIGN));
1280 NodePair falseExpr=flattenExpressionNode(tn.getFalseExpr(),fals_temp);
1281 FlatOpNode fonF=new FlatOpNode(out_temp, fals_temp, null, new Operation(Operation.ASSIGN));
1283 FlatNop nopend=new FlatNop();
1285 cond.getEnd().addNext(fcb);
1287 fcb.addTrueNext(trueExpr.getBegin());
1288 fcb.addFalseNext(falseExpr.getBegin());
1290 trueExpr.getEnd().addNext(fonT);
1291 fonT.addNext(nopend);
1293 falseExpr.getEnd().addNext(fonF);
1294 fonF.addNext(nopend);
1296 return new NodePair(cond.getBegin(), nopend);
1299 private NodePair flattenBlockStatementNode(BlockStatementNode bsn) {
1300 switch(bsn.kind()) {
1301 case Kind.BlockExpressionNode:
1302 return flattenBlockExpressionNode((BlockExpressionNode)bsn);
1304 case Kind.DeclarationNode:
1305 return flattenDeclarationNode((DeclarationNode)bsn);
1307 case Kind.TagDeclarationNode:
1308 return flattenTagDeclarationNode((TagDeclarationNode)bsn);
1310 case Kind.IfStatementNode:
1311 return flattenIfStatementNode((IfStatementNode)bsn);
1314 return flattenLoopNode((LoopNode)bsn);
1316 case Kind.ReturnNode:
1317 return flattenReturnNode((IR.Tree.ReturnNode)bsn);
1319 case Kind.TaskExitNode:
1320 return flattenTaskExitNode((IR.Tree.TaskExitNode)bsn);
1322 case Kind.SubBlockNode:
1323 return flattenSubBlockNode((SubBlockNode)bsn);
1325 case Kind.AtomicNode:
1326 return flattenAtomicNode((AtomicNode)bsn);
1328 case Kind.SynchronizedNode:
1329 return flattenSynchronizedNode((SynchronizedNode)bsn);
1332 return flattenSESENode((SESENode)bsn);
1334 case Kind.ContinueBreakNode:
1335 return flattenContinueBreakNode((ContinueBreakNode)bsn);