generalize NumberedDominators; don't rely on INodeWithNumber
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2057 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
c2d315fecb
commit
7a91db9fe6
|
@ -60,10 +60,11 @@ public abstract class Dominators<T> {
|
|||
|
||||
/**
|
||||
* @param G
|
||||
* The graph
|
||||
* The graph
|
||||
* @param root
|
||||
* The root from which to compute dominators
|
||||
* @throws IllegalArgumentException if G is null
|
||||
* The root from which to compute dominators
|
||||
* @throws IllegalArgumentException
|
||||
* if G is null
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Dominators(Graph<T> G, T root) throws IllegalArgumentException {
|
||||
|
@ -78,10 +79,9 @@ public abstract class Dominators<T> {
|
|||
this.vertex = (T[]) new Object[G.getNumberOfNodes() + 1];
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Dominators<T> make(Graph<T> G, T root) {
|
||||
if (G instanceof NumberedGraph && root instanceof INodeWithNumber) {
|
||||
return new NumberedDominators((NumberedGraph)G, (INodeWithNumber)root);
|
||||
if (G instanceof NumberedGraph) {
|
||||
return new NumberedDominators<T>((NumberedGraph<T>) G, root);
|
||||
} else {
|
||||
return new GenericDominators<T>(G, root);
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ public abstract class Dominators<T> {
|
|||
* See TOPLAS 1(1), July 1979, p 128 for details.
|
||||
*
|
||||
* @param node
|
||||
* the node to evaluate
|
||||
* the node to evaluate
|
||||
* @return the node as described above
|
||||
*/
|
||||
private T EVAL(T node) {
|
||||
|
@ -363,7 +363,7 @@ public abstract class Dominators<T> {
|
|||
* This recursive method performs the path compression
|
||||
*
|
||||
* @param node
|
||||
* node of interest
|
||||
* node of interest
|
||||
*/
|
||||
private void compress(T node) {
|
||||
if (getAncestor(getAncestor(node)) != null) {
|
||||
|
@ -382,9 +382,9 @@ public abstract class Dominators<T> {
|
|||
* the number of nodes.
|
||||
*
|
||||
* @param node1
|
||||
* a basic node corresponding to the source of the new edge
|
||||
* a basic node corresponding to the source of the new edge
|
||||
* @param node2
|
||||
* a basic node corresponding to the source of the new edge
|
||||
* a basic node corresponding to the source of the new edge
|
||||
*/
|
||||
private void LINK(T node1, T node2) {
|
||||
if (DEBUG) {
|
||||
|
@ -579,5 +579,5 @@ public abstract class Dominators<T> {
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.util.graph;
|
||||
|
||||
|
||||
/**
|
||||
* Calculate dominators using Langauer and Tarjan's fastest algorithm. TOPLAS
|
||||
* 1(1), July 1979. This implementation uses path compression and results in a
|
||||
|
@ -23,19 +22,15 @@ package com.ibm.wala.util.graph;
|
|||
* @author Julian Dolby
|
||||
*/
|
||||
|
||||
public class NumberedDominators<T extends INodeWithNumber>
|
||||
extends Dominators<T>
|
||||
{
|
||||
public class NumberedDominators<T> extends Dominators<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public NumberedDominators(NumberedGraph<T> G, T root)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
public NumberedDominators(NumberedGraph<T> G, T root) throws IllegalArgumentException {
|
||||
super(G, root);
|
||||
|
||||
this.infoMap = new Object[ G.getMaxNumber()+1 ];
|
||||
for(T n : G) {
|
||||
infoMap[ n.getGraphNodeId() ] = new DominatorInfo(n);
|
||||
this.infoMap = new Object[G.getMaxNumber() + 1];
|
||||
for (T n : G) {
|
||||
infoMap[G.getNumber(n)] = new DominatorInfo(n);
|
||||
}
|
||||
|
||||
analyze();
|
||||
|
@ -43,17 +38,17 @@ public class NumberedDominators<T extends INodeWithNumber>
|
|||
|
||||
@Override
|
||||
public NumberedGraph<T> getGraph() {
|
||||
return (NumberedGraph<T>)G;
|
||||
return (NumberedGraph<T>) G;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look-aside table for DominatorInfo objects
|
||||
*/
|
||||
private final Object[] infoMap;
|
||||
|
||||
|
||||
@Override
|
||||
protected final DominatorInfo getInfo(T node) {
|
||||
return (DominatorInfo)infoMap[ node.getGraphNodeId() ];
|
||||
return (DominatorInfo) infoMap[getGraph().getNumber(node)];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue