KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > scalar > LocalNameStandardizer


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai
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 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30
31 package soot.jimple.toolkits.scalar;
32
33 import soot.*;
34 import soot.jimple.toolkits.typing.*;
35 import soot.util.*;
36 import java.util.*;
37
38 public class LocalNameStandardizer extends BodyTransformer
39 {
40     public LocalNameStandardizer( Singletons.Global g ) {}
41     public static LocalNameStandardizer v() { return G.v().soot_jimple_toolkits_scalar_LocalNameStandardizer(); }
42
43     protected void internalTransform(Body body, String JavaDoc phaseName, Map options)
44     {
45         boolean onlyStackName = PhaseOptions.getBoolean(options, "only-stack-locals");
46
47         // Change the names to the standard forms now.
48
{
49             int objectCount = 0;
50             int intCount = 0;
51             int longCount = 0;
52             int floatCount = 0;
53             int doubleCount = 0;
54             int addressCount = 0;
55             int errorCount = 0;
56             int nullCount = 0;
57
58             Iterator localIt = body.getLocals().iterator();
59
60             while(localIt.hasNext())
61             {
62                 Local l = (Local) localIt.next();
63                 String JavaDoc prefix = "";
64                 
65                 if(l.getName().startsWith("$"))
66                     prefix = "$";
67                 else
68                 {
69                     if (onlyStackName)
70                         continue;
71                 }
72                     
73                 if(l.getType().equals(BooleanType.v()))
74                     l.setName(prefix + "z" + intCount++);
75                 else if(l.getType().equals(ByteType.v()))
76                     l.setName(prefix + "b" + longCount++);
77                 else if(l.getType().equals(ShortType.v()))
78                     l.setName(prefix + "s" + longCount++);
79                 else if(l.getType().equals(CharType.v()))
80                     l.setName(prefix + "c" + longCount++);
81                 else if(l.getType().equals(IntType.v()))
82                     l.setName(prefix + "i" + longCount++);
83                 else if(l.getType().equals(LongType.v()))
84                     l.setName(prefix + "l" + longCount++);
85                 else if(l.getType().equals(DoubleType.v()))
86                     l.setName(prefix + "d" + doubleCount++);
87                 else if(l.getType().equals(FloatType.v()))
88                     l.setName(prefix + "f" + floatCount++);
89                 else if(l.getType().equals(StmtAddressType.v()))
90                     l.setName(prefix + "a" + addressCount++);
91                 else if(l.getType().equals(ErroneousType.v()) ||
92                     l.getType().equals(UnknownType.v()))
93                 {
94                     l.setName(prefix + "e" + errorCount++);
95                 }
96                 else if(l.getType().equals(NullType.v()))
97                     l.setName(prefix + "n" + nullCount++);
98                 else
99                     l.setName(prefix + "r" + objectCount++);
100             }
101         }
102     }
103 }
104
105
106
107
Popular Tags