KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > vna > ValueNumberDataflow


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003,2004 University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 JavaDoc;
23 import java.util.Map JavaDoc;
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.Frame;
30 import edu.umd.cs.findbugs.ba.SignatureParser;
31
32 public class ValueNumberDataflow extends 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 JavaDoc<ValueNumber, Integer JavaDoc> getValueNumberToParamMap(Method method) {
45         return getValueNumberToParamMap(method.getSignature(), method.isStatic());
46     }
47     
48     /**
49      * Build map of value numbers to param indices.
50      * The first parameter has index 0, the second has index 1, etc.
51      *
52      * @param methodSignature signature of the method analyzed by the ValueNumberAnalysis
53      * @param isStatic true if the method is static, false if not
54      * @return the value number to parameter index map
55      */

56     public Map JavaDoc<ValueNumber, Integer JavaDoc> getValueNumberToParamMap(String JavaDoc methodSignature, boolean isStatic) {
57         HashMap JavaDoc<ValueNumber, Integer JavaDoc> valueNumberToParamMap =
58             new HashMap JavaDoc<ValueNumber, Integer JavaDoc>();
59         
60         ValueNumberFrame frameAtEntry = getStartFact(getCFG().getEntry());
61
62         int numParams = new SignatureParser(methodSignature).getNumParameters();
63         int shift = isStatic ? 0 : 1;
64         for (int i = 0; i < numParams; ++i) {
65             valueNumberToParamMap.put(
66                     frameAtEntry.getValue(i + shift), (Integer JavaDoc)(i));
67         }
68         
69         return valueNumberToParamMap;
70         
71     }
72 }
73
74 // vim:ts=4
75
Popular Tags