KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > toolkits > base > finders > SequenceFinder


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.toolkits.base.finders;
21
22 import soot.*;
23 import soot.dava.*;
24 import java.util.*;
25 import soot.util.*;
26 import soot.dava.internal.asg.*;
27 import soot.dava.internal.SET.*;
28 import soot.dava.internal.AST.*;
29
30 public class SequenceFinder implements FactFinder
31 {
32     public SequenceFinder( Singletons.Global g ) {}
33     public static SequenceFinder v() { return G.v().soot_dava_toolkits_base_finders_SequenceFinder(); }
34
35     public void find( DavaBody body, AugmentedStmtGraph asg, SETNode SET) throws RetriggerAnalysisException
36     {
37     Dava.v().log( "SequenceFinder::find()");
38
39     SET.find_StatementSequences( this, body);
40     }
41
42     public void find_StatementSequences( SETNode SETParent, IterableSet body, HashSet childUnion, DavaBody davaBody)
43     {
44     Iterator bit = body.iterator();
45     while (bit.hasNext()) {
46         AugmentedStmt as = (AugmentedStmt) bit.next();
47
48         if (childUnion.contains( as))
49         continue;
50         
51         IterableSet sequenceBody = new IterableSet();
52
53         while (as.bpreds.size() == 1) {
54         AugmentedStmt pas = (AugmentedStmt) as.bpreds.get(0);
55         if ((body.contains( pas) == false) || (childUnion.contains( pas) == true))
56             break;
57
58         as = pas;
59         }
60
61         while ((body.contains( as)) && (childUnion.contains( as) == false)) {
62
63         childUnion.add( as);
64         sequenceBody.addLast( as);
65         
66         if (as.bsuccs.isEmpty() == false)
67             as = (AugmentedStmt) as.bsuccs.get(0);
68
69         if (as.bpreds.size() != 1)
70             break;
71         }
72
73         SETParent.add_Child( new SETStatementSequenceNode( sequenceBody, davaBody), (IterableSet) SETParent.get_Body2ChildChain().get( body));
74     }
75     }
76 }
77
Popular Tags