2007-02-02 17:25:09 +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.js.ipa.callgraph;
|
|
|
|
|
2010-11-02 19:11:58 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
2007-07-06 22:09:08 +00:00
|
|
|
import com.ibm.wala.cast.ipa.callgraph.AstCFAPointerKeys;
|
2013-01-08 01:18:27 +00:00
|
|
|
import com.ibm.wala.cast.ipa.callgraph.ReflectedFieldPointerKey;
|
2010-11-02 19:11:58 +00:00
|
|
|
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
2011-04-04 15:23:58 +00:00
|
|
|
import com.ibm.wala.classLoader.IClass;
|
2010-11-02 19:11:58 +00:00
|
|
|
import com.ibm.wala.classLoader.IField;
|
2007-07-20 15:20:23 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
2007-02-02 17:25:09 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
2011-04-04 15:23:58 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey;
|
2012-12-18 18:11:59 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
|
2010-11-02 19:11:58 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
2007-06-01 03:32:56 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2010-11-02 19:11:58 +00:00
|
|
|
import com.ibm.wala.types.TypeReference;
|
|
|
|
import com.ibm.wala.util.collections.EmptyIterator;
|
2012-12-18 18:11:59 +00:00
|
|
|
import com.ibm.wala.util.strings.Atom;
|
2007-02-02 17:25:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Common utilities for CFA-style call graph builders.
|
|
|
|
*/
|
2012-01-06 21:19:49 +00:00
|
|
|
public abstract class JSCFABuilder extends JSSSAPropagationCallGraphBuilder {
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2007-07-20 15:20:23 +00:00
|
|
|
public JSCFABuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) {
|
2010-11-02 19:11:58 +00:00
|
|
|
super(cha, options, cache, new AstCFAPointerKeys() {
|
|
|
|
|
|
|
|
private boolean isBogusKey(InstanceKey K) {
|
|
|
|
TypeReference t = K.getConcreteType().getReference();
|
|
|
|
return t == JavaScriptTypes.Null || t == JavaScriptTypes.Undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PointerKey getPointerKeyForObjectCatalog(InstanceKey I) {
|
|
|
|
if (isBogusKey(I)) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return super.getPointerKeyForObjectCatalog(I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField f) {
|
|
|
|
if (isBogusKey(I)) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return super.getPointerKeyForInstanceField(I, f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
|
|
|
|
if (isBogusKey(I)) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return super.getPointerKeyForArrayContents(I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Iterator<PointerKey> getPointerKeysForReflectedFieldRead(InstanceKey I, InstanceKey F) {
|
|
|
|
if (isBogusKey(I)) {
|
|
|
|
return EmptyIterator.instance();
|
|
|
|
} else {
|
|
|
|
return super.getPointerKeysForReflectedFieldRead(I, F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Iterator<PointerKey> getPointerKeysForReflectedFieldWrite(InstanceKey I, InstanceKey F) {
|
2013-01-08 01:18:27 +00:00
|
|
|
if (isBogusKey(I)) {
|
2010-11-02 19:11:58 +00:00
|
|
|
return EmptyIterator.instance();
|
|
|
|
} else {
|
|
|
|
return super.getPointerKeysForReflectedFieldWrite(I, F);
|
|
|
|
}
|
|
|
|
}
|
2012-12-18 18:11:59 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected PointerKey getInstanceFieldPointerKeyForConstant(InstanceKey I, ConstantKey F) {
|
|
|
|
Object v = F.getValue();
|
2014-10-28 20:09:32 +00:00
|
|
|
String strVal = JSCallGraphUtil.simulateToStringForPropertyNames(v);
|
2013-01-08 01:18:27 +00:00
|
|
|
// if we know the string representation of the constant, use it...
|
|
|
|
if (strVal != null) {
|
|
|
|
IField f = I.getConcreteType().getField(Atom.findOrCreateUnicodeAtom(strVal));
|
2012-12-18 18:11:59 +00:00
|
|
|
return getPointerKeyForInstanceField(I, f);
|
|
|
|
|
2013-01-08 01:18:27 +00:00
|
|
|
// ...otherwise it is some unknown string
|
2012-12-18 18:11:59 +00:00
|
|
|
} else {
|
2013-01-08 01:18:27 +00:00
|
|
|
return ReflectedFieldPointerKey.mapped(new ConcreteTypeKey(getFieldNameType(F)), I);
|
2012-12-18 18:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 01:18:27 +00:00
|
|
|
/**
|
|
|
|
* All values used as property names get implicitly converted to strings in JavaScript.
|
|
|
|
* @see com.ibm.wala.cast.ipa.callgraph.DelegatingAstPointerKeys#getFieldNameType(com.ibm.wala.ipa.callgraph.propagation.InstanceKey)
|
|
|
|
*/
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2013-01-08 01:18:27 +00:00
|
|
|
protected IClass getFieldNameType(InstanceKey F) {
|
|
|
|
return F.getConcreteType().getClassHierarchy().lookupClass(JavaScriptTypes.String);
|
2014-10-28 20:09:32 +00:00
|
|
|
}
|
2010-11-02 19:11:58 +00:00
|
|
|
});
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|