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.bcp;
21:
22: import org.apache.bcel.generic.ConstantPoolGen;
23: import org.apache.bcel.generic.FieldInstruction;
24: import org.apache.bcel.generic.Instruction;
25: import org.apache.bcel.generic.InstructionHandle;
26: import org.apache.bcel.generic.PUTFIELD;
27: import org.apache.bcel.generic.PUTSTATIC;
28:
29: import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
30: import edu.umd.cs.findbugs.ba.vna.ValueNumber;
31: import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
32:
33: /**
34: * A PatternElement representing a store to a field.
35: * Variables represent the field and the value stored.
36: *
37: * @author David Hovemeyer
38: * @see PatternElement
39: */
40: public class Store extends FieldAccess {
41: /**
42: * Constructor.
43: *
44: * @param fieldVarName the name of the field variable
45: * @param valueVarName the name of the variable representing the value stored
46: */
47: public Store(String fieldVarName, String valueVarName) {
48: super (fieldVarName, valueVarName);
49: }
50:
51: @Override
52: public MatchResult match(InstructionHandle handle,
53: ConstantPoolGen cpg, ValueNumberFrame before,
54: ValueNumberFrame after, BindingSet bindingSet)
55: throws DataflowAnalysisException {
56:
57: Instruction ins = handle.getInstruction();
58: FieldInstruction fieldIns;
59: Variable field;
60:
61: // The instruction must be PUTFIELD or PUTSTATIC
62: if (ins instanceof PUTFIELD) {
63: fieldIns = (PUTFIELD) ins;
64: int numSlots = before.getNumSlots();
65: ValueNumber ref = before.getValue(isLongOrDouble(fieldIns,
66: cpg) ? numSlots - 3 : numSlots - 2);
67: field = new FieldVariable(ref, fieldIns.getClassName(cpg),
68: fieldIns.getFieldName(cpg), fieldIns
69: .getSignature(cpg));
70: } else if (ins instanceof PUTSTATIC) {
71: fieldIns = (PUTSTATIC) ins;
72: field = new FieldVariable(fieldIns.getClassName(cpg),
73: fieldIns.getFieldName(cpg), fieldIns
74: .getSignature(cpg));
75: } else
76: return null;
77:
78: Variable value = snarfFieldValue(fieldIns, cpg, before);
79:
80: return checkConsistent(field, value, bindingSet);
81: }
82: }
83:
84: // vim:ts=4
|