KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > pointer > ParameterAliasTagger


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Ondrej Lhotak
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.jimple.toolkits.pointer;
21 import soot.*;
22 import soot.tagkit.*;
23 import soot.jimple.*;
24 import java.util.*;
25
26 /** Adds colour tags to indicate potential aliasing between method parameters. */
27 public class ParameterAliasTagger extends BodyTransformer {
28     public ParameterAliasTagger( Singletons.Global g ) {}
29     public static ParameterAliasTagger v() { return G.v().soot_jimple_toolkits_pointer_ParameterAliasTagger(); }
30
31     protected void internalTransform(
32             Body b, String JavaDoc phaseName, Map options)
33     {
34         PointsToAnalysis pa = Scene.v().getPointsToAnalysis();
35         Set parms = new HashSet();
36
37         for( Iterator sIt = b.getUnits().iterator(); sIt.hasNext(); ) {
38
39             final Stmt s = (Stmt) sIt.next();
40             if( !(s instanceof IdentityStmt) ) continue;
41             IdentityStmt is = (IdentityStmt) s;
42             ValueBox vb = is.getRightOpBox();
43             if( !(vb.getValue() instanceof ParameterRef) ) continue;
44             ParameterRef pr = (ParameterRef) vb.getValue();
45             if( !(pr.getType() instanceof RefLikeType) ) continue;
46             parms.add(is);
47         }
48
49         int colour = 0;
50         while( !parms.isEmpty() ) {
51             fill( parms, (IdentityStmt) parms.iterator().next(), colour++, pa );
52         }
53     }
54     private void fill( Set parms, IdentityStmt parm, int colour, PointsToAnalysis pa ) {
55         if( !parms.contains(parm) ) return;
56         parm.getRightOpBox().addTag( new ColorTag(colour, "Parameter Alias") );
57         parms.remove( parm );
58         PointsToSet ps = pa.reachingObjects( (Local) parm.getLeftOp() );
59         for( Iterator parm2It = (new LinkedList(parms)).iterator(); parm2It.hasNext(); ) {
60             final IdentityStmt parm2 = (IdentityStmt) parm2It.next();
61             if( ps.hasNonEmptyIntersection(
62                         pa.reachingObjects( (Local) parm2.getLeftOp() ) ) ) {
63                 fill( parms, parm2, colour, pa );
64             }
65         }
66     }
67 }
68
69
Popular Tags