6 public class BuildFlat {
8 public BuildFlat(State st) {
12 public void buildflat() {
13 Iterator it=state.classset.iterator();
15 ClassDescriptor cn=(ClassDescriptor)it.next();
20 private void flattenClass(ClassDescriptor cn) {
21 Iterator methodit=cn.getMethods();
22 while(methodit.hasNext()) {
23 MethodDescriptor md=(MethodDescriptor)methodit.next();
24 BlockNode bn=state.getMethodBody(md);
25 FlatNode fn=flattenBlockNode(bn).getBegin();
26 FlatMethod fm=new FlatMethod(md, fn);
27 state.addFlatCode(md,fm);
31 private NodePair flattenBlockNode(BlockNode bn) {
34 for(int i=0;i<bn.size();i++) {
35 NodePair np=flattenBlockStatementNode(bn.get(i));
36 FlatNode np_begin=np.getBegin();
37 FlatNode np_end=np.getEnd();
44 end.addNext(np_begin);
48 return new NodePair(begin,end);
51 private NodePair flattenExpressionNode(ExpressionNode en) {
55 private NodePair flattenDeclarationNode(DeclarationNode dn) {
59 private NodePair flattenIfStatementNode(IfStatementNode isn) {
63 private NodePair flattenLoopNode(LoopNode ln) {
67 private NodePair flattenReturnNode(ReturnNode rn) {
71 private NodePair flattenSubBlockNode(SubBlockNode sbn) {
75 private NodePair flattenBlockStatementNode(BlockStatementNode bsn) {
77 case Kind.BlockExpressionNode:
78 return flattenExpressionNode((ExpressionNode)bsn);
80 case Kind.DeclarationNode:
81 return flattenDeclarationNode((DeclarationNode)bsn);
83 case Kind.IfStatementNode:
84 return flattenIfStatementNode((IfStatementNode)bsn);
87 return flattenLoopNode((LoopNode)bsn);
90 return flattenReturnNode((ReturnNode)bsn);
92 case Kind.SubBlockNode:
93 return flattenSubBlockNode((SubBlockNode)bsn);