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) {
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
PointerKey ifk = getInstanceFieldPointerKeyForConstant(I, (ConstantKey<?>) F);
|
2012-12-18 18:11:59 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
protected PointerKey getInstanceFieldPointerKeyForConstant(InstanceKey I, ConstantKey<?> F) {
|
2012-12-18 18:11:59 +00:00
|
|
|
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) {
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
PointerKey ifk = getInstanceFieldPointerKeyForConstant(I, (ConstantKey<?>) F);
|
2012-12-18 18:11:59 +00:00
|
|
|
if (ifk != null) {
|
2017-03-12 03:20:51 +00:00
|
|
|
return new NonNullSingletonIterator<>(ifk);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-25 16:06:09 +00:00
|
|
|
PointerKey x = ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(getFieldNameType(F)), I);
|
|
|
|
return new NonNullSingletonIterator<>(x);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|