KickJava   Java API By Example, From Geeks To Geeks.

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


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 ASTIfNode extends ASTControlFlowNode
31 {
32     private List body;
33
34     public ASTIfNode( SETNodeLabel label, ConditionExpr condition, List body)
35     {
36     super( label, condition);
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 ASTIfNode( SETNodeLabel label, ASTCondition condition, List body)
49     {
50     super( label, condition);
51     this.body = body;
52
53     subBodies.add( body);
54     }
55
56
57     /*
58       Nomair A. Naeem 21-FEB-05
59       Used by OrAggregatorTwo
60     */

61     public List getIfBody(){
62     return body;
63     }
64
65     public Object JavaDoc clone()
66     {
67     return new ASTIfNode( get_Label(), get_Condition(), body);
68     }
69
70     /*
71       Nomair A. Naeem 19-FEB-2005
72       Added to support aggregation of conditions
73     */

74     public void replace(SETNodeLabel label,ASTCondition condition, List body){
75     this.body=body;
76     subBodies= new ArrayList();
77     subBodies.add(body);
78     set_Condition(condition);
79     set_Label(label);
80     }
81
82
83     /*
84       Nomair A Naeem 20-FEB-2005
85       Added for UselessLabeledBlockRemover
86     */

87     public void replaceBody(List body){
88     this.body=body;
89     subBodies=new ArrayList();
90     subBodies.add(body);
91     }
92
93
94     public void toString(UnitPrinter up)
95     {
96         label_toString(up);
97
98         up.literal( "if" );
99         up.literal( " " );
100         up.literal( "(" );
101         condition.toString( up );
102     up.literal( ")");
103         up.newline();
104     
105         up.literal( "{" );
106         up.newline();
107
108         up.incIndent();
109     body_toString( up, body );
110         up.decIndent();
111
112         up.literal( "}" );
113         up.newline();
114     }
115     public String JavaDoc toString()
116     {
117     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
118     
119     b.append( label_toString());
120
121     b.append( "if (");
122     b.append( get_Condition().toString());
123     b.append( ")");
124     b.append( NEWLINE);
125     
126     b.append( "{");
127     b.append( NEWLINE);
128
129     b.append( body_toString(body));
130
131     b.append( "}");
132     b.append( NEWLINE);
133
134     return b.toString();
135     }
136
137
138
139     /*
140       Nomair A. Naeem, 7-FEB-05
141       Part of Visitor Design Implementation for AST
142       See: soot.dava.toolkits.base.AST.analysis For details
143     */

144     public void apply(Analysis a){
145     a.caseASTIfNode(this);
146     }
147 }
148
Popular Tags