WALA/com.ibm.wala.core/src/com/ibm/wala/analysis/pointers/HeapGraph.java

79 lines
2.4 KiB
Java
Raw Normal View History

/*******************************************************************************
* 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.analysis.pointers;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import com.ibm.wala.ipa.callgraph.propagation.HeapModel;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.util.collections.Filter;
import com.ibm.wala.util.graph.NumberedGraph;
import com.ibm.wala.util.graph.impl.NumberedNodeIterator;
import com.ibm.wala.util.graph.traverse.DFS;
import com.ibm.wala.util.intset.IntSet;
/**
* A Graph view of a pointer analysis solution.
*
* Nodes in the Graph are PointerKeys and InstanceKeys.
*
* There is an edge from a PointerKey P to an InstanceKey I iff the
* PointerAnalysis indicates that P may point to I.
*
* There is an edge from an InstanceKey I to a PointerKey P iff - P represents a
* field of an object instance modelled by I, or - P represents the array
* contents of array instance I.
*
* @author sfink
*
*/
public abstract class HeapGraph implements NumberedGraph<Object> {
private final HeapModel hm;
protected HeapGraph(HeapModel hm) {
this.hm = hm;
}
/*
* @see com.ibm.wala.util.graph.NumberedNodeManager#iterateNodes(com.ibm.wala.util.intset.IntSet)
*/
public Iterator<Object> iterateNodes(IntSet s) {
return new NumberedNodeIterator<Object>(s, this);
}
public Collection<Object> getReachableInstances(Set<Object> roots) {
Filter f = new Filter() {
public boolean accepts(Object o) {
return (o instanceof InstanceKey);
}
};
return DFS.getReachableNodes(this, roots, f);
}
/*
* @see com.ibm.wala.util.graph.Graph#removeNode(com.ibm.wala.util.graph.Node)
*/
public void removeNodeAndEdges(Object N) {
throw new UnsupportedOperationException();
}
/**
* @return Returns the heap model used in this pointer analysis.
*/
public HeapModel getHeapModel() {
return hm;
}
}