just format
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1569 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
b31268787f
commit
8f103735d0
|
@ -18,15 +18,12 @@ import com.ibm.wala.util.*;
|
|||
import com.ibm.wala.util.collections.*;
|
||||
import com.ibm.wala.util.debug.*;
|
||||
|
||||
public abstract class
|
||||
CAstRewriter<C extends CAstRewriter.RewriteContext<K>,
|
||||
K extends CAstRewriter.CopyKey<K>>
|
||||
{
|
||||
public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K extends CAstRewriter.CopyKey<K>> {
|
||||
|
||||
protected static final boolean DEBUG = false;
|
||||
|
||||
public interface CopyKey<Self extends CopyKey> {
|
||||
|
||||
|
||||
int hashCode();
|
||||
|
||||
boolean equals(Object o);
|
||||
|
@ -36,7 +33,7 @@ public abstract class
|
|||
};
|
||||
|
||||
public interface RewriteContext<K extends CopyKey> {
|
||||
|
||||
|
||||
K key();
|
||||
|
||||
};
|
||||
|
@ -74,78 +71,70 @@ public abstract class
|
|||
return oldTarget;
|
||||
}
|
||||
|
||||
private CAstControlFlowMap copyFlow(Map nodeMap,
|
||||
CAstControlFlowMap orig,
|
||||
CAstSourcePositionMap newSrc)
|
||||
{
|
||||
private CAstControlFlowMap copyFlow(Map nodeMap, CAstControlFlowMap orig, CAstSourcePositionMap newSrc) {
|
||||
Set<CAstNode> mappedOutsideNodes = HashSetFactory.make(1);
|
||||
CAstControlFlowRecorder newMap = new CAstControlFlowRecorder(newSrc);
|
||||
Collection oldSources = orig.getMappedNodes();
|
||||
|
||||
for(Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext(); ) {
|
||||
for (Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) NS.next();
|
||||
Pair N = (Pair)entry.getKey();
|
||||
Pair N = (Pair) entry.getKey();
|
||||
CAstNode oldSource = (CAstNode) N.fst;
|
||||
CopyKey key = (CopyKey) N.snd;
|
||||
|
||||
|
||||
CAstNode newSource = (CAstNode) entry.getValue();
|
||||
Assertions._assert(newSource != null);
|
||||
|
||||
newMap.map(newSource, newSource);
|
||||
|
||||
if (DEBUG) {
|
||||
Trace.println("\n\nlooking at "+key+":"+CAstPrinter.print(oldSource));
|
||||
Trace.println("\n\nlooking at " + key + ":" + CAstPrinter.print(oldSource));
|
||||
}
|
||||
|
||||
if (oldSources.contains(oldSource)) {
|
||||
Iterator LS = orig.getTargetLabels(oldSource).iterator();
|
||||
if (orig.getTarget(oldSource, null) != null) {
|
||||
LS = new IteratorPlusOne(LS, null);
|
||||
}
|
||||
Iterator LS = orig.getTargetLabels(oldSource).iterator();
|
||||
if (orig.getTarget(oldSource, null) != null) {
|
||||
LS = new IteratorPlusOne(LS, null);
|
||||
}
|
||||
|
||||
while (LS.hasNext()) {
|
||||
Object label = LS.next();
|
||||
CAstNode oldTarget = orig.getTarget(oldSource, label);
|
||||
while (LS.hasNext()) {
|
||||
Object label = LS.next();
|
||||
CAstNode oldTarget = orig.getTarget(oldSource, label);
|
||||
|
||||
if (DEBUG) {
|
||||
Trace.println("old: "+label+" --> "+CAstPrinter.print(oldTarget));
|
||||
}
|
||||
if (DEBUG) {
|
||||
Trace.println("old: " + label + " --> " + CAstPrinter.print(oldTarget));
|
||||
}
|
||||
|
||||
Pair targetKey;
|
||||
CopyKey k = key;
|
||||
do {
|
||||
targetKey = new Pair(oldTarget, k);
|
||||
if (k != null) {
|
||||
k = k.parent();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (! nodeMap.containsKey(targetKey));
|
||||
|
||||
CAstNode newTarget;
|
||||
if (nodeMap.containsKey(targetKey)) {
|
||||
newTarget = (CAstNode) nodeMap.get(targetKey);
|
||||
newMap.add(newSource, newTarget, label);
|
||||
|
||||
} else {
|
||||
newTarget = flowOutTo(nodeMap, oldSource, label, oldTarget, orig, newSrc);
|
||||
Pair targetKey;
|
||||
CopyKey k = key;
|
||||
do {
|
||||
targetKey = new Pair(oldTarget, k);
|
||||
if (k != null) {
|
||||
k = k.parent();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (!nodeMap.containsKey(targetKey));
|
||||
|
||||
CAstNode newTarget;
|
||||
if (nodeMap.containsKey(targetKey)) {
|
||||
newTarget = (CAstNode) nodeMap.get(targetKey);
|
||||
newMap.add(newSource, newTarget, label);
|
||||
if (newTarget != CAstControlFlowMap.EXCEPTION_TO_EXIT
|
||||
&&
|
||||
!mappedOutsideNodes.contains(newTarget))
|
||||
{
|
||||
mappedOutsideNodes.add(newTarget);
|
||||
|
||||
} else {
|
||||
newTarget = flowOutTo(nodeMap, oldSource, label, oldTarget, orig, newSrc);
|
||||
newMap.add(newSource, newTarget, label);
|
||||
if (newTarget != CAstControlFlowMap.EXCEPTION_TO_EXIT && !mappedOutsideNodes.contains(newTarget)) {
|
||||
mappedOutsideNodes.add(newTarget);
|
||||
newMap.map(newTarget, newTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Trace.println("mapping:old: " + CAstPrinter.print(oldSource) +
|
||||
"-- " + label + " --> " + CAstPrinter.print(oldTarget));
|
||||
Trace.println("mapping:new: " + CAstPrinter.print(newSource) +
|
||||
"-- " + label + " --> " + CAstPrinter.print(newTarget));
|
||||
}
|
||||
}
|
||||
if (DEBUG) {
|
||||
Trace.println("mapping:old: " + CAstPrinter.print(oldSource) + "-- " + label + " --> " + CAstPrinter.print(oldTarget));
|
||||
Trace.println("mapping:new: " + CAstPrinter.print(newSource) + "-- " + label + " --> " + CAstPrinter.print(newTarget));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,36 +143,36 @@ public abstract class
|
|||
|
||||
private CAstSourcePositionMap copySource(Map nodeMap, CAstSourcePositionMap orig) {
|
||||
CAstSourcePositionRecorder newMap = new CAstSourcePositionRecorder();
|
||||
for(Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext(); ) {
|
||||
Map.Entry entry = (Map.Entry)NS.next();
|
||||
Pair N = (Pair)entry.getKey();
|
||||
for (Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) NS.next();
|
||||
Pair N = (Pair) entry.getKey();
|
||||
CAstNode oldNode = (CAstNode) N.fst;
|
||||
|
||||
|
||||
CAstNode newNode = (CAstNode) entry.getValue();
|
||||
|
||||
|
||||
if (orig.getPosition(oldNode) != null) {
|
||||
newMap.setPosition(newNode, orig.getPosition(oldNode));
|
||||
newMap.setPosition(newNode, orig.getPosition(oldNode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return newMap;
|
||||
}
|
||||
|
||||
private CAstNodeTypeMap copyTypes(Map nodeMap, CAstNodeTypeMap orig) {
|
||||
if (orig != null) {
|
||||
CAstNodeTypeMapRecorder newMap = new CAstNodeTypeMapRecorder();
|
||||
for(Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext(); ) {
|
||||
Map.Entry entry = (Map.Entry) NS.next();
|
||||
Pair N = (Pair)entry.getKey();
|
||||
CAstNode oldNode = (CAstNode) N.fst;
|
||||
|
||||
CAstNode newNode = (CAstNode) entry.getValue();
|
||||
|
||||
if (orig.getNodeType(oldNode) != null) {
|
||||
newMap.add(newNode, orig.getNodeType(oldNode));
|
||||
}
|
||||
for (Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) NS.next();
|
||||
Pair N = (Pair) entry.getKey();
|
||||
CAstNode oldNode = (CAstNode) N.fst;
|
||||
|
||||
CAstNode newNode = (CAstNode) entry.getValue();
|
||||
|
||||
if (orig.getNodeType(oldNode) != null) {
|
||||
newMap.add(newNode, orig.getNodeType(oldNode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return newMap;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -193,47 +182,39 @@ public abstract class
|
|||
private Map copyChildren(Map nodeMap, Map children) {
|
||||
final Map newChildren = new LinkedHashMap();
|
||||
|
||||
for(Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext(); ) {
|
||||
Map.Entry entry = (Map.Entry)NS.next();
|
||||
Pair N = (Pair)entry.getKey();
|
||||
for (Iterator NS = nodeMap.entrySet().iterator(); NS.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) NS.next();
|
||||
Pair N = (Pair) entry.getKey();
|
||||
CAstNode oldNode = (CAstNode) N.fst;
|
||||
|
||||
|
||||
CAstNode newNode = (CAstNode) entry.getValue();
|
||||
|
||||
|
||||
if (children.containsKey(oldNode)) {
|
||||
Set newEntities = new LinkedHashSet();
|
||||
newChildren.put(newNode, newEntities);
|
||||
for(Iterator oldEntities = ((Collection)children.get(oldNode)).iterator();
|
||||
oldEntities.hasNext(); )
|
||||
{
|
||||
newEntities.add( rewrite((CAstEntity)oldEntities.next() ) );
|
||||
}
|
||||
Set newEntities = new LinkedHashSet();
|
||||
newChildren.put(newNode, newEntities);
|
||||
for (Iterator oldEntities = ((Collection) children.get(oldNode)).iterator(); oldEntities.hasNext();) {
|
||||
newEntities.add(rewrite((CAstEntity) oldEntities.next()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Iterator keys = children.entrySet().iterator(); keys.hasNext();) {
|
||||
|
||||
for (Iterator keys = children.entrySet().iterator(); keys.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) keys.next();
|
||||
Object key = entry.getKey();
|
||||
if (! (key instanceof CAstNode)) {
|
||||
Set newEntities = new LinkedHashSet();
|
||||
newChildren.put(key, newEntities);
|
||||
for(Iterator oldEntities = ((Collection)entry.getValue()).iterator();
|
||||
oldEntities.hasNext(); )
|
||||
{
|
||||
newEntities.add( rewrite((CAstEntity)oldEntities.next() ) );
|
||||
}
|
||||
if (!(key instanceof CAstNode)) {
|
||||
Set newEntities = new LinkedHashSet();
|
||||
newChildren.put(key, newEntities);
|
||||
for (Iterator oldEntities = ((Collection) entry.getValue()).iterator(); oldEntities.hasNext();) {
|
||||
newEntities.add(rewrite((CAstEntity) oldEntities.next()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newChildren;
|
||||
}
|
||||
|
||||
public Rewrite rewrite(CAstNode root,
|
||||
final CAstControlFlowMap cfg,
|
||||
final CAstSourcePositionMap pos,
|
||||
final CAstNodeTypeMap types,
|
||||
final Map<CAstNode, Collection<CAstEntity>> children)
|
||||
{
|
||||
public Rewrite rewrite(CAstNode root, final CAstControlFlowMap cfg, final CAstSourcePositionMap pos, final CAstNodeTypeMap types,
|
||||
final Map<CAstNode, Collection<CAstEntity>> children) {
|
||||
final Map<CAstNode, CAstNode> nodes = HashMapFactory.make();
|
||||
final CAstNode newRoot = copyNodes(root, rootContext, nodes);
|
||||
return new Rewrite() {
|
||||
|
|
Loading…
Reference in New Issue