// for synchronized blocks
Stack<TempDescriptor> lockStack;
+
+ // maps tree node to the set of flat node that is translated from the tree node
+ // WARNING: ONLY DID FOR NAMENODE NOW!
+ Hashtable<TreeNode,Set<FlatNode>> mapNode2FlatNodeSet;
public BuildFlat(State st, TypeUtil typeutil) {
state=st;
this.breakset=new HashSet();
this.continueset=new HashSet();
this.lockStack = new Stack<TempDescriptor>();
+ this.mapNode2FlatNodeSet=new Hashtable<TreeNode,Set<FlatNode>>();
}
public Hashtable getMap() {
NodePair np=flattenBlockStatementNode(bn.get(i));
FlatNode np_begin=np.getBegin();
FlatNode np_end=np.getEnd();
- if(bn.getLabel()!=null) {
- // interim implementation to have the labeled statement
- state.fn2labelMap.put(np_begin, bn.getLabel());
- }
if (begin==null) {
begin=np_begin;
}
if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
- MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
- FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+ 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(fc);
+ last.addNext(fc1);
+ fc1.addNext(fc);
last=fc;
} else {
FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
}
if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
- MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
- FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+ 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(fc);
+ last.addNext(fc1);
+ fc1.addNext(fc);
last=fc;
} else {
FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
- ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
- MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
- FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
- fc.setNumLine(an.getNumLine());
- src_tmp=tmp;
- last.addNext(fc);
- last=fc;
+ 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);
+ last=fc;
} else {
FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
fon.setNumLine(an.getNumLine());
if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
- ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
- MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
- FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
- fc.setNumLine(an.getNumLine());
- src_tmp=tmp;
- last.addNext(fc);
+ 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);
if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
- ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
- MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
- FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
- fc.setNumLine(an.getNumLine());
+ 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=fc;
+ first=fc1;
else
- last.addNext(fc);
+ last.addNext(fc1);
src_tmp=tmp;
last=fc;
} else {
}
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());
}
FlatOpNode fon=new FlatOpNode(out_temp, tmp, null, new Operation(Operation.ASSIGN));
fon.setNumLine(nn.getNumLine());
+ addMapNode2FlatNodeSet(nn,fon);
return new NodePair(fon,fon);
}
}
} 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, temp_left, new TempDescriptor[] {temp_right});
+ 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(fc);
+ right.getEnd().addNext(fc1);
+ fc1.addNext(fc);
return new NodePair(left.getBegin(), fc);
}
}
private NodePair flattenLoopNode(LoopNode ln) {
+
HashSet oldbs=breakset;
HashSet oldcs=continueset;
breakset=new HashSet();
}
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));
}
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));
}
breakset=oldbs;
continueset=oldcs;
+ if(ln.getLabel()!=null){
+ state.fn2labelMap.put(begin, ln.getLabel());
+ }
return new NodePair(begin,nopend);
} else throw new Error();
}
}
throw new Error();
}
+
+ private void addMapNode2FlatNodeSet(TreeNode tn, FlatNode fn){
+ Set<FlatNode> fnSet=mapNode2FlatNodeSet.get(tn);
+ if(fnSet==null){
+ fnSet=new HashSet<FlatNode>();
+ mapNode2FlatNodeSet.put(tn, fnSet);
+ }
+ fnSet.add(fn);
+ }
+
+ public Set<FlatNode> getFlatNodeSet(TreeNode tn){
+ // WARNING: ONLY DID FOR NAMENODE NOW!
+ assert(tn instanceof NameNode);
+ return mapNode2FlatNodeSet.get(tn);
+ }
+
}