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.IFNONNULL;
24: import org.apache.bcel.generic.IFNULL;
25: import org.apache.bcel.generic.Instruction;
26: import org.apache.bcel.generic.InstructionHandle;
27:
28: import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
29: import edu.umd.cs.findbugs.ba.Edge;
30: import edu.umd.cs.findbugs.ba.EdgeTypes;
31: import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
32:
33: public class IfNull extends OneVariableInstruction implements EdgeTypes {
34:
35: public IfNull(String varName) {
36: super (varName);
37: }
38:
39: @Override
40: public MatchResult match(InstructionHandle handle,
41: ConstantPoolGen cpg, ValueNumberFrame before,
42: ValueNumberFrame after, BindingSet bindingSet)
43: throws DataflowAnalysisException {
44:
45: // Instruction must be IFNULL or IFNONNULL.
46: Instruction ins = handle.getInstruction();
47: if (!(ins instanceof IFNULL || ins instanceof IFNONNULL))
48: return null;
49:
50: // Ensure reference used is consistent with previous uses of
51: // same variable.
52: LocalVariable ref = new LocalVariable(before.getTopValue());
53: return addOrCheckDefinition(ref, bindingSet);
54: }
55:
56: @Override
57: public boolean acceptBranch(Edge edge, InstructionHandle source) {
58: boolean isIfNull = (source.getInstruction() instanceof IFNULL);
59: return edge.getType() == (isIfNull ? IFCMP_EDGE
60: : FALL_THROUGH_EDGE);
61: }
62: }
63:
64: // vim:ts=4
|