Merge branch 'master' of github.com:wala/WALA

This commit is contained in:
Ben Liblit 2017-03-11 20:21:51 -06:00
commit 1cf7f0f3d3
687 changed files with 8005 additions and 1937 deletions

View File

@ -11,6 +11,7 @@ import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
import com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory; import com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory;
import com.ibm.wala.classLoader.SourceDirectoryTreeModule; import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
@ -19,8 +20,8 @@ import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
import com.ibm.wala.ipa.callgraph.CallGraphStats; import com.ibm.wala.ipa.callgraph.CallGraphStats;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util; import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.properties.WalaProperties; import com.ibm.wala.properties.WalaProperties;
import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.ClassLoaderReference;
@ -58,7 +59,7 @@ public class SourceDirCallGraph {
scope.addToScope(JavaSourceAnalysisScope.SOURCE, new SourceDirectoryTreeModule(new File(sourceDir))); scope.addToScope(JavaSourceAnalysisScope.SOURCE, new SourceDirectoryTreeModule(new File(sourceDir)));
// build the class hierarchy // build the class hierarchy
IClassHierarchy cha = ClassHierarchy.make(scope, new ECJClassLoaderFactory(scope.getExclusions())); IClassHierarchy cha = ClassHierarchyFactory.make(scope, new ECJClassLoaderFactory(scope.getExclusions()));
System.out.println(cha.getNumberOfClasses() + " classes"); System.out.println(cha.getNumberOfClasses() + " classes");
System.out.println(Warnings.asString()); System.out.println(Warnings.asString());
Warnings.clear(); Warnings.clear();
@ -67,7 +68,7 @@ public class SourceDirCallGraph {
options.setEntrypoints(entrypoints); options.setEntrypoints(entrypoints);
// you can dial down reflection handling if you like // you can dial down reflection handling if you like
// options.setReflectionOptions(ReflectionOptions.NONE); // options.setReflectionOptions(ReflectionOptions.NONE);
AnalysisCache cache = new AnalysisCache(AstIRFactory.makeDefaultFactory()); AnalysisCache cache = new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
//CallGraphBuilder builder = new ZeroCFABuilderFactory().make(options, cache, cha, scope, false); //CallGraphBuilder builder = new ZeroCFABuilderFactory().make(options, cache, cha, scope, false);
CallGraphBuilder builder = new ZeroOneContainerCFABuilderFactory().make(options, cache, cha, scope, false); CallGraphBuilder builder = new ZeroOneContainerCFABuilderFactory().make(options, cache, cha, scope, false);
System.out.println("building call graph..."); System.out.println("building call graph...");

View File

@ -1066,7 +1066,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
* NOT INCLUDING first parameter 'this' (for non-static methods) * NOT INCLUDING first parameter 'this' (for non-static methods)
*/ */
@Override @Override
public List getArgumentTypes() { public List<CAstType> getArgumentTypes() {
return fParameterTypes; return fParameterTypes;
} }
@ -1085,13 +1085,13 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
} }
@Override @Override
public Collection getSupertypes() { public Collection<CAstType> getSupertypes() {
Assertions.UNREACHABLE("CAstType.FunctionImpl#getSupertypes() called???"); Assertions.UNREACHABLE("CAstType.FunctionImpl#getSupertypes() called???");
return null; return null;
} }
@Override @Override
public Collection/* <CAstType> */getExceptionTypes() { public Collection<CAstType>/* <CAstType> */getExceptionTypes() {
if (fExceptionTypes == null) { if (fExceptionTypes == null) {
fExceptionTypes = new LinkedHashSet<CAstType>(); fExceptionTypes = new LinkedHashSet<CAstType>();
if (fDecl != null) if (fDecl != null)

View File

@ -122,7 +122,7 @@ public class JDTTypeDictionary extends CAstTypeDictionaryImpl {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Collection getSupertypes() { public Collection<CAstType> getSupertypes() {
if (fEltJdtType.isPrimitive()) if (fEltJdtType.isPrimitive())
return Collections.singleton(getCAstTypeFor(fAst.resolveWellKnownType("java.lang.Object"))); return Collections.singleton(getCAstTypeFor(fAst.resolveWellKnownType("java.lang.Object")));
// TODO: there is no '.isReference()' as in Polyglot: is this right? enum? I think if it's another array it will // TODO: there is no '.isReference()' as in Polyglot: is this right? enum? I think if it's another array it will

View File

@ -71,7 +71,6 @@ import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.Pair; import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.io.TemporaryFile; import com.ibm.wala.util.io.TemporaryFile;
/** /**

View File

@ -2,6 +2,6 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -7,9 +7,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -106,7 +106,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -2,6 +2,6 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -73,7 +73,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -2,6 +2,6 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -74,7 +74,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -23,14 +23,16 @@ import com.ibm.wala.classLoader.ClassLoaderFactory;
import com.ibm.wala.classLoader.Module; import com.ibm.wala.classLoader.Module;
import com.ibm.wala.client.AbstractAnalysisEngine; import com.ibm.wala.client.AbstractAnalysisEngine;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraphBuilder; import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.impl.Util; import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.SSAOptions; import com.ibm.wala.ssa.SSAOptions;
import com.ibm.wala.ssa.SymbolTable; import com.ibm.wala.ssa.SymbolTable;
@ -133,7 +135,7 @@ public abstract class JavaSourceAnalysisEngine<I extends InstanceKey> extends Ab
ClassLoaderFactory factory = getClassLoaderFactory(scope.getExclusions()); ClassLoaderFactory factory = getClassLoaderFactory(scope.getExclusions());
try { try {
cha = ClassHierarchy.make(getScope(), factory); cha = ClassHierarchyFactory.make(getScope(), factory);
} catch (ClassHierarchyException e) { } catch (ClassHierarchyException e) {
System.err.println("Class Hierarchy construction failed"); System.err.println("Class Hierarchy construction failed");
System.err.println(e.toString()); System.err.println(e.toString());
@ -148,8 +150,8 @@ public abstract class JavaSourceAnalysisEngine<I extends InstanceKey> extends Ab
} }
@Override @Override
public AnalysisCache makeDefaultCache() { public IAnalysisCacheView makeDefaultCache() {
return new AnalysisCache(AstIRFactory.makeDefaultFactory()); return new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
} }
@Override @Override
@ -170,7 +172,7 @@ public abstract class JavaSourceAnalysisEngine<I extends InstanceKey> extends Ab
} }
@Override @Override
protected CallGraphBuilder getCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) { protected CallGraphBuilder getCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache) {
return new ZeroCFABuilderFactory().make(options, cache, cha, scope, false); return new ZeroCFABuilderFactory().make(options, cache, cha, scope, false);
} }
} }

View File

@ -15,6 +15,7 @@ import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraphBuilder; import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.impl.Util; import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys; import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
@ -26,7 +27,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
*/ */
public class ZeroCFABuilderFactory { public class ZeroCFABuilderFactory {
public CallGraphBuilder make(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope, boolean keepPointsTo) { public CallGraphBuilder make(AnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope, boolean keepPointsTo) {
Util.addDefaultSelectors(options, cha); Util.addDefaultSelectors(options, cha);
Util.addDefaultBypassLogic(options, scope, Util.class.getClassLoader(), cha); Util.addDefaultBypassLogic(options, scope, Util.class.getClassLoader(), cha);
return new AstJavaZeroXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.NONE); return new AstJavaZeroXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.NONE);

View File

@ -12,6 +12,7 @@ package com.ibm.wala.cast.java.ipa.callgraph;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.propagation.cfa.DefaultPointerKeyFactory; import com.ibm.wala.ipa.callgraph.propagation.cfa.DefaultPointerKeyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
@ -20,7 +21,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
*/ */
public class AstJavaCFABuilder extends AstJavaSSAPropagationCallGraphBuilder { public class AstJavaCFABuilder extends AstJavaSSAPropagationCallGraphBuilder {
public AstJavaCFABuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) { public AstJavaCFABuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache) {
super(cha, options, cache, new DefaultPointerKeyFactory()); super(cha, options, cache, new DefaultPointerKeyFactory());
} }

View File

@ -25,6 +25,7 @@ import com.ibm.wala.fixpoint.UnaryOperator;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.propagation.AbstractFieldPointerKey; import com.ibm.wala.ipa.callgraph.propagation.AbstractFieldPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey; import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
@ -42,7 +43,7 @@ import com.ibm.wala.util.strings.Atom;
public class AstJavaSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraphBuilder { public class AstJavaSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraphBuilder {
protected AstJavaSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache, protected AstJavaSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache,
PointerKeyFactory pointerKeyFactory) { PointerKeyFactory pointerKeyFactory) {
super(cha, options, cache, pointerKeyFactory); super(cha, options, cache, pointerKeyFactory);
} }

View File

@ -14,6 +14,7 @@ import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.ContextSelector; import com.ibm.wala.ipa.callgraph.ContextSelector;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.impl.DefaultContextSelector; import com.ibm.wala.ipa.callgraph.impl.DefaultContextSelector;
import com.ibm.wala.ipa.callgraph.impl.DelegatingContextSelector; import com.ibm.wala.ipa.callgraph.impl.DelegatingContextSelector;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter; import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
@ -25,7 +26,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
*/ */
public class AstJavaZeroXCFABuilder extends AstJavaCFABuilder { public class AstJavaZeroXCFABuilder extends AstJavaCFABuilder {
public AstJavaZeroXCFABuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache, public AstJavaZeroXCFABuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache,
ContextSelector appContextSelector, SSAContextInterpreter appContextInterpreter, int instancePolicy) { ContextSelector appContextSelector, SSAContextInterpreter appContextInterpreter, int instancePolicy) {
super(cha, options, cache); super(cha, options, cache);

View File

@ -65,6 +65,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.shrikeCT.AnnotationsReader.ConstantElementValue; import com.ibm.wala.shrikeCT.AnnotationsReader.ConstantElementValue;
import com.ibm.wala.shrikeCT.AnnotationsReader.ElementValue; import com.ibm.wala.shrikeCT.AnnotationsReader.ElementValue;
import com.ibm.wala.shrikeCT.ClassConstants; import com.ibm.wala.shrikeCT.ClassConstants;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAThrowInstruction; import com.ibm.wala.ssa.SSAThrowInstruction;
import com.ibm.wala.ssa.SymbolTable; import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.ClassLoaderReference;
@ -170,7 +171,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
} }
private void addMethod(CAstEntity methodEntity, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock, private void addMethod(CAstEntity methodEntity, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock,
Map<IBasicBlock, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) { Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
declaredMethods.put(Util.methodEntityToSelector(methodEntity), new ConcreteJavaMethod(methodEntity, owner, cfg, symtab, declaredMethods.put(Util.methodEntityToSelector(methodEntity), new ConcreteJavaMethod(methodEntity, owner, cfg, symtab,
hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo)); hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo));
} }
@ -251,7 +252,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
private final TypeReference[] exceptionTypes; private final TypeReference[] exceptionTypes;
public JavaEntityMethod(CAstEntity methodEntity, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock, public JavaEntityMethod(CAstEntity methodEntity, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock,
Map<IBasicBlock, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) { Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
super(owner, methodEntity.getQualifiers(), cfg, symtab, MethodReference.findOrCreate(owner.getReference(), Util super(owner, methodEntity.getQualifiers(), cfg, symtab, MethodReference.findOrCreate(owner.getReference(), Util
.methodEntityToSelector(methodEntity)), hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo, JavaSourceLoaderImpl.this.getAnnotations(methodEntity)); .methodEntityToSelector(methodEntity)), hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo, JavaSourceLoaderImpl.this.getAnnotations(methodEntity));
this.parameterTypes = computeParameterTypes(methodEntity); this.parameterTypes = computeParameterTypes(methodEntity);
@ -369,7 +370,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
*/ */
public class ConcreteJavaMethod extends JavaEntityMethod { public class ConcreteJavaMethod extends JavaEntityMethod {
public ConcreteJavaMethod(CAstEntity methodEntity, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock, public ConcreteJavaMethod(CAstEntity methodEntity, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock,
Map<IBasicBlock, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) { Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
super(methodEntity, owner, cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo); super(methodEntity, owner, cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo);
} }
@ -522,7 +523,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
} }
public void defineFunction(CAstEntity n, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock, public void defineFunction(CAstEntity n, IClass owner, AbstractCFG cfg, SymbolTable symtab, boolean hasCatchBlock,
Map<IBasicBlock, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) { Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
((JavaClass) owner).addMethod(n, owner, cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo); ((JavaClass) owner).addMethod(n, owner, cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo);
} }

View File

@ -37,6 +37,7 @@ import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.ModuleEntry; import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SymbolTable; import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.FieldReference; import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeName; import com.ibm.wala.types.TypeName;
@ -244,8 +245,8 @@ public class JavaCAst2IRTranslator extends AstTranslator {
} }
@Override @Override
protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG cfg, SymbolTable symtab, protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG<SSAInstruction, ? extends IBasicBlock<SSAInstruction>> cfg, SymbolTable symtab,
boolean hasCatchBlock, Map<IBasicBlock,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, boolean hasCatchBlock, Map<IBasicBlock<SSAInstruction>,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo,
DebuggingInformation debugInfo) { DebuggingInformation debugInfo) {
// N.B.: base class may actually ask to create a synthetic type to wrap // N.B.: base class may actually ask to create a synthetic type to wrap
// code bodies, so we may see other things than TYPE_ENTITY here. // code bodies, so we may see other things than TYPE_ENTITY here.
@ -415,7 +416,7 @@ public class JavaCAst2IRTranslator extends AstTranslator {
return new CAstType.Class() { return new CAstType.Class() {
@Override @Override
public Collection getSupertypes() { public Collection<CAstType> getSupertypes() {
return Collections.emptySet(); return Collections.emptySet();
} }

View File

@ -43,7 +43,7 @@ public class JavaPrimitiveTypeMap {
} }
@Override @Override
public Collection getSupertypes() { public Collection<CAstType> getSupertypes() {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
} }

View File

@ -4,6 +4,6 @@
<classpathentry kind="src" path="tests"/> <classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="lib" path="lib/htmlparser-1.4.jar"/> <classpathentry kind="lib" path="lib/htmlparser-1.4.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -73,7 +73,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -23,9 +23,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import nu.validator.htmlparser.common.XmlViolationPolicy;
import nu.validator.htmlparser.sax.HtmlParser;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler; import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
@ -39,6 +36,9 @@ import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
import com.ibm.wala.cast.tree.impl.LineNumberPosition; import com.ibm.wala.cast.tree.impl.LineNumberPosition;
import com.ibm.wala.util.collections.Pair; import com.ibm.wala.util.collections.Pair;
import nu.validator.htmlparser.common.XmlViolationPolicy;
import nu.validator.htmlparser.sax.HtmlParser;
public class NuValidatorHtmlParser implements IHtmlParser { public class NuValidatorHtmlParser implements IHtmlParser {
@Override @Override

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.cast.js.nodejs"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.cast.js"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.core"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.util"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="testdata"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.ibm.wala.cast.js.nodejs.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,43 @@
/******************************************************************************
* Copyright (c) 2002 - 2016 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:
* Brian Pfretzschner - initial implementation
*****************************************************************************/
package com.ibm.wala.cast.js.nodejs.test;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URL;
import org.junit.Test;
import com.ibm.wala.cast.js.nodejs.NodejsCallGraphBuilderUtil;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
/**
* @author Brian Pfretzschner <brian.pfretzschner@gmail.com>
*/
public class NodejsRequireJsonTest {
@Test
public void test() throws Exception {
URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireJsonTest/index.js");
File file = new File(fileUrl.toURI());
PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
String cgString = CG.toString();
assertTrue(cgString.contains("Lempty/jsonModule>"));
assertTrue(cgString.contains("Lnested/jsonModule>"));
assertTrue(cgString.contains("Lpackage/jsonModule>"));
assertTrue(!cgString.contains("?"));
}
}

View File

@ -0,0 +1,98 @@
/******************************************************************************
* Copyright (c) 2002 - 2016 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:
* Brian Pfretzschner - initial implementation
*****************************************************************************/
package com.ibm.wala.cast.js.nodejs.test;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URL;
import org.junit.Test;
import com.ibm.wala.cast.js.nodejs.NodejsCallGraphBuilderUtil;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
/**
* @author Brian Pfretzschner <brian.pfretzschner@gmail.com>
*/
public class NodejsRequireTargetSelectorResolveTest {
@Test
public void testRequireSimple() throws Exception {
URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireSimple/index.js");
File file = new File(fileUrl.toURI());
PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
String cgString = CG.toString();
assertTrue(cgString.contains("Lmod/nodejsModule/moduleSource/exec>"));
assertTrue(cgString.contains("Lmod/nodejsModule/moduleSource/SomeClass/hello>"));
assertTrue(!cgString.contains("?"));
}
@Test
public void testRequireStaticCircular() throws Exception {
URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireStaticCircular/index.js");
File file = new File(fileUrl.toURI());
PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
String cgString = CG.toString();
assertTrue(cgString.contains("Llib1/nodejsModule/moduleSource/lib1>"));
assertTrue(cgString.contains("Llib2/nodejsModule/moduleSource/lib2>"));
assertTrue(!cgString.contains("?"));
}
@Test
public void testRequireDynamic() throws Exception {
URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireDynamic/index.js");
File file = new File(fileUrl.toURI());
PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
String cgString = CG.toString();
assertTrue(cgString.contains("Llib1/nodejsModule/moduleSource/lib1>"));
assertTrue(cgString.contains("Llib2/nodejsModule/moduleSource/lib2>"));
assertTrue(!cgString.contains("?"));
}
@Test
public void testRequireNodeModules() throws Exception {
URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireNodeModules/index.js");
File file = new File(fileUrl.toURI());
PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
String cgString = CG.toString();
assertTrue(cgString.contains("Lnode_modules_lib_node_modules_sublib_sublib/nodejsModule/moduleSource"));
assertTrue(!cgString.contains("?"));
}
@Test
public void testRequireCoreModules() throws Exception {
URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireCoreModules.js");
File file = new File(fileUrl.toURI());
PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
String cgString = CG.toString();
assertTrue(cgString.contains("Lutil/nodejsModule/moduleSource/util"));
assertTrue(cgString.contains("Lhttps/nodejsModule/moduleSource/https"));
assertTrue(cgString.contains("Lhttp/nodejsModule/moduleSource/http"));
}
}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,3 @@
var empty = require('./empty.json');
var empty = require('./nested.json');
var empty = require('./package.json');

View File

@ -0,0 +1 @@
{ num: 7, obj: { val1: "hello", num: 77 } }

View File

@ -0,0 +1,15 @@
{
"name": "test2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"poc-lettersonly-gm": "^1.0.1",
"validator": "^5.5.0"
}
}

View File

@ -0,0 +1,2 @@
var util = require('util');
var util = require('https');

View File

@ -0,0 +1,9 @@
var lib1 = myRequire('lib1', true);
lib1();
function myRequire(name, local) {
var prefix = '';
if (local) prefix = './';
return require(prefix+name);
}

View File

@ -0,0 +1,5 @@
var lib2 = require('./lib2');
module.exports = function lib1() {
lib2();
};

View File

@ -0,0 +1,5 @@
var lib1 = require('./lib1');
module.exports = function lib2() {
lib1();
};

View File

@ -0,0 +1,2 @@
require('./helper');
require('sublib');

View File

@ -0,0 +1,2 @@
module.exports = function lib2() {
};

View File

@ -0,0 +1,2 @@
var mod = require('./mod');
mod.exec();

View File

@ -0,0 +1,8 @@
function SomeClass() {
this.hello = function hello() {}
}
exports.exec = function exec() {
var c = new SomeClass();
c.hello();
};

View File

@ -0,0 +1,2 @@
var lib1 = require('./lib1');
lib1();

View File

@ -0,0 +1,5 @@
var lib2 = require('./lib2');
module.exports = function lib1() {
lib2();
};

View File

@ -0,0 +1,5 @@
var lib1 = require('./lib1');
module.exports = function lib2() {
lib1();
};

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="dat">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.cast"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.cast.js"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.cast.js.rhino"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.core"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.util"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/com.ibm.wala.shrike"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.ibm.wala.cast.js.nodejs</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,39 @@
<project name="com.ibm.wala.cast.js.nodejs" default="download-core-libs" basedir=".">
<description>
WALA Nodejs Front-end
</description>
<property name="nodejs-release" location="nodejs.zip" />
<property name="core-modules" location="dat/core-modules" />
<target name="download-core-libs">
<!-- 0a604e92e258c5ee2752d763e50721e35053f135 is v0.12.4-release -->
<get src="https://api.github.com/repos/nodejs/node/zipball/0a604e92e258c5ee2752d763e50721e35053f135"
dest="${nodejs-release}" />
<tempfile property="unzip-dest" />
<unzip src="${nodejs-release}"
dest="${unzip-dest}">
<patternset>
<include name="*/lib/**" />
</patternset>
</unzip>
<mkdir dir="${core-modules}" />
<move todir="${core-modules}"
flatten="true">
<fileset dir="${unzip-dest}">
<include name="*/lib/*.js" />
</fileset>
</move>
<!-- Cleanup -->
<delete includeemptydirs="true">
<fileset dir="${unzip-dest}" includes="**" />
<fileset file="${nodejs-release}" />
</delete>
</target>
</project>

View File

@ -0,0 +1,4 @@
rules:
# Custom rules in tools/eslint-rules
require-buffer: 2
buffer-constructor: 2

View File

@ -0,0 +1 @@
*.js

View File

@ -0,0 +1,13 @@
var timerId = 0;
function setTimeout(cb, t) {
cb();
return timerId++;
}
function setInterval(cb, t) {
return setTimeout(function () {
cb();
setInterval(cb, t);
}, t);
}

View File

@ -0,0 +1,3 @@
(function jsonModule() {
return /*/ WALA-INSERT-CODE-HERE /*/;
})();

View File

@ -0,0 +1,12 @@
(function nodejsModule() {
var module = {
require: function __WALA__require(id) {},
exports: {}
};
(function moduleSource(exports, require, module, __filename, __dirname) {
/*/ WALA-INSERT-CODE-HERE /*/
})(module.exports, module.require, module, '/*/ WALA-INSERT-FILENAME-HERE /*/', '/*/ WALA-INSERT-DIRNAME-HERE /*/');
return module.exports;
})();

View File

@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibm.wala.cast.js.nodejs</groupId>
<artifactId>com.ibm.wala.cast.js.nodejs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>dat</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,114 @@
/******************************************************************************
* Copyright (c) 2002 - 2016 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:
* Brian Pfretzschner - initial implementation
*****************************************************************************/
package com.ibm.wala.cast.js.nodejs;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import com.ibm.wala.cast.ipa.callgraph.CAstAnalysisScope;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.ipa.callgraph.StandardFunctionTargetSelector;
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JavaScriptEntryPoints;
import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.Language;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.ContextSelector;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IRFactory;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
/**
* @author Brian Pfretzschner <brian.pfretzschner@gmail.com>
*/
public class NodejsCallGraphBuilderUtil extends JSCallGraphUtil {
public static PropagationCallGraphBuilder makeCGBuilder(File mainFile)
throws IOException, IllegalArgumentException, CancelException, WalaException {
return makeCGBuilder(mainFile.getParentFile(), mainFile);
}
public static PropagationCallGraphBuilder makeCGBuilder(File workingDir, File mainFile)
throws IOException, IllegalArgumentException, CancelException, WalaException {
JavaScriptTranslatorFactory translatorFactory = new CAstRhinoTranslatorFactory();
JSCallGraphUtil.setTranslatorFactory(translatorFactory);
Language language = JavaScriptLoader.JS;
Collection<Language> languages = Collections.singleton(language);
IRFactory<IMethod> irFactory = new AstIRFactory.AstDefaultIRFactory();
AnalysisCache cache = new AnalysisCache(irFactory);
JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory, null);
SourceFileModule mainSourceModule = CAstCallGraphUtil.makeSourceModule(mainFile.toURI().toURL(),
mainFile.getName());
String mainFileClassName = NodejsRequiredSourceModule.convertFileToClassName(workingDir, mainFile);
SourceModule[] files = new SourceModule[] {
JSCallGraphUtil.getPrologueFile("prologue.js"),
JSCallGraphUtil.getPrologueFile("extended-prologue.js"),
new NodejsRequiredSourceModule(mainFileClassName, mainFile, mainSourceModule) };
CAstAnalysisScope scope = new CAstAnalysisScope(files, loaders, languages);
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, language, null);
com.ibm.wala.cast.js.util.Util.checkForFrontEndErrors(cha);
// Make Script Roots
Iterable<Entrypoint> roots = new JavaScriptEntryPoints(cha, loaders.getTheLoader());
// Make Options
JSAnalysisOptions options = new JSAnalysisOptions(scope, roots);
options.setUseConstantSpecificKeys(true);
options.setUseStacksForLexicalScoping(true);
options.setHandleCallApply(true);
// Important to be able to identify what file are required
options.setTraceStringConstants(true);
com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha);
MethodTargetSelector baseSelector = new StandardFunctionTargetSelector(cha, options.getMethodTargetSelector());
NodejsRequireTargetSelector requireTargetSelector = new NodejsRequireTargetSelector(workingDir, baseSelector);
options.setSelector(requireTargetSelector);
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null,
ZeroXInstanceKeys.ALLOCATIONS, true);
// A little hacky, but the instance of RequireTargetSelector is required to build the CallGraphBuilder
// and the RequireTargetSelector also needs the CallGraphBuilder instance.
requireTargetSelector.setCallGraphBuilder(builder);
ContextSelector contextSelector = new PropertyNameContextSelector(cache, 2, builder.getContextSelector());
builder.setContextSelector(contextSelector);
return builder;
}
}

View File

@ -0,0 +1,343 @@
/******************************************************************************
* Copyright (c) 2002 - 2016 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:
* Brian Pfretzschner - initial implementation
*****************************************************************************/
package com.ibm.wala.cast.js.nodejs;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.json.JSONObject;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.ssa.JavaScriptInvoke;
import com.ibm.wala.cast.js.types.JavaScriptMethods;
import com.ibm.wala.cast.js.types.JavaScriptTypes;
import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey;
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.intset.OrdinalSet;
import com.ibm.wala.util.ssa.ClassLookupException;
/**
* This class is used by WALA internals to resolve to what functions a call
* could potentially invoke.
*
* @author Brian Pfretzschner <brian.pfretzschner@gmail.com>
*/
public class NodejsRequireTargetSelector implements MethodTargetSelector {
private File rootDir;
private MethodTargetSelector base;
private PropagationCallGraphBuilder builder;
private HashMap<String, IMethod> previouslyRequired = HashMapFactory.make();
public NodejsRequireTargetSelector(File rootDir, MethodTargetSelector base) {
this.rootDir = rootDir;
this.base = base;
}
public void setCallGraphBuilder(PropagationCallGraphBuilder builder) {
this.builder = builder;
}
/**
* Basic idea: If the called method is named "__WALA__require", it is most likely
* the require-function mock from the module-wrapper. To figure out what file
* shall be required, pointer analysis is used to identify strings that can
* flow into the require call. That file is than loaded, wrapped into the
* module wrapper and returned as method that will be invoked. Therefore,
* there will never be an call graph edge to the require function call,
* the require function is replaced by the file that is included through
* the require call.
*
* {@inheritDoc}
*/
@Override
public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) {
PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis();
JavaScriptLoader jsLoader = (JavaScriptLoader) builder.getClassHierarchy().getLoader(JavaScriptTypes.jsLoader);
IMethod calledMethod = base.getCalleeTarget(caller, site, receiver);
if (calledMethod != null && calledMethod.getDeclaringClass().toString().endsWith("/__WALA__require")) {
JavaScriptInvoke callInstr = getInvokeInstruction(caller, site);
Set<String> targets = getRequireTargets(pointerAnalysis, caller, callInstr);
if (targets.size() == 0) {
// There is no possible call target
throw new RuntimeException("No require target found in method: "+caller.getMethod());
}
for (String target : targets) {
try {
File workingDir = new File(receiver.getSourceFileName()).getParentFile();
SourceModule sourceModule = resolve(rootDir, workingDir, target);
if (previouslyRequired.containsKey(sourceModule.getClassName())) {
return previouslyRequired.get(sourceModule.getClassName());
}
String className = "L" + sourceModule.getClassName() + "/nodejsModule";
if (sourceModule instanceof NodejsRequiredSourceModule
&& ((NodejsRequiredSourceModule) sourceModule).getFile().toString().endsWith(".json")) {
className = "L" + sourceModule.getClassName() + "/jsonModule";
}
JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy(), jsLoader, sourceModule);
IClass script = builder.getClassHierarchy()
.lookupClass(TypeReference.findOrCreate(jsLoader.getReference(), className));
IMethod method = script.getMethod(JavaScriptMethods.fnSelector);
previouslyRequired.put(sourceModule.getClassName(), method);
return method;
}
catch (IOException e) {
e.printStackTrace();
}
}
}
return calledMethod;
}
private JavaScriptInvoke getInvokeInstruction(CGNode caller, CallSiteReference site) {
IR callerIR = caller.getIR();
SSAAbstractInvokeInstruction callInstrs[] = callerIR.getCalls(site);
assert callInstrs.length == 1;
return (JavaScriptInvoke) callInstrs[0];
}
private Set<String> getRequireTargets(PointerAnalysis<InstanceKey> pointerAnalysis, CGNode caller,
JavaScriptInvoke callInstr) {
HashSet<String> set = HashSetFactory.make();
PointerKey pk = builder.getPointerKeyForLocal(caller, callInstr.getUse(2));
OrdinalSet<InstanceKey> instanceKeys = pointerAnalysis.getPointsToSet(pk);
for (InstanceKey instanceKey : instanceKeys) {
if (instanceKey instanceof ConstantKey<?>) {
Object value = ((ConstantKey<?>) instanceKey).getValue();
if (value instanceof String) {
set.add((String) value);
}
else {
System.err.println("NodejsRequireTargetSelector: Unexpected value: " + value);
return HashSetFactory.make();
}
}
else if (instanceKey instanceof ConcreteTypeKey) {
// Cannot do anything with this information...
}
else {
System.err.println("NodejsRequireTargetSelector: Unexpected instanceKey: " + instanceKey.getClass() + " -- " + instanceKey);
return HashSetFactory.make();
}
}
return set;
}
/**
* Implements the Nodejs require.resolve algorithm,
* see https://nodejs.org/api/modules.html#modules_all_together
*
* require(X) from module at path Y
* 1. If X is a core module,
* a. return the core module
* b. STOP
* 2. If X begins with './' or '/' or '../'
* a. LOAD_AS_FILE(Y + X)
* b. LOAD_AS_DIRECTORY(Y + X)
* 3. LOAD_NODE_MODULES(X, dirname(Y))
* 4. THROW "not found"
*
* @param dir Y in the pseudo algorithm
* @param target X in the pseudo algorithm
* @return
* @throws IOException
*/
public static SourceFileModule resolve(File rootDir, File dir, String target) throws IOException {
if (NodejsRequiredCoreModule.isCoreModule(target))
return NodejsRequiredCoreModule.make(target);
if (target.startsWith("./") || target.startsWith("/") || target.startsWith("../")) {
SourceFileModule module = loadAsFile(rootDir, new File(dir, target));
if (module != null) return module;
module = loadAsDirectory(rootDir, new File(dir, target));
if (module != null) return module;
}
SourceFileModule module = loadNodeModules(rootDir, dir, target);
if (module != null) return module;
throw new ClassLookupException("Required module not found: "+target+" in "+dir);
}
/**
* LOAD_AS_FILE(X)
* 1. If X is a file, load X as JavaScript text. STOP
* 2. If X.js is a file, load X.js as JavaScript text. STOP
* 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
* 4. If X.node is a file, load X.node as binary addon. STOP
*
* @param f
* @return
* @throws IOException
*/
private static SourceFileModule loadAsFile(File rootDir, File f) throws IOException {
// 1.
if (f.isFile())
return NodejsRequiredSourceModule.make(rootDir, f);
// 2.
File jsFile = new File(f+".js");
if (jsFile.isFile())
return NodejsRequiredSourceModule.make(rootDir, jsFile);
// 3.
File jsonFile = new File(f+".json");
if (jsonFile.isFile())
return NodejsRequiredSourceModule.make(rootDir, jsonFile);
// Skip 4. step
return null;
}
/**
* LOAD_AS_DIRECTORY(X)
* 1. If X/package.json is a file,
* a. Parse X/package.json, and look for "main" field.
* b. let M = X + (json main field)
* c. LOAD_AS_FILE(M)
* 2. If X/index.js is a file, load X/index.js as JavaScript text. STOP
* 3. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
* 4. If X/index.node is a file, load X/index.node as binary addon. STOP
*
* @param d
* @return
* @throws IOException
*/
private static SourceFileModule loadAsDirectory(File rootDir, File d) throws IOException {
// 1.
File packageJsonFile = new File(d, "package.json");
if (packageJsonFile.isFile()) {
// 1.a.
String packageJsonContent = FileUtils.readFileToString(packageJsonFile);
JSONObject packageJson = new JSONObject(packageJsonContent);
if (packageJson.has("main")) {
String mainFileName = packageJson.getString("main");
// 1.b.
File mainFile = new File(d, mainFileName);
// 1.c.
return loadAsFile(rootDir, mainFile);
}
}
// 2.
File jsFile = new File(d, "index.js");
if (jsFile.isFile())
return NodejsRequiredSourceModule.make(rootDir, jsFile);
// 3.
File jsonFile = new File(d, "index.json");
if (jsonFile.isFile())
return NodejsRequiredSourceModule.make(rootDir, jsonFile);
// Skip 4. step
return null;
}
/**
* LOAD_NODE_MODULES(X, START)
* 1. let DIRS=NODE_MODULES_PATHS(START)
* 2. for each DIR in DIRS:
* a. LOAD_AS_FILE(DIR/X)
* b. LOAD_AS_DIRECTORY(DIR/X)
*
* @param dir
* @param target
* @return
* @throws IOException
*/
private static SourceFileModule loadNodeModules(File rootDir, File d, String target) throws IOException {
List<File> dirs = nodeModulePaths(rootDir, d);
for (File dir : dirs) {
SourceFileModule module = loadAsFile(rootDir, new File(dir, target));
if (module != null) return module;
module = loadAsDirectory(rootDir, new File(dir, target));
if (module != null) return module;
}
return null;
}
/**
* NODE_MODULES_PATHS(START)
* 1. let PARTS = path split(START)
* 2. let I = count of PARTS - 1
* 3. let DIRS = []
* 4. while I >= 0,
* a. if PARTS[I] = "node_modules" CONTINUE
* b. DIR = path join(PARTS[0 .. I] + "node_modules")
* c. DIRS = DIRS + DIR
* d. let I = I - 1
* 5. return DIRS
*
* @param d
* @return
* @throws IOException
*/
private static List<File> nodeModulePaths(File rootDir, File d) throws IOException {
LinkedList<File> dirs = new LinkedList<>();
while (d.getCanonicalPath().startsWith(rootDir.getCanonicalPath()) && d.toPath().getNameCount() > 0) {
// 4.a.
if (!d.getName().equals("node_modules")) {
// 4.b. and 4.c.
dirs.add(new File(d, "node_modules"));
}
// 4.d.
d = d.getParentFile();
}
return dirs;
}
}

View File

@ -0,0 +1,60 @@
/******************************************************************************
* Copyright (c) 2002 - 2016 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:
* Brian Pfretzschner - initial implementation
*****************************************************************************/
package com.ibm.wala.cast.js.nodejs;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
import org.apache.commons.io.FilenameUtils;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.util.collections.HashSetFactory;
/**
* @author Brian Pfretzschner <brian.pfretzschner@gmail.com>
*/
public class NodejsRequiredCoreModule extends NodejsRequiredSourceModule {
/**
* Core modules list for Nodejs v6.2.2
* https://github.com/nodejs/node/blob/v6.2.2/lib/internal/module.js
*/
private static final Set<String> CORE_MODULES = HashSetFactory.make(Arrays.asList(
"assert", "buffer", "child_process", "cluster", "crypto", "dgram", "dns", "domain", "events", "fs", "http",
"https", "net", "os", "path", "punycode", "querystring", "readline", "repl", "stream", "string_decoder",
"tls", "tty", "url", "util", "v8", "vm", "zlib",
// Non-public files
"timers", "constants", "freelist", "smalloc",
"_debugger", "_http_agent", "_http_client", "_http_common", "_http_incoming", "_http_outgoing",
"_http_server", "_linklist", "_stream_duplex", "_stream_passthrough", "_stream_readable",
"_stream_transform", "_stream_writable", "_tls_common", "_tls_legacy", "_tls_wrap"));
private final static File CORE_MODULES_FOLDER = new File(NodejsRequiredCoreModule.class.getClassLoader().getResource("core-modules").getPath());
protected NodejsRequiredCoreModule(File f, SourceFileModule clonedFrom) throws IOException {
super(FilenameUtils.getBaseName(f.getName()), f, clonedFrom);
}
public static NodejsRequiredCoreModule make(String name) throws IOException {
File file = new File(CORE_MODULES_FOLDER, name+".js");
SourceFileModule sourceFileModule = CAstCallGraphUtil.makeSourceModule(file.toURI().toURL(), file.getName());
return new NodejsRequiredCoreModule(file, sourceFileModule);
}
public static boolean isCoreModule(String name) {
return CORE_MODULES.contains(name);
}
}

View File

@ -0,0 +1,149 @@
/******************************************************************************
* Copyright (c) 2002 - 2016 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:
* Brian Pfretzschner - initial implementation
*****************************************************************************/
package com.ibm.wala.cast.js.nodejs;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.util.debug.Assertions;
/**
* This class is intended to be used whenever a JavaScript module is dynamically
* required by JavaScript (CommonJS). The required file will be loaded and
* wrapped in a function call to simulate the real behavior of a CommonJS
* environment. The resulting function will be named GLOBAL_PREFIX + relative
* file-name. To retrieve the final function name, use getFunctioName().
*
* @author Brian Pfretzschner <brian.pfretzschner@gmail.com>
*/
public class NodejsRequiredSourceModule extends SourceFileModule {
private final static String MODULE_WRAPPER_FILENAME = "module-wrapper.js";
private final static String JSON_WRAPPER_FILENAME = "json-wrapper.js";
private final static String FILENAME_PLACEHOLDER = "/*/ WALA-INSERT-FILENAME-HERE /*/";
private final static String DIRNAME_PLACEHOLDER = "/*/ WALA-INSERT-DIRNAME-HERE /*/";
private final static String CODE_PLACEHOLDER = "/*/ WALA-INSERT-CODE-HERE /*/";
private static String MODULE_WRAPPER_SOURCE = null;
private static String JSON_WRAPPER_SOURCE = null;
private final String className;
/**
* @param workingDir
* Must be a direct or indirect parent folder of file f.
* @param f
* Must be a file located below folder workingDir.
* @param clonedFrom
* @throws IOException
*/
protected NodejsRequiredSourceModule(String className, File f, SourceFileModule clonedFrom) throws IOException {
super(f, clonedFrom);
// Generate className based on the given file name
this.className = className;
assert className.matches("[a-zA-Z_$][0-9a-zA-Z_$]*") : "Invalid className: " + className;
if (MODULE_WRAPPER_SOURCE == null || JSON_WRAPPER_SOURCE == null) {
// Populate the cache that hold the module wrapper source code
loadWrapperSources();
}
}
@Override
public InputStream getInputStream() {
InputStream inputStream = super.getInputStream();
String moduleSource = null;
try {
moduleSource = IOUtils.toString(inputStream);
} catch (IOException e) {
Assertions.UNREACHABLE(e.getMessage());
}
String wrapperSource = null;
String ext = FilenameUtils.getExtension(getFile().toString()).toLowerCase();
if (ext.equals("js")) {
// JS file -> use module wrapper
wrapperSource = MODULE_WRAPPER_SOURCE;
}
else if (ext.equals("json")) {
// JSON file -> use JSON wrapper
wrapperSource = JSON_WRAPPER_SOURCE;
}
else {
// No clue -> try module wrapper
System.err.println("NodejsRequiredSourceModule: Unsupported file type ("+ext+"), continue anyway.");
wrapperSource = MODULE_WRAPPER_SOURCE;
}
String wrappedModuleSource = wrapperSource
.replace(FILENAME_PLACEHOLDER, getFile().getName())
.replace(DIRNAME_PLACEHOLDER, getFile().getParent().toString())
.replace(CODE_PLACEHOLDER, moduleSource);
return IOUtils.toInputStream(wrappedModuleSource);
}
@Override
public String getClassName() {
return className;
}
private void loadWrapperSources() throws IOException {
MODULE_WRAPPER_SOURCE = loadWrapperSource(MODULE_WRAPPER_FILENAME);
JSON_WRAPPER_SOURCE = loadWrapperSource(JSON_WRAPPER_FILENAME);
}
private String loadWrapperSource(String filename) throws IOException {
URL url = NodejsRequiredSourceModule.class.getClassLoader().getResource(filename);
Path wrapperPath = Paths.get(url.getPath());
byte[] wrapperSourceBin = Files.readAllBytes(wrapperPath);
return new String(wrapperSourceBin, Charset.defaultCharset());
}
/**
* Generate a className based on the file name and path of the module file.
* The path should be encoded in the className since the file name is not unique.
*
* @param rootDir
* @param file
* @return
*/
public static String convertFileToClassName(File rootDir, File file) {
URI normalizedWorkingDirURI = rootDir.getAbsoluteFile().toURI().normalize();
URI normalizedFileURI = file.getAbsoluteFile().toURI().normalize();
String relativePath = normalizedWorkingDirURI.relativize(normalizedFileURI).getPath();
return FilenameUtils.removeExtension(relativePath)
.replace("/", "_")
.replace("-", "__")
.replace(".", "__");
}
public static NodejsRequiredSourceModule make(File rootDir, File file) throws IOException {
String className = convertFileToClassName(rootDir, file);
SourceFileModule sourceFileModule = CAstCallGraphUtil.makeSourceModule(file.toURI().toURL(), file.getName());
return new NodejsRequiredSourceModule(className, file, sourceFileModule);
}
}

View File

@ -18,6 +18,7 @@ import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.Language; import com.ibm.wala.classLoader.Language;
import com.ibm.wala.classLoader.SourceURLModule; import com.ibm.wala.classLoader.SourceURLModule;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
@ -34,7 +35,7 @@ import com.ibm.wala.util.strings.Atom;
public class Driver { public class Driver {
public static void addDefaultDispatchLogic(AnalysisOptions options, AnalysisScope scope, IClassHierarchy cha) { public static void addDefaultDispatchLogic(AnalysisOptions options, AnalysisScope scope, IClassHierarchy cha, AnalysisCache cache) {
com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha); com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha);
Map<Atom,MethodTargetSelector> methodTargetSelectors = HashMapFactory.make(); Map<Atom,MethodTargetSelector> methodTargetSelectors = HashMapFactory.make();
@ -77,11 +78,11 @@ public class Driver {
AnalysisOptions options = new AnalysisOptions(scope, roots); AnalysisOptions options = new AnalysisOptions(scope, roots);
addDefaultDispatchLogic(options, scope, cha);
IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory(); IRFactory<IMethod> factory = AstIRFactory.makeDefaultFactory();
AnalysisCache cache = new AnalysisCache(factory); AnalysisCache cache = new AnalysisCacheImpl(factory);
addDefaultDispatchLogic(options, scope, cha, cache);
JavaJavaScriptHybridCallGraphBuilder b = new JavaJavaScriptHybridCallGraphBuilder(cha, options, cache); JavaJavaScriptHybridCallGraphBuilder b = new JavaJavaScriptHybridCallGraphBuilder(cha, options, cache);

View File

@ -5,16 +5,14 @@ import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import junit.framework.AssertionFailedError;
import org.junit.Before; import org.junit.Before;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error; import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.DefaultSourceExtractor; import com.ibm.wala.cast.js.html.DefaultSourceExtractor;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraph; import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraph;
import com.ibm.wala.cast.js.test.FieldBasedCGUtil; import com.ibm.wala.cast.js.test.FieldBasedCGUtil;
import com.ibm.wala.cast.js.test.TestJSCallGraphShape;
import com.ibm.wala.cast.js.test.FieldBasedCGUtil.BuilderType; import com.ibm.wala.cast.js.test.FieldBasedCGUtil.BuilderType;
import com.ibm.wala.cast.js.test.TestJSCallGraphShape;
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory; import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
import com.ibm.wala.cast.js.util.CallGraph2JSON; import com.ibm.wala.cast.js.util.CallGraph2JSON;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
@ -22,6 +20,8 @@ import com.ibm.wala.util.NullProgressMonitor;
import com.ibm.wala.util.ProgressMaster; import com.ibm.wala.util.ProgressMaster;
import com.ibm.wala.util.WalaException; import com.ibm.wala.util.WalaException;
import junit.framework.AssertionFailedError;
public abstract class AbstractFieldBasedTest extends TestJSCallGraphShape { public abstract class AbstractFieldBasedTest extends TestJSCallGraphShape {
protected FieldBasedCGUtil util; protected FieldBasedCGUtil util;
@ -66,8 +66,7 @@ public abstract class AbstractFieldBasedTest extends TestJSCallGraphShape {
} }
} }
@SuppressWarnings("unused") protected void dumpCG(JSCallGraph cg) {
private void dumpCG(JSCallGraph cg) {
CallGraph2JSON.IGNORE_HARNESS = false; CallGraph2JSON.IGNORE_HARNESS = false;
Map<String, Set<String>> edges = CallGraph2JSON.extractEdges(cg); Map<String, Set<String>> edges = CallGraph2JSON.extractEdges(cg);
for(String callsite : edges.keySet()) for(String callsite : edges.keySet())

View File

@ -18,10 +18,12 @@ public class FieldBasedCGGamesTest extends AbstractFieldBasedTest {
runTestExceptOnTravis(new URL("http://www.themaninblue.com/experiment/BunnyHunt/"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST); runTestExceptOnTravis(new URL("http://www.themaninblue.com/experiment/BunnyHunt/"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST);
} }
/*
@Test @Test
public void testBomberman() throws IOException, WalaException, Error, CancelException { public void testBomberman() throws IOException, WalaException, Error, CancelException {
runTestExceptOnTravis(new URL("http://www.e-forum.ro/bomberman/dynagame.html"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST); runTestExceptOnTravis(new URL("http://www.e-forum.ro/bomberman/dynagame.html"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST);
} }
*/
@Test @Test
public void testBeslimed() throws IOException, WalaException, Error, CancelException { public void testBeslimed() throws IOException, WalaException, Error, CancelException {
@ -34,11 +36,13 @@ public class FieldBasedCGGamesTest extends AbstractFieldBasedTest {
runTestExceptOnTravis(new URL("http://www.pixastic.com/labs/digg_attack/"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST); runTestExceptOnTravis(new URL("http://www.pixastic.com/labs/digg_attack/"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST);
} }
@Ignore
@Test @Test
public void testRiverRaider() throws IOException, WalaException, Error, CancelException { public void testRiverRaider() throws IOException, WalaException, Error, CancelException {
runTestExceptOnTravis(new URL("http://playstar.mobi/games/riverraider/index.html?playerId=&gameId=8&highscore=102425"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST); runTestExceptOnTravis(new URL("http://playstar.mobi/games/riverraider/index.html?playerId=&gameId=8&highscore=102425"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST);
} }
@Ignore
@Test @Test
public void testSolitaire() throws IOException, WalaException, Error, CancelException { public void testSolitaire() throws IOException, WalaException, Error, CancelException {
runTestExceptOnTravis(new URL("http://www.inmensia.com/files/solitaire1.0.html"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST); runTestExceptOnTravis(new URL("http://www.inmensia.com/files/solitaire1.0.html"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST);
@ -53,6 +57,7 @@ public class FieldBasedCGGamesTest extends AbstractFieldBasedTest {
} }
} }
@Ignore
@Test @Test
public void testMinesweeper() throws IOException, WalaException, Error, CancelException { public void testMinesweeper() throws IOException, WalaException, Error, CancelException {
runTestExceptOnTravis(new URL("http://www.inmensia.com/files/minesweeper1.0.html"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST); runTestExceptOnTravis(new URL("http://www.inmensia.com/files/minesweeper1.0.html"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST);

View File

@ -2,17 +2,17 @@ package com.ibm.wala.cast.js.rhino.callgraph.fieldbased.test;
import java.io.IOException; import java.io.IOException;
import junit.framework.AssertionFailedError;
import org.junit.Test; import org.junit.Test;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error; import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.JSSourceExtractor; import com.ibm.wala.cast.js.html.JSSourceExtractor;
import com.ibm.wala.cast.js.test.TestSimplePageCallGraphShape;
import com.ibm.wala.cast.js.test.FieldBasedCGUtil.BuilderType; import com.ibm.wala.cast.js.test.FieldBasedCGUtil.BuilderType;
import com.ibm.wala.cast.js.test.TestSimplePageCallGraphShape;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException; import com.ibm.wala.util.WalaException;
import junit.framework.AssertionFailedError;
public class FieldBasedComparisonTest extends AbstractFieldBasedTest { public class FieldBasedComparisonTest extends AbstractFieldBasedTest {
private void test(String file, Object[][] assertions, BuilderType builderType) throws IOException, WalaException, Error, CancelException { private void test(String file, Object[][] assertions, BuilderType builderType) throws IOException, WalaException, Error, CancelException {

View File

@ -17,8 +17,6 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Properties; import java.util.Properties;
import junit.framework.Assert;
import com.ibm.wala.cast.js.html.DefaultSourceExtractor; import com.ibm.wala.cast.js.html.DefaultSourceExtractor;
import com.ibm.wala.cast.js.html.JSSourceExtractor; import com.ibm.wala.cast.js.html.JSSourceExtractor;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
@ -40,6 +38,8 @@ import com.ibm.wala.util.io.CommandLine;
import com.ibm.wala.util.io.FileProvider; import com.ibm.wala.util.io.FileProvider;
import com.ibm.wala.util.io.FileUtil; import com.ibm.wala.util.io.FileUtil;
import junit.framework.Assert;
/** /**
* Utility class for building call graphs of HTML pages. * Utility class for building call graphs of HTML pages.
* *

View File

@ -35,8 +35,8 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.ipa.callgraph.impl.Everywhere; import com.ibm.wala.ipa.callgraph.impl.Everywhere;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.IRFactory; import com.ibm.wala.ssa.IRFactory;
@ -100,7 +100,7 @@ public class PrintIRs {
SourceModule[] scripts = p.fst.toArray(new SourceModule[] {}); SourceModule[] scripts = p.fst.toArray(new SourceModule[] {});
JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(JSCallGraphUtil.getTranslatorFactory()); JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(JSCallGraphUtil.getTranslatorFactory());
CAstAnalysisScope scope = new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS)); CAstAnalysisScope scope = new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS));
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS); IClassHierarchy cha = ClassHierarchyFactory.make(scope, loaders, JavaScriptLoader.JS);
Util.checkForFrontEndErrors(cha); Util.checkForFrontEndErrors(cha);
printIRsForCHA(cha, new Predicate<String>() { printIRsForCHA(cha, new Predicate<String>() {

View File

@ -37,7 +37,7 @@ public class TestCPA {
builder.setContextSelector(new CPAContextSelector(builder.getContextSelector())); builder.setContextSelector(new CPAContextSelector(builder.getContextSelector()));
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
JSCallGraphUtil.AVOID_DUMP = false; JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
} }
} }

View File

@ -2,7 +2,7 @@
<classpath> <classpath>
<classpathentry kind="src" path="source"/> <classpathentry kind="src" path="source"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="lib/rhino-1.7.6.jar"/> <classpathentry kind="lib" path="lib/rhino-1.7.6.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -73,7 +73,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -11,7 +11,6 @@
package com.ibm.wala.cast.js.translator; package com.ibm.wala.cast.js.translator;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst; import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.js.translator.JavaScriptLoopUnwindingTranslatorFactory;
import com.ibm.wala.cast.tree.CAst; import com.ibm.wala.cast.tree.CAst;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;

View File

@ -10,51 +10,13 @@
*****************************************************************************/ *****************************************************************************/
package com.ibm.wala.cast.js.translator; package com.ibm.wala.cast.js.translator;
import java.io.IOException; import com.ibm.wala.cast.ir.translator.RewritingTranslatorToCAst;
import java.util.LinkedList;
import java.util.List;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst; import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.tree.CAstEntity;
import com.ibm.wala.cast.tree.impl.CAstImpl; import com.ibm.wala.cast.tree.impl.CAstImpl;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory; import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.classLoader.SourceModule;
public class CAstRhinoTranslator implements TranslatorToCAst { public class CAstRhinoTranslator extends RewritingTranslatorToCAst implements TranslatorToCAst {
private final List<CAstRewriterFactory> rewriters = new LinkedList<CAstRewriterFactory>(); public CAstRhinoTranslator(ModuleEntry m, boolean replicateForDoLoops) {
private final SourceModule M; super(m, new RhinoToAstTranslator(new CAstImpl(), m, m.getName(), replicateForDoLoops));
private final boolean replicateForDoLoops;
public CAstRhinoTranslator(SourceModule M, boolean replicateForDoLoops) {
this.M = M;
this.replicateForDoLoops = replicateForDoLoops;
} }
@Override
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory, boolean prepend) {
if(prepend)
rewriters.add(0, factory);
else
rewriters.add(factory);
}
@Override
public CAstEntity translateToCAst() throws IOException, Error {
String N;
if (M instanceof SourceFileModule) {
N = ((SourceFileModule) M).getClassName();
} else {
N = M.getName();
}
CAstImpl Ast = new CAstImpl();
CAstEntity entity = new RhinoToAstTranslator(Ast, M, N, replicateForDoLoops).translateToCAst();
for(CAstRewriterFactory rwf : rewriters)
entity = rwf.createCAstRewriter(Ast).rewrite(entity);
return entity;
}
} }

View File

@ -12,12 +12,12 @@ package com.ibm.wala.cast.js.translator;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst; import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.tree.CAst; import com.ibm.wala.cast.tree.CAst;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.ModuleEntry;
public class CAstRhinoTranslatorFactory implements JavaScriptTranslatorFactory { public class CAstRhinoTranslatorFactory implements JavaScriptTranslatorFactory {
@Override @Override
public TranslatorToCAst make(CAst ast, SourceModule M) { public TranslatorToCAst make(CAst ast, ModuleEntry M) {
return new CAstRhinoTranslator(M, false); return new CAstRhinoTranslator(M, false);
} }
} }

View File

@ -11,6 +11,7 @@
package com.ibm.wala.cast.js.translator; package com.ibm.wala.cast.js.translator;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -90,7 +91,6 @@ import org.mozilla.javascript.ast.XmlString;
import org.mozilla.javascript.ast.Yield; import org.mozilla.javascript.ast.Yield;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst; import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.DoLoopTranslator;
import com.ibm.wala.cast.js.html.MappedSourceModule; import com.ibm.wala.cast.js.html.MappedSourceModule;
import com.ibm.wala.cast.js.ipa.callgraph.JSSSAPropagationCallGraphBuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSSSAPropagationCallGraphBuilder;
import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.loader.JavaScriptLoader;
@ -108,8 +108,12 @@ import com.ibm.wala.cast.tree.CAstType;
import com.ibm.wala.cast.tree.impl.CAstOperator; import com.ibm.wala.cast.tree.impl.CAstOperator;
import com.ibm.wala.cast.tree.impl.CAstSymbolImpl; import com.ibm.wala.cast.tree.impl.CAstSymbolImpl;
import com.ibm.wala.cast.tree.impl.RangePosition; import com.ibm.wala.cast.tree.impl.RangePosition;
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.cast.tree.visit.CAstVisitor; import com.ibm.wala.cast.tree.visit.CAstVisitor;
import com.ibm.wala.cast.util.CAstPattern; import com.ibm.wala.cast.util.CAstPattern;
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.util.collections.EmptyIterator; import com.ibm.wala.util.collections.EmptyIterator;
import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashMapFactory;
@ -117,7 +121,7 @@ import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.warnings.Warning; import com.ibm.wala.util.warnings.Warning;
public class RhinoToAstTranslator { public class RhinoToAstTranslator implements TranslatorToCAst {
/** /**
* a dummy name to use for standard function calls, only used to distinguish * a dummy name to use for standard function calls, only used to distinguish
@ -536,7 +540,7 @@ public class RhinoToAstTranslator {
} }
private Position makePosition(AstNode n) { private Position makePosition(AstNode n) {
URL url = sourceModule.getURL(); URL url = ((SourceModule)sourceModule).getURL();
int line = n.getLineno(); int line = n.getLineno();
Position pos = new RangePosition(url, line, n.getAbsolutePosition(), n.getAbsolutePosition()+n.getLength()); Position pos = new RangePosition(url, line, n.getAbsolutePosition(), n.getAbsolutePosition()+n.getLength());
@ -2423,7 +2427,7 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
private final String scriptName; private final String scriptName;
private final SourceModule sourceModule; private final ModuleEntry sourceModule;
final private Reader sourceReader; final private Reader sourceReader;
@ -2431,12 +2435,17 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
private final DoLoopTranslator doLoopTranslator; private final DoLoopTranslator doLoopTranslator;
public RhinoToAstTranslator(CAst Ast, SourceModule M, String scriptName, boolean replicateForDoLoops) { public RhinoToAstTranslator(CAst Ast, ModuleEntry m, String scriptName, boolean replicateForDoLoops) {
this.Ast = Ast; this.Ast = Ast;
this.scriptName = scriptName; this.scriptName = scriptName;
this.sourceModule = M; this.sourceModule = m;
this.sourceReader = sourceModule.getInputReader(); this.sourceReader = new InputStreamReader(sourceModule.getInputStream());
this.doLoopTranslator = new DoLoopTranslator(replicateForDoLoops, Ast); this.doLoopTranslator = new DoLoopTranslator(replicateForDoLoops, Ast);
} }
@Override
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory, boolean prepend) {
assert false;
}
} }

View File

@ -2,6 +2,6 @@
<classpath> <classpath>
<classpathentry kind="src" path="harness-src"/> <classpathentry kind="src" path="harness-src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -74,7 +74,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -31,12 +31,14 @@ import com.ibm.wala.cast.js.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory; import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory; import com.ibm.wala.cast.js.translator.JavaScriptTranslatorFactory;
import com.ibm.wala.cast.js.util.Util; import com.ibm.wala.cast.js.util.Util;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule; import com.ibm.wala.classLoader.SourceURLModule;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis; import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.cha.ClassHierarchy; import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.MonitorUtil.IProgressMonitor; import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
@ -74,7 +76,7 @@ public class FieldBasedCGUtil {
public Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildScriptCG(URL url, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException { public Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildScriptCG(URL url, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException {
JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory); JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory);
SourceModule[] scripts = new SourceModule[]{ Module[] scripts = new Module[]{
new SourceURLModule(url), new SourceURLModule(url),
JSCallGraphBuilderUtil.getPrologueFile("prologue.js") JSCallGraphBuilderUtil.getPrologueFile("prologue.js")
}; };
@ -83,7 +85,7 @@ public class FieldBasedCGUtil {
public Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildTestCG(String dir, String name, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException { public Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildTestCG(String dir, String name, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException {
JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory); JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory);
SourceModule[] scripts = JSCallGraphBuilderUtil.makeSourceModules(dir, name); Module[] scripts = JSCallGraphBuilderUtil.makeSourceModules(dir, name);
return buildCG(loaders, scripts, builderType, monitor, supportFullPointerAnalysis); return buildCG(loaders, scripts, builderType, monitor, supportFullPointerAnalysis);
} }
@ -93,14 +95,14 @@ public class FieldBasedCGUtil {
return buildCG(loaders, scripts, builderType, monitor, supportFullPointerAnalysis); return buildCG(loaders, scripts, builderType, monitor, supportFullPointerAnalysis);
} }
public Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildCG(JavaScriptLoaderFactory loaders, SourceModule[] scripts, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException { public Pair<JSCallGraph, PointerAnalysis<ObjectVertex>> buildCG(JavaScriptLoaderFactory loaders, Module[] scripts, BuilderType builderType, IProgressMonitor monitor, boolean supportFullPointerAnalysis) throws IOException, WalaException, CancelException {
CAstAnalysisScope scope = new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS)); CAstAnalysisScope scope = new CAstAnalysisScope(scripts, loaders, Collections.singleton(JavaScriptLoader.JS));
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS); IClassHierarchy cha = ClassHierarchyFactory.make(scope, loaders, JavaScriptLoader.JS);
Util.checkForFrontEndErrors(cha); Util.checkForFrontEndErrors(cha);
Iterable<Entrypoint> roots = JSCallGraphUtil.makeScriptRoots(cha); Iterable<Entrypoint> roots = JSCallGraphUtil.makeScriptRoots(cha);
FieldBasedCallGraphBuilder builder = null; FieldBasedCallGraphBuilder builder = null;
AnalysisCache cache = new AnalysisCache(AstIRFactory.makeDefaultFactory()); AnalysisCache cache = new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
switch(builderType) { switch(builderType) {
case PESSIMISTIC: case PESSIMISTIC:
builder = new PessimisticCallGraphBuilder(cha, JSCallGraphUtil.makeOptions(scope, cha, roots), cache, supportFullPointerAnalysis); builder = new PessimisticCallGraphBuilder(cha, JSCallGraphUtil.makeOptions(scope, cha, roots), cache, supportFullPointerAnalysis);

View File

@ -33,10 +33,10 @@ import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
import com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction.CorrelatedPairExtractorFactory; import com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction.CorrelatedPairExtractorFactory;
import com.ibm.wala.cast.js.loader.JavaScriptLoader; import com.ibm.wala.cast.js.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory; import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.CGBuilderType;
import com.ibm.wala.cast.loader.CAstAbstractLoader; import com.ibm.wala.cast.loader.CAstAbstractLoader;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory; import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule; import com.ibm.wala.classLoader.SourceURLModule;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
@ -44,6 +44,7 @@ import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder; import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys; import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
@ -123,13 +124,13 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
return makeScope(makeSourceModules(dir, name, JSCallGraphBuilderUtil.class.getClassLoader()), loaders, JavaScriptLoader.JS); return makeScope(makeSourceModules(dir, name, JSCallGraphBuilderUtil.class.getClassLoader()), loaders, JavaScriptLoader.JS);
} }
public static SourceModule[] makeSourceModules(String dir, String name) throws IOException { public static Module[] makeSourceModules(String dir, String name) throws IOException {
return makeSourceModules(dir, name, JSCallGraphBuilderUtil.class.getClassLoader()); return makeSourceModules(dir, name, JSCallGraphBuilderUtil.class.getClassLoader());
} }
public static SourceModule[] makeSourceModules(String dir, String name, ClassLoader loader) throws IOException { public static Module[] makeSourceModules(String dir, String name, ClassLoader loader) throws IOException {
URL script = getURLforFile(dir, name, loader); URL script = getURLforFile(dir, name, loader);
SourceModule[] modules = new SourceModule[] { Module[] modules = new Module[] {
(script.openConnection() instanceof JarURLConnection)? new SourceURLModule(script): makeSourceModule(script, dir, name), (script.openConnection() instanceof JarURLConnection)? new SourceURLModule(script): makeSourceModule(script, dir, name),
getPrologueFile("prologue.js") getPrologueFile("prologue.js")
}; };
@ -187,7 +188,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
} }
public static SourceModule[] makeHtmlScope(URL url, JavaScriptLoaderFactory loaders, Function<Void,JSSourceExtractor> fExtractor) { public static SourceModule[] makeHtmlScope(URL url, JavaScriptLoaderFactory loaders, Function<Void,JSSourceExtractor> fExtractor) {
Set<SourceModule> scripts = HashSetFactory.make(); Set<Module> scripts = HashSetFactory.make();
JavaScriptLoader.addBootstrapFile(WebUtil.preamble); JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
scripts.add(getPrologueFile("prologue.js")); scripts.add(getPrologueFile("prologue.js"));
@ -206,9 +207,9 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
} }
public static CallGraph makeHTMLCG(URL url, Function<Void, JSSourceExtractor> fExtractor) throws IOException, IllegalArgumentException, CancelException, WalaException { public static CallGraph makeHTMLCG(URL url, Function<Void, JSSourceExtractor> fExtractor) throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder b = makeHTMLCGBuilder(url, fExtractor); SSAPropagationCallGraphBuilder b = makeHTMLCGBuilder(url, fExtractor);
CallGraph CG = b.makeCallGraph(b.getOptions()); CallGraph CG = b.makeCallGraph(b.getOptions());
dumpCG(b.getPointerAnalysis(), CG); dumpCG(b.getCFAContextInterpreter(), b.getPointerAnalysis(), CG);
return CG; return CG;
} }

View File

@ -34,12 +34,12 @@ import com.ibm.wala.util.WalaException;
public abstract class TestArgumentSensitivity extends TestJSCallGraphShape { public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
protected static final Object[][] assertionsForArgs = new Object[][] { protected static final Object[][] assertionsForArgs = new Object[][] {
new Object[] { ROOT, new String[] { "tests/args.js" } }, new Object[] { ROOT, new String[] { "args.js" } },
new Object[] { new Object[] {
"tests/args.js", "args.js",
new String[] { "tests/args.js/a" } }, new String[] { "args.js/a" } },
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/x"} }, new Object[] { "args.js/a", new String[] { "args.js/x"} },
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/y", "tests/args.js/z", "!tests/args.js/wrong" } } }; new Object[] { "args.js/a", new String[] { "args.js/y", "args.js/z", "!args.js/wrong" } } };
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException, WalaException { @Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException, WalaException {
JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(null); JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(null);
@ -58,7 +58,7 @@ public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
CallGraph CG = builder.makeCallGraph(options); CallGraph CG = builder.makeCallGraph(options);
// CAstCallGraphUtil.AVOID_DUMP = false; // CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForArgs); verifyGraphAssertions(CG, assertionsForArgs);
} }

View File

@ -38,7 +38,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
URL url = getClass().getClassLoader().getResource("pages/page3.html"); URL url = getClass().getClassLoader().getResource("pages/page3.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url); JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
} }
@Test public void testPage3WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException { @Test public void testPage3WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -46,7 +46,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url); JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder); addHackedForInLoopSensitivity(builder);
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
} }
@Ignore("This test now blows up due to proper handling of the || construct, used in extend(). Should handle this eventually.") @Ignore("This test now blows up due to proper handling of the || construct, used in extend(). Should handle this eventually.")
@ -55,7 +55,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url); JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder); addHackedForInLoopSensitivity(builder);
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
} }
/* /*
@ -70,88 +70,88 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
private static final Object[][] assertionsForBadForin = new Object[][] { private static final Object[][] assertionsForBadForin = new Object[][] {
new Object[] { ROOT, new Object[] { ROOT,
new String[] { "tests/badforin.js" } }, new String[] { "badforin.js" } },
new Object[] { "tests/badforin.js", new Object[] { "badforin.js",
new String[] { "tests/badforin.js/testForIn", "tests/badforin.js/_check_obj_foo", "tests/badforin.js/_check_obj_bar", "tests/badforin.js/_check_copy_foo", "tests/badforin.js/_check_copy_bar"} }, new String[] { "badforin.js/testForIn", "badforin.js/_check_obj_foo", "badforin.js/_check_obj_bar", "badforin.js/_check_copy_foo", "badforin.js/_check_copy_bar"} },
new Object[] { "tests/badforin.js/testForIn", new Object[] { "badforin.js/testForIn",
new String[] { "tests/badforin.js/testForIn1", "tests/badforin.js/testForIn2" } }, new String[] { "badforin.js/testForIn1", "badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_obj_foo", new Object[] { "badforin.js/_check_obj_foo",
new String[] { "tests/badforin.js/testForIn1" } }, new String[] { "badforin.js/testForIn1" } },
new Object[] { "tests/badforin.js/_check_copy_foo", new Object[] { "badforin.js/_check_copy_foo",
new String[] { "tests/badforin.js/testForIn1" } }, new String[] { "badforin.js/testForIn1" } },
new Object[] { "tests/badforin.js/_check_obj_bar", new Object[] { "badforin.js/_check_obj_bar",
new String[] { "tests/badforin.js/testForIn2" } }, new String[] { "badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_copy_bar", new Object[] { "badforin.js/_check_copy_bar",
new String[] { "tests/badforin.js/testForIn2" } } new String[] { "badforin.js/testForIn2" } }
}; };
@Test public void testBadForInWithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException { @Test public void testBadForInWithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js"); JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForBadForin); verifyGraphAssertions(CG, assertionsForBadForin);
} }
private static final Object[][] assertionsForBadForinHackPrecision = new Object[][] { private static final Object[][] assertionsForBadForinHackPrecision = new Object[][] {
new Object[] { "tests/badforin.js/_check_obj_foo", new Object[] { "badforin.js/_check_obj_foo",
new String[] { "!tests/badforin.js/testForIn2" } }, new String[] { "!badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_copy_foo", new Object[] { "badforin.js/_check_copy_foo",
new String[] { "!tests/badforin.js/testForIn2" } }, new String[] { "!badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_obj_bar", new Object[] { "badforin.js/_check_obj_bar",
new String[] { "!tests/badforin.js/testForIn1" } }, new String[] { "!badforin.js/testForIn1" } },
new Object[] { "tests/badforin.js/_check_copy_bar", new Object[] { "badforin.js/_check_copy_bar",
new String[] { "!tests/badforin.js/testForIn1" } } new String[] { "!badforin.js/testForIn1" } }
}; };
@Test public void testBadForInWithHack() throws IOException, IllegalArgumentException, CancelException, WalaException { @Test public void testBadForInWithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js"); JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
addHackedForInLoopSensitivity(B); addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForBadForin); verifyGraphAssertions(CG, assertionsForBadForin);
verifyGraphAssertions(CG, assertionsForBadForinHackPrecision); verifyGraphAssertions(CG, assertionsForBadForinHackPrecision);
} }
private static final Object[][] assertionsForbadforin2 = new Object[][] { private static final Object[][] assertionsForbadforin2 = new Object[][] {
new Object[] { ROOT, new Object[] { ROOT,
new String[] { "tests/badforin2.js" } }, new String[] { "badforin2.js" } },
new Object[] { "tests/badforin2.js", new Object[] { "badforin2.js",
new String[] { "tests/badforin2.js/testForIn", "tests/badforin2.js/_check_obj_foo", "tests/badforin2.js/_check_obj_bar", "tests/badforin2.js/_check_copy_foo", "tests/badforin2.js/_check_copy_bar"} }, new String[] { "badforin2.js/testForIn", "badforin2.js/_check_obj_foo", "badforin2.js/_check_obj_bar", "badforin2.js/_check_copy_foo", "badforin2.js/_check_copy_bar"} },
new Object[] { "tests/badforin2.js/testForIn", new Object[] { "badforin2.js/testForIn",
new String[] { "tests/badforin2.js/testForIn1", "tests/badforin2.js/testForIn2" } }, new String[] { "badforin2.js/testForIn1", "badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_obj_foo", new Object[] { "badforin2.js/_check_obj_foo",
new String[] { "tests/badforin2.js/testForIn1" } }, new String[] { "badforin2.js/testForIn1" } },
new Object[] { "tests/badforin2.js/_check_copy_foo", new Object[] { "badforin2.js/_check_copy_foo",
new String[] { "tests/badforin2.js/testForIn1" } }, new String[] { "badforin2.js/testForIn1" } },
new Object[] { "tests/badforin2.js/_check_obj_bar", new Object[] { "badforin2.js/_check_obj_bar",
new String[] { "tests/badforin2.js/testForIn2" } }, new String[] { "badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_copy_bar", new Object[] { "badforin2.js/_check_copy_bar",
new String[] { "tests/badforin2.js/testForIn2" } } new String[] { "badforin2.js/testForIn2" } }
}; };
@Test public void testbadforin2WithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException { @Test public void testbadforin2WithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js"); JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForbadforin2); verifyGraphAssertions(CG, assertionsForbadforin2);
} }
private static final Object[][] assertionsForbadforin2HackPrecision = new Object[][] { private static final Object[][] assertionsForbadforin2HackPrecision = new Object[][] {
new Object[] { "tests/badforin2.js/_check_obj_foo", new Object[] { "badforin2.js/_check_obj_foo",
new String[] { "!tests/badforin2.js/testForIn2" } }, new String[] { "!badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_copy_foo", new Object[] { "badforin2.js/_check_copy_foo",
new String[] { "!tests/badforin2.js/testForIn2" } }, new String[] { "!badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_obj_bar", new Object[] { "badforin2.js/_check_obj_bar",
new String[] { "!tests/badforin2.js/testForIn1" } }, new String[] { "!badforin2.js/testForIn1" } },
new Object[] { "tests/badforin2.js/_check_copy_bar", new Object[] { "badforin2.js/_check_copy_bar",
new String[] { "!tests/badforin2.js/testForIn1" } } new String[] { "!badforin2.js/testForIn1" } }
}; };
@Test public void testbadforin2WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException { @Test public void testbadforin2WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js"); JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
addHackedForInLoopSensitivity(B); addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForbadforin2); verifyGraphAssertions(CG, assertionsForbadforin2);
verifyGraphAssertions(CG, assertionsForbadforin2HackPrecision); verifyGraphAssertions(CG, assertionsForbadforin2HackPrecision);
} }
@ -160,7 +160,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin3.js"); JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin3.js");
addHackedForInLoopSensitivity(B); addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
} }

View File

@ -41,6 +41,6 @@ public class TestJQueryExamples extends TestJSCallGraphShape {
URL url = getClass().getClassLoader().getResource("pages/jquery/ex1.html"); URL url = getClass().getClassLoader().getResource("pages/jquery/ex1.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url); JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
} }
} }

View File

@ -19,7 +19,6 @@ import org.junit.Test;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil; import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector; import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
@ -39,11 +38,11 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
protected static final Object[][] assertionsForArgs = new Object[][] { protected static final Object[][] assertionsForArgs = new Object[][] {
new Object[] { ROOT, new String[] { "tests/args.js" } }, new Object[] { ROOT, new String[] { "args.js" } },
new Object[] { new Object[] {
"tests/args.js", "args.js",
new String[] { "tests/args.js/a" } }, new String[] { "args.js/a" } },
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/x", "tests/args.js/y" } } }; new Object[] { "args.js/a", new String[] { "args.js/x", "args.js/y" } } };
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, WalaException { @Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "args.js"); CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "args.js");
@ -51,16 +50,16 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
protected static final Object[][] assertionsForSimple = new Object[][] { protected static final Object[][] assertionsForSimple = new Object[][] {
new Object[] { ROOT, new String[] { "tests/simple.js" } }, new Object[] { ROOT, new String[] { "simple.js" } },
new Object[] { new Object[] {
"tests/simple.js", "simple.js",
new String[] { "tests/simple.js/bad", "tests/simple.js/silly", "tests/simple.js/fib", "tests/simple.js/stranger", new String[] { "simple.js/bad", "simple.js/silly", "simple.js/fib", "simple.js/stranger",
"tests/simple.js/trivial", "tests/simple.js/rubbish", "tests/simple.js/weirder" } }, "simple.js/trivial", "simple.js/rubbish", "simple.js/weirder" } },
new Object[] { "tests/simple.js/trivial", new String[] { "tests/simple.js/trivial/inc" } }, new Object[] { "simple.js/trivial", new String[] { "simple.js/trivial/inc" } },
new Object[] { "tests/simple.js/rubbish", new Object[] { "simple.js/rubbish",
new String[] { "tests/simple.js/weirder", "tests/simple.js/stranger", "tests/simple.js/rubbish" } }, new String[] { "simple.js/weirder", "simple.js/stranger", "simple.js/rubbish" } },
new Object[] { "tests/simple.js/fib", new String[] { "tests/simple.js/fib" } }, new Object[] { "simple.js/fib", new String[] { "simple.js/fib" } },
new Object[] { "tests/simple.js/weirder", new String[] { "prologue.js/Math_abs" } } }; new Object[] { "simple.js/weirder", new String[] { "prologue.js/Math_abs" } } };
@Test @Test
public void testSimple() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testSimple() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -69,12 +68,12 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForObjects = new Object[][] { private static final Object[][] assertionsForObjects = new Object[][] {
new Object[] { ROOT, new String[] { "tests/objects.js" } }, new Object[] { ROOT, new String[] { "objects.js" } },
new Object[] { "tests/objects.js", new Object[] { "objects.js",
new String[] { "tests/objects.js/objects_are_fun", "tests/objects.js/other", "tests/objects.js/something" } }, new String[] { "objects.js/objects_are_fun", "objects.js/other", "objects.js/something" } },
new Object[] { "tests/objects.js/other", new Object[] { "objects.js/other",
new String[] { "tests/objects.js/something", "tests/objects.js/objects_are_fun/nothing" } }, new String[] { "objects.js/something", "objects.js/objects_are_fun/nothing" } },
new Object[] { "tests/objects.js/objects_are_fun", new String[] { "tests/objects.js/other", "tests/objects.js/whatever" } } }; new Object[] { "objects.js/objects_are_fun", new String[] { "objects.js/other", "objects.js/whatever" } } };
@Test @Test
public void testObjects() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testObjects() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -83,34 +82,34 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] cfgAssertionsForInherit = new Object[][] { private static final Object[][] cfgAssertionsForInherit = new Object[][] {
new Object[]{"ctor:tests/inherit.js/objectMasquerading/Rectangle", new Object[]{"ctor:inherit.js/objectMasquerading/Rectangle",
new int[][]{{1,7},{2},{3,7},{4,7},{5,6},{7},{7}} new int[][]{{1,7},{2},{3,7},{4,7},{5,6},{7},{7}}
}, },
new Object[]{"ctor:tests/inherit.js/sharedClassObject/Rectangle", new Object[]{"ctor:inherit.js/sharedClassObject/Rectangle",
new int[][]{{1,7},{2},{3,7},{4,7},{5,6},{7},{7}} new int[][]{{1,7},{2},{3,7},{4,7},{5,6},{7},{7}}
} }
}; };
private static final Object[][] assertionsForInherit = new Object[][] { private static final Object[][] assertionsForInherit = new Object[][] {
new Object[] { ROOT, new String[] { "tests/inherit.js" } }, new Object[] { ROOT, new String[] { "inherit.js" } },
new Object[] { new Object[] {
"tests/inherit.js", "inherit.js",
new String[] { "tests/inherit.js/objectMasquerading", "tests/inherit.js/objectMasquerading/Rectangle/area", new String[] { "inherit.js/objectMasquerading", "inherit.js/objectMasquerading/Rectangle/area",
"tests/inherit.js/Polygon/shape", "tests/inherit.js/sharedClassObject", "inherit.js/Polygon/shape", "inherit.js/sharedClassObject",
"tests/inherit.js/sharedClassObject/Rectangle/area" } }, "inherit.js/sharedClassObject/Rectangle/area" } },
new Object[]{ new Object[]{
"tests/inherit.js/objectMasquerading", "inherit.js/objectMasquerading",
new String[]{"ctor:tests/inherit.js/objectMasquerading/Rectangle"}}, new String[]{"ctor:inherit.js/objectMasquerading/Rectangle"}},
new Object[]{ new Object[]{
"ctor:tests/inherit.js/objectMasquerading/Rectangle" , "ctor:inherit.js/objectMasquerading/Rectangle" ,
new String[]{"tests/inherit.js/objectMasquerading/Rectangle"}}, new String[]{"inherit.js/objectMasquerading/Rectangle"}},
new Object[]{"tests/inherit.js/objectMasquerading/Rectangle", new Object[]{"inherit.js/objectMasquerading/Rectangle",
new String[]{"tests/inherit.js/Polygon"}}, new String[]{"inherit.js/Polygon"}},
new Object[]{ new Object[]{
"tests/inherit.js/sharedClassObject", "inherit.js/sharedClassObject",
new String[]{"ctor:tests/inherit.js/sharedClassObject/Rectangle"}}, new String[]{"ctor:inherit.js/sharedClassObject/Rectangle"}},
new Object[]{"ctor:tests/inherit.js/sharedClassObject/Rectangle", new Object[]{"ctor:inherit.js/sharedClassObject/Rectangle",
new String[]{"tests/inherit.js/sharedClassObject/Rectangle"}} new String[]{"inherit.js/sharedClassObject/Rectangle"}}
}; };
@Test @Test
@ -121,8 +120,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForNewfn = new Object[][] { private static final Object[][] assertionsForNewfn = new Object[][] {
new Object[] { ROOT, new String[] { "tests/newfn.js" } }, new Object[] { ROOT, new String[] { "newfn.js" } },
new Object[] { "tests/newfn.js", new Object[] { "newfn.js",
new String[] { "suffix:ctor$1/_fromctor", "suffix:ctor$2/_fromctor", "suffix:ctor$3/_fromctor" } } }; new String[] { "suffix:ctor$1/_fromctor", "suffix:ctor$2/_fromctor", "suffix:ctor$3/_fromctor" } } };
@Test @Test
@ -132,11 +131,11 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForControlflow = new Object[][] { private static final Object[][] assertionsForControlflow = new Object[][] {
new Object[] { ROOT, new String[] { "tests/control-flow.js" } }, new Object[] { ROOT, new String[] { "control-flow.js" } },
new Object[] { new Object[] {
"tests/control-flow.js", "control-flow.js",
new String[] { "tests/control-flow.js/testSwitch", "tests/control-flow.js/testDoWhile", new String[] { "control-flow.js/testSwitch", "control-flow.js/testDoWhile",
"tests/control-flow.js/testWhile", "tests/control-flow.js/testFor", "tests/control-flow.js/testReturn" } } }; "control-flow.js/testWhile", "control-flow.js/testFor", "control-flow.js/testReturn" } } };
@Test @Test
public void testControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -145,12 +144,12 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForMoreControlflow = new Object[][] { private static final Object[][] assertionsForMoreControlflow = new Object[][] {
new Object[] { ROOT, new String[] { "tests/more-control-flow.js" } }, new Object[] { ROOT, new String[] { "more-control-flow.js" } },
new Object[] { new Object[] {
"tests/more-control-flow.js", "more-control-flow.js",
new String[] { "tests/more-control-flow.js/testSwitch", "tests/more-control-flow.js/testIfConvertedSwitch", new String[] { "more-control-flow.js/testSwitch", "more-control-flow.js/testIfConvertedSwitch",
"tests/more-control-flow.js/testDoWhile", "tests/more-control-flow.js/testWhile", "more-control-flow.js/testDoWhile", "more-control-flow.js/testWhile",
"tests/more-control-flow.js/testFor", "tests/more-control-flow.js/testReturn" } } }; "more-control-flow.js/testFor", "more-control-flow.js/testReturn" } } };
@Test @Test
public void testMoreControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testMoreControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -158,30 +157,30 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
verifyGraphAssertions(CG, assertionsForMoreControlflow); verifyGraphAssertions(CG, assertionsForMoreControlflow);
} }
private static final Object[][] assertionsForForin = new Object[][] { new Object[] { ROOT, new String[] { "tests/forin.js" } }, private static final Object[][] assertionsForForin = new Object[][] { new Object[] { ROOT, new String[] { "forin.js" } },
new Object[] { "tests/forin.js", new String[] { "tests/forin.js/testForIn" } }, new Object[] { "forin.js", new String[] { "forin.js/testForIn" } },
new Object[] { "tests/forin.js/testForIn", new String[] { "tests/forin.js/testForIn1", "tests/forin.js/testForIn2" } } }; new Object[] { "forin.js/testForIn", new String[] { "forin.js/testForIn1", "forin.js/testForIn2" } } };
@Test @Test
public void testForin() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testForin() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "forin.js"); JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "forin.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false; // JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForForin); verifyGraphAssertions(CG, assertionsForForin);
} }
private static final Object[][] assertionsForSimpleLexical = new Object[][] { private static final Object[][] assertionsForSimpleLexical = new Object[][] {
new Object[] { ROOT, new String[] { "tests/simple-lexical.js" } }, new Object[] { ROOT, new String[] { "simple-lexical.js" } },
new Object[] { "tests/simple-lexical.js", new String[] { "tests/simple-lexical.js/outer" } }, new Object[] { "simple-lexical.js", new String[] { "simple-lexical.js/outer" } },
new Object[] { new Object[] {
"tests/simple-lexical.js/outer", "simple-lexical.js/outer",
new String[] { "tests/simple-lexical.js/outer/indirect", "tests/simple-lexical.js/outer/inner", new String[] { "simple-lexical.js/outer/indirect", "simple-lexical.js/outer/inner",
"tests/simple-lexical.js/outer/inner2", "tests/simple-lexical.js/outer/inner3" } }, "simple-lexical.js/outer/inner2", "simple-lexical.js/outer/inner3" } },
new Object[] { "tests/simple-lexical.js/outer/inner2", new Object[] { "simple-lexical.js/outer/inner2",
new String[] { "tests/simple-lexical.js/outer/inner", "tests/simple-lexical.js/outer/inner3" } }, new String[] { "simple-lexical.js/outer/inner", "simple-lexical.js/outer/inner3" } },
new Object[] { "tests/simple-lexical.js/outer/indirect", new Object[] { "simple-lexical.js/outer/indirect",
new String[] { "tests/simple-lexical.js/outer/inner", "tests/simple-lexical.js/outer/inner3" } } }; new String[] { "simple-lexical.js/outer/inner", "simple-lexical.js/outer/inner3" } } };
@Test @Test
public void testSimpleLexical() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testSimpleLexical() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -196,7 +195,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForLexicalMultiple = new Object[][] { private static final Object[][] assertionsForLexicalMultiple = new Object[][] {
new Object[] { ROOT, new String[] { "tests/lexical_multiple_calls.js" } }, new Object[] { ROOT, new String[] { "lexical_multiple_calls.js" } },
new Object[] { "suffix:lexical_multiple_calls.js", new String[] { "suffix:reachable1" } }, new Object[] { "suffix:lexical_multiple_calls.js", new String[] { "suffix:reachable1" } },
new Object[] { "suffix:lexical_multiple_calls.js", new String[] { "suffix:reachable2" } }}; new Object[] { "suffix:lexical_multiple_calls.js", new String[] { "suffix:reachable2" } }};
@ -208,19 +207,19 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
private static final Object[][] assertionsForTry = new Object[][] { private static final Object[][] assertionsForTry = new Object[][] {
new Object[] { ROOT, new String[] { "tests/try.js" } }, new Object[] { ROOT, new String[] { "try.js" } },
new Object[] { "tests/try.js", new Object[] { "try.js",
new String[] { "tests/try.js/tryCatch", "tests/try.js/tryFinally", "tests/try.js/tryCatchFinally" } }, new String[] { "try.js/tryCatch", "try.js/tryFinally", "try.js/tryCatchFinally" } },
new Object[] { "tests/try.js/tryCatch", new Object[] { "try.js/tryCatch",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/two" } }, new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/two" } },
new Object[] { "tests/try.js/tryFinally", new Object[] { "try.js/tryFinally",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/two" } }, new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/two" } },
new Object[] { "tests/try.js/tryCatchFinally", new Object[] { "try.js/tryCatchFinally",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/three", "tests/try.js/two" } }, new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/three", "try.js/two" } },
new Object[] { "tests/try.js/tryCatchTwice", new Object[] { "try.js/tryCatchTwice",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/three", "tests/try.js/two" } }, new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/three", "try.js/two" } },
new Object[] { "tests/try.js/testRet", new Object[] { "try.js/testRet",
new String[] { "tests/try.js/three", "tests/try.js/two" } } new String[] { "try.js/three", "try.js/two" } }
}; };
@Test @Test
@ -237,8 +236,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForStringOp = new Object[][] { private static final Object[][] assertionsForStringOp = new Object[][] {
new Object[] { ROOT, new String[] { "tests/string-op.js" } }, new Object[] { ROOT, new String[] { "string-op.js" } },
new Object[] { "tests/string-op.js", new String[] { "tests/string-op.js/getOp", "tests/string-op.js/plusNum" } } }; new Object[] { "string-op.js", new String[] { "string-op.js/getOp", "string-op.js/plusNum" } } };
@Test @Test
public void testStringOp() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testStringOp() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -249,11 +248,11 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForUpward = new Object[][] { private static final Object[][] assertionsForUpward = new Object[][] {
new Object[] { ROOT, new String[] { "tests/upward.js" } }, new Object[] { ROOT, new String[] { "upward.js" } },
new Object[] { new Object[] {
"tests/upward.js", "upward.js",
new String[] { "tests/upward.js/Obj/setit", "tests/upward.js/Obj/getit", "tests/upward.js/tester1", new String[] { "upward.js/Obj/setit", "upward.js/Obj/getit", "upward.js/tester1",
"tests/upward.js/tester2" } } }; "upward.js/tester2" } } };
@Test @Test
public void testUpward() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testUpward() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -262,21 +261,21 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForStringPrims = new Object[][] { private static final Object[][] assertionsForStringPrims = new Object[][] {
new Object[] { ROOT, new String[] { "tests/string-prims.js" } }, new Object[] { ROOT, new String[] { "string-prims.js" } },
new Object[] { "tests/string-prims.js", new String[] { "prologue.js/String_prototype_split", "prologue.js/String_prototype_toUpperCase" } } }; new Object[] { "string-prims.js", new String[] { "prologue.js/String_prototype_split", "prologue.js/String_prototype_toUpperCase" } } };
@Test @Test
public void testStringPrims() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testStringPrims() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-prims.js"); SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-prims.js");
B.getOptions().setTraceStringConstants(true); B.getOptions().setTraceStringConstants(true);
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false; // JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForStringPrims); verifyGraphAssertions(CG, assertionsForStringPrims);
} }
private static final Object[][] assertionsForNested = new Object[][] { new Object[] { ROOT, new String[] { "tests/nested.js" } }, private static final Object[][] assertionsForNested = new Object[][] { new Object[] { ROOT, new String[] { "nested.js" } },
new Object[] { "tests/nested.js", new String[] { "tests/nested.js/f", "tests/nested.js/f/ff", "tests/nested.js/f/ff/fff" } } }; new Object[] { "nested.js", new String[] { "nested.js/f", "nested.js/f/ff", "nested.js/f/ff/fff" } } };
@Test @Test
public void testNested() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testNested() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -286,7 +285,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForInstanceof = new Object[][] { new Object[] { ROOT, private static final Object[][] assertionsForInstanceof = new Object[][] { new Object[] { ROOT,
new String[] { "tests/instanceof.js" } } }; new String[] { "instanceof.js" } } };
@Test @Test
public void testInstanceof() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testInstanceof() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -297,7 +296,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
/* /*
* private static final Object[][] assertionsForWith = new Object[][] { new * private static final Object[][] assertionsForWith = new Object[][] { new
* Object[] { ROOT, new String[] { "tests/with.js" } } }; * Object[] { ROOT, new String[] { "with.js" } } };
* *
* @Test public void testWith() throws IOException, IllegalArgumentException, * @Test public void testWith() throws IOException, IllegalArgumentException,
* CancelException { PropagationCallGraphBuilder B = * CancelException { PropagationCallGraphBuilder B =
@ -325,8 +324,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForMultivar = new Object[][] { private static final Object[][] assertionsForMultivar = new Object[][] {
new Object[] { ROOT, new String[] { "tests/multivar.js" } }, new Object[] { ROOT, new String[] { "multivar.js" } },
new Object[] { "tests/multivar.js", new String[] { "tests/multivar.js/a", "tests/multivar.js/bf", "tests/multivar.js/c" } } }; new Object[] { "multivar.js", new String[] { "multivar.js/a", "multivar.js/bf", "multivar.js/c" } } };
@Test @Test
public void testMultivar() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testMultivar() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -335,7 +334,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForPrototypeContamination = new Object[][] { private static final Object[][] assertionsForPrototypeContamination = new Object[][] {
new Object[] { ROOT, new String[] { "tests/prototype_contamination_bug.js" } }, new Object[] { ROOT, new String[] { "prototype_contamination_bug.js" } },
new Object[] { "suffix:test1", new String[] { "suffix:foo_of_A" } }, new Object[] { "suffix:test1", new String[] { "suffix:foo_of_A" } },
new Object[] { "suffix:test2", new String[] { "suffix:foo_of_B" } } }; new Object[] { "suffix:test2", new String[] { "suffix:foo_of_B" } } };
@ -370,14 +369,14 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
List<CGNode> succs = Iterator2Collection.toList(cg.getSuccNodes(n)); List<CGNode> succs = Iterator2Collection.toList(cg.getSuccNodes(n));
Assert Assert
.assertEquals( .assertEquals(
"[Node: <Code body of function Ltests/function_call.js/foo> Context: Everywhere, Node: <Code body of function Ltests/function_call.js/bar> Context: Everywhere]", "[Node: <Code body of function Lfunction_call.js/foo> Context: Everywhere, Node: <Code body of function Lfunction_call.js/bar> Context: Everywhere]",
succs.toString()); succs.toString());
} }
} }
} }
private static final Object[][] assertionsForFunctionApply = new Object[][] { private static final Object[][] assertionsForFunctionApply = new Object[][] {
new Object[] { ROOT, new String[] { "tests/function_apply.js" } }, new Object[] { ROOT, new String[] { "function_apply.js" } },
new Object[] { "suffix:function_apply.js", new String[] { "suffix:theOne" } }, new Object[] { "suffix:function_apply.js", new String[] { "suffix:theOne" } },
new Object[] { "suffix:function_apply.js", new String[] { "suffix:theTwo" } } }; new Object[] { "suffix:function_apply.js", new String[] { "suffix:theTwo" } } };
@ -389,7 +388,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForFunctionApply2 = new Object[][] { private static final Object[][] assertionsForFunctionApply2 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/function_apply2.js" } }, new Object[] { ROOT, new String[] { "function_apply2.js" } },
new Object[] { "suffix:function_apply2.js", new String[] { "suffix:theThree" } } }; new Object[] { "suffix:function_apply2.js", new String[] { "suffix:theThree" } } };
@Test @Test
@ -399,7 +398,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForFunctionApply3 = new Object[][] { private static final Object[][] assertionsForFunctionApply3 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/function_apply3.js" } }, new Object[] { ROOT, new String[] { "function_apply3.js" } },
new Object[] { "suffix:apply", new String[] { "suffix:foo" } } }; new Object[] { "suffix:apply", new String[] { "suffix:foo" } } };
@Test @Test
@ -409,7 +408,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForWrap1 = new Object[][] { private static final Object[][] assertionsForWrap1 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/wrap1.js" } }, new Object[] { ROOT, new String[] { "wrap1.js" } },
new Object[] { "suffix:wrap1.js", new String[] { "suffix:i_am_reachable" } } }; new Object[] { "suffix:wrap1.js", new String[] { "suffix:i_am_reachable" } } };
@Test @Test
@ -419,7 +418,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForWrap2 = new Object[][] { private static final Object[][] assertionsForWrap2 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/wrap2.js" } }, new Object[] { ROOT, new String[] { "wrap2.js" } },
new Object[] { "suffix:wrap2.js", new String[] { "suffix:i_am_reachable" } } }; new Object[] { "suffix:wrap2.js", new String[] { "suffix:i_am_reachable" } } };
@Test @Test
@ -429,7 +428,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForWrap3 = new Object[][] { private static final Object[][] assertionsForWrap3 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/wrap3.js" } }, new Object[] { ROOT, new String[] { "wrap3.js" } },
new Object[] { "suffix:wrap3.js", new String[] { "suffix:i_am_reachable" } } }; new Object[] { "suffix:wrap3.js", new String[] { "suffix:i_am_reachable" } } };
@Test @Test
@ -439,7 +438,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForComplexCall = new Object[][] { private static final Object[][] assertionsForComplexCall = new Object[][] {
new Object[] { ROOT, new String[] { "tests/complex_call.js" } }, new Object[] { ROOT, new String[] { "complex_call.js" } },
new Object[] { "suffix:call.js", new String[] { "suffix:f3" } } }; new Object[] { "suffix:call.js", new String[] { "suffix:f3" } } };
@Test @Test
@ -452,7 +451,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
private static final Object[][] assertionsForGlobalObj = new Object[][] { private static final Object[][] assertionsForGlobalObj = new Object[][] {
new Object[] { ROOT, new String[] { "tests/global_object.js" } }, new Object[] { ROOT, new String[] { "global_object.js" } },
new Object[] { "suffix:global_object.js", new String[] { "suffix:biz" } } }; new Object[] { "suffix:global_object.js", new String[] { "suffix:biz" } } };
@Test @Test
@ -462,7 +461,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForGlobalObj2 = new Object[][] { private static final Object[][] assertionsForGlobalObj2 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/global_object2.js" } }, new Object[] { ROOT, new String[] { "global_object2.js" } },
new Object[] { "suffix:global_object2.js", new String[] { "suffix:foo" } } }; new Object[] { "suffix:global_object2.js", new String[] { "suffix:foo" } } };
@Test @Test
@ -473,21 +472,21 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
private static final Object[][] assertionsForReturnThis = new Object[][] { private static final Object[][] assertionsForReturnThis = new Object[][] {
new Object[] { ROOT, new String[] { "tests/return_this.js" } }, new Object[] { ROOT, new String[] { "return_this.js" } },
new Object[] { "suffix:return_this.js", new String[] { "suffix:foo" } }, new Object[] { "suffix:return_this.js", new String[] { "suffix:foo" } },
new Object[] { "suffix:return_this.js", new String[] { "suffix:bar" } } }; new Object[] { "suffix:return_this.js", new String[] { "suffix:bar" } } };
@Test @Test
public void testReturnThis() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testReturnThis() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "return_this.js"); SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "return_this.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false; // JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForReturnThis); verifyGraphAssertions(CG, assertionsForReturnThis);
} }
private static final Object[][] assertionsForReturnThis2 = new Object[][] { private static final Object[][] assertionsForReturnThis2 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/return_this2.js" } }, new Object[] { ROOT, new String[] { "return_this2.js" } },
new Object[] { "suffix:return_this2.js", new String[] { "suffix:A" } }, new Object[] { "suffix:return_this2.js", new String[] { "suffix:A" } },
new Object[] { "suffix:return_this2.js", new String[] { "suffix:foo" } }, new Object[] { "suffix:return_this2.js", new String[] { "suffix:foo" } },
new Object[] { "suffix:return_this2.js", new String[] { "suffix:test1" } }, new Object[] { "suffix:return_this2.js", new String[] { "suffix:test1" } },
@ -505,7 +504,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForArguments = new Object[][] { private static final Object[][] assertionsForArguments = new Object[][] {
new Object[] { ROOT, new String[] { "tests/arguments.js" } }, new Object[] { ROOT, new String[] { "arguments.js" } },
new Object[] { "suffix:arguments.js", new String[] { "suffix:f" } }, new Object[] { "suffix:arguments.js", new String[] { "suffix:f" } },
new Object[] { "suffix:f", new String[] { "!suffix:g1", "!suffix:g2", "suffix:g3", } } new Object[] { "suffix:f", new String[] { "!suffix:g1", "!suffix:g2", "suffix:g3", } }
}; };
@ -517,7 +516,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForFunctionIsAFunction = new Object[][] { private static final Object[][] assertionsForFunctionIsAFunction = new Object[][] {
new Object[] { ROOT, new String[] { "tests/Function_is_a_function.js" } }, new Object[] { ROOT, new String[] { "Function_is_a_function.js" } },
new Object[] { "suffix:Function_is_a_function.js", new String[] { "suffix:Function_prototype_call" } } }; new Object[] { "suffix:Function_is_a_function.js", new String[] { "suffix:Function_prototype_call" } } };
@Test @Test
@ -527,7 +526,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForLexicalBroken = new Object[][] { private static final Object[][] assertionsForLexicalBroken = new Object[][] {
new Object[] { ROOT, new String[] { "tests/lexical_broken.js" } }, new Object[] { ROOT, new String[] { "lexical_broken.js" } },
new Object[] { "suffix:lexical_broken.js", new String[] { "suffix:f" } }, new Object[] { "suffix:lexical_broken.js", new String[] { "suffix:f" } },
new Object[] { "suffix:f", new String[] { "suffix:g" } } new Object[] { "suffix:f", new String[] { "suffix:g" } }
}; };
@ -544,7 +543,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForScopingOverwriteFunction = new Object[][] { private static final Object[][] assertionsForScopingOverwriteFunction = new Object[][] {
new Object[] { ROOT, new String[] { "tests/scoping_test.js" } }, new Object[] { ROOT, new String[] { "scoping_test.js" } },
new Object[] { "suffix:scoping_test.js", new String[] { "suffix:i_am_reachable" } } new Object[] { "suffix:scoping_test.js", new String[] { "suffix:i_am_reachable" } }
}; };
@ -555,7 +554,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForNestedParamAssign = new Object[][] { private static final Object[][] assertionsForNestedParamAssign = new Object[][] {
new Object[] { ROOT, new String[] { "tests/nested_assign_to_param.js" } }, new Object[] { ROOT, new String[] { "nested_assign_to_param.js" } },
new Object[] { "suffix:nested_assign_to_param.js", new String[] { "suffix:i_am_reachable" } } new Object[] { "suffix:nested_assign_to_param.js", new String[] { "suffix:i_am_reachable" } }
}; };
@ -566,24 +565,24 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForDispatch = new Object[][] { private static final Object[][] assertionsForDispatch = new Object[][] {
new Object[] { ROOT, new String[] { "tests/dispatch.js" } }, new Object[] { ROOT, new String[] { "dispatch.js" } },
new Object[] { "tests/dispatch.js", new String[] { "tests/dispatch.js/left_outer", "tests/dispatch.js/right_outer" } }, new Object[] { "dispatch.js", new String[] { "dispatch.js/left_outer", "dispatch.js/right_outer" } },
new Object[] { "tests/dispatch.js/left_outer", new String[]{ "tests/dispatch.js/left_inner" } }, new Object[] { "dispatch.js/left_outer", new String[]{ "dispatch.js/left_inner" } },
new Object[] { "tests/dispatch.js/right_outer", new String[]{ "tests/dispatch.js/right_inner" } } new Object[] { "dispatch.js/right_outer", new String[]{ "dispatch.js/right_inner" } }
}; };
@Test @Test
public void testDispatch() throws IOException, IllegalArgumentException, CancelException, WalaException { public void testDispatch() throws IOException, IllegalArgumentException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch.js"); SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false; // JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDispatch); verifyGraphAssertions(CG, assertionsForDispatch);
} }
private static final Object[][] assertionsForDispatchSameTarget = new Object[][] { private static final Object[][] assertionsForDispatchSameTarget = new Object[][] {
new Object[] { ROOT, new String[] { "tests/dispatch_same_target.js" } }, new Object[] { ROOT, new String[] { "dispatch_same_target.js" } },
new Object[] { "tests/dispatch_same_target.js/f3", new String[] { "tests/dispatch_same_target.js/f4" } } new Object[] { "dispatch_same_target.js/f3", new String[] { "dispatch_same_target.js/f4" } }
}; };
@ -598,8 +597,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
private static final Object[][] assertionsForForInPrototype = new Object[][] { private static final Object[][] assertionsForForInPrototype = new Object[][] {
new Object[] { ROOT, new String[] { "tests/for_in_prototype.js" } }, new Object[] { ROOT, new String[] { "for_in_prototype.js" } },
new Object[] { "tests/for_in_prototype.js", new String[] { "suffix:A", new Object[] { "for_in_prototype.js", new String[] { "suffix:A",
"suffix:reachable", "suffix:reachable",
"suffix:also_reachable" } } "suffix:also_reachable" } }
}; };
@ -611,8 +610,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForArrayIndexConv = new Object[][] { private static final Object[][] assertionsForArrayIndexConv = new Object[][] {
new Object[] { ROOT, new String[] { "tests/array_index_conv.js" } }, new Object[] { ROOT, new String[] { "array_index_conv.js" } },
new Object[] { "tests/array_index_conv.js", new String[] { "suffix:reachable1", new Object[] { "array_index_conv.js", new String[] { "suffix:reachable1",
"suffix:reachable2", "suffix:reachable2",
"suffix:reachable3", "suffix:reachable3",
"suffix:reachable4" } } "suffix:reachable4" } }
@ -626,8 +625,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForArrayIndexConv2 = new Object[][] { private static final Object[][] assertionsForArrayIndexConv2 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/array_index_conv2.js" } }, new Object[] { ROOT, new String[] { "array_index_conv2.js" } },
new Object[] { "tests/array_index_conv2.js", new String[] { "suffix:invokeOnA" } }, new Object[] { "array_index_conv2.js", new String[] { "suffix:invokeOnA" } },
new Object[] { "suffix:invokeOnA", new String[] { "suffix:reachable", new Object[] { "suffix:invokeOnA", new String[] { "suffix:reachable",
"suffix:also_reachable", "suffix:also_reachable",
"suffix:reachable_too" } } "suffix:reachable_too" } }
@ -644,8 +643,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForDateProperty = new Object[][] { private static final Object[][] assertionsForDateProperty = new Object[][] {
new Object[] { ROOT, new String[] { "tests/date-property.js" } }, new Object[] { ROOT, new String[] { "date-property.js" } },
new Object[] { "tests/date-property.js", new String[] { "suffix:_fun" } } new Object[] { "date-property.js", new String[] { "suffix:_fun" } }
}; };
@Test @Test
@ -657,8 +656,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
verifyGraphAssertions(CG, assertionsForDateProperty); verifyGraphAssertions(CG, assertionsForDateProperty);
} }
private static final Object[][] assertionsForDeadCode = new Object[][] { private static final Object[][] assertionsForDeadCode = new Object[][] {
new Object[] { ROOT, new String[] { "tests/dead.js" } }, new Object[] { ROOT, new String[] { "dead.js" } },
new Object[] { "tests/dead.js", new String[] { "suffix:twoReturns" } } new Object[] { "dead.js", new String[] { "suffix:twoReturns" } }
}; };
@Test @Test
@ -671,10 +670,10 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForShadow = new Object[][] { private static final Object[][] assertionsForShadow = new Object[][] {
new Object[] { ROOT, new String[] { "tests/shadow_test.js" } }, new Object[] { ROOT, new String[] { "shadow_test.js" } },
new Object[] { "tests/shadow_test.js", new String[] { "tests/shadow_test.js/test" } }, new Object[] { "shadow_test.js", new String[] { "shadow_test.js/test" } },
new Object[] { "tests/shadow_test.js/test", new String[] { "tests/shadow_test.js/bad" } }, new Object[] { "shadow_test.js/test", new String[] { "shadow_test.js/bad" } },
new Object[] { "tests/shadow_test.js/test", new String[] { "tests/shadow_test.js/global_bad" } } new Object[] { "shadow_test.js/test", new String[] { "shadow_test.js/global_bad" } }
}; };
@Test @Test
@ -685,8 +684,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
} }
private static final Object[][] assertionsForExtend = new Object[][] { private static final Object[][] assertionsForExtend = new Object[][] {
new Object[] { ROOT, new String[] { "tests/extend.js" } }, new Object[] { ROOT, new String[] { "extend.js" } },
new Object[] { "tests/extend.js", new String[] { "suffix:bar", "!suffix:foo" } } new Object[] { "extend.js", new String[] { "suffix:bar", "!suffix:foo" } }
}; };
@Test @Test
@ -712,7 +711,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
boolean save = CAstCallGraphUtil.AVOID_DUMP; boolean save = CAstCallGraphUtil.AVOID_DUMP;
//CAstCallGraphUtil.AVOID_DUMP = false; //CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save; CAstCallGraphUtil.AVOID_DUMP = save;
} }
@ -725,56 +724,56 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
monitor.beginTask("build CG", 1); monitor.beginTask("build CG", 1);
CallGraph CG = B.makeCallGraph(B.getOptions(), monitor); CallGraph CG = B.makeCallGraph(B.getOptions(), monitor);
monitor.done(); monitor.done();
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
} }
@Test @Test
public void testTutorialExample() throws IllegalArgumentException, IOException, CancelException, WalaException { public void testTutorialExample() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "tutorial-example.js"); SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "tutorial-example.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
// verifyGraphAssertions(CG, assertionsForDateProperty); // verifyGraphAssertions(CG, assertionsForDateProperty);
} }
private static final Object[][] assertionsForLoops = new Object[][] { private static final Object[][] assertionsForLoops = new Object[][] {
new Object[] { ROOT, new String[] { "tests/loops.js" } }, new Object[] { ROOT, new String[] { "loops.js" } },
new Object[] { "tests/loops.js", new String[] { "tests/loops.js/three", "tests/loops.js/four"} } new Object[] { "loops.js", new String[] { "loops.js/three", "loops.js/four"} }
}; };
@Ignore("need to fix this. bug from Sukyoung's group") @Ignore("need to fix this. bug from Sukyoung's group")
@Test @Test
public void testLoops() throws IllegalArgumentException, IOException, CancelException, WalaException { public void testLoops() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "loops.js"); SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "loops.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
boolean x = CAstCallGraphUtil.AVOID_DUMP; boolean x = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = x; CAstCallGraphUtil.AVOID_DUMP = x;
verifyGraphAssertions(CG, assertionsForLoops); verifyGraphAssertions(CG, assertionsForLoops);
} }
private static final Object[][] assertionsForPrimitiveStrings = new Object[][] { private static final Object[][] assertionsForPrimitiveStrings = new Object[][] {
new Object[] { ROOT, new String[] { "tests/primitive_strings.js" } }, new Object[] { ROOT, new String[] { "primitive_strings.js" } },
new Object[] { "tests/primitive_strings.js", new String[] { "tests/primitive_strings.js/f1", "tests/primitive_strings.js/f1"} }, new Object[] { "primitive_strings.js", new String[] { "primitive_strings.js/f1", "primitive_strings.js/f1"} },
new Object[] { "tests/primitive_strings.js/f2", new String[] { "prologue.js/String_prototype_concat" } }, new Object[] { "primitive_strings.js/f2", new String[] { "prologue.js/String_prototype_concat" } },
new Object[] { "tests/primitive_strings.js/f1", new String[] { "prologue.js/String_prototype_concat" } }, new Object[] { "primitive_strings.js/f1", new String[] { "prologue.js/String_prototype_concat" } },
}; };
@Ignore("need to fix this. bug from Sukyoung's group") @Ignore("need to fix this. bug from Sukyoung's group")
@Test @Test
public void testPrimitiveStrings() throws IllegalArgumentException, IOException, CancelException, WalaException { public void testPrimitiveStrings() throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "primitive_strings.js"); SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "primitive_strings.js");
CallGraph CG = B.makeCallGraph(B.getOptions()); CallGraph CG = B.makeCallGraph(B.getOptions());
boolean x = CAstCallGraphUtil.AVOID_DUMP; boolean x = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = x; CAstCallGraphUtil.AVOID_DUMP = x;
verifyGraphAssertions(CG, assertionsForPrimitiveStrings); verifyGraphAssertions(CG, assertionsForPrimitiveStrings);
} }
Object[][] renamingAssertions = { Object[][] renamingAssertions = {
{ "tests/rename-example.js/f", new Name[]{ new Name(9, 7, "x"), new Name(9, 7, "y") } }, { "rename-example.js/f", new Name[]{ new Name(9, 7, "x"), new Name(9, 7, "y") } },
{ "tests/rename-example.js/ff", new Name[]{ new Name(11, 10, "x"), new Name(11, 10, "y"), new Name(11, 10, "z") } } { "rename-example.js/ff", new Name[]{ new Name(11, 10, "x"), new Name(11, 10, "y"), new Name(11, 10, "z") } }
}; };
@Test @Test

View File

@ -19,6 +19,7 @@ import org.junit.Test;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil; import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.js.html.IHtmlParser; import com.ibm.wala.cast.js.html.IHtmlParser;
import com.ibm.wala.cast.js.html.IHtmlParserFactory; import com.ibm.wala.cast.js.html.IHtmlParserFactory;
import com.ibm.wala.cast.js.html.JSSourceExtractor;
import com.ibm.wala.cast.js.html.WebUtil; import com.ibm.wala.cast.js.html.WebUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder; import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
@ -36,12 +37,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
@Override @Override
@Before @Before
public void setUp() { public void setUp() {
WebUtil.setFactory(new IHtmlParserFactory() { JSSourceExtractor.USE_TEMP_NAME = false;
@Override
public IHtmlParser getParser() {
return getParser();
}
});
} }
private static final Object[][] assertionsForPage1 = new Object[][] { private static final Object[][] assertionsForPage1 = new Object[][] {
@ -270,7 +266,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url); JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
// JSCallGraphBuilderUtil.AVOID_DUMP = false; // JSCallGraphBuilderUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
verifySourceAssertions(CG, sourceAssertionsForList); verifySourceAssertions(CG, sourceAssertionsForList);
} }
@ -292,7 +288,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
URL url = getClass().getClassLoader().getResource("pages/windowx.html"); URL url = getClass().getClassLoader().getResource("pages/windowx.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url); JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForWindowx); verifyGraphAssertions(CG, assertionsForWindowx);
} }
@ -306,7 +302,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
URL url = getClass().getClassLoader().getResource("pages/windowonload.html"); URL url = getClass().getClassLoader().getResource("pages/windowonload.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url); JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions()); CallGraph CG = builder.makeCallGraph(builder.getOptions());
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG); CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForWindowOnload); verifyGraphAssertions(CG, assertionsForWindowOnload);
} }

View File

@ -4,6 +4,6 @@
<classpathentry kind="src" path="dat"/> <classpathentry kind="src" path="dat"/>
<classpathentry exported="true" kind="lib" path="lib/jericho-html-3.2.jar"/> <classpathentry exported="true" kind="lib" path="lib/jericho-html-3.2.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -74,7 +74,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=di
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -39,11 +39,13 @@ import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.Context; import com.ibm.wala.ipa.callgraph.Context;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.MethodTargetSelector; import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
import com.ibm.wala.ipa.callgraph.impl.AbstractRootMethod; import com.ibm.wala.ipa.callgraph.impl.AbstractRootMethod;
import com.ibm.wala.ipa.callgraph.impl.ContextInsensitiveSelector; import com.ibm.wala.ipa.callgraph.impl.ContextInsensitiveSelector;
import com.ibm.wala.ipa.callgraph.impl.Everywhere; import com.ibm.wala.ipa.callgraph.impl.Everywhere;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis; import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.callgraph.propagation.cfa.DefaultSSAInterpreter; import com.ibm.wala.ipa.callgraph.propagation.cfa.DefaultSSAInterpreter;
import com.ibm.wala.ipa.callgraph.propagation.cfa.DelegatingSSAContextInterpreter; import com.ibm.wala.ipa.callgraph.propagation.cfa.DelegatingSSAContextInterpreter;
import com.ibm.wala.ipa.callgraph.propagation.cfa.nCFAContextSelector; import com.ibm.wala.ipa.callgraph.propagation.cfa.nCFAContextSelector;
@ -70,17 +72,17 @@ public abstract class FieldBasedCallGraphBuilder {
// standard call graph machinery // standard call graph machinery
protected final AnalysisOptions options; protected final AnalysisOptions options;
protected final AnalysisCache cache; protected final IAnalysisCacheView cache;
protected final JavaScriptConstructorFunctions constructors; protected final JavaScriptConstructorFunctions constructors;
protected final MethodTargetSelector targetSelector; public final MethodTargetSelector targetSelector;
protected final boolean supportFullPointerAnalysis; protected final boolean supportFullPointerAnalysis;
private static final boolean LOG_TIMINGS = true; private static final boolean LOG_TIMINGS = true;
public FieldBasedCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache, boolean supportFullPointerAnalysis) { public FieldBasedCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView iAnalysisCacheView, boolean supportFullPointerAnalysis) {
this.cha = cha; this.cha = cha;
this.options = options; this.options = options;
this.cache = cache; this.cache = iAnalysisCacheView;
this.constructors = new JavaScriptConstructorFunctions(cha); this.constructors = new JavaScriptConstructorFunctions(cha);
this.targetSelector = setupMethodTargetSelector(cha, constructors, options); this.targetSelector = setupMethodTargetSelector(cha, constructors, options);
this.supportFullPointerAnalysis = supportFullPointerAnalysis; this.supportFullPointerAnalysis = supportFullPointerAnalysis;
@ -89,7 +91,7 @@ public abstract class FieldBasedCallGraphBuilder {
private MethodTargetSelector setupMethodTargetSelector(IClassHierarchy cha, JavaScriptConstructorFunctions constructors2, AnalysisOptions options) { private MethodTargetSelector setupMethodTargetSelector(IClassHierarchy cha, JavaScriptConstructorFunctions constructors2, AnalysisOptions options) {
MethodTargetSelector result = new JavaScriptConstructTargetSelector(constructors2, options.getMethodTargetSelector()); MethodTargetSelector result = new JavaScriptConstructTargetSelector(constructors2, options.getMethodTargetSelector());
if (options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply()) { if (options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply()) {
result = new JavaScriptFunctionApplyTargetSelector(new JavaScriptFunctionDotCallTargetSelector(result)); result = new JavaScriptFunctionApplyTargetSelector(new JavaScriptFunctionDotCallTargetSelector(result, cache));
} }
return result; return result;
} }
@ -137,14 +139,19 @@ public abstract class FieldBasedCallGraphBuilder {
/** /**
* Extract a call graph from a given flow graph. * Extract a call graph from a given flow graph.
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected JSCallGraph extract(FlowGraph flowgraph, Iterable<? extends Entrypoint> eps, IProgressMonitor monitor) throws CancelException { public JSCallGraph extract(FlowGraph flowgraph, Iterable<? extends Entrypoint> eps, IProgressMonitor monitor) throws CancelException {
DelegatingSSAContextInterpreter interpreter = new DelegatingSSAContextInterpreter(new AstContextInsensitiveSSAContextInterpreter(options, cache), new DefaultSSAInterpreter(options, cache));
return extract(interpreter, flowgraph, eps, monitor);
}
@SuppressWarnings("deprecation")
public JSCallGraph extract(SSAContextInterpreter interpreter, FlowGraph flowgraph, Iterable<? extends Entrypoint> eps, IProgressMonitor monitor) throws CancelException {
// set up call graph // set up call graph
final JSCallGraph cg = new JSCallGraph(cha, options, cache); final JSCallGraph cg = new JSCallGraph(cha, options, cache);
cg.init(); cg.init();
// setup context interpreters // setup context interpreters
DelegatingSSAContextInterpreter interpreter = new DelegatingSSAContextInterpreter(new AstContextInsensitiveSSAContextInterpreter(options, cache), new DefaultSSAInterpreter(options, cache));
if (options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply()) { if (options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply()) {
interpreter = new DelegatingSSAContextInterpreter(new JavaScriptFunctionApplyContextInterpreter(options, cache), interpreter); interpreter = new DelegatingSSAContextInterpreter(new JavaScriptFunctionApplyContextInterpreter(options, cache), interpreter);
} }
@ -206,7 +213,7 @@ public abstract class FieldBasedCallGraphBuilder {
return cg; return cg;
} }
private boolean handleFunctionCallOrApplyInvocation(FlowGraph flowgraph, IProgressMonitor monitor, final JSCallGraph cg, public boolean handleFunctionCallOrApplyInvocation(FlowGraph flowgraph, IProgressMonitor monitor, final JSCallGraph cg,
CallVertex callVertex, CGNode caller, CallSiteReference site, CallVertex callVertex, CGNode caller, CallSiteReference site,
IMethod target) throws CancelException { IMethod target) throws CancelException {
// use to get 1-level of call string for Function.prototype.call, to // use to get 1-level of call string for Function.prototype.call, to
@ -220,6 +227,7 @@ public abstract class FieldBasedCallGraphBuilder {
OrdinalSet<FuncVertex> reflectiveTargets = getReflectiveTargets(flowgraph, callVertex, monitor); OrdinalSet<FuncVertex> reflectiveTargets = getReflectiveTargets(flowgraph, callVertex, monitor);
System.err.println("adding callees " + reflectiveTargets + " for " + caller); System.err.println("adding callees " + reflectiveTargets + " for " + caller);
// there should only be one call site in the synthetic method // there should only be one call site in the synthetic method
// CallSiteReference reflectiveCallSite = cache.getIRFactory().makeIR(functionPrototypeCallNode.getMethod(), Everywhere.EVERYWHERE, options.getSSAOptions()).iterateCallSites().next();
CallSiteReference reflectiveCallSite = functionPrototypeCallNode.getIR().iterateCallSites().next(); CallSiteReference reflectiveCallSite = functionPrototypeCallNode.getIR().iterateCallSites().next();
for (FuncVertex f : reflectiveTargets) { for (FuncVertex f : reflectiveTargets) {
IMethod reflectiveTgtMethod = targetSelector.getCalleeTarget(functionPrototypeCallNode, reflectiveCallSite, f.getConcreteType()); IMethod reflectiveTgtMethod = targetSelector.getCalleeTarget(functionPrototypeCallNode, reflectiveCallSite, f.getConcreteType());
@ -228,7 +236,7 @@ public abstract class FieldBasedCallGraphBuilder {
return ret; return ret;
} }
private boolean addEdgeToJSCallGraph(final JSCallGraph cg, CallSiteReference site, IMethod target, CGNode caller) public boolean addEdgeToJSCallGraph(final JSCallGraph cg, CallSiteReference site, IMethod target, CGNode caller)
throws CancelException { throws CancelException {
return addCGEdgeWithContext(cg, site, target, caller, Everywhere.EVERYWHERE); return addCGEdgeWithContext(cg, site, target, caller, Everywhere.EVERYWHERE);
} }
@ -276,7 +284,7 @@ public abstract class FieldBasedCallGraphBuilder {
/** /**
* Extract call edges from the flow graph into high-level representation. * Extract call edges from the flow graph into high-level representation.
*/ */
protected Set<Pair<CallVertex, FuncVertex>> extractCallGraphEdges(FlowGraph flowgraph, IProgressMonitor monitor) throws CancelException { public Set<Pair<CallVertex, FuncVertex>> extractCallGraphEdges(FlowGraph flowgraph, IProgressMonitor monitor) throws CancelException {
VertexFactory factory = flowgraph.getVertexFactory(); VertexFactory factory = flowgraph.getVertexFactory();
final Set<Pair<CallVertex, FuncVertex>> result = HashSetFactory.make(); final Set<Pair<CallVertex, FuncVertex>> result = HashSetFactory.make();

View File

@ -18,13 +18,11 @@ import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.FuncVertex;
import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VarVertex; import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VarVertex;
import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VertexFactory; import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VertexFactory;
import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions; import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions;
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptConstructorFunctions;
import com.ibm.wala.cast.js.ssa.JavaScriptInvoke; import com.ibm.wala.cast.js.ssa.JavaScriptInvoke;
import com.ibm.wala.cast.js.types.JavaScriptMethods; import com.ibm.wala.cast.js.types.JavaScriptMethods;
import com.ibm.wala.cast.types.AstMethodReference;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.MethodTargetSelector; import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.MonitorUtil; import com.ibm.wala.util.MonitorUtil;
@ -46,8 +44,8 @@ public class OptimisticCallgraphBuilder extends FieldBasedCallGraphBuilder {
private final boolean handleCallApply; private final boolean handleCallApply;
public OptimisticCallgraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache, boolean supportFullPointerAnalysis) { public OptimisticCallgraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView iAnalysisCacheView, boolean supportFullPointerAnalysis) {
super(cha, options, cache, supportFullPointerAnalysis); super(cha, options, iAnalysisCacheView, supportFullPointerAnalysis);
handleCallApply = options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply(); handleCallApply = options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply();
} }

View File

@ -15,7 +15,6 @@ import java.util.Iterator;
import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.FlowGraph; import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.FlowGraph;
import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.FuncVertex; import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.FuncVertex;
import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VertexFactory; import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VertexFactory;
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptConstructorFunctions;
import com.ibm.wala.cast.js.ssa.JavaScriptInvoke; import com.ibm.wala.cast.js.ssa.JavaScriptInvoke;
import com.ibm.wala.cast.js.types.JavaScriptTypes; import com.ibm.wala.cast.js.types.JavaScriptTypes;
import com.ibm.wala.cast.loader.AstMethod; import com.ibm.wala.cast.loader.AstMethod;
@ -24,7 +23,7 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.MethodTargetSelector; import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.DefUse; import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.IR;
@ -42,8 +41,8 @@ import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
* *
*/ */
public class PessimisticCallGraphBuilder extends FieldBasedCallGraphBuilder { public class PessimisticCallGraphBuilder extends FieldBasedCallGraphBuilder {
public PessimisticCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache, boolean supportFullPointerAnalysis) { public PessimisticCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView iAnalysisCacheView, boolean supportFullPointerAnalysis) {
super(cha, options, cache, supportFullPointerAnalysis); super(cha, options, iAnalysisCacheView, supportFullPointerAnalysis);
} }
@Override @Override

View File

@ -21,15 +21,12 @@ import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VarVertex;
import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.Vertex; import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.Vertex;
import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VertexFactory; import com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph.vertices.VertexFactory;
import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions; import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions;
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptConstructorFunctions;
import com.ibm.wala.cast.js.ssa.JavaScriptInvoke; import com.ibm.wala.cast.js.ssa.JavaScriptInvoke;
import com.ibm.wala.cast.js.types.JavaScriptMethods; import com.ibm.wala.cast.js.types.JavaScriptMethods;
import com.ibm.wala.cast.types.AstMethodReference; import com.ibm.wala.cast.types.AstMethodReference;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.MonitorUtil; import com.ibm.wala.util.MonitorUtil;
import com.ibm.wala.util.MonitorUtil.IProgressMonitor; import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
@ -69,7 +66,7 @@ public class WorklistBasedOptimisticCallgraphBuilder extends FieldBasedCallGraph
} }
@Override @Override
protected Set<Pair<CallVertex,FuncVertex>> extractCallGraphEdges(FlowGraph flowgraph, IProgressMonitor monitor) throws CancelException { public Set<Pair<CallVertex,FuncVertex>> extractCallGraphEdges(FlowGraph flowgraph, IProgressMonitor monitor) throws CancelException {
VertexFactory factory = flowgraph.getVertexFactory(); VertexFactory factory = flowgraph.getVertexFactory();
Set<Vertex> worklist = HashSetFactory.make(); Set<Vertex> worklist = HashSetFactory.make();
Map<Vertex, Set<FuncVertex>> reachingFunctions = HashMapFactory.make(); Map<Vertex, Set<FuncVertex>> reachingFunctions = HashMapFactory.make();

View File

@ -12,7 +12,7 @@
package com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph; package com.ibm.wala.cast.js.callgraph.fieldbased.flowgraph;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.functions.Function; import com.ibm.wala.util.functions.Function;
@ -20,7 +20,7 @@ public class FilteredFlowGraphBuilder extends FlowGraphBuilder {
private final Function<IMethod, Boolean> filter; private final Function<IMethod, Boolean> filter;
public FilteredFlowGraphBuilder(IClassHierarchy cha, AnalysisCache cache, boolean fullPointerAnalysis, Function<IMethod, Boolean> filter) { public FilteredFlowGraphBuilder(IClassHierarchy cha, IAnalysisCacheView cache, boolean fullPointerAnalysis, Function<IMethod, Boolean> filter) {
super(cha, cache, fullPointerAnalysis); super(cha, cache, fullPointerAnalysis);
this.filter = filter; this.filter = filter;
} }

View File

@ -39,9 +39,9 @@ import com.ibm.wala.classLoader.IField;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.classLoader.ProgramCounter; import com.ibm.wala.classLoader.ProgramCounter;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.impl.Everywhere; import com.ibm.wala.ipa.callgraph.impl.Everywhere;
import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey; import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey.TypeFilter; import com.ibm.wala.ipa.callgraph.propagation.FilteredPointerKey.TypeFilter;
@ -180,7 +180,7 @@ public class FlowGraph implements Iterable<Vertex> {
return graph.iterator(); return graph.iterator();
} }
public PointerAnalysis<ObjectVertex> getPointerAnalysis(final CallGraph cg, final AnalysisCache cache, final IProgressMonitor monitor) throws CancelException { public PointerAnalysis<ObjectVertex> getPointerAnalysis(final CallGraph cg, final IAnalysisCacheView cache, final IProgressMonitor monitor) throws CancelException {
return new PointerAnalysis<ObjectVertex>() { return new PointerAnalysis<ObjectVertex>() {
private final Map<Pair<PrototypeField,ObjectVertex>,PrototypeFieldVertex> proto = HashMapFactory.make(); private final Map<Pair<PrototypeField,ObjectVertex>,PrototypeFieldVertex> proto = HashMapFactory.make();
@ -189,7 +189,7 @@ public class FlowGraph implements Iterable<Vertex> {
private final ExtensionGraph<Vertex> dataflow = new ExtensionGraph<Vertex>(graph); private final ExtensionGraph<Vertex> dataflow = new ExtensionGraph<Vertex>(graph);
protected IR getIR(final AnalysisCache cache, FuncVertex func) { protected IR getIR(final IAnalysisCacheView cache, FuncVertex func) {
return cache.getIR(func.getConcreteType().getMethod(AstMethodReference.fnSelector)); return cache.getIR(func.getConcreteType().getMethod(AstMethodReference.fnSelector));
} }

View File

@ -38,7 +38,7 @@ import com.ibm.wala.cast.loader.AstMethod.LexicalInformation;
import com.ibm.wala.cast.types.AstMethodReference; import com.ibm.wala.cast.types.AstMethodReference;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSAGetCaughtExceptionInstruction; import com.ibm.wala.ssa.SSAGetCaughtExceptionInstruction;
@ -60,10 +60,10 @@ import com.ibm.wala.util.intset.IntSet;
*/ */
public class FlowGraphBuilder { public class FlowGraphBuilder {
private final IClassHierarchy cha; private final IClassHierarchy cha;
private final AnalysisCache cache; private final IAnalysisCacheView cache;
private final boolean supportFullPointerAnalysis; private final boolean supportFullPointerAnalysis;
public FlowGraphBuilder(IClassHierarchy cha, AnalysisCache cache, boolean supportPointerAnalysis) { public FlowGraphBuilder(IClassHierarchy cha, IAnalysisCacheView cache, boolean supportPointerAnalysis) {
this.cha = cha; this.cha = cha;
this.cache = cache; this.cache = cache;
this.supportFullPointerAnalysis = supportPointerAnalysis; this.supportFullPointerAnalysis = supportPointerAnalysis;
@ -104,9 +104,6 @@ public class FlowGraphBuilder {
public void visitFunction(FlowGraph flowgraph, IMethod method) { public void visitFunction(FlowGraph flowgraph, IMethod method) {
{ {
if (method.toString().contains("ctor") && method.toString().contains("dollar_init")) {
System.err.println("found it");
}
IR ir = cache.getIR(method); IR ir = cache.getIR(method);
FlowGraphSSAVisitor visitor = new FlowGraphSSAVisitor(ir, flowgraph); FlowGraphSSAVisitor visitor = new FlowGraphSSAVisitor(ir, flowgraph);

View File

@ -34,17 +34,19 @@ import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.client.AbstractAnalysisEngine; import com.ibm.wala.client.AbstractAnalysisEngine;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.CallGraphBuilder; import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException; import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis; import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ipa.cha.SeqClassHierarchyFactory;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.MonitorUtil.IProgressMonitor; import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.collections.HashSetFactory;
@ -72,7 +74,7 @@ public abstract class JavaScriptAnalysisEngine<I extends InstanceKey> extends Ab
@Override @Override
public IClassHierarchy buildClassHierarchy() { public IClassHierarchy buildClassHierarchy() {
try { try {
return ClassHierarchy.make(getScope(), loaderFactory, JavaScriptLoader.JS); return setClassHierarchy(SeqClassHierarchyFactory.make(getScope(), loaderFactory, JavaScriptLoader.JS));
} catch (ClassHierarchyException e) { } catch (ClassHierarchyException e) {
Assertions.UNREACHABLE(e.toString()); Assertions.UNREACHABLE(e.toString());
return null; return null;
@ -99,8 +101,8 @@ public abstract class JavaScriptAnalysisEngine<I extends InstanceKey> extends Ab
} }
@Override @Override
public AnalysisCache makeDefaultCache() { public IAnalysisCacheView makeDefaultCache() {
return new AnalysisCache(AstIRFactory.makeDefaultFactory()); return new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
} }
@Override @Override
@ -140,7 +142,7 @@ public abstract class JavaScriptAnalysisEngine<I extends InstanceKey> extends Ab
@Override @Override
protected CallGraphBuilder<ObjectVertex> getCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, final AnalysisCache cache) { protected CallGraphBuilder<ObjectVertex> getCallGraphBuilder(final IClassHierarchy cha, AnalysisOptions options, final IAnalysisCacheView cache) {
Set<Entrypoint> roots = HashSetFactory.make(); Set<Entrypoint> roots = HashSetFactory.make();
for(Entrypoint e : options.getEntrypoints()) { for(Entrypoint e : options.getEntrypoints()) {
roots.add(e); roots.add(e);
@ -176,10 +178,15 @@ public abstract class JavaScriptAnalysisEngine<I extends InstanceKey> extends Ab
} }
@Override @Override
public AnalysisCache getAnalysisCache() { public IAnalysisCacheView getAnalysisCache() {
return cache; return cache;
} }
@Override
public IClassHierarchy getClassHierarchy() {
return cha;
}
}; };
} }
} }
@ -187,7 +194,7 @@ public abstract class JavaScriptAnalysisEngine<I extends InstanceKey> extends Ab
public static class PropagationJavaScriptAnalysisEngine extends JavaScriptAnalysisEngine<InstanceKey> { public static class PropagationJavaScriptAnalysisEngine extends JavaScriptAnalysisEngine<InstanceKey> {
@Override @Override
protected CallGraphBuilder getCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) { protected CallGraphBuilder getCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache) {
return new ZeroCFABuilderFactory().make((JSAnalysisOptions) options, cache, cha, scope, false); return new ZeroCFABuilderFactory().make((JSAnalysisOptions) options, cache, cha, scope, false);
} }
} }

View File

@ -16,6 +16,7 @@ import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraphBuilder; import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys; import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
@ -26,7 +27,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
*/ */
public class ZeroCFABuilderFactory { public class ZeroCFABuilderFactory {
public CallGraphBuilder make(JSAnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope, public CallGraphBuilder make(JSAnalysisOptions options, IAnalysisCacheView cache, IClassHierarchy cha, AnalysisScope scope,
boolean keepPointsTo) { boolean keepPointsTo) {
com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha); com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha);
options.setSelector(new StandardFunctionTargetSelector(cha, options.getMethodTargetSelector())); options.setSelector(new StandardFunctionTargetSelector(cha, options.getMethodTargetSelector()));

View File

@ -17,18 +17,18 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import net.htmlparser.jericho.Config;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Logger;
import net.htmlparser.jericho.LoggerProvider;
import net.htmlparser.jericho.Source;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst; import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
import com.ibm.wala.cast.js.html.IHtmlCallback; import com.ibm.wala.cast.js.html.IHtmlCallback;
import com.ibm.wala.cast.js.html.IHtmlParser; import com.ibm.wala.cast.js.html.IHtmlParser;
import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.warnings.Warning; import com.ibm.wala.util.warnings.Warning;
import net.htmlparser.jericho.Config;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Logger;
import net.htmlparser.jericho.LoggerProvider;
import net.htmlparser.jericho.Source;
/** /**
* @author danielk * @author danielk

View File

@ -17,16 +17,16 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Map; import java.util.Map;
import net.htmlparser.jericho.Attribute;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Segment;
import com.ibm.wala.cast.js.html.ITag; import com.ibm.wala.cast.js.html.ITag;
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position; import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
import com.ibm.wala.cast.tree.impl.AbstractSourcePosition; import com.ibm.wala.cast.tree.impl.AbstractSourcePosition;
import com.ibm.wala.util.collections.HashMapFactory; import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.Pair; import com.ibm.wala.util.collections.Pair;
import net.htmlparser.jericho.Attribute;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.Segment;
/** /**
* ITag impel for Jericho generated tags * ITag impel for Jericho generated tags
* @author danielk * @author danielk

View File

@ -46,6 +46,7 @@ import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ssa.DefUse; import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAOptions; import com.ibm.wala.ssa.SSAOptions;
import com.ibm.wala.ssa.SymbolTable; import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;
@ -64,7 +65,7 @@ public class ArgumentSpecialization {
@Override @Override
public IR getIR(CGNode node) { public IR getIR(CGNode node) {
if (node.getMethod() instanceof Retranslatable) { if (node.getMethod() instanceof Retranslatable) {
return getAnalysisCache().getSSACache().findOrCreateIR(node.getMethod(), node.getContext(), options.getSSAOptions()); return getAnalysisCache().getIR(node.getMethod(), node.getContext());
} else { } else {
return super.getIR(node); return super.getIR(node);
} }
@ -73,7 +74,7 @@ public class ArgumentSpecialization {
@Override @Override
public DefUse getDU(CGNode node) { public DefUse getDU(CGNode node) {
if (node.getMethod() instanceof Retranslatable) { if (node.getMethod() instanceof Retranslatable) {
return getAnalysisCache().getSSACache().findOrCreateDU(node.getMethod(), node.getContext(), options.getSSAOptions()); return getAnalysisCache().getDefUse(getIR(node));
} else { } else {
return super.getDU(node); return super.getDU(node);
} }
@ -309,8 +310,8 @@ public class ArgumentSpecialization {
} }
@Override @Override
protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG cfg, SymbolTable symtab, protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG<SSAInstruction, ? extends IBasicBlock<SSAInstruction>> cfg, SymbolTable symtab,
boolean hasCatchBlock, Map<IBasicBlock,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation LI, boolean hasCatchBlock, Map<IBasicBlock<SSAInstruction>,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation LI,
DebuggingInformation debugInfo) { DebuggingInformation debugInfo) {
if (N == codeBodyEntity) { if (N == codeBodyEntity) {
specializedCode = myloader.makeCodeBodyCode(cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, LI, debugInfo, method.getDeclaringClass()); specializedCode = myloader.makeCodeBodyCode(cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, LI, debugInfo, method.getDeclaringClass());

View File

@ -19,6 +19,7 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IField; import com.ibm.wala.classLoader.IField;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey; import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey;
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey; import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
@ -33,7 +34,7 @@ import com.ibm.wala.util.strings.Atom;
*/ */
public abstract class JSCFABuilder extends JSSSAPropagationCallGraphBuilder { public abstract class JSCFABuilder extends JSSSAPropagationCallGraphBuilder {
public JSCFABuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) { public JSCFABuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache) {
super(cha, options, cache, new AstCFAPointerKeys() { super(cha, options, cache, new AstCFAPointerKeys() {
private boolean isBogusKey(InstanceKey K) { private boolean isBogusKey(InstanceKey K) {

View File

@ -22,9 +22,9 @@ import com.ibm.wala.cfg.InducedCFG;
import com.ibm.wala.classLoader.CallSiteReference; import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference; import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.impl.Everywhere; import com.ibm.wala.ipa.callgraph.impl.Everywhere;
import com.ibm.wala.ipa.callgraph.impl.FakeRootMethod; import com.ibm.wala.ipa.callgraph.impl.FakeRootMethod;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
@ -37,7 +37,7 @@ import com.ibm.wala.util.collections.HashSetFactory;
public class JSCallGraph extends AstCallGraph { public class JSCallGraph extends AstCallGraph {
public JSCallGraph(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) { public JSCallGraph(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache) {
super(cha, options, cache); super(cha, options, cache);
} }
@ -46,7 +46,7 @@ public class JSCallGraph extends AstCallGraph {
public static class JSFakeRoot extends ScriptFakeRoot { public static class JSFakeRoot extends ScriptFakeRoot {
public JSFakeRoot(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache) { public JSFakeRoot(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache) {
super(fakeRoot, cha.lookupClass(JavaScriptTypes.FakeRoot), cha, options, cache); super(fakeRoot, cha.lookupClass(JavaScriptTypes.FakeRoot), cha, options, cache);
} }

View File

@ -11,11 +11,14 @@
package com.ibm.wala.cast.js.ipa.callgraph; package com.ibm.wala.cast.js.ipa.callgraph;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Reader;
import java.net.URL; import java.net.URL;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -41,19 +44,25 @@ import com.ibm.wala.cfg.AbstractCFG;
import com.ibm.wala.cfg.IBasicBlock; import com.ibm.wala.cfg.IBasicBlock;
import com.ibm.wala.classLoader.ClassLoaderFactory; import com.ibm.wala.classLoader.ClassLoaderFactory;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule; import com.ibm.wala.classLoader.SourceURLModule;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.Entrypoint; import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.cha.ClassHierarchy; import com.ibm.wala.ipa.callgraph.impl.ClassHierarchyClassTargetSelector;
import com.ibm.wala.ipa.callgraph.impl.ClassHierarchyMethodTargetSelector;
import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SymbolTable; import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.MethodReference; import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeName; import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.NonNullSingletonIterator;
public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil { public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil {
@ -84,7 +93,9 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
* (keepIRs), * (keepIRs),
*/roots); */roots);
com.ibm.wala.ipa.callgraph.impl.Util.addDefaultSelectors(options, cha); options.setSelector(new ClassHierarchyMethodTargetSelector(cha));
options.setSelector(new ClassHierarchyClassTargetSelector(cha));
options.setSelector(new StandardFunctionTargetSelector(cha, options.getMethodTargetSelector())); options.setSelector(new StandardFunctionTargetSelector(cha, options.getMethodTargetSelector()));
options.setUseConstantSpecificKeys(true); options.setUseConstantSpecificKeys(true);
@ -115,7 +126,7 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
return makeHierarchy(scope, loaders); return makeHierarchy(scope, loaders);
} }
public static IClassHierarchy makeHierarchy(AnalysisScope scope, ClassLoaderFactory loaders) throws ClassHierarchyException { public static IClassHierarchy makeHierarchy(AnalysisScope scope, ClassLoaderFactory loaders) throws ClassHierarchyException {
return ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS); return ClassHierarchyFactory.make(scope, loaders, JavaScriptLoader.JS);
} }
public static JavaScriptEntryPoints makeScriptRoots(IClassHierarchy cha) { public static JavaScriptEntryPoints makeScriptRoots(IClassHierarchy cha) {
@ -175,15 +186,15 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
return loadAdditionalFile(cha, cl, new SourceURLModule(url)); return loadAdditionalFile(cha, cl, new SourceURLModule(url));
} }
public static Set<String> loadAdditionalFile(IClassHierarchy cha, JavaScriptLoader cl, SourceModule M) public static Set<String> loadAdditionalFile(IClassHierarchy cha, JavaScriptLoader cl, ModuleEntry M)
throws IOException { throws IOException {
try { try {
TranslatorToCAst toCAst = getTranslatorFactory().make(new CAstImpl(), M); TranslatorToCAst toCAst = getTranslatorFactory().make(new CAstImpl(), M);
final Set<String> names = new HashSet<String>(); final Set<String> names = new HashSet<String>();
JSAstTranslator toIR = new JSAstTranslator(cl) { JSAstTranslator toIR = new JSAstTranslator(cl) {
@Override @Override
protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG cfg, SymbolTable symtab, protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG<SSAInstruction, ? extends IBasicBlock<SSAInstruction>> cfg, SymbolTable symtab,
boolean hasCatchBlock, Map<IBasicBlock,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation LI, boolean hasCatchBlock, Map<IBasicBlock<SSAInstruction>,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation LI,
DebuggingInformation debugInfo) { DebuggingInformation debugInfo) {
String fnName = "L" + composeEntityName(definingContext, N); String fnName = "L" + composeEntityName(definingContext, N);
names.add(fnName); names.add(fnName);
@ -244,13 +255,76 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
} }
} }
public static SourceModule getPrologueFile(final String name) { public static class Bootstrap implements SourceModule, Module, ModuleEntry {
return new SourceURLModule(JSCallGraphUtil.class.getClassLoader().getResource(name)) { private String name;
@Override private InputStream stream;
public String getName() { private final URL url;
return name;
} public Bootstrap(String name, InputStream stream, URL url) {
}; this.name = name;
this.stream = stream;
this.url = url;
}
@Override
public Iterator<? extends ModuleEntry> getEntries() {
return new NonNullSingletonIterator<Bootstrap>(this);
}
@Override
public boolean isClassFile() {
return false;
}
@Override
public boolean isSourceFile() {
return true;
}
@Override
public InputStream getInputStream() {
return stream;
}
@Override
public boolean isModuleFile() {
return false;
}
@Override
public Module asModule() {
return this;
}
@Override
public String getClassName() {
return getName();
}
@Override
public Module getContainer() {
return null;
}
@Override
public String getName() {
return name;
}
@Override
public Reader getInputReader() {
// TODO Auto-generated method stub
return null;
}
@Override
public URL getURL() {
return url;
}
};
public static Module getPrologueFile(final String name) {
return new Bootstrap(name, JSCallGraphUtil.class.getClassLoader().getResourceAsStream(name), JSCallGraphUtil.class.getClassLoader().getResource(name));
} }
} }

View File

@ -48,6 +48,7 @@ import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph; import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.impl.ExplicitCallGraph; import com.ibm.wala.ipa.callgraph.impl.ExplicitCallGraph;
import com.ibm.wala.ipa.callgraph.propagation.AbstractFieldPointerKey; import com.ibm.wala.ipa.callgraph.propagation.AbstractFieldPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey; import com.ibm.wala.ipa.callgraph.propagation.ConcreteTypeKey;
@ -68,6 +69,7 @@ import com.ibm.wala.shrikeBT.BinaryOpInstruction;
import com.ibm.wala.shrikeBT.IUnaryOpInstruction; import com.ibm.wala.shrikeBT.IUnaryOpInstruction;
import com.ibm.wala.ssa.DefUse; import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.IRView;
import com.ibm.wala.ssa.SSAAbstractBinaryInstruction; import com.ibm.wala.ssa.SSAAbstractBinaryInstruction;
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
import com.ibm.wala.ssa.SSABinaryOpInstruction; import com.ibm.wala.ssa.SSABinaryOpInstruction;
@ -79,7 +81,6 @@ import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.CancelException; import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.CancelRuntimeException; import com.ibm.wala.util.CancelRuntimeException;
import com.ibm.wala.util.MonitorUtil; import com.ibm.wala.util.MonitorUtil;
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.intset.IntSet; import com.ibm.wala.util.intset.IntSet;
import com.ibm.wala.util.intset.IntSetAction; import com.ibm.wala.util.intset.IntSetAction;
@ -150,7 +151,7 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
this.scriptBaseURL = url; this.scriptBaseURL = url;
} }
protected JSSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache, protected JSSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache,
PointerKeyFactory pointerKeyFactory) { PointerKeyFactory pointerKeyFactory) {
super(cha, options, cache, pointerKeyFactory); super(cha, options, cache, pointerKeyFactory);
globalObject = new GlobalObjectKey(cha.lookupClass(JavaScriptTypes.Root)); globalObject = new GlobalObjectKey(cha.lookupClass(JavaScriptTypes.Root));
@ -555,12 +556,7 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
private Position getInstructionPosition(SSAInstruction instruction) { private Position getInstructionPosition(SSAInstruction instruction) {
IMethod method = node.getMethod(); IMethod method = node.getMethod();
if (method instanceof AstMethod) { if (method instanceof AstMethod) {
SSAInstruction[] instructions = ir.getInstructions(); return ((AstMethod) method).getSourcePosition(instruction.iindex);
for (int ind = basicBlock.getFirstInstructionIndex(); ind <= basicBlock.getLastInstructionIndex(); ind++) {
if (instruction.equals(instructions[ind])) {
return ((AstMethod) method).getSourcePosition(ind);
}
}
} }
return null; return null;
} }
@ -1027,10 +1023,11 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
public static void processCallingConstraintsInternal(AstSSAPropagationCallGraphBuilder builder, CGNode caller, SSAAbstractInvokeInstruction instruction, CGNode target, public static void processCallingConstraintsInternal(AstSSAPropagationCallGraphBuilder builder, CGNode caller, SSAAbstractInvokeInstruction instruction, CGNode target,
InstanceKey[][] constParams, PointerKey uniqueCatchKey) { InstanceKey[][] constParams, PointerKey uniqueCatchKey) {
IR sourceIR = builder.getCFAContextInterpreter().getIR(caller);
IRView sourceIR = builder.getCFAContextInterpreter().getIRView(caller);
SymbolTable sourceST = sourceIR.getSymbolTable(); SymbolTable sourceST = sourceIR.getSymbolTable();
IR targetIR = builder.getCFAContextInterpreter().getIR(target); IRView targetIR = builder.getCFAContextInterpreter().getIRView(target);
SymbolTable targetST = targetIR.getSymbolTable(); SymbolTable targetST = targetIR.getSymbolTable();
JSConstraintVisitor targetVisitor = null; JSConstraintVisitor targetVisitor = null;

View File

@ -10,10 +10,10 @@
*****************************************************************************/ *****************************************************************************/
package com.ibm.wala.cast.js.ipa.callgraph; package com.ibm.wala.cast.js.ipa.callgraph;
import com.ibm.wala.cast.ipa.callgraph.OneLevelForLexicalAccessFunctions;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisScope; import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.ContextSelector; import com.ibm.wala.ipa.callgraph.ContextSelector;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.MethodTargetSelector; import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
import com.ibm.wala.ipa.callgraph.impl.ContextInsensitiveSelector; import com.ibm.wala.ipa.callgraph.impl.ContextInsensitiveSelector;
import com.ibm.wala.ipa.callgraph.impl.DelegatingContextSelector; import com.ibm.wala.ipa.callgraph.impl.DelegatingContextSelector;
@ -32,13 +32,13 @@ public class JSZeroOrOneXCFABuilder extends JSCFABuilder {
private static final boolean USE_OBJECT_SENSITIVITY = false; private static final boolean USE_OBJECT_SENSITIVITY = false;
public JSZeroOrOneXCFABuilder(IClassHierarchy cha, JSAnalysisOptions options, AnalysisCache cache, public JSZeroOrOneXCFABuilder(IClassHierarchy cha, JSAnalysisOptions options, IAnalysisCacheView cache,
ContextSelector appContextSelector, SSAContextInterpreter appContextInterpreter, int instancePolicy, boolean doOneCFA) { ContextSelector appContextSelector, SSAContextInterpreter appContextInterpreter, int instancePolicy, boolean doOneCFA) {
super(cha, options, cache); super(cha, options, cache);
SSAContextInterpreter contextInterpreter = setupSSAContextInterpreter(cha, options, cache, appContextInterpreter); SSAContextInterpreter contextInterpreter = setupSSAContextInterpreter(cha, options, cache, appContextInterpreter);
setupMethodTargetSelector(cha, options); setupMethodTargetSelector(cha, options, cache);
setupContextSelector(options, appContextSelector, doOneCFA); setupContextSelector(options, appContextSelector, doOneCFA);
@ -71,11 +71,11 @@ public class JSZeroOrOneXCFABuilder extends JSCFABuilder {
} }
private void setupMethodTargetSelector(IClassHierarchy cha, JSAnalysisOptions options) { private void setupMethodTargetSelector(IClassHierarchy cha, JSAnalysisOptions options, IAnalysisCacheView cache) {
MethodTargetSelector targetSelector = new JavaScriptConstructTargetSelector(cha, options MethodTargetSelector targetSelector = new JavaScriptConstructTargetSelector(cha, options
.getMethodTargetSelector()); .getMethodTargetSelector());
if (options.handleCallApply()) { if (options.handleCallApply()) {
targetSelector = new JavaScriptFunctionApplyTargetSelector(new JavaScriptFunctionDotCallTargetSelector(targetSelector)); targetSelector = new JavaScriptFunctionApplyTargetSelector(new JavaScriptFunctionDotCallTargetSelector(targetSelector, cache));
} }
if (options.useLoadFileTargetSelector()) { if (options.useLoadFileTargetSelector()) {
targetSelector = new LoadFileTargetSelector(targetSelector, this); targetSelector = new LoadFileTargetSelector(targetSelector, this);
@ -83,7 +83,7 @@ public class JSZeroOrOneXCFABuilder extends JSCFABuilder {
options.setSelector(targetSelector); options.setSelector(targetSelector);
} }
private SSAContextInterpreter setupSSAContextInterpreter(IClassHierarchy cha, JSAnalysisOptions options, AnalysisCache cache, private SSAContextInterpreter setupSSAContextInterpreter(IClassHierarchy cha, JSAnalysisOptions options, IAnalysisCacheView cache,
SSAContextInterpreter appContextInterpreter) { SSAContextInterpreter appContextInterpreter) {
SSAContextInterpreter contextInterpreter = makeDefaultContextInterpreters(appContextInterpreter, options, cha); SSAContextInterpreter contextInterpreter = makeDefaultContextInterpreters(appContextInterpreter, options, cha);
if (options.handleCallApply()) { if (options.handleCallApply()) {

View File

@ -21,6 +21,7 @@ import com.ibm.wala.ipa.callgraph.AnalysisCache;
import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.CGNode; import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.ContextItem; import com.ibm.wala.ipa.callgraph.ContextItem;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ssa.ConstantValue; import com.ibm.wala.ssa.ConstantValue;
import com.ibm.wala.ssa.DefUse; import com.ibm.wala.ssa.DefUse;
import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.IR;
@ -38,7 +39,7 @@ public class JavaScriptFunctionApplyContextInterpreter extends AstContextInsensi
private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/Function_prototype_apply"); private static final TypeName APPLY_TYPE_NAME = TypeName.findOrCreate("Lprologue.js/Function_prototype_apply");
public JavaScriptFunctionApplyContextInterpreter(AnalysisOptions options, AnalysisCache cache) { public JavaScriptFunctionApplyContextInterpreter(AnalysisOptions options, IAnalysisCacheView cache) {
super(options, cache); super(options, cache);
} }

Some files were not shown because too many files have changed in this diff Show More