KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > internal > SET > SETStatementSequenceNode


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

19
20 package soot.dava.internal.SET;
21
22 import soot.*;
23 import soot.util.*;
24 import java.util.*;
25 import soot.dava.*;
26 import soot.jimple.*;
27 import soot.dava.internal.asg.*;
28 import soot.dava.internal.AST.*;
29 import soot.dava.internal.javaRep.*;
30
31 public class SETStatementSequenceNode extends SETNode
32 {
33     private DavaBody davaBody;
34     private boolean hasContinue;
35
36     public SETStatementSequenceNode( IterableSet body, DavaBody davaBody)
37     {
38     super( body);
39     add_SubBody( body);
40
41     this.davaBody = davaBody;
42
43     hasContinue = false;
44     }
45
46     public SETStatementSequenceNode( IterableSet body)
47     {
48     this( body, null);
49     }
50
51     public boolean has_Continue()
52     {
53     return hasContinue;
54     }
55
56     public IterableSet get_NaturalExits()
57     {
58     IterableSet c = new IterableSet();
59     AugmentedStmt last = (AugmentedStmt) get_Body().getLast();
60     
61     if ((last.csuccs != null) && (last.csuccs.isEmpty() == false))
62         c.add( last);
63
64     return c;
65     }
66
67     public ASTNode emit_AST()
68     {
69     List l = new LinkedList();
70     
71     boolean isStaticInitializer = davaBody.getMethod().getName().equals( SootMethod.staticInitializerName);
72     
73     Iterator it = get_Body().iterator();
74     while (it.hasNext()) {
75         AugmentedStmt as = (AugmentedStmt) it.next();
76         Stmt s = as.get_Stmt();
77
78         if (davaBody != null) {
79         
80         if ((s instanceof ReturnVoidStmt) && (isStaticInitializer))
81             continue;
82
83         if (s instanceof GotoStmt)
84             continue;
85
86         if (s instanceof MonitorStmt)
87             continue;
88         
89         /*
90           January 12th 2006
91           Trying to fix the super problem we need to not ignore constructor unit
92           i.e. this or super
93           
94         */

95         if (s == davaBody.get_ConstructorUnit()){
96             //System.out.println("ALLOWING this.init STMT TO GET ADDED..............SETStatementSequenceNode");
97
// continue;
98
}
99
100
101
102         if (s instanceof IdentityStmt) {
103             IdentityStmt ids = (IdentityStmt) s;
104             
105             Value
106             rightOp = ids.getRightOp(),
107             leftOp = ids.getLeftOp();
108             
109             if (davaBody.get_ThisLocals().contains( leftOp))
110             continue;
111             
112             if (rightOp instanceof ParameterRef)
113             continue;
114
115             if (rightOp instanceof CaughtExceptionRef)
116             continue;
117         }
118         }
119
120         l.add( as);
121     }
122
123     if (l.isEmpty())
124         return null;
125     else
126         return new ASTStatementSequenceNode( l);
127     }
128
129     public AugmentedStmt get_EntryStmt()
130     {
131     return (AugmentedStmt) get_Body().getFirst();
132     }
133
134
135     public void insert_AbruptStmt( DAbruptStmt stmt)
136     {
137     if (hasContinue)
138         return;
139
140     get_Body().addLast( new AugmentedStmt( stmt));
141     hasContinue = stmt.is_Continue();
142     }
143
144     protected boolean resolve( SETNode parent)
145     {
146     throw new RuntimeException JavaDoc( "Attempting auto-nest a SETStatementSequenceNode.");
147     }
148 }
149
Popular Tags