delete CallGraph.getInterpreter() and CFGProvider

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1345 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-07-05 03:04:50 +00:00
parent 04e7807ce5
commit e34aa83beb
3 changed files with 42 additions and 47 deletions

View File

@ -47,7 +47,7 @@ public class Util {
for (Iterator x = CG.iterator(); x.hasNext();) { for (Iterator x = CG.iterator(); x.hasNext();) {
CGNode N = (CGNode) x.next(); CGNode N = (CGNode) x.next();
Trace.println("\nIR of node " + N); Trace.println("\nIR of node " + N);
IR ir = ((SSAContextInterpreter) CG.getInterpreter(N)).getIR(N, builder.getWarnings()); IR ir = N.getIR(builder.getWarnings());
if (ir != null) { if (ir != null) {
Trace.println(ir); Trace.println(ir);
} else { } else {

View File

@ -10,10 +10,17 @@
*****************************************************************************/ *****************************************************************************/
package com.ibm.wala.cast.tree.impl; package com.ibm.wala.cast.tree.impl;
import com.ibm.wala.cast.tree.*; import java.util.Collection;
import com.ibm.wala.util.debug.Assertions; import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.*; import com.ibm.wala.cast.tree.CAstControlFlowMap;
import com.ibm.wala.cast.tree.CAstNode;
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
/** /**
* An implementation of a CAstControlFlowMap that is designed to be used by * An implementation of a CAstControlFlowMap that is designed to be used by

View File

@ -23,8 +23,7 @@ public abstract class CAstRewriter<RewriteContext> {
protected final RewriteContext rootContext; protected final RewriteContext rootContext;
public CAstRewriter(CAst Ast, boolean recursive, RewriteContext rootContext) public CAstRewriter(CAst Ast, boolean recursive, RewriteContext rootContext) {
{
this.Ast = Ast; this.Ast = Ast;
this.recursive = recursive; this.recursive = recursive;
this.rootContext = rootContext; this.rootContext = rootContext;
@ -40,24 +39,19 @@ public abstract class CAstRewriter<RewriteContext> {
CAstNodeTypeMap newTypes(); CAstNodeTypeMap newTypes();
Map<CAstNode,Collection<CAstEntity>> newChildren(); Map<CAstNode, Collection<CAstEntity>> newChildren();
} }
protected abstract CAstNode copyNodes(CAstNode root, RewriteContext context, Map<CAstNode, CAstNode> nodeMap); protected abstract CAstNode copyNodes(CAstNode root, RewriteContext context, Map<CAstNode, CAstNode> nodeMap);
protected CAstNode flowOutTo(Map<CAstNode, CAstNode> nodeMap, protected CAstNode flowOutTo(Map<CAstNode, CAstNode> nodeMap, CAstNode oldSource, Object label, CAstNode oldTarget,
CAstNode oldSource, CAstControlFlowMap orig, CAstSourcePositionMap src) {
Object label,
CAstNode oldTarget,
CAstControlFlowMap orig,
CAstSourcePositionMap src)
{
return oldTarget; return oldTarget;
} }
private CAstControlFlowMap copyFlow(Map<CAstNode, CAstNode> nodeMap, CAstControlFlowMap orig, CAstSourcePositionMap src) { private CAstControlFlowMap copyFlow(Map<CAstNode, CAstNode> nodeMap, CAstControlFlowMap orig, CAstSourcePositionMap src) {
Set mappedOutsideNodes = new HashSet(1); Set<CAstNode> mappedOutsideNodes = new HashSet<CAstNode>(1);
Collection<CAstNode> oldSources = orig.getMappedNodes(); Collection<CAstNode> oldSources = orig.getMappedNodes();
CAstControlFlowRecorder newMap = new CAstControlFlowRecorder(src); CAstControlFlowRecorder newMap = new CAstControlFlowRecorder(src);
for (Iterator<CAstNode> NS = nodeMap.keySet().iterator(); NS.hasNext();) { for (Iterator<CAstNode> NS = nodeMap.keySet().iterator(); NS.hasNext();) {
@ -70,15 +64,12 @@ public abstract class CAstRewriter<RewriteContext> {
if (nodeMap.containsKey(oldTarget)) { if (nodeMap.containsKey(oldTarget)) {
newMap.add(newNode, nodeMap.get(oldTarget), null); newMap.add(newNode, nodeMap.get(oldTarget), null);
} else { } else {
CAstNode tgt = flowOutTo(nodeMap, old, null, oldTarget, orig, src); CAstNode tgt = flowOutTo(nodeMap, old, null, oldTarget, orig, src);
newMap.add(newNode, tgt, null); newMap.add(newNode, tgt, null);
if (tgt != CAstControlFlowMap.EXCEPTION_TO_EXIT if (tgt != CAstControlFlowMap.EXCEPTION_TO_EXIT && !mappedOutsideNodes.contains(tgt)) {
&& mappedOutsideNodes.add(tgt);
!mappedOutsideNodes.contains(tgt)) newMap.map(tgt, tgt);
{ }
mappedOutsideNodes.add(tgt);
newMap.map(tgt, tgt);
}
} }
} }
@ -88,15 +79,12 @@ public abstract class CAstRewriter<RewriteContext> {
if (nodeMap.containsKey(oldTarget)) { if (nodeMap.containsKey(oldTarget)) {
newMap.add(newNode, nodeMap.get(oldTarget), label); newMap.add(newNode, nodeMap.get(oldTarget), label);
} else { } else {
CAstNode tgt = flowOutTo(nodeMap, old, null, oldTarget, orig, src); CAstNode tgt = flowOutTo(nodeMap, old, null, oldTarget, orig, src);
newMap.add(newNode, tgt, label); newMap.add(newNode, tgt, label);
if (tgt != CAstControlFlowMap.EXCEPTION_TO_EXIT if (tgt != CAstControlFlowMap.EXCEPTION_TO_EXIT && !mappedOutsideNodes.contains(tgt)) {
&& mappedOutsideNodes.add(tgt);
!mappedOutsideNodes.contains(tgt)) newMap.map(tgt, tgt);
{ }
mappedOutsideNodes.add(tgt);
newMap.map(tgt, tgt);
}
} }
} }
} }
@ -142,8 +130,8 @@ public abstract class CAstRewriter<RewriteContext> {
} }
} }
private Map<CAstNode,Collection<CAstEntity>> copyChildren(Map nodeMap, Map<CAstNode,Collection<CAstEntity>> children) { private Map<CAstNode, Collection<CAstEntity>> copyChildren(Map nodeMap, Map<CAstNode, Collection<CAstEntity>> children) {
final Map<CAstNode,Collection<CAstEntity>> newChildren = new LinkedHashMap<CAstNode,Collection<CAstEntity>>(); final Map<CAstNode, Collection<CAstEntity>> newChildren = new LinkedHashMap<CAstNode, Collection<CAstEntity>>();
for (Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext();) { for (Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext();) {
Map.Entry entry = (Map.Entry) NS.next(); Map.Entry entry = (Map.Entry) NS.next();
@ -153,20 +141,20 @@ public abstract class CAstRewriter<RewriteContext> {
if (children.containsKey(oldNode)) { if (children.containsKey(oldNode)) {
Set<CAstEntity> newEntities = new LinkedHashSet<CAstEntity>(); Set<CAstEntity> newEntities = new LinkedHashSet<CAstEntity>();
newChildren.put(newNode, newEntities); newChildren.put(newNode, newEntities);
for (Iterator oldEntities = ((Collection) children.get(oldNode)).iterator(); oldEntities.hasNext();) { for (Iterator oldEntities = children.get(oldNode).iterator(); oldEntities.hasNext();) {
CAstEntity oldE = (CAstEntity) oldEntities.next(); CAstEntity oldE = (CAstEntity) oldEntities.next();
newEntities.add(recursive ? rewrite(oldE) : oldE); newEntities.add(recursive ? rewrite(oldE) : oldE);
} }
} }
} }
for (Iterator<Map.Entry<CAstNode,Collection<CAstEntity>>> keys = children.entrySet().iterator(); keys.hasNext();) { for (Iterator<Map.Entry<CAstNode, Collection<CAstEntity>>> keys = children.entrySet().iterator(); keys.hasNext();) {
Map.Entry<CAstNode,Collection<CAstEntity>> entry = keys.next(); Map.Entry<CAstNode, Collection<CAstEntity>> entry = keys.next();
CAstNode key = entry.getKey(); CAstNode key = entry.getKey();
if (!(key instanceof CAstNode)) { if (!(key instanceof CAstNode)) {
Set<CAstEntity> newEntities = new LinkedHashSet<CAstEntity>(); Set<CAstEntity> newEntities = new LinkedHashSet<CAstEntity>();
newChildren.put(key, newEntities); newChildren.put(key, newEntities);
for (Iterator oldEntities = ((Collection) entry.getValue()).iterator(); oldEntities.hasNext();) { for (Iterator oldEntities = entry.getValue().iterator(); oldEntities.hasNext();) {
CAstEntity oldE = (CAstEntity) oldEntities.next(); CAstEntity oldE = (CAstEntity) oldEntities.next();
newEntities.add(recursive ? rewrite(oldE) : oldE); newEntities.add(recursive ? rewrite(oldE) : oldE);
} }
@ -177,7 +165,7 @@ public abstract class CAstRewriter<RewriteContext> {
} }
public Rewrite rewrite(CAstNode root, final CAstControlFlowMap cfg, final CAstSourcePositionMap pos, final CAstNodeTypeMap types, public Rewrite rewrite(CAstNode root, final CAstControlFlowMap cfg, final CAstSourcePositionMap pos, final CAstNodeTypeMap types,
final Map<CAstNode,Collection<CAstEntity>> children) { final Map<CAstNode, Collection<CAstEntity>> children) {
final Map<CAstNode, CAstNode> nodes = new HashMap<CAstNode, CAstNode>(); final Map<CAstNode, CAstNode> nodes = new HashMap<CAstNode, CAstNode>();
final CAstNode newRoot = copyNodes(root, rootContext, nodes); final CAstNode newRoot = copyNodes(root, rootContext, nodes);
return new Rewrite() { return new Rewrite() {
@ -187,7 +175,7 @@ public abstract class CAstRewriter<RewriteContext> {
private CAstNodeTypeMap theTypes = null; private CAstNodeTypeMap theTypes = null;
private Map<CAstNode,Collection<CAstEntity>> theChildren = null; private Map<CAstNode, Collection<CAstEntity>> theChildren = null;
public CAstNode newRoot() { public CAstNode newRoot() {
return newRoot; return newRoot;
@ -195,7 +183,7 @@ public abstract class CAstRewriter<RewriteContext> {
public CAstControlFlowMap newCfg() { public CAstControlFlowMap newCfg() {
if (theCfg == null) if (theCfg == null)
theCfg = copyFlow(nodes, cfg, newPos()); theCfg = copyFlow(nodes, cfg, newPos());
return theCfg; return theCfg;
} }
@ -211,7 +199,7 @@ public abstract class CAstRewriter<RewriteContext> {
return theTypes; return theTypes;
} }
public Map<CAstNode,Collection<CAstEntity>> newChildren() { public Map<CAstNode, Collection<CAstEntity>> newChildren() {
if (theChildren == null) if (theChildren == null)
theChildren = copyChildren(nodes, children); theChildren = copyChildren(nodes, children);
return theChildren; return theChildren;
@ -262,13 +250,13 @@ public abstract class CAstRewriter<RewriteContext> {
} else if (recursive) { } else if (recursive) {
Map<CAstNode, Collection<CAstEntity>> children = root.getAllScopedEntities(); Map<CAstNode, Collection<CAstEntity>> children = root.getAllScopedEntities();
final Map<CAstNode,Collection<CAstEntity>> newChildren = new LinkedHashMap<CAstNode,Collection<CAstEntity>>(); final Map<CAstNode, Collection<CAstEntity>> newChildren = new LinkedHashMap<CAstNode, Collection<CAstEntity>>();
for (Iterator<Map.Entry<CAstNode,Collection<CAstEntity>>> keys = children.entrySet().iterator(); keys.hasNext();) { for (Iterator<Map.Entry<CAstNode, Collection<CAstEntity>>> keys = children.entrySet().iterator(); keys.hasNext();) {
Map.Entry<CAstNode,Collection<CAstEntity>> entry = keys.next(); Map.Entry<CAstNode, Collection<CAstEntity>> entry = keys.next();
CAstNode key = entry.getKey(); CAstNode key = entry.getKey();
Set<CAstEntity> newValues = new LinkedHashSet<CAstEntity>(); Set<CAstEntity> newValues = new LinkedHashSet<CAstEntity>();
newChildren.put(key, newValues); newChildren.put(key, newValues);
for (Iterator es = ((Collection) entry.getValue()).iterator(); es.hasNext();) { for (Iterator es = entry.getValue().iterator(); es.hasNext();) {
newValues.add(rewrite((CAstEntity) es.next())); newValues.add(rewrite((CAstEntity) es.next()));
} }
} }
@ -280,13 +268,13 @@ public abstract class CAstRewriter<RewriteContext> {
public Iterator getScopedEntities(CAstNode construct) { public Iterator getScopedEntities(CAstNode construct) {
if (newChildren.containsKey(construct)) { if (newChildren.containsKey(construct)) {
return ((Collection) newChildren.get(construct)).iterator(); return newChildren.get(construct).iterator();
} else { } else {
return EmptyIterator.instance(); return EmptyIterator.instance();
} }
} }
public Map<CAstNode,Collection<CAstEntity>> getAllScopedEntities() { public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
return newChildren; return newChildren;
} }
}; };