KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > internal > AST > ASTDoWhileNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
3  * Copyright (C) 2004-2005 Nomair A. Naeem
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */

20
21 package soot.dava.internal.AST;
22
23 import java.util.*;
24 import soot.*;
25 import soot.jimple.*;
26 import soot.dava.internal.SET.*;
27 import soot.dava.toolkits.base.AST.*;
28 import soot.dava.toolkits.base.AST.analysis.*;
29
30 public class ASTDoWhileNode extends ASTControlFlowNode
31 {
32     private List body;
33
34     public ASTDoWhileNode( SETNodeLabel label, ConditionExpr ce, List body)
35     {
36     super( label, ce);
37     this.body = body;
38
39     subBodies.add( body);
40     }
41
42     /*
43       Nomair A. Naeem 17-FEB-05
44       Needed because of change of grammar of condition being stored as a ASTCondition rather
45       than the ConditionExpr which was the case before
46     */

47     public ASTDoWhileNode( SETNodeLabel label, ASTCondition ce, List body)
48     {
49     super( label, ce);
50     this.body = body;
51
52     subBodies.add( body);
53     }
54
55     /*
56       Nomair A Naeem 20-FEB-2005
57       Added for UselessLabeledBlockRemover
58     */

59     public void replaceBody(List body){
60     this.body=body;
61     subBodies=new ArrayList();
62     subBodies.add(body);
63     }
64
65     public Object JavaDoc clone()
66     {
67     return new ASTDoWhileNode( get_Label(), get_Condition(), body);
68     }
69
70     public void toString( UnitPrinter up )
71     {
72     label_toString( up);
73
74         up.literal( "do" );
75         up.newline();
76
77         up.literal( "{" );
78         up.newline();
79
80         up.incIndent();
81     body_toString( up, body );
82         up.decIndent();
83
84         up.literal( "}" );
85         up.newline();
86
87         up.literal( "while" );
88         up.literal( " " );
89         up.literal( "(" );
90         condition.toString(up);
91         up.literal( ")" );
92         up.literal( ";" );
93         up.newline();
94     }
95
96     public String JavaDoc toString()
97     {
98     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
99     
100     b.append( label_toString());
101
102     b.append( "do");
103     b.append( NEWLINE);
104
105     b.append( "{");
106     b.append( NEWLINE);
107
108     b.append( body_toString(body));
109
110     b.append( "}");
111     b.append( NEWLINE);
112
113     b.append( "while (");
114     b.append( get_Condition().toString());
115     b.append( ");");
116     b.append( NEWLINE);
117
118     return b.toString();
119     }
120
121     /*
122       Nomair A. Naeem, 7-FEB-05
123       Part of Visitor Design Implementation for AST
124       See: soot.dava.toolkits.base.AST.analysis For details
125     */

126     public void apply(Analysis a){
127     a.caseASTDoWhileNode(this);
128     }
129 }
130
Popular Tags