2007-02-02 17:17:13 +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.cast.ipa.callgraph;
|
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import com.ibm.wala.classLoader.IField;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory;
|
2007-07-11 21:07:32 +00:00
|
|
|
import com.ibm.wala.util.collections.HashMapFactory;
|
|
|
|
import com.ibm.wala.util.collections.HashSetFactory;
|
2007-07-06 22:09:29 +00:00
|
|
|
import com.ibm.wala.util.collections.NonNullSingletonIterator;
|
2008-01-24 22:05:51 +00:00
|
|
|
import com.ibm.wala.util.strings.Atom;
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
public class DelegatingAstPointerKeys implements AstPointerKeyFactory {
|
|
|
|
private final PointerKeyFactory base;
|
|
|
|
|
|
|
|
public DelegatingAstPointerKeys(PointerKeyFactory base) {
|
|
|
|
this.base = base;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) {
|
|
|
|
return base.getPointerKeyForLocal(node, valueNumber);
|
|
|
|
}
|
|
|
|
|
2007-03-12 02:00:43 +00:00
|
|
|
public FilteredPointerKey getFilteredPointerKeyForLocal(CGNode node, int valueNumber, FilteredPointerKey.TypeFilter filter) {
|
2007-02-02 17:17:13 +00:00
|
|
|
return base.getFilteredPointerKeyForLocal(node, valueNumber, filter);
|
|
|
|
}
|
|
|
|
|
2007-02-08 20:45:07 +00:00
|
|
|
public PointerKey getPointerKeyForReturnValue(CGNode node) {
|
2007-02-02 17:17:13 +00:00
|
|
|
return base.getPointerKeyForReturnValue(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerKey getPointerKeyForExceptionalReturnValue(CGNode node) {
|
|
|
|
return base.getPointerKeyForExceptionalReturnValue(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerKey getPointerKeyForStaticField(IField f) {
|
|
|
|
return base.getPointerKeyForStaticField(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerKey getPointerKeyForObjectCatalog(InstanceKey I) {
|
|
|
|
return new ObjectPropertyCatalogKey(I);
|
|
|
|
}
|
|
|
|
|
2007-07-11 21:07:32 +00:00
|
|
|
private final Map<IField, Set<PointerKey>> specificStringKeys = HashMapFactory.make();
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField f) {
|
|
|
|
PointerKey fk = base.getPointerKeyForInstanceField(I, f);
|
2007-02-08 20:45:07 +00:00
|
|
|
if (!specificStringKeys.containsKey(f)) {
|
2007-07-11 21:07:32 +00:00
|
|
|
HashSet<PointerKey> s = HashSetFactory.make();
|
|
|
|
specificStringKeys.put(f, s);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
2007-02-08 20:45:07 +00:00
|
|
|
specificStringKeys.get(f).add(fk);
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
return fk;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
|
|
|
|
return base.getPointerKeyForArrayContents(I);
|
|
|
|
}
|
|
|
|
|
2007-02-08 20:45:07 +00:00
|
|
|
public Iterator<PointerKey> getPointerKeysForReflectedFieldRead(InstanceKey I, InstanceKey F) {
|
|
|
|
List<PointerKey> result = new LinkedList<PointerKey>();
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
// FIXME: current only constant string are handled
|
|
|
|
if (F instanceof ConstantKey) {
|
2007-02-08 20:45:07 +00:00
|
|
|
Object v = ((ConstantKey) F).getValue();
|
2007-02-02 17:17:13 +00:00
|
|
|
if (v instanceof String) {
|
2007-02-08 20:45:07 +00:00
|
|
|
IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom((String) v));
|
|
|
|
result.add(getPointerKeyForInstanceField(I, f));
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.add(ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(F.getConcreteType()), I));
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
return result.iterator();
|
|
|
|
}
|
|
|
|
|
2007-02-08 20:45:07 +00:00
|
|
|
public Iterator<PointerKey> getPointerKeysForReflectedFieldWrite(InstanceKey I, InstanceKey F) {
|
2007-02-02 17:17:13 +00:00
|
|
|
// FIXME: current only constant string are handled
|
|
|
|
if (F instanceof ConstantKey) {
|
2007-02-08 20:45:07 +00:00
|
|
|
Object v = ((ConstantKey) F).getValue();
|
2007-02-02 17:17:13 +00:00
|
|
|
if (v instanceof String) {
|
2007-02-08 20:45:07 +00:00
|
|
|
IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom((String) v));
|
|
|
|
return new NonNullSingletonIterator<PointerKey>(getPointerKeyForInstanceField(I, f));
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-08 20:45:07 +00:00
|
|
|
return new NonNullSingletonIterator<PointerKey>(ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(F.getConcreteType()), I));
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|