KickJava   Java API By Example, From Geeks To Geeks.

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


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 ASTWhileNode extends ASTControlFlowNode
31 {
32     private List body;
33
34     public ASTWhileNode( SETNodeLabel label, ConditionExpr ce, List body)
35     {
36     super( label, ce);
37     this.body = body;
38
39     subBodies.add( body);
40     }
41
42
43     /*
44       Nomair A. Naeem 17-FEB-05
45       Needed because of change of grammar of condition being stored as a ASTCondition rather
46       than the ConditionExpr which was the case before
47     */

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

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

120     public void apply(Analysis a){
121     a.caseASTWhileNode(this);
122     }
123 }
124
Popular Tags