01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 1997-1999 Raja Vallee-Rai
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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: package soot.jimple.toolkits.scalar;
27:
28: import soot.*;
29: import java.util.*;
30:
31: public class LocalNameStandardizer extends BodyTransformer {
32: public LocalNameStandardizer(Singletons.Global g) {
33: }
34:
35: public static LocalNameStandardizer v() {
36: return G.v()
37: .soot_jimple_toolkits_scalar_LocalNameStandardizer();
38: }
39:
40: protected void internalTransform(Body body, String phaseName,
41: Map options) {
42: boolean onlyStackName = PhaseOptions.getBoolean(options,
43: "only-stack-locals");
44:
45: // Change the names to the standard forms now.
46: {
47: int objectCount = 0;
48: int intCount = 0;
49: int longCount = 0;
50: int floatCount = 0;
51: int doubleCount = 0;
52: int addressCount = 0;
53: int errorCount = 0;
54: int nullCount = 0;
55:
56: Iterator localIt = body.getLocals().iterator();
57:
58: while (localIt.hasNext()) {
59: Local l = (Local) localIt.next();
60: String prefix = "";
61:
62: if (l.getName().startsWith("$"))
63: prefix = "$";
64: else {
65: if (onlyStackName)
66: continue;
67: }
68:
69: if (l.getType().equals(BooleanType.v()))
70: l.setName(prefix + "z" + intCount++);
71: else if (l.getType().equals(ByteType.v()))
72: l.setName(prefix + "b" + longCount++);
73: else if (l.getType().equals(ShortType.v()))
74: l.setName(prefix + "s" + longCount++);
75: else if (l.getType().equals(CharType.v()))
76: l.setName(prefix + "c" + longCount++);
77: else if (l.getType().equals(IntType.v()))
78: l.setName(prefix + "i" + longCount++);
79: else if (l.getType().equals(LongType.v()))
80: l.setName(prefix + "l" + longCount++);
81: else if (l.getType().equals(DoubleType.v()))
82: l.setName(prefix + "d" + doubleCount++);
83: else if (l.getType().equals(FloatType.v()))
84: l.setName(prefix + "f" + floatCount++);
85: else if (l.getType().equals(StmtAddressType.v()))
86: l.setName(prefix + "a" + addressCount++);
87: else if (l.getType().equals(ErroneousType.v())
88: || l.getType().equals(UnknownType.v())) {
89: l.setName(prefix + "e" + errorCount++);
90: } else if (l.getType().equals(NullType.v()))
91: l.setName(prefix + "n" + nullCount++);
92: else
93: l.setName(prefix + "r" + objectCount++);
94: }
95: }
96: }
97: }
|