more IllegalArgumentExceptions and related cleanups

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1717 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-09-04 00:58:16 +00:00
parent 83b6561c03
commit b9b20a28b5
10 changed files with 57 additions and 51 deletions

View File

@ -98,9 +98,9 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
/** /**
* @param cg * @param cg
* Governing call graph * Governing call graph
* @param noCollapse * @param noCollapse
* set of nodes in the call graph which cannot be collapsed * set of nodes in the call graph which cannot be collapsed
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public PartiallyCollapsedSupergraph(CallGraph cg, Collection<CGNode> noCollapse) { public PartiallyCollapsedSupergraph(CallGraph cg, Collection<CGNode> noCollapse) {
@ -109,12 +109,12 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
/** /**
* @param cg * @param cg
* Governing call graph * Governing call graph
* @param noCollapse * @param noCollapse
* set of nodes in the call graph which cannot be collapsed * set of nodes in the call graph which cannot be collapsed
* @param relevant * @param relevant
* set of nodes which are relevant and should be included in the * set of nodes which are relevant and should be included in the
* supergraph * supergraph
*/ */
public PartiallyCollapsedSupergraph(CallGraph cg, Collection<CGNode> noCollapse, Filter<CGNode> relevant) { public PartiallyCollapsedSupergraph(CallGraph cg, Collection<CGNode> noCollapse, Filter<CGNode> relevant) {
@ -131,7 +131,8 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
} }
} }
this.noCollapse = noCollapse; this.noCollapse = noCollapse;
this.partialIPFG = new InterproceduralCFG(cg, new Filtersection<CGNode>(relevant, new CollectionFilter<CGNode>(noCollapse)), true); this.partialIPFG = new InterproceduralCFG(cg, new Filtersection<CGNode>(relevant, new CollectionFilter<CGNode>(noCollapse)),
true);
if (DEBUG_LEVEL > 0) { if (DEBUG_LEVEL > 0) {
Trace.println("IPFG \n" + partialIPFG.toString()); Trace.println("IPFG \n" + partialIPFG.toString());
} }
@ -164,11 +165,10 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
return cg.getFakeRootNode(); return cg.getFakeRootNode();
} }
public Object getEntryForProcedure(Object p) { public Object getEntryForProcedure(CGNode n) {
if (Assertions.verifyAssertions) { if (Assertions.verifyAssertions) {
Assertions._assert(p != null); Assertions._assert(n != null);
} }
CGNode n = (CGNode) p;
if (noCollapse.contains(n)) { if (noCollapse.contains(n)) {
// p is cg node which is expanded in the IPFG // p is cg node which is expanded in the IPFG
return partialIPFG.getEntry(n); return partialIPFG.getEntry(n);
@ -179,7 +179,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
} }
public Object[] getEntries(Object n) { public Object[] getEntries(Object n) {
Object p = getProcOf(n); CGNode p = getProcOf(n);
return new Object[] { getEntryForProcedure(p) }; return new Object[] { getEntryForProcedure(p) };
} }
@ -202,9 +202,8 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
if (object == null) { if (object == null) {
throw new IllegalArgumentException("object == null"); throw new IllegalArgumentException("object == null");
} }
if (object instanceof IBasicBlock) { if (object instanceof BasicBlockInContext) {
IBasicBlock b = (IBasicBlock) object; return partialIPFG.hasCall((BasicBlockInContext) object);
return partialIPFG.hasCall((BasicBlockInContext) b);
} else { } else {
if (Assertions.verifyAssertions) { if (Assertions.verifyAssertions) {
if (!(object instanceof CollapsedNode)) { if (!(object instanceof CollapsedNode)) {
@ -244,7 +243,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
} }
public Iterator<? extends Object> getReturnSites(Object object) { public Iterator<? extends Object> getReturnSites(Object object) {
if (object instanceof IBasicBlock) { if (object instanceof BasicBlockInContext) {
return partialIPFG.getReturnSites((BasicBlockInContext) object); return partialIPFG.getReturnSites((BasicBlockInContext) object);
} else { } else {
CGNode n = nodeManager.getProcOfCollapsedNode(object); CGNode n = nodeManager.getProcOfCollapsedNode(object);
@ -253,7 +252,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
} }
public Iterator<? extends Object> getCallSites(Object object) { public Iterator<? extends Object> getCallSites(Object object) {
if (object instanceof IBasicBlock) { if (object instanceof BasicBlockInContext) {
return partialIPFG.getCallSites((BasicBlockInContext) object); return partialIPFG.getCallSites((BasicBlockInContext) object);
} else { } else {
CGNode n = nodeManager.getProcOfCollapsedNode(object); CGNode n = nodeManager.getProcOfCollapsedNode(object);
@ -296,7 +295,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
*/ */
private void computeTransverseEdges() { private void computeTransverseEdges() {
// compute transverse edges that originate from basic blocks // compute transverse edges that originate from basic blocks
for (BasicBlockInContext bb: partialIPFG) { for (BasicBlockInContext bb : partialIPFG) {
if (partialIPFG.hasCall(bb)) { if (partialIPFG.hasCall(bb)) {
Set targets = partialIPFG.getCallTargets(bb); Set targets = partialIPFG.getCallTargets(bb);
for (Iterator it2 = targets.iterator(); it2.hasNext();) { for (Iterator it2 = targets.iterator(); it2.hasNext();) {
@ -698,7 +697,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
* TODO: refactor to avoid allocation? * TODO: refactor to avoid allocation?
* *
* @param n * @param n
* a collapsible node * a collapsible node
* @return an object that represents entry to this node * @return an object that represents entry to this node
*/ */
public CollapsedNode getCollapsedEntry(CGNode n) { public CollapsedNode getCollapsedEntry(CGNode n) {
@ -713,7 +712,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
* TODO: refactor to avoid allocation? * TODO: refactor to avoid allocation?
* *
* @param n * @param n
* a collapsible node * a collapsible node
* @return an object that represents entry to this node * @return an object that represents entry to this node
*/ */
public CollapsedNode getCollapsedExit(CGNode n) { public CollapsedNode getCollapsedExit(CGNode n) {
@ -787,7 +786,11 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
return partialIPFG.iterator(); return partialIPFG.iterator();
} }
public int getNumber(Object N) { public int getNumber(Object N) throws IllegalArgumentException {
if (!(N instanceof BasicBlockInContext) && !(N instanceof CollapsedNode)) {
throw new IllegalArgumentException(
"(not ( N instanceof com.ibm.wala.ipa.cfg.BasicBlockInContext ) ) and (not ( N instanceof com.ibm.wala.dataflow.IFDS.PartiallyCollapsedSupergraph$CollapsedNode ) )");
}
if (N instanceof CollapsedNode) { if (N instanceof CollapsedNode) {
return ((CollapsedNode) N).number; return ((CollapsedNode) N).number;
} else { } else {
@ -853,7 +856,7 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
*/ */
public boolean isReturn(Object object) { public boolean isReturn(Object object) {
if (object instanceof BasicBlockInContext) { if (object instanceof BasicBlockInContext) {
return partialIPFG.isReturn((BasicBlockInContext)object); return partialIPFG.isReturn((BasicBlockInContext) object);
} else { } else {
if (nodeManager.isCollapsedExit(object)) { if (nodeManager.isCollapsedExit(object)) {
CGNode node = getProcOf(object); CGNode node = getProcOf(object);

View File

@ -28,8 +28,11 @@ public class BitVectorMinusVector extends UnaryOperator<BitVectorVariable> {
@Override @Override
public byte evaluate(BitVectorVariable lhs, BitVectorVariable rhs) throws IllegalArgumentException { public byte evaluate(BitVectorVariable lhs, BitVectorVariable rhs) throws IllegalArgumentException, IllegalArgumentException {
if (lhs == null) {
throw new IllegalArgumentException("lhs == null");
}
if (rhs == null) { if (rhs == null) {
throw new IllegalArgumentException("rhs == null"); throw new IllegalArgumentException("rhs == null");
} }

View File

@ -27,8 +27,10 @@ public class BitVectorOr extends UnaryOperator<BitVectorVariable> {
@Override @Override
public byte evaluate(BitVectorVariable lhs, BitVectorVariable rhs) { public byte evaluate(BitVectorVariable lhs, BitVectorVariable rhs) throws IllegalArgumentException {
if (lhs == null) {
throw new IllegalArgumentException("lhs == null");
}
BitVectorVariable U = new BitVectorVariable(); BitVectorVariable U = new BitVectorVariable();
U.copyState(lhs); U.copyState(lhs);
U.addAll(rhs); U.addAll(rhs);

View File

@ -207,10 +207,13 @@ public class ContextSensitiveStateMachine implements StateMachine<IFlowLabel> {
/* /*
* @see com.ibm.wala.demandpa.alg.statemachine.StateMachine#transition(com.ibm.wala.demandpa.alg.statemachine.StateMachine.State, java.lang.Object) * @see com.ibm.wala.demandpa.alg.statemachine.StateMachine#transition(com.ibm.wala.demandpa.alg.statemachine.StateMachine.State, java.lang.Object)
*/ */
public State transition(State prevState, IFlowLabel label) throws IllegalArgumentException { public State transition(State prevState, IFlowLabel label) throws IllegalArgumentException, IllegalArgumentException {
if (prevState == null) { if (prevState == null) {
throw new IllegalArgumentException("prevState == null"); throw new IllegalArgumentException("prevState == null");
} }
if (!(prevState instanceof CallStack)) {
throw new IllegalArgumentException("not ( prevState instanceof com.ibm.wala.demandpa.alg.CallStack ) ");
}
CallStack prevStack = (CallStack) prevState; CallStack prevStack = (CallStack) prevState;
if (!prevStack.isEmpty() && recursiveCallSites.contains(prevStack.peek())) { if (!prevStack.isEmpty() && recursiveCallSites.contains(prevStack.peek())) {
// just pop off the call site // just pop off the call site

View File

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.ibm.wala.ipa.callgraph.propagation; package com.ibm.wala.ipa.callgraph.propagation;
import com.ibm.wala.classLoader.ArrayClass;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
@ -74,7 +75,7 @@ public class AllocationSiteInstanceKeys implements InstanceKeyFactory {
} }
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) { public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation); ArrayClass type = (ArrayClass) options.getClassTargetSelector().getAllocatedTarget(node, allocation);
if (type == null) { if (type == null) {
Warnings.add(ResolutionFailure.create(node, allocation)); Warnings.add(ResolutionFailure.create(node, allocation));
return null; return null;

View File

@ -27,14 +27,14 @@ public final class MultiNewArrayAllocationSiteKey extends AllocationSiteKey {
* @return null if the element type is a primitive * @return null if the element type is a primitive
* @throws IllegalArgumentException if T == null * @throws IllegalArgumentException if T == null
*/ */
private static IClass myElementType(IClass T, int d) throws IllegalArgumentException { private static IClass myElementType(ArrayClass T, int d) throws IllegalArgumentException, IllegalArgumentException {
if (T == null) { if (T == null) {
throw new IllegalArgumentException("T == null"); throw new IllegalArgumentException("T == null");
} }
if (d == 0) { if (d == 0) {
return ((ArrayClass) T).getElementClass(); return T.getElementClass();
} else { } else {
IClass element = ((ArrayClass)T).getElementClass(); ArrayClass element = (ArrayClass) T.getElementClass();
if (element == null) { if (element == null) {
return null; return null;
} else { } else {
@ -43,7 +43,7 @@ public final class MultiNewArrayAllocationSiteKey extends AllocationSiteKey {
} }
} }
public MultiNewArrayAllocationSiteKey(CGNode node, NewSiteReference allocation, IClass type, int dim) { public MultiNewArrayAllocationSiteKey(CGNode node, NewSiteReference allocation, ArrayClass type, int dim) {
super(node, allocation, myElementType(type, dim)); super(node, allocation, myElementType(type, dim));
this.dim = dim; this.dim = dim;
} }

View File

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package com.ibm.wala.ipa.callgraph.propagation; package com.ibm.wala.ipa.callgraph.propagation;
import com.ibm.wala.classLoader.ArrayClass;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
@ -75,7 +76,7 @@ public class SmushedAllocationSiteInstanceKeys implements InstanceKeyFactory {
} }
public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) { public InstanceKey getInstanceKeyForMultiNewArray(CGNode node, NewSiteReference allocation, int dim) {
IClass type = options.getClassTargetSelector().getAllocatedTarget(node, allocation); ArrayClass type = (ArrayClass) options.getClassTargetSelector().getAllocatedTarget(node, allocation);
if (type == null) { if (type == null) {
Warnings.add(ResolutionFailure.create(node, allocation)); Warnings.add(ResolutionFailure.create(node, allocation));
return null; return null;

View File

@ -11,31 +11,25 @@
package com.ibm.wala.ipa.summaries; package com.ibm.wala.ipa.summaries;
import com.ibm.wala.cfg.ControlFlowGraph; import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SyntheticMethod; import com.ibm.wala.classLoader.SyntheticMethod;
import com.ibm.wala.ipa.callgraph.Context; import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.IRFactory; import com.ibm.wala.ssa.IRFactory;
import com.ibm.wala.ssa.SSAOptions; import com.ibm.wala.ssa.SSAOptions;
import com.ibm.wala.util.debug.Assertions;
public class SyntheticIRFactory implements IRFactory { public class SyntheticIRFactory implements IRFactory<SyntheticMethod> {
public ControlFlowGraph makeCFG(IMethod method, Context C) { public ControlFlowGraph makeCFG(SyntheticMethod method, Context C) {
if (method == null) { if (method == null) {
throw new IllegalArgumentException("method is null"); throw new IllegalArgumentException("method is null");
} }
Assertions._assert(method.isSynthetic()); return method.makeControlFlowGraph();
SyntheticMethod sm = (SyntheticMethod) method;
return sm.makeControlFlowGraph();
} }
public IR makeIR(IMethod method, Context C, SSAOptions options) { public IR makeIR(SyntheticMethod method, Context C, SSAOptions options) {
if (method == null) { if (method == null) {
throw new IllegalArgumentException("method is null"); throw new IllegalArgumentException("method is null");
} }
Assertions._assert(method.isSynthetic()); return method.makeIR(options);
SyntheticMethod sm = (SyntheticMethod) method;
return sm.makeIR(options);
} }
} }

View File

@ -14,6 +14,7 @@ import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.ShrikeCTMethod; import com.ibm.wala.classLoader.ShrikeCTMethod;
import com.ibm.wala.classLoader.ShrikeIRFactory; import com.ibm.wala.classLoader.ShrikeIRFactory;
import com.ibm.wala.classLoader.SyntheticMethod;
import com.ibm.wala.ipa.callgraph.Context; import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.summaries.SyntheticIRFactory; import com.ibm.wala.ipa.summaries.SyntheticIRFactory;
import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.Assertions;
@ -35,7 +36,7 @@ public class DefaultIRFactory implements IRFactory<IMethod> {
throw new IllegalArgumentException("method cannot be null"); throw new IllegalArgumentException("method cannot be null");
} }
if (method.isSynthetic()) { if (method.isSynthetic()) {
return syntheticFactory.makeCFG(method, C); return syntheticFactory.makeCFG((SyntheticMethod)method, C);
} else if (method instanceof ShrikeCTMethod) { } else if (method instanceof ShrikeCTMethod) {
return shrikeFactory.makeCFG((ShrikeCTMethod) method, C); return shrikeFactory.makeCFG((ShrikeCTMethod) method, C);
} else { } else {
@ -52,7 +53,7 @@ public class DefaultIRFactory implements IRFactory<IMethod> {
throw new IllegalArgumentException("method cannot be null"); throw new IllegalArgumentException("method cannot be null");
} }
if (method.isSynthetic()) { if (method.isSynthetic()) {
return syntheticFactory.makeIR(method, C, options); return syntheticFactory.makeIR((SyntheticMethod)method, C, options);
} else if (method instanceof ShrikeCTMethod) { } else if (method instanceof ShrikeCTMethod) {
return shrikeFactory.makeIR((ShrikeCTMethod) method, C, options); return shrikeFactory.makeIR((ShrikeCTMethod) method, C, options);
} else { } else {

View File

@ -729,11 +729,10 @@ public class SSACFG implements ControlFlowGraph<ISSABasicBlock> {
/* /*
* @see com.ibm.wala.util.graph.NumberedGraph#getNumber(com.ibm.wala.util.graph.Node) * @see com.ibm.wala.util.graph.NumberedGraph#getNumber(com.ibm.wala.util.graph.Node)
*/ */
public int getNumber(ISSABasicBlock N) throws IllegalArgumentException { public int getNumber(ISSABasicBlock b) throws IllegalArgumentException {
if (N == null) { if (b == null) {
throw new IllegalArgumentException("N == null"); throw new IllegalArgumentException("N == null");
} }
BasicBlock b = (BasicBlock) N;
return b.getNumber(); return b.getNumber();
} }
@ -1028,11 +1027,10 @@ public class SSACFG implements ControlFlowGraph<ISSABasicBlock> {
return getSuccNodeNumbers(src).contains(getNumber(dst)); return getSuccNodeNumbers(src).contains(getNumber(dst));
} }
public IntSet getSuccNodeNumbers(ISSABasicBlock node) throws IllegalArgumentException { public IntSet getSuccNodeNumbers(ISSABasicBlock b) throws IllegalArgumentException {
if (node == null) { if (b == null) {
throw new IllegalArgumentException("node == null"); throw new IllegalArgumentException("b == null");
} }
BasicBlock b = (BasicBlock) node;
IBasicBlock n = cfg.getNode(b.getNumber()); IBasicBlock n = cfg.getNode(b.getNumber());
return cfg.getSuccNodeNumbers(n); return cfg.getSuccNodeNumbers(n);
} }