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.client;
|
|
|
|
|
2007-02-08 19:07:30 +00:00
|
|
|
import java.io.IOException;
|
2007-12-11 16:34:02 +00:00
|
|
|
import java.util.Collections;
|
2007-02-08 19:07:30 +00:00
|
|
|
import java.util.jar.JarFile;
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2007-02-08 19:07:30 +00:00
|
|
|
import com.ibm.wala.cast.ipa.callgraph.CAstAnalysisScope;
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
|
2007-07-06 22:09:08 +00:00
|
|
|
import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptEntryPoints;
|
|
|
|
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
|
|
|
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
|
2007-02-08 19:07:30 +00:00
|
|
|
import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory;
|
|
|
|
import com.ibm.wala.cast.js.types.JavaScriptTypes;
|
|
|
|
import com.ibm.wala.classLoader.Module;
|
|
|
|
import com.ibm.wala.classLoader.SourceFileModule;
|
|
|
|
import com.ibm.wala.client.impl.AbstractAnalysisEngine;
|
2007-07-20 15:20:23 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
2007-07-06 22:09:08 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
|
|
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2007-02-08 19:07:30 +00:00
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
2007-02-02 17:25:09 +00:00
|
|
|
|
|
|
|
public class JavaScriptAnalysisEngine extends AbstractAnalysisEngine {
|
|
|
|
|
|
|
|
protected JavaScriptLoaderFactory loaderFactory;
|
|
|
|
|
|
|
|
protected JavaScriptTranslatorFactory translatorFactory;
|
|
|
|
|
|
|
|
protected boolean keepIRs = true;
|
|
|
|
|
|
|
|
public JavaScriptAnalysisEngine() {
|
2007-02-09 15:34:25 +00:00
|
|
|
setCallGraphBuilderFactory(new com.ibm.wala.cast.js.client.impl.ZeroCFABuilderFactory());
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:34:25 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2007-02-02 17:25:09 +00:00
|
|
|
protected void buildAnalysisScope() {
|
|
|
|
try {
|
2007-02-12 18:30:10 +00:00
|
|
|
if (translatorFactory == null) {
|
2007-05-15 17:44:43 +00:00
|
|
|
translatorFactory = new JavaScriptTranslatorFactory.CAstRhinoFactory();
|
2007-02-12 18:30:10 +00:00
|
|
|
}
|
|
|
|
|
2007-02-02 17:25:09 +00:00
|
|
|
loaderFactory = new JavaScriptLoaderFactory(translatorFactory);
|
|
|
|
|
2007-02-09 15:34:25 +00:00
|
|
|
SourceFileModule[] files = (SourceFileModule[]) moduleFiles.toArray(new SourceFileModule[moduleFiles.size()]);
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2007-12-11 16:34:02 +00:00
|
|
|
scope = new CAstAnalysisScope(files, loaderFactory, Collections.singleton(JavaScriptLoader.JS));
|
2007-02-02 17:25:09 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
Assertions.UNREACHABLE(e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-10 05:26:56 +00:00
|
|
|
public IClassHierarchy buildClassHierarchy() {
|
2007-02-02 17:25:09 +00:00
|
|
|
try {
|
2007-07-06 22:09:08 +00:00
|
|
|
return ClassHierarchy.make(getScope(), loaderFactory, JavaScriptLoader.JS);
|
2007-02-02 17:25:09 +00:00
|
|
|
} catch (ClassHierarchyException e) {
|
|
|
|
Assertions.UNREACHABLE(e.toString());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTranslatorFactory(JavaScriptTranslatorFactory factory) {
|
2007-02-09 15:34:25 +00:00
|
|
|
this.translatorFactory = factory;
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setJ2SELibraries(JarFile[] libs) {
|
|
|
|
Assertions.UNREACHABLE("Illegal to call setJ2SELibraries");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setJ2SELibraries(Module[] libs) {
|
|
|
|
Assertions.UNREACHABLE("Illegal to call setJ2SELibraries");
|
|
|
|
}
|
|
|
|
|
2007-06-01 03:32:56 +00:00
|
|
|
protected Iterable<Entrypoint> makeDefaultEntrypoints(AnalysisScope scope, IClassHierarchy cha) {
|
2007-05-15 17:44:43 +00:00
|
|
|
return new JavaScriptEntryPoints(cha, cha.getLoader(JavaScriptTypes.jsLoader));
|
2007-02-12 18:30:10 +00:00
|
|
|
}
|
|
|
|
|
2007-07-20 15:20:23 +00:00
|
|
|
@Override
|
|
|
|
public AnalysisCache makeDefaultCache() {
|
|
|
|
return new AnalysisCache(AstIRFactory.makeDefaultFactory(keepIRs));
|
|
|
|
}
|
|
|
|
|
2007-05-15 17:44:43 +00:00
|
|
|
public AnalysisOptions getDefaultOptions(Iterable<Entrypoint> roots) {
|
2007-07-20 15:20:23 +00:00
|
|
|
final AnalysisOptions options = new AnalysisOptions(scope, roots);
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2007-02-09 15:34:25 +00:00
|
|
|
options.setUseConstantSpecificKeys(true);
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2007-02-09 15:34:25 +00:00
|
|
|
options.setUseStacksForLexicalScoping(true);
|
|
|
|
|
2007-02-02 17:25:09 +00:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
}
|