KickJava   Java API By Example, From Geeks To Geeks.

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


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

49     public ASTIfElseNode( SETNodeLabel label, ASTCondition condition, List ifBody, List elseBody)
50     {
51     super( label, condition);
52     this.ifBody = ifBody;
53     this.elseBody = elseBody;
54
55     subBodies.add( ifBody);
56     subBodies.add( elseBody);
57     }
58
59     /*
60       Nomair A. Naeem 19-FEB-2005
61       Added to support aggregation of conditions
62     */

63     public void replace(SETNodeLabel newLabel,ASTCondition newCond,List newBody,List bodyTwo){
64     this.ifBody=newBody;
65     this.elseBody=bodyTwo;
66     subBodies= new ArrayList();
67     subBodies.add(newBody);
68     subBodies.add(bodyTwo);
69     set_Condition(newCond);
70     set_Label(newLabel);
71     
72     }
73
74
75     /*
76       Nomair A. Naeem 21-FEB-2005
77       Added to support UselessLabelBlockRemover
78     */

79     public void replaceBody(List ifBody,List elseBody){
80     this.ifBody=ifBody;
81     this.elseBody=elseBody;
82
83     subBodies= new ArrayList();
84     subBodies.add(ifBody);
85     subBodies.add(elseBody);
86     }
87
88
89     /*
90       Nomair A. Naeem 21-FEB-2005
91       Added to support OrAggregatorTwo
92     */

93     public void replaceElseBody(List elseBody){
94     this.elseBody=elseBody;
95
96     subBodies= new ArrayList();
97     subBodies.add(ifBody);
98     subBodies.add(elseBody);
99     }
100
101
102     /*
103       Nomair A. Naeem 21-FEB-05
104       Used by OrAggregatorTwo
105     */

106     public List getIfBody(){
107     return ifBody;
108     }
109
110     public List getElseBody(){
111     return elseBody;
112     }
113
114
115
116
117     public Object JavaDoc clone()
118     {
119     return new ASTIfElseNode( get_Label(), get_Condition(), ifBody, elseBody);
120     }
121
122     public void toString( UnitPrinter up )
123     {
124         label_toString( up );
125
126         up.literal( "if" );
127         up.literal( " " );
128         up.literal( "(" );
129         condition.toString( up );
130         up.literal( ")" );
131         up.newline();
132     
133         up.literal( "{" );
134         up.newline();
135
136         up.incIndent();
137         body_toString( up, ifBody );
138         up.decIndent();
139
140         up.literal( "}" );
141         up.newline();
142
143         up.literal( "else" );
144         up.newline();
145
146         up.literal( "{" );
147         up.newline();
148
149         up.incIndent();
150         body_toString( up, elseBody );
151         up.decIndent();
152
153         up.literal( "}" );
154         up.newline();
155     }
156
157     public String JavaDoc toString()
158     {
159     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
160     
161     b.append( label_toString());
162
163     b.append( "if (");
164     b.append( get_Condition().toString());
165     b.append( ")");
166     b.append( NEWLINE);
167     
168     b.append( "{");
169     b.append( NEWLINE);
170
171     b.append( body_toString(ifBody));
172
173     b.append( "}");
174     b.append( NEWLINE);
175
176     b.append( "else");
177     b.append( NEWLINE);
178
179     b.append( "{");
180     b.append( NEWLINE);
181
182     b.append( body_toString(elseBody));
183
184     b.append( "}");
185     b.append( NEWLINE);
186
187     return b.toString();
188     }
189
190     /*
191       Nomair A. Naeem, 7-FEB-05
192       Part of Visitor Design Implementation for AST
193       See: soot.dava.toolkits.base.AST.analysis For details
194     */

195     public void apply(Analysis a){
196     a.caseASTIfElseNode(this);
197     }
198
199 }
200
Popular Tags