Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * fb-contrib - Auxiliary detectors for Java programs
   * Copyright (C) 2005-2015 Dave Brosius
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 package com.mebigfatguy.fbcontrib.detect;
 
 import java.util.Set;
 
 
 
Looks for methods that store the return result in a local variable, and then immediately returns that local variable.
 
 {
 	enum State {SEEN_NOTHING, SEEN_STORE, SEEN_LOAD }
 
 	private static final BitSet branchInstructions = new BitSet();
 	private static final BitSet binaryOps = new BitSet();
 	static {
 
 	    .set();
 	    .set();
 	    .set();
 	    .set();
 	    .set();
 	    .set();
 	    .set();
         .set();  
        .set();  
        .set();
        .set();
	}
	private final BugReporter bugReporter;
	private OpcodeStack stack;
	private State state;
	private int storeReg;

constructs a USBR detector given the reporter to report bugs on

Parameters:
bugReporter the sync of bug reports
		this. = bugReporter;
	}

implements the visitor to create and clear the branchTargets

Parameters:
classContext the context object for the currently parsed class
	public void visitClassContext(ClassContext classContext) {
		try {
			 = new OpcodeStack();
			super.visitClassContext(classContext);
finally {
			 = null;
			 = null;
			 = null;
		}
	}
implements the visitor to make sure method returns a value, and then clears the targets

Parameters:
obj the context object of the currently parsed code block
	public void visitCode(Code obj) {
		Method m = getMethod();
		String sig = m.getSignature();
		Type t = Type.getReturnType(sig);
		if (!t.equals(.)) {
			for (CodeException ce : ces) {
				if (ce.getCatchType() != 0) {
				}
			}
			super.visitCode(obj);
		}
	}

implements the visitor to look for store of registers immediately before returns of that register

Parameters:
seen the opcode of the currently parsed instruction
	public void sawOpcode(int seen) {
		int lhsReg = -1;
		try {
	        .precomputation(this);
	        
	        switch () {
					if (!.contains(Integer.valueOf(getPC()))) {
						if (lookForStore(seen)) {
							if (.getStackDepth() >= 1) {
								Integer reg = (Integer)item.getUserValue();
								if ((reg == null) || (reg.intValue() != )) {
								}
							}
						}
					}
				break;
					if (.contains(Integer.valueOf(getPC()))) {
						break;
					}
				break;
				case :
					if ((seen >= ) && (seen <= )) {
							.addClass(this)
							.addMethod(this)
					}
				break;
			}
			if (.get(seen)) {
			}
			lhsReg = processBinOp(seen);
finally {
			TernaryPatcher.pre(seen);
			.sawOpcode(thisseen);
			TernaryPatcher.post(seen);
			if ((lhsReg > -1) && (.getStackDepth() >= 1)) {
				item.setUserValue(Integer.valueOf(lhsReg));
			}
		}
	}

checks if the current opcode is a store, if so saves the register

Parameters:
seen the opcode of the currently parsed instruction
Returns:
if a store was seen
	private boolean lookForStore(int seen) {
		if ((seen >= ) && (seen <= ))
		else if ((seen >= ) && (seen <= ))
			 = seen - ;
		else if ((seen >= ) && (seen <= ))
			 = seen - ;
		else if ((seen >= ) && (seen <= ))
			 = seen - ;
		else if ((seen >= ) && (seen <= ))
			 = seen - ;
		else if ((seen >= ) && (seen <= ))
			 = seen - ;
		else
			return false;
		return true;
	}

looks for a load of the register that was just stored

Parameters:
seen the opcode of the currently parsed instruction
Returns:
if the load was seen
	private boolean lookForLoad(int seen) {
		int loadReg;
		if ((seen >= ) && (seen <= ))
			loadReg = getRegisterOperand();
		else if ((seen >= ) && (seen <= ))
			loadReg = seen - ;
		else if ((seen >= ) && (seen <= ))
			loadReg = seen - ;
		else if ((seen >= ) && (seen <= ))
			loadReg = seen - ;
		else if ((seen >= ) && (seen <= ))
			loadReg = seen - ;
		else if ((seen >= ) && (seen <= ))
			loadReg = seen - ;
		else
			return false;
		return ( == loadReg);
	}

looks for instructions that are binary operators, and if it is saves the left hand side register (if it exists) in the userValue.

Parameters:
seen the opcode of the currently parsed instruction
Returns:
the lhs register number if it exists or -1
	private int processBinOp(int seen) {
		if (.get(seen)) {
			if (.getStackDepth() >= 2) {
				return item.getRegisterNumber();
			}
		}
		return -1;
	}
New to GrepCode? Check out our FAQ X