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.GETFIELD;
25: import org.apache.bcel.generic.GETSTATIC;
26: import org.apache.bcel.generic.Instruction;
27: import org.apache.bcel.generic.InstructionHandle;
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 load from a field.
35: * Variables represent the field and the result of the load.
36: *
37: * @author David Hovemeyer
38: * @see PatternElement
39: */
40: public class Load extends FieldAccess {
41:
42: /**
43: * Constructor.
44: *
45: * @param fieldVarName the name of the field variable
46: * @param resultVarName the name of the result variable
47: */
48: public Load(String fieldVarName, String resultVarName) {
49: super (fieldVarName, resultVarName);
50: }
51:
52: @Override
53: public MatchResult match(InstructionHandle handle,
54: ConstantPoolGen cpg, ValueNumberFrame before,
55: ValueNumberFrame after, BindingSet bindingSet)
56: throws DataflowAnalysisException {
57:
58: Variable field;
59: Instruction ins = handle.getInstruction();
60: FieldInstruction fieldIns;
61:
62: // The instruction must be GETFIELD or GETSTATIC
63: if (ins instanceof GETFIELD) {
64: fieldIns = (GETFIELD) ins;
65: ValueNumber ref = before.getTopValue();
66: field = new FieldVariable(ref, fieldIns.getClassName(cpg),
67: fieldIns.getFieldName(cpg), fieldIns
68: .getSignature(cpg));
69: } else if (ins instanceof GETSTATIC) {
70: fieldIns = (GETSTATIC) ins;
71: field = new FieldVariable(fieldIns.getClassName(cpg),
72: fieldIns.getFieldName(cpg), fieldIns
73: .getSignature(cpg));
74: } else
75: return null;
76:
77: Variable result = snarfFieldValue(fieldIns, cpg, after);
78:
79: return checkConsistent(field, result, bindingSet);
80: }
81: }
82:
83: // vim:ts=4
|