add some generics

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2093 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-12-04 20:44:04 +00:00
parent 3109dfa77a
commit 3e33169ecc
5 changed files with 67 additions and 48 deletions

View File

@ -13,7 +13,6 @@ package com.ibm.wala.cast.ir.ssa.analysis;
import java.util.Iterator;
import com.ibm.wala.cfg.ControlFlowGraph;
import com.ibm.wala.cfg.IBasicBlock;
import com.ibm.wala.dataflow.graph.AbstractMeetOperator;
import com.ibm.wala.dataflow.graph.BitVectorSolver;
import com.ibm.wala.dataflow.graph.BitVectorUnion;
@ -22,6 +21,7 @@ import com.ibm.wala.dataflow.graph.ITransferFunctionProvider;
import com.ibm.wala.fixedpoint.impl.UnaryOperator;
import com.ibm.wala.fixpoint.BitVectorVariable;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.ISSABasicBlock;
import com.ibm.wala.ssa.SSACFG;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAPhiInstruction;
@ -48,11 +48,11 @@ public class LiveAnalysis {
BitVector getLiveBefore(int instr);
}
public static LiveAnalysis.Result perform(final ControlFlowGraph cfg, final SymbolTable symtab) {
public static LiveAnalysis.Result perform(final ControlFlowGraph<ISSABasicBlock> cfg, final SymbolTable symtab) {
return perform(cfg, symtab, new BitVector());
}
public static LiveAnalysis.Result perform(final ControlFlowGraph cfg, final SymbolTable symtab, final BitVector considerLiveAtExit) {
public static LiveAnalysis.Result perform(final ControlFlowGraph<ISSABasicBlock> cfg, final SymbolTable symtab, final BitVector considerLiveAtExit) {
final BitVectorIntSet liveAtExit = new BitVectorIntSet(considerLiveAtExit);
final SSAInstruction[] instructions = (SSAInstruction[]) cfg.getInstructions();
@ -152,15 +152,15 @@ public class LiveAnalysis {
}
}
final BitVectorSolver<IBasicBlock> S = new BitVectorSolver<IBasicBlock>(new IKilldallFramework<IBasicBlock, BitVectorVariable>() {
private final Graph<IBasicBlock> G = GraphInverter.invert(cfg);
final BitVectorSolver<ISSABasicBlock> S = new BitVectorSolver<ISSABasicBlock>(new IKilldallFramework<ISSABasicBlock, BitVectorVariable>() {
private final Graph<ISSABasicBlock> G = GraphInverter.invert(cfg);
public Graph<IBasicBlock> getFlowGraph() {
public Graph<ISSABasicBlock> getFlowGraph() {
return G;
}
public ITransferFunctionProvider<IBasicBlock, BitVectorVariable> getTransferFunctionProvider() {
return new ITransferFunctionProvider<IBasicBlock, BitVectorVariable>() {
public ITransferFunctionProvider<ISSABasicBlock, BitVectorVariable> getTransferFunctionProvider() {
return new ITransferFunctionProvider<ISSABasicBlock, BitVectorVariable>() {
public boolean hasNodeTransferFunctions() {
return true;
@ -170,7 +170,7 @@ public class LiveAnalysis {
return false;
}
public UnaryOperator<BitVectorVariable> getNodeTransferFunction(IBasicBlock node) {
public UnaryOperator<BitVectorVariable> getNodeTransferFunction(ISSABasicBlock node) {
if (((SSACFG.BasicBlock) node).isExitBlock()) {
return new ExitBlockGenKillOperator();
} else {
@ -178,7 +178,7 @@ public class LiveAnalysis {
}
}
public UnaryOperator<BitVectorVariable> getEdgeTransferFunction(IBasicBlock s, IBasicBlock d) {
public UnaryOperator<BitVectorVariable> getEdgeTransferFunction(ISSABasicBlock s, ISSABasicBlock d) {
Assertions.UNREACHABLE();
return null;
}

View File

@ -3168,7 +3168,7 @@ public abstract class AstTranslator extends CAstVisitor
visitor.visit(switchValue, context, visitor);
int v = getValue(switchValue);
Collection caseLabels = ctrl.getTargetLabels(n);
Collection<Object> caseLabels = ctrl.getTargetLabels(n);
Map<Object, PreBasicBlock> labelToBlock = new LinkedHashMap<Object, PreBasicBlock>();
for (Iterator kases = caseLabels.iterator(); kases.hasNext();) {
Object x = kases.next();

View File

@ -15,62 +15,81 @@ import java.util.Collection;
import com.ibm.wala.util.debug.Assertions;
/**
* The control flow information for the CAPA AST of a particular
* entity. An ast may contain various nodes that pertain to control
* flow---such as gotos, branches, exceptions and so on---and this map
* denotes the target ast nodes of ast nodes that are control flow
* instructions. The label is fairly arbitrary---it will depend on
* the language, producers and consumers of the tree---but is
* generally expected to be things like case labels, exception types,
* conditional outcomes and so on.
*
* The control flow information for the CAPA AST of a particular entity. An ast
* may contain various nodes that pertain to control flow---such as gotos,
* branches, exceptions and so on---and this map denotes the target ast nodes of
* ast nodes that are control flow instructions. The label is fairly
* arbitrary---it will depend on the language, producers and consumers of the
* tree---but is generally expected to be things like case labels, exception
* types, conditional outcomes and so on.
*
* @author Julian Dolby (dolby@us.ibm.com)
*
*
*/
public interface CAstControlFlowMap {
/**
* A distinguished label that means this control flow is the
* default target of a switch (or case) statement as found in many
* procedural languages.
/**
* A distinguished label that means this control flow is the default target of
* a switch (or case) statement as found in many procedural languages.
*/
public static final Object SWITCH_DEFAULT = new Object();
/**
* A distinguished target that means this control flow is the target
* of an uncaught exception.
* A distinguished target that means this control flow is the target of an
* uncaught exception.
*/
public static final CAstNode EXCEPTION_TO_EXIT = new CAstNode() {
public int getKind() { return CAstNode.CONSTANT; }
public Object getValue() { return this; }
public CAstNode getChild(int n) { Assertions.UNREACHABLE(); return null; }
public int getChildCount() { return 0;}
public String toString() { return "EXCEPTION_TO_EXIT"; }
public int hashCode() { return getKind()*toString().hashCode(); }
public boolean equals(Object o) { return o == this; }
};
public int getKind() {
return CAstNode.CONSTANT;
}
public Object getValue() {
return this;
}
public CAstNode getChild(int n) {
Assertions.UNREACHABLE();
return null;
}
public int getChildCount() {
return 0;
}
public String toString() {
return "EXCEPTION_TO_EXIT";
}
public int hashCode() {
return getKind() * toString().hashCode();
}
public boolean equals(Object o) {
return o == this;
}
};
/**
* Return the target ast node of the control-flow instruction
* denoted by from with respect to the given label.
* Return the target ast node of the control-flow instruction denoted by from
* with respect to the given label.
*/
CAstNode getTarget(CAstNode from, Object label);
/**
* Return a collection of all labels for which the control-flow ast
* node <code>from</code> has a target.
* Return a collection of all labels for which the control-flow ast node
* <code>from</code> has a target.
*/
Collection getTargetLabels(CAstNode from);
Collection<Object> getTargetLabels(CAstNode from);
/**
* Return a collection of control-flow ast nodes that have this one
* as a possible target.
* Return a collection of control-flow ast nodes that have this one as a
* possible target.
*/
Collection getSourceNodes(CAstNode to);
/**
* Returns an iterator of all CAstNodes for which this map contains
* control flow mapping information.
* Returns an iterator of all CAstNodes for which this map contains control
* flow mapping information.
*/
Collection<CAstNode> getMappedNodes();
}

View File

@ -86,11 +86,11 @@ public class CAstControlFlowRecorder implements CAstControlFlowMap {
return null;
}
public Collection getTargetLabels(CAstNode from) {
public Collection<Object> getTargetLabels(CAstNode from) {
if (labelMap.containsKey(CAstToNode.get(from))) {
return (Set) labelMap.get(CAstToNode.get(from));
return labelMap.get(CAstToNode.get(from));
} else {
return Collections.EMPTY_SET;
return Collections.emptySet();
}
}

View File

@ -106,7 +106,7 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
}
if (oldSources.contains(oldSource)) {
Iterator LS = orig.getTargetLabels(oldSource).iterator();
Iterator<Object> LS = orig.getTargetLabels(oldSource).iterator();
if (orig.getTarget(oldSource, null) != null) {
LS = IteratorPlusOne.make(LS, null);
}