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.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;
|
2008-02-15 20:48:38 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
2009-06-12 14:39:19 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
2006-11-22 17:38:46 +00:00
|
|
|
import com.ibm.wala.util.collections.Filter;
|
2009-06-12 14:39:19 +00:00
|
|
|
import com.ibm.wala.util.graph.Graph;
|
2006-11-22 17:38:46 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2009-06-12 14:39:19 +00:00
|
|
|
* A {@link Graph} view of a pointer analysis solution.
|
2006-11-22 17:38:46 +00:00
|
|
|
*
|
2009-06-12 14:39:19 +00:00
|
|
|
* Nodes in the Graph are {@link PointerKey}s and {@link InstanceKey}s.
|
2006-11-22 17:38:46 +00:00
|
|
|
*
|
2009-06-12 14:39:19 +00:00
|
|
|
* There is an edge from a PointerKey P to an InstanceKey I iff the PointerAnalysis indicates that P may point to I.
|
2006-11-22 17:38:46 +00:00
|
|
|
*
|
2009-06-12 14:39:19 +00:00
|
|
|
* There is an edge from an InstanceKey I to a PointerKey P iff - P represents a field of an object instance modeled by I, or - P
|
|
|
|
* represents the array contents of array instance I.
|
2006-11-22 17:38:46 +00:00
|
|
|
*/
|
|
|
|
public abstract class HeapGraph implements NumberedGraph<Object> {
|
|
|
|
|
2008-02-15 20:48:38 +00:00
|
|
|
private final PointerAnalysis pa;
|
2007-05-30 19:05:23 +00:00
|
|
|
|
2008-02-15 20:48:38 +00:00
|
|
|
protected HeapGraph(PointerAnalysis pa) {
|
2009-03-11 16:57:32 +00:00
|
|
|
if (pa == null) {
|
|
|
|
throw new IllegalArgumentException("null pa ");
|
|
|
|
}
|
2008-02-15 20:48:38 +00:00
|
|
|
this.pa = pa;
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
2007-05-30 19:05:23 +00:00
|
|
|
|
2006-11-22 17:38:46 +00:00
|
|
|
public Iterator<Object> iterateNodes(IntSet s) {
|
2007-05-30 19:05:23 +00:00
|
|
|
return new NumberedNodeIterator<Object>(s, this);
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2007-05-30 19:05:23 +00:00
|
|
|
|
2007-08-22 16:33:45 +00:00
|
|
|
public void removeNodeAndEdges(Object N) throws UnsupportedOperationException {
|
2007-08-21 02:46:01 +00:00
|
|
|
throw new UnsupportedOperationException();
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-13 16:25:55 +00:00
|
|
|
* @return the heap model used in this pointer analysis.
|
2006-11-22 17:38:46 +00:00
|
|
|
*/
|
|
|
|
public HeapModel getHeapModel() {
|
2008-02-15 20:48:38 +00:00
|
|
|
return pa.getHeapModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerAnalysis getPointerAnalysis() {
|
|
|
|
return pa;
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|