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.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-12-18 18:11:59 +00:00
|
|
|
import com.ibm.wala.classLoader.IClass;
|
2007-07-06 22:09:29 +00:00
|
|
|
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;
|
2012-12-18 18:11:59 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceFieldKey;
|
2007-07-06 22:09:29 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public PointerKey getPointerKeyForLocal(CGNode node, int valueNumber) {
|
|
|
|
return base.getPointerKeyForLocal(node, valueNumber);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
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);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
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);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public PointerKey getPointerKeyForExceptionalReturnValue(CGNode node) {
|
|
|
|
return base.getPointerKeyForExceptionalReturnValue(node);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public PointerKey getPointerKeyForStaticField(IField f) {
|
|
|
|
return base.getPointerKeyForStaticField(f);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public PointerKey getPointerKeyForObjectCatalog(InstanceKey I) {
|
|
|
|
return new ObjectPropertyCatalogKey(I);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField f) {
|
2011-05-05 14:31:47 +00:00
|
|
|
return base.getPointerKeyForInstanceField(I, f);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
|
|
|
|
return base.getPointerKeyForArrayContents(I);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2013-01-08 01:18:27 +00:00
|
|
|
public Iterator<PointerKey> getPointerKeysForReflectedFieldWrite(InstanceKey I, InstanceKey F) {
|
2017-03-12 03:20:51 +00:00
|
|
|
List<PointerKey> result = new LinkedList<>();
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
if (F instanceof ConstantKey) {
|
2012-12-18 18:11:59 +00:00
|
|
|
PointerKey ifk = getInstanceFieldPointerKeyForConstant(I, (ConstantKey) F);
|
|
|
|
if (ifk != null) {
|
|
|
|
result.add(ifk);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 18:11:59 +00:00
|
|
|
result.add(ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(getFieldNameType(F)), I));
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
return result.iterator();
|
|
|
|
}
|
|
|
|
|
2012-12-18 18:11:59 +00:00
|
|
|
/**
|
|
|
|
* get type for F appropriate for use in a field name.
|
|
|
|
*
|
|
|
|
* @param F
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
protected IClass getFieldNameType(InstanceKey F) {
|
|
|
|
return F.getConcreteType();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* if F is a supported constant representing a field, return the corresponding {@link InstanceFieldKey} for I. Otherwise, return <code>null</code>.
|
|
|
|
* @param F
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
protected PointerKey getInstanceFieldPointerKeyForConstant(InstanceKey I, ConstantKey F) {
|
|
|
|
Object v = F.getValue();
|
2007-02-02 17:17:13 +00:00
|
|
|
// FIXME: current only constant string are handled
|
2012-12-18 18:11:59 +00:00
|
|
|
if (v instanceof String) {
|
|
|
|
IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom((String) v));
|
|
|
|
return getPointerKeyForInstanceField(I, f);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2013-01-08 01:18:27 +00:00
|
|
|
public Iterator<PointerKey> getPointerKeysForReflectedFieldRead(InstanceKey I, InstanceKey F) {
|
2007-02-02 17:17:13 +00:00
|
|
|
if (F instanceof ConstantKey) {
|
2012-12-18 18:11:59 +00:00
|
|
|
PointerKey ifk = getInstanceFieldPointerKeyForConstant(I, (ConstantKey) F);
|
|
|
|
if (ifk != null) {
|
2017-03-12 03:20:51 +00:00
|
|
|
return new NonNullSingletonIterator<>(ifk);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-18 18:11:59 +00:00
|
|
|
return new NonNullSingletonIterator<PointerKey>(ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(getFieldNameType(F)), I));
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|