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;
|
|
|
|
|
2007-07-06 22:09:08 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
|
|
|
import com.ibm.wala.ipa.callgraph.ContextSelector;
|
2017-02-03 01:33:27 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
2012-01-06 21:46:50 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
|
2012-01-06 21:44:53 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.impl.ContextInsensitiveSelector;
|
2007-07-06 22:09:08 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.impl.DelegatingContextSelector;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
|
2012-01-06 21:26:01 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.cfa.DelegatingSSAContextInterpreter;
|
2007-11-16 20:57:58 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
|
2008-01-30 15:43:32 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.cfa.nCFAContextSelector;
|
2007-06-01 03:32:56 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2007-02-02 17:25:09 +00:00
|
|
|
|
|
|
|
/**
|
2012-01-06 21:29:27 +00:00
|
|
|
* 0-x-CFA Call graph builder, optimized to not disambiguate instances of
|
|
|
|
* "uninteresting" types
|
2007-02-02 17:25:09 +00:00
|
|
|
*/
|
2007-11-06 04:14:03 +00:00
|
|
|
public class JSZeroOrOneXCFABuilder extends JSCFABuilder {
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2012-01-06 21:48:01 +00:00
|
|
|
private static final boolean USE_OBJECT_SENSITIVITY = false;
|
2012-01-06 21:46:50 +00:00
|
|
|
|
2012-01-06 21:29:27 +00:00
|
|
|
|
2017-02-03 01:33:27 +00:00
|
|
|
public JSZeroOrOneXCFABuilder(IClassHierarchy cha, JSAnalysisOptions options, IAnalysisCacheView cache,
|
2012-01-06 21:29:27 +00:00
|
|
|
ContextSelector appContextSelector, SSAContextInterpreter appContextInterpreter, int instancePolicy, boolean doOneCFA) {
|
2007-07-20 15:20:23 +00:00
|
|
|
super(cha, options, cache);
|
2007-07-06 22:09:08 +00:00
|
|
|
|
2012-02-17 20:22:30 +00:00
|
|
|
SSAContextInterpreter contextInterpreter = setupSSAContextInterpreter(cha, options, cache, appContextInterpreter);
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2017-03-25 22:18:27 +00:00
|
|
|
setupMethodTargetSelector(cha, options);
|
2012-02-17 20:22:30 +00:00
|
|
|
|
|
|
|
setupContextSelector(options, appContextSelector, doOneCFA);
|
2012-02-17 20:20:26 +00:00
|
|
|
|
2012-02-17 20:22:30 +00:00
|
|
|
setInstanceKeys(new JavaScriptScopeMappingInstanceKeys(cha, this, new JavaScriptConstructorInstanceKeys(new ZeroXInstanceKeys(
|
|
|
|
options, cha, contextInterpreter, instancePolicy))));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupContextSelector(JSAnalysisOptions options, ContextSelector appContextSelector, boolean doOneCFA) {
|
|
|
|
// baseline selector
|
2012-02-17 20:21:18 +00:00
|
|
|
ContextSelector def = new ContextInsensitiveSelector();
|
|
|
|
ContextSelector contextSelector = appContextSelector == null ? def : new DelegatingContextSelector(appContextSelector, def);
|
2012-02-17 20:22:30 +00:00
|
|
|
|
2012-02-17 20:22:55 +00:00
|
|
|
// JavaScriptConstructorContextSelector ensures at least a 0-1-CFA (i.e.,
|
|
|
|
// Andersen's-style) heap abstraction. This level of heap abstraction is
|
|
|
|
// _necessary_ for correctness (we rely on it when handling lexical scoping)
|
2013-06-07 16:48:00 +00:00
|
|
|
contextSelector = new JavaScriptConstructorContextSelector(contextSelector);
|
2012-02-17 20:22:30 +00:00
|
|
|
|
2014-08-07 20:02:48 +00:00
|
|
|
//contextSelector = new OneLevelForLexicalAccessFunctions(contextSelector);
|
2012-02-17 20:22:55 +00:00
|
|
|
|
2012-02-17 20:21:18 +00:00
|
|
|
if (USE_OBJECT_SENSITIVITY) {
|
|
|
|
contextSelector = new ObjectSensitivityContextSelector(contextSelector);
|
|
|
|
}
|
2012-02-17 20:20:26 +00:00
|
|
|
if (options.handleCallApply()) {
|
2012-02-17 20:21:18 +00:00
|
|
|
contextSelector = new JavaScriptFunctionApplyContextSelector(contextSelector);
|
2012-02-17 20:20:26 +00:00
|
|
|
}
|
2012-02-17 20:21:18 +00:00
|
|
|
if (doOneCFA) {
|
|
|
|
contextSelector = new nCFAContextSelector(1, contextSelector);
|
|
|
|
}
|
|
|
|
setContextSelector(contextSelector);
|
2012-02-17 20:22:30 +00:00
|
|
|
}
|
2012-02-17 20:21:18 +00:00
|
|
|
|
2012-02-17 20:23:37 +00:00
|
|
|
|
2017-03-25 22:18:27 +00:00
|
|
|
private void setupMethodTargetSelector(IClassHierarchy cha, JSAnalysisOptions options) {
|
2012-02-17 20:22:30 +00:00
|
|
|
MethodTargetSelector targetSelector = new JavaScriptConstructTargetSelector(cha, options
|
|
|
|
.getMethodTargetSelector());
|
|
|
|
if (options.handleCallApply()) {
|
2017-03-25 22:18:27 +00:00
|
|
|
targetSelector = new JavaScriptFunctionApplyTargetSelector(new JavaScriptFunctionDotCallTargetSelector(targetSelector));
|
2012-02-17 20:22:30 +00:00
|
|
|
}
|
|
|
|
if (options.useLoadFileTargetSelector()) {
|
|
|
|
targetSelector = new LoadFileTargetSelector(targetSelector, this);
|
|
|
|
}
|
|
|
|
options.setSelector(targetSelector);
|
|
|
|
}
|
|
|
|
|
2017-02-03 01:33:27 +00:00
|
|
|
private SSAContextInterpreter setupSSAContextInterpreter(IClassHierarchy cha, JSAnalysisOptions options, IAnalysisCacheView cache,
|
2012-02-17 20:22:30 +00:00
|
|
|
SSAContextInterpreter appContextInterpreter) {
|
|
|
|
SSAContextInterpreter contextInterpreter = makeDefaultContextInterpreters(appContextInterpreter, options, cha);
|
|
|
|
if (options.handleCallApply()) {
|
|
|
|
contextInterpreter = new DelegatingSSAContextInterpreter(new JavaScriptFunctionApplyContextInterpreter(options, cache),
|
|
|
|
contextInterpreter);
|
|
|
|
}
|
|
|
|
setContextInterpreter(contextInterpreter);
|
|
|
|
return contextInterpreter;
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-06 21:29:27 +00:00
|
|
|
* @param options
|
|
|
|
* options that govern call graph construction
|
|
|
|
* @param cha
|
|
|
|
* governing class hierarchy
|
|
|
|
* @param cl
|
|
|
|
* classloader that can find DOMO resources
|
|
|
|
* @param scope
|
|
|
|
* representation of the analysis scope
|
|
|
|
* @param xmlFiles
|
|
|
|
* set of Strings that are names of XML files holding bypass logic
|
|
|
|
* specifications.
|
2007-02-02 17:25:09 +00:00
|
|
|
* @return a 0-1-Opt-CFA Call Graph Builder.
|
|
|
|
*/
|
2017-03-16 02:06:19 +00:00
|
|
|
public static JSCFABuilder make(JSAnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, ClassLoader cl,
|
2008-01-10 22:05:37 +00:00
|
|
|
AnalysisScope scope, String[] xmlFiles, byte instancePolicy, boolean doOneCFA) {
|
2007-07-06 22:09:08 +00:00
|
|
|
com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha);
|
2017-11-28 20:26:09 +00:00
|
|
|
for (String xmlFile : xmlFiles) {
|
|
|
|
com.ibm.wala.ipa.callgraph.impl.Util.addBypassLogic(options, scope, cl, xmlFile, cha);
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
2010-05-12 17:19:54 +00:00
|
|
|
return new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, instancePolicy, doOneCFA);
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|