2006-11-22 17:38:46 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.ibm.wala.ssa;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import com.ibm.wala.types.TypeReference;
|
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author sfink
|
2007-04-26 20:35:25 +00:00
|
|
|
*
|
2006-11-22 17:38:46 +00:00
|
|
|
*/
|
|
|
|
public class SSAInstanceofInstruction extends SSAInstruction {
|
|
|
|
private final int result;
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
private final int ref;
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
private final TypeReference checkedType;
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
SSAInstanceofInstruction(int result, int ref, TypeReference checkedType) {
|
|
|
|
super();
|
|
|
|
this.result = result;
|
|
|
|
this.ref = ref;
|
|
|
|
this.checkedType = checkedType;
|
|
|
|
}
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
|
2007-04-26 20:35:25 +00:00
|
|
|
return new SSAInstanceofInstruction(defs == null || defs.length == 0 ? result : defs[0], uses == null ? ref : uses[0],
|
|
|
|
checkedType);
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String toString(SymbolTable symbolTable, ValueDecorator d) {
|
|
|
|
return getValueString(symbolTable, d, result) + " = instanceof " + getValueString(symbolTable, d, ref) + " " + checkedType;
|
|
|
|
}
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
/**
|
|
|
|
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
|
|
|
|
*/
|
2007-04-26 20:35:25 +00:00
|
|
|
public void visit(IVisitor v) throws NullPointerException {
|
2006-11-22 17:38:46 +00:00
|
|
|
v.visitInstanceof(this);
|
|
|
|
}
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
/**
|
|
|
|
* @see com.ibm.wala.ssa.SSAInstruction#getDef()
|
|
|
|
*/
|
|
|
|
public boolean hasDef() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDef() {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDef(int i) {
|
|
|
|
Assertions._assert(i == 0);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TypeReference getCheckedType() {
|
|
|
|
return checkedType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see com.ibm.wala.ssa.SSAInstruction#getNumberOfUses()
|
|
|
|
*/
|
|
|
|
public int getNumberOfDefs() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getNumberOfUses() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see com.ibm.wala.ssa.SSAInstruction#getUse(int)
|
|
|
|
*/
|
|
|
|
public int getUse(int j) {
|
|
|
|
if (Assertions.verifyAssertions)
|
|
|
|
Assertions._assert(j == 0);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int hashCode() {
|
|
|
|
return ref * 677 ^ result * 3803;
|
|
|
|
}
|
2007-04-26 20:35:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
2006-11-22 17:38:46 +00:00
|
|
|
* @see com.ibm.wala.ssa.Instruction#isFallThrough()
|
|
|
|
*/
|
|
|
|
public boolean isFallThrough() {
|
|
|
|
return true;
|
|
|
|
}
|
2007-04-26 20:35:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
2006-11-22 17:38:46 +00:00
|
|
|
* @see com.ibm.wala.ssa.Instruction#getExceptionTypes()
|
|
|
|
*/
|
2007-02-08 20:17:02 +00:00
|
|
|
public Collection<TypeReference> getExceptionTypes() {
|
2006-11-22 17:38:46 +00:00
|
|
|
return null;
|
|
|
|
}
|
2007-04-26 20:35:25 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
/**
|
|
|
|
* @return Returns the ref.
|
|
|
|
*/
|
|
|
|
public int getRef() {
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
}
|