01: /*
02: * Bytecode Analysis Framework
03: * Copyright (C) 2003,2004 University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.ba.vna;
21:
22: import java.util.HashMap;
23: import java.util.Map;
24:
25: import org.apache.bcel.classfile.Method;
26:
27: import edu.umd.cs.findbugs.ba.AbstractDataflow;
28: import edu.umd.cs.findbugs.ba.CFG;
29: import edu.umd.cs.findbugs.ba.SignatureParser;
30:
31: public class ValueNumberDataflow extends
32: AbstractDataflow<ValueNumberFrame, ValueNumberAnalysis> {
33: public ValueNumberDataflow(CFG cfg, ValueNumberAnalysis analysis) {
34: super (cfg, analysis);
35: }
36:
37: /**
38: * Build map of value numbers to param indices.
39: * The first parameter has index 0, the second has index 1, etc.
40: *
41: * @param method the method analyzed by the ValueNumberAnalysis
42: * @return the value number to parameter index map
43: */
44: public Map<ValueNumber, Integer> getValueNumberToParamMap(
45: Method method) {
46: return getValueNumberToParamMap(method.getSignature(), method
47: .isStatic());
48: }
49:
50: /**
51: * Build map of value numbers to param indices.
52: * The first parameter has index 0, the second has index 1, etc.
53: *
54: * @param methodSignature signature of the method analyzed by the ValueNumberAnalysis
55: * @param isStatic true if the method is static, false if not
56: * @return the value number to parameter index map
57: */
58: public Map<ValueNumber, Integer> getValueNumberToParamMap(
59: String methodSignature, boolean isStatic) {
60: HashMap<ValueNumber, Integer> valueNumberToParamMap = new HashMap<ValueNumber, Integer>();
61:
62: ValueNumberFrame frameAtEntry = getStartFact(getCFG()
63: .getEntry());
64:
65: int numParams = new SignatureParser(methodSignature)
66: .getNumParameters();
67: int shift = isStatic ? 0 : 1;
68: for (int i = 0; i < numParams; ++i) {
69: valueNumberToParamMap.put(frameAtEntry.getValue(i + shift),
70: (Integer) (i));
71: }
72:
73: return valueNumberToParamMap;
74:
75: }
76: }
77:
78: // vim:ts=4
|