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.classLoader.SourceDirectoryTreeModule;
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.AnalysisScope;
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.Entrypoint;
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.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.properties.WalaProperties;
import com.ibm.wala.types.ClassLoaderReference;
@ -58,7 +59,7 @@ public class SourceDirCallGraph {
scope.addToScope(JavaSourceAnalysisScope.SOURCE, new SourceDirectoryTreeModule(new File(sourceDir)));
// 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(Warnings.asString());
Warnings.clear();
@ -67,7 +68,7 @@ public class SourceDirCallGraph {
options.setEntrypoints(entrypoints);
// you can dial down reflection handling if you like
// 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 ZeroOneContainerCFABuilderFactory().make(options, cache, cha, scope, false);
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)
*/
@Override
public List getArgumentTypes() {
public List<CAstType> getArgumentTypes() {
return fParameterTypes;
}
@ -1085,13 +1085,13 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
}
@Override
public Collection getSupertypes() {
public Collection<CAstType> getSupertypes() {
Assertions.UNREACHABLE("CAstType.FunctionImpl#getSupertypes() called???");
return null;
}
@Override
public Collection/* <CAstType> */getExceptionTypes() {
public Collection<CAstType>/* <CAstType> */getExceptionTypes() {
if (fExceptionTypes == null) {
fExceptionTypes = new LinkedHashSet<CAstType>();
if (fDecl != null)

View File

@ -122,7 +122,7 @@ public class JDTTypeDictionary extends CAstTypeDictionaryImpl {
@Override
@SuppressWarnings("unchecked")
public Collection getSupertypes() {
public Collection<CAstType> getSupertypes() {
if (fEltJdtType.isPrimitive())
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

View File

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

View File

@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<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"/>
</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.codegen.inlineJsrBytecode=enabled
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.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.localVariable=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.unusedWarningToken=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.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -26,4 +26,4 @@ public class Array1 {
sum += ary[j];
}
}
}
}

View File

@ -14,4 +14,4 @@ public class ArrayLiteral1 {
int[] a= new int[] { 0, 1, 2, 3, 5 };
Object[] b= new Object[] { null, "hi", new Integer(55), new int[] { 3, 1, 4 } };
}
}
}

View File

@ -42,4 +42,4 @@ public class Breaks {
(new Breaks()).testBreakFromIf("whatever", new Ref(args));
}
}
}

View File

@ -34,4 +34,4 @@ public class Casts {
int i2 = i1 + s1;
}
}
}

View File

@ -35,4 +35,4 @@ class SubFunkySupers extends FunkySupers {
//class EE { class X {} }
//class Y extends EE.X { Y(EE e) { e.super(); } }
// DOESNT WORK IN POLYGLOT!!!
// DOESNT WORK IN POLYGLOT!!!

View File

@ -37,4 +37,4 @@ class Derived extends Base {
public String bar(int x) {
return Integer.toHexString(x);
}
}
}

View File

@ -26,4 +26,4 @@ class Sub extends InnerClassSuper {
so.test();
}
}
}
}

View File

@ -84,4 +84,4 @@ public class MiniaturSliceBug {
(new MiniaturSliceBug()).validNonDispatchedCall(new IntWrapper(-1));
}
}
}

View File

@ -20,4 +20,4 @@ public class Scoping1 {
System.out.println(x);
}
}
}
}

View File

@ -25,4 +25,4 @@ public class Scoping2 {
System.out.println(x);
}
}
}
}

View File

@ -19,4 +19,4 @@ public class StaticNesting {
value= 0;
}
}
}
}

View File

@ -167,4 +167,4 @@ public class InnerClassAA {
}
}
}
}
}

View File

@ -55,4 +55,4 @@ class Sub extends InnerClassSuperA {
so.test();
}
}
}
}

View File

@ -72,4 +72,4 @@ public class GenericMemberClasses<T>
System.out.println(x);
}
}
}
}

View File

@ -69,4 +69,4 @@ public class NotSoSimpleEnums {
(new NotSoSimpleEnums()).doit(d);
}
}
}
}

View File

@ -19,4 +19,4 @@ public class NonPrimaryTopLevel {
class Foo {
}
}

View File

@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<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"/>
</classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
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.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.localVariable=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.unusedPrivateMember=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.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<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"/>
</classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
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.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.localVariable=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.unusedPrivateMember=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.alignment_for_arguments_in_allocation_expression=16
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.client.AbstractAnalysisEngine;
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.AnalysisScope;
import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
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.propagation.InstanceKey;
import com.ibm.wala.ipa.cha.ClassHierarchy;
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.ssa.SSAOptions;
import com.ibm.wala.ssa.SymbolTable;
@ -133,7 +135,7 @@ public abstract class JavaSourceAnalysisEngine<I extends InstanceKey> extends Ab
ClassLoaderFactory factory = getClassLoaderFactory(scope.getExclusions());
try {
cha = ClassHierarchy.make(getScope(), factory);
cha = ClassHierarchyFactory.make(getScope(), factory);
} catch (ClassHierarchyException e) {
System.err.println("Class Hierarchy construction failed");
System.err.println(e.toString());
@ -148,8 +150,8 @@ public abstract class JavaSourceAnalysisEngine<I extends InstanceKey> extends Ab
}
@Override
public AnalysisCache makeDefaultCache() {
return new AnalysisCache(AstIRFactory.makeDefaultFactory());
public IAnalysisCacheView makeDefaultCache() {
return new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
}
@Override
@ -170,7 +172,7 @@ public abstract class JavaSourceAnalysisEngine<I extends InstanceKey> extends Ab
}
@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);
}
}

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.AnalysisScope;
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.propagation.cfa.ZeroXInstanceKeys;
import com.ibm.wala.ipa.cha.IClassHierarchy;
@ -26,7 +27,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
*/
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.addDefaultBypassLogic(options, scope, Util.class.getClassLoader(), cha);
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.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
import com.ibm.wala.ipa.callgraph.propagation.cfa.DefaultPointerKeyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy;
@ -20,7 +21,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
*/
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());
}

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.AnalysisOptions;
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.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
@ -42,7 +43,7 @@ import com.ibm.wala.util.strings.Atom;
public class AstJavaSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraphBuilder {
protected AstJavaSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache,
protected AstJavaSSAPropagationCallGraphBuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache,
PointerKeyFactory 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.AnalysisScope;
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.DelegatingContextSelector;
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 AstJavaZeroXCFABuilder(IClassHierarchy cha, AnalysisOptions options, AnalysisCache cache,
public AstJavaZeroXCFABuilder(IClassHierarchy cha, AnalysisOptions options, IAnalysisCacheView cache,
ContextSelector appContextSelector, SSAContextInterpreter appContextInterpreter, int instancePolicy) {
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.ElementValue;
import com.ibm.wala.shrikeCT.ClassConstants;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SSAThrowInstruction;
import com.ibm.wala.ssa.SymbolTable;
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,
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,
hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo));
}
@ -251,7 +252,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
private final TypeReference[] exceptionTypes;
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
.methodEntityToSelector(methodEntity)), hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo, JavaSourceLoaderImpl.this.getAnnotations(methodEntity));
this.parameterTypes = computeParameterTypes(methodEntity);
@ -369,7 +370,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
*/
public class ConcreteJavaMethod extends JavaEntityMethod {
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);
}
@ -522,7 +523,7 @@ public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
}
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);
}

View File

@ -37,6 +37,7 @@ import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.FieldReference;
import com.ibm.wala.types.TypeName;
@ -244,8 +245,8 @@ public class JavaCAst2IRTranslator extends AstTranslator {
}
@Override
protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG cfg, SymbolTable symtab,
boolean hasCatchBlock, Map<IBasicBlock,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo,
protected void defineFunction(CAstEntity N, WalkContext definingContext, AbstractCFG<SSAInstruction, ? extends IBasicBlock<SSAInstruction>> cfg, SymbolTable symtab,
boolean hasCatchBlock, Map<IBasicBlock<SSAInstruction>,TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo,
DebuggingInformation debugInfo) {
// 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.
@ -415,7 +416,7 @@ public class JavaCAst2IRTranslator extends AstTranslator {
return new CAstType.Class() {
@Override
public Collection getSupertypes() {
public Collection<CAstType> getSupertypes() {
return Collections.emptySet();
}

View File

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

View File

@ -4,6 +4,6 @@
<classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<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"/>
</classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
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.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.localVariable=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.unusedPrivateMember=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.alignment_for_arguments_in_allocation_expression=16
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.Stack;
import nu.validator.htmlparser.common.XmlViolationPolicy;
import nu.validator.htmlparser.sax.HtmlParser;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
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.util.collections.Pair;
import nu.validator.htmlparser.common.XmlViolationPolicy;
import nu.validator.htmlparser.sax.HtmlParser;
public class NuValidatorHtmlParser implements IHtmlParser {
@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.SourceURLModule;
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.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoint;
@ -34,7 +35,7 @@ import com.ibm.wala.util.strings.Atom;
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);
Map<Atom,MethodTargetSelector> methodTargetSelectors = HashMapFactory.make();
@ -77,11 +78,11 @@ public class Driver {
AnalysisOptions options = new AnalysisOptions(scope, roots);
addDefaultDispatchLogic(options, scope, cha);
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);

View File

@ -5,16 +5,14 @@ import java.net.URL;
import java.util.Map;
import java.util.Set;
import junit.framework.AssertionFailedError;
import org.junit.Before;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.DefaultSourceExtractor;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraph;
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.TestJSCallGraphShape;
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
import com.ibm.wala.cast.js.util.CallGraph2JSON;
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.WalaException;
import junit.framework.AssertionFailedError;
public abstract class AbstractFieldBasedTest extends TestJSCallGraphShape {
protected FieldBasedCGUtil util;
@ -66,8 +66,7 @@ public abstract class AbstractFieldBasedTest extends TestJSCallGraphShape {
}
}
@SuppressWarnings("unused")
private void dumpCG(JSCallGraph cg) {
protected void dumpCG(JSCallGraph cg) {
CallGraph2JSON.IGNORE_HARNESS = false;
Map<String, Set<String>> edges = CallGraph2JSON.extractEdges(cg);
for(String callsite : edges.keySet())
@ -75,4 +74,4 @@ public abstract class AbstractFieldBasedTest extends TestJSCallGraphShape {
System.out.println(callsite + " -> " + callee);
}
}
}

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);
}
/*
@Test
public void testBomberman() throws IOException, WalaException, Error, CancelException {
runTestExceptOnTravis(new URL("http://www.e-forum.ro/bomberman/dynagame.html"), new Object[][]{}, BuilderType.OPTIMISTIC_WORKLIST);
}
*/
@Test
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);
}
@Ignore
@Test
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);
}
@Ignore
@Test
public void testSolitaire() throws IOException, WalaException, Error, CancelException {
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
public void testMinesweeper() throws IOException, WalaException, Error, CancelException {
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 junit.framework.AssertionFailedError;
import org.junit.Test;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
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.TestSimplePageCallGraphShape;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
import junit.framework.AssertionFailedError;
public class FieldBasedComparisonTest extends AbstractFieldBasedTest {
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.util.Properties;
import junit.framework.Assert;
import com.ibm.wala.cast.js.html.DefaultSourceExtractor;
import com.ibm.wala.cast.js.html.JSSourceExtractor;
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.FileUtil;
import junit.framework.Assert;
/**
* 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.SourceModule;
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.ClassHierarchyFactory;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.IRFactory;
@ -100,7 +100,7 @@ public class PrintIRs {
SourceModule[] scripts = p.fst.toArray(new SourceModule[] {});
JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(JSCallGraphUtil.getTranslatorFactory());
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);
printIRsForCHA(cha, new Predicate<String>() {

View File

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

View File

@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="source"/>
<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="output" path="bin"/>
</classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
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.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.localVariable=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.unusedPrivateMember=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.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0

View File

@ -11,7 +11,6 @@
package com.ibm.wala.cast.js.translator;
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.classLoader.SourceModule;

View File

@ -10,51 +10,13 @@
*****************************************************************************/
package com.ibm.wala.cast.js.translator;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import com.ibm.wala.cast.ir.translator.RewritingTranslatorToCAst;
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.rewrite.CAstRewriterFactory;
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;
import com.ibm.wala.classLoader.ModuleEntry;
public class CAstRhinoTranslator implements TranslatorToCAst {
private final List<CAstRewriterFactory> rewriters = new LinkedList<CAstRewriterFactory>();
private final SourceModule M;
private final boolean replicateForDoLoops;
public CAstRhinoTranslator(SourceModule M, boolean replicateForDoLoops) {
this.M = M;
this.replicateForDoLoops = replicateForDoLoops;
public class CAstRhinoTranslator extends RewritingTranslatorToCAst implements TranslatorToCAst {
public CAstRhinoTranslator(ModuleEntry m, boolean replicateForDoLoops) {
super(m, new RhinoToAstTranslator(new CAstImpl(), m, m.getName(), 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.tree.CAst;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.ModuleEntry;
public class CAstRhinoTranslatorFactory implements JavaScriptTranslatorFactory {
@Override
public TranslatorToCAst make(CAst ast, SourceModule M) {
public TranslatorToCAst make(CAst ast, ModuleEntry M) {
return new CAstRhinoTranslator(M, false);
}
}

View File

@ -11,6 +11,7 @@
package com.ibm.wala.cast.js.translator;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
@ -90,7 +91,6 @@ import org.mozilla.javascript.ast.XmlString;
import org.mozilla.javascript.ast.Yield;
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.ipa.callgraph.JSSSAPropagationCallGraphBuilder;
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.CAstSymbolImpl;
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.util.CAstPattern;
import com.ibm.wala.classLoader.ModuleEntry;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.util.collections.EmptyIterator;
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.warnings.Warning;
public class RhinoToAstTranslator {
public class RhinoToAstTranslator implements TranslatorToCAst {
/**
* 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) {
URL url = sourceModule.getURL();
URL url = ((SourceModule)sourceModule).getURL();
int line = n.getLineno();
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 SourceModule sourceModule;
private final ModuleEntry sourceModule;
final private Reader sourceReader;
@ -2431,12 +2435,17 @@ private CAstNode[] walkChildren(final Node n, WalkContext context) {
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.scriptName = scriptName;
this.sourceModule = M;
this.sourceReader = sourceModule.getInputReader();
this.sourceModule = m;
this.sourceReader = new InputStreamReader(sourceModule.getInputStream());
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>
<classpathentry kind="src" path="harness-src"/>
<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"/>
</classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
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.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.localVariable=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.unusedPrivateMember=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.alignment_for_arguments_in_allocation_expression=16
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.translator.JavaScriptTranslatorFactory;
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.SourceURLModule;
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.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.util.CancelException;
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 {
JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory);
SourceModule[] scripts = new SourceModule[]{
Module[] scripts = new Module[]{
new SourceURLModule(url),
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 {
JavaScriptLoaderFactory loaders = new JavaScriptLoaderFactory(translatorFactory);
SourceModule[] scripts = JSCallGraphBuilderUtil.makeSourceModules(dir, name);
Module[] scripts = JSCallGraphBuilderUtil.makeSourceModules(dir, name);
return buildCG(loaders, scripts, builderType, monitor, supportFullPointerAnalysis);
}
@ -93,14 +95,14 @@ public class FieldBasedCGUtil {
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));
IClassHierarchy cha = ClassHierarchy.make(scope, loaders, JavaScriptLoader.JS);
IClassHierarchy cha = ClassHierarchyFactory.make(scope, loaders, JavaScriptLoader.JS);
Util.checkForFrontEndErrors(cha);
Iterable<Entrypoint> roots = JSCallGraphUtil.makeScriptRoots(cha);
FieldBasedCallGraphBuilder builder = null;
AnalysisCache cache = new AnalysisCache(AstIRFactory.makeDefaultFactory());
AnalysisCache cache = new AnalysisCacheImpl(AstIRFactory.makeDefaultFactory());
switch(builderType) {
case PESSIMISTIC:
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.loader.JavaScriptLoader;
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.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule;
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.Entrypoint;
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.cha.ClassHierarchyException;
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);
}
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());
}
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);
SourceModule[] modules = new SourceModule[] {
Module[] modules = new Module[] {
(script.openConnection() instanceof JarURLConnection)? new SourceURLModule(script): makeSourceModule(script, dir, name),
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) {
Set<SourceModule> scripts = HashSetFactory.make();
Set<Module> scripts = HashSetFactory.make();
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
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 {
PropagationCallGraphBuilder b = makeHTMLCGBuilder(url, fExtractor);
SSAPropagationCallGraphBuilder b = makeHTMLCGBuilder(url, fExtractor);
CallGraph CG = b.makeCallGraph(b.getOptions());
dumpCG(b.getPointerAnalysis(), CG);
dumpCG(b.getCFAContextInterpreter(), b.getPointerAnalysis(), CG);
return CG;
}

View File

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

View File

@ -38,7 +38,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
URL url = getClass().getClassLoader().getResource("pages/page3.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
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 {
@ -46,7 +46,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder);
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.")
@ -55,7 +55,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder);
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[][] {
new Object[] { ROOT,
new String[] { "tests/badforin.js" } },
new Object[] { "tests/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 Object[] { "tests/badforin.js/testForIn",
new String[] { "tests/badforin.js/testForIn1", "tests/badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_obj_foo",
new String[] { "tests/badforin.js/testForIn1" } },
new Object[] { "tests/badforin.js/_check_copy_foo",
new String[] { "tests/badforin.js/testForIn1" } },
new Object[] { "tests/badforin.js/_check_obj_bar",
new String[] { "tests/badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_copy_bar",
new String[] { "tests/badforin.js/testForIn2" } }
new String[] { "badforin.js" } },
new Object[] { "badforin.js",
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[] { "badforin.js/testForIn",
new String[] { "badforin.js/testForIn1", "badforin.js/testForIn2" } },
new Object[] { "badforin.js/_check_obj_foo",
new String[] { "badforin.js/testForIn1" } },
new Object[] { "badforin.js/_check_copy_foo",
new String[] { "badforin.js/testForIn1" } },
new Object[] { "badforin.js/_check_obj_bar",
new String[] { "badforin.js/testForIn2" } },
new Object[] { "badforin.js/_check_copy_bar",
new String[] { "badforin.js/testForIn2" } }
};
@Test public void testBadForInWithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForBadForin);
}
private static final Object[][] assertionsForBadForinHackPrecision = new Object[][] {
new Object[] { "tests/badforin.js/_check_obj_foo",
new String[] { "!tests/badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_copy_foo",
new String[] { "!tests/badforin.js/testForIn2" } },
new Object[] { "tests/badforin.js/_check_obj_bar",
new String[] { "!tests/badforin.js/testForIn1" } },
new Object[] { "tests/badforin.js/_check_copy_bar",
new String[] { "!tests/badforin.js/testForIn1" } }
new Object[] { "badforin.js/_check_obj_foo",
new String[] { "!badforin.js/testForIn2" } },
new Object[] { "badforin.js/_check_copy_foo",
new String[] { "!badforin.js/testForIn2" } },
new Object[] { "badforin.js/_check_obj_bar",
new String[] { "!badforin.js/testForIn1" } },
new Object[] { "badforin.js/_check_copy_bar",
new String[] { "!badforin.js/testForIn1" } }
};
@Test public void testBadForInWithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForBadForin);
verifyGraphAssertions(CG, assertionsForBadForinHackPrecision);
}
private static final Object[][] assertionsForbadforin2 = new Object[][] {
new Object[] { ROOT,
new String[] { "tests/badforin2.js" } },
new Object[] { "tests/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 Object[] { "tests/badforin2.js/testForIn",
new String[] { "tests/badforin2.js/testForIn1", "tests/badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_obj_foo",
new String[] { "tests/badforin2.js/testForIn1" } },
new Object[] { "tests/badforin2.js/_check_copy_foo",
new String[] { "tests/badforin2.js/testForIn1" } },
new Object[] { "tests/badforin2.js/_check_obj_bar",
new String[] { "tests/badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_copy_bar",
new String[] { "tests/badforin2.js/testForIn2" } }
new String[] { "badforin2.js" } },
new Object[] { "badforin2.js",
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[] { "badforin2.js/testForIn",
new String[] { "badforin2.js/testForIn1", "badforin2.js/testForIn2" } },
new Object[] { "badforin2.js/_check_obj_foo",
new String[] { "badforin2.js/testForIn1" } },
new Object[] { "badforin2.js/_check_copy_foo",
new String[] { "badforin2.js/testForIn1" } },
new Object[] { "badforin2.js/_check_obj_bar",
new String[] { "badforin2.js/testForIn2" } },
new Object[] { "badforin2.js/_check_copy_bar",
new String[] { "badforin2.js/testForIn2" } }
};
@Test public void testbadforin2WithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForbadforin2);
}
private static final Object[][] assertionsForbadforin2HackPrecision = new Object[][] {
new Object[] { "tests/badforin2.js/_check_obj_foo",
new String[] { "!tests/badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_copy_foo",
new String[] { "!tests/badforin2.js/testForIn2" } },
new Object[] { "tests/badforin2.js/_check_obj_bar",
new String[] { "!tests/badforin2.js/testForIn1" } },
new Object[] { "tests/badforin2.js/_check_copy_bar",
new String[] { "!tests/badforin2.js/testForIn1" } }
new Object[] { "badforin2.js/_check_obj_foo",
new String[] { "!badforin2.js/testForIn2" } },
new Object[] { "badforin2.js/_check_copy_foo",
new String[] { "!badforin2.js/testForIn2" } },
new Object[] { "badforin2.js/_check_obj_bar",
new String[] { "!badforin2.js/testForIn1" } },
new Object[] { "badforin2.js/_check_copy_bar",
new String[] { "!badforin2.js/testForIn1" } }
};
@Test public void testbadforin2WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForbadforin2);
verifyGraphAssertions(CG, assertionsForbadforin2HackPrecision);
}
@ -160,7 +160,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin3.js");
addHackedForInLoopSensitivity(B);
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");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
}
}

View File

@ -396,4 +396,4 @@ public abstract class TestPointerAnalyses {
public void testInherit() throws IOException, WalaException, CancelException {
testTestScript("tests", "inherit.js", nameFilter("tests/inherit.js"), new CheckPointers());
}
}
}

View File

@ -19,7 +19,6 @@ import org.junit.Test;
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.JSCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
@ -39,11 +38,11 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
protected static final Object[][] assertionsForArgs = new Object[][] {
new Object[] { ROOT, new String[] { "tests/args.js" } },
new Object[] { ROOT, new String[] { "args.js" } },
new Object[] {
"tests/args.js",
new String[] { "tests/args.js/a" } },
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/x", "tests/args.js/y" } } };
"args.js",
new String[] { "args.js/a" } },
new Object[] { "args.js/a", new String[] { "args.js/x", "args.js/y" } } };
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, WalaException {
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "args.js");
@ -51,16 +50,16 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
protected static final Object[][] assertionsForSimple = new Object[][] {
new Object[] { ROOT, new String[] { "tests/simple.js" } },
new Object[] { ROOT, new String[] { "simple.js" } },
new Object[] {
"tests/simple.js",
new String[] { "tests/simple.js/bad", "tests/simple.js/silly", "tests/simple.js/fib", "tests/simple.js/stranger",
"tests/simple.js/trivial", "tests/simple.js/rubbish", "tests/simple.js/weirder" } },
new Object[] { "tests/simple.js/trivial", new String[] { "tests/simple.js/trivial/inc" } },
new Object[] { "tests/simple.js/rubbish",
new String[] { "tests/simple.js/weirder", "tests/simple.js/stranger", "tests/simple.js/rubbish" } },
new Object[] { "tests/simple.js/fib", new String[] { "tests/simple.js/fib" } },
new Object[] { "tests/simple.js/weirder", new String[] { "prologue.js/Math_abs" } } };
"simple.js",
new String[] { "simple.js/bad", "simple.js/silly", "simple.js/fib", "simple.js/stranger",
"simple.js/trivial", "simple.js/rubbish", "simple.js/weirder" } },
new Object[] { "simple.js/trivial", new String[] { "simple.js/trivial/inc" } },
new Object[] { "simple.js/rubbish",
new String[] { "simple.js/weirder", "simple.js/stranger", "simple.js/rubbish" } },
new Object[] { "simple.js/fib", new String[] { "simple.js/fib" } },
new Object[] { "simple.js/weirder", new String[] { "prologue.js/Math_abs" } } };
@Test
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[][] {
new Object[] { ROOT, new String[] { "tests/objects.js" } },
new Object[] { "tests/objects.js",
new String[] { "tests/objects.js/objects_are_fun", "tests/objects.js/other", "tests/objects.js/something" } },
new Object[] { "tests/objects.js/other",
new String[] { "tests/objects.js/something", "tests/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[] { ROOT, new String[] { "objects.js" } },
new Object[] { "objects.js",
new String[] { "objects.js/objects_are_fun", "objects.js/other", "objects.js/something" } },
new Object[] { "objects.js/other",
new String[] { "objects.js/something", "objects.js/objects_are_fun/nothing" } },
new Object[] { "objects.js/objects_are_fun", new String[] { "objects.js/other", "objects.js/whatever" } } };
@Test
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[][] {
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 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}}
}
};
private static final Object[][] assertionsForInherit = new Object[][] {
new Object[] { ROOT, new String[] { "tests/inherit.js" } },
new Object[] { ROOT, new String[] { "inherit.js" } },
new Object[] {
"tests/inherit.js",
new String[] { "tests/inherit.js/objectMasquerading", "tests/inherit.js/objectMasquerading/Rectangle/area",
"tests/inherit.js/Polygon/shape", "tests/inherit.js/sharedClassObject",
"tests/inherit.js/sharedClassObject/Rectangle/area" } },
"inherit.js",
new String[] { "inherit.js/objectMasquerading", "inherit.js/objectMasquerading/Rectangle/area",
"inherit.js/Polygon/shape", "inherit.js/sharedClassObject",
"inherit.js/sharedClassObject/Rectangle/area" } },
new Object[]{
"tests/inherit.js/objectMasquerading",
new String[]{"ctor:tests/inherit.js/objectMasquerading/Rectangle"}},
"inherit.js/objectMasquerading",
new String[]{"ctor:inherit.js/objectMasquerading/Rectangle"}},
new Object[]{
"ctor:tests/inherit.js/objectMasquerading/Rectangle" ,
new String[]{"tests/inherit.js/objectMasquerading/Rectangle"}},
new Object[]{"tests/inherit.js/objectMasquerading/Rectangle",
new String[]{"tests/inherit.js/Polygon"}},
"ctor:inherit.js/objectMasquerading/Rectangle" ,
new String[]{"inherit.js/objectMasquerading/Rectangle"}},
new Object[]{"inherit.js/objectMasquerading/Rectangle",
new String[]{"inherit.js/Polygon"}},
new Object[]{
"tests/inherit.js/sharedClassObject",
new String[]{"ctor:tests/inherit.js/sharedClassObject/Rectangle"}},
new Object[]{"ctor:tests/inherit.js/sharedClassObject/Rectangle",
new String[]{"tests/inherit.js/sharedClassObject/Rectangle"}}
"inherit.js/sharedClassObject",
new String[]{"ctor:inherit.js/sharedClassObject/Rectangle"}},
new Object[]{"ctor:inherit.js/sharedClassObject/Rectangle",
new String[]{"inherit.js/sharedClassObject/Rectangle"}}
};
@Test
@ -121,8 +120,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForNewfn = new Object[][] {
new Object[] { ROOT, new String[] { "tests/newfn.js" } },
new Object[] { "tests/newfn.js",
new Object[] { ROOT, new String[] { "newfn.js" } },
new Object[] { "newfn.js",
new String[] { "suffix:ctor$1/_fromctor", "suffix:ctor$2/_fromctor", "suffix:ctor$3/_fromctor" } } };
@Test
@ -132,11 +131,11 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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[] {
"tests/control-flow.js",
new String[] { "tests/control-flow.js/testSwitch", "tests/control-flow.js/testDoWhile",
"tests/control-flow.js/testWhile", "tests/control-flow.js/testFor", "tests/control-flow.js/testReturn" } } };
"control-flow.js",
new String[] { "control-flow.js/testSwitch", "control-flow.js/testDoWhile",
"control-flow.js/testWhile", "control-flow.js/testFor", "control-flow.js/testReturn" } } };
@Test
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[][] {
new Object[] { ROOT, new String[] { "tests/more-control-flow.js" } },
new Object[] { ROOT, new String[] { "more-control-flow.js" } },
new Object[] {
"tests/more-control-flow.js",
new String[] { "tests/more-control-flow.js/testSwitch", "tests/more-control-flow.js/testIfConvertedSwitch",
"tests/more-control-flow.js/testDoWhile", "tests/more-control-flow.js/testWhile",
"tests/more-control-flow.js/testFor", "tests/more-control-flow.js/testReturn" } } };
"more-control-flow.js",
new String[] { "more-control-flow.js/testSwitch", "more-control-flow.js/testIfConvertedSwitch",
"more-control-flow.js/testDoWhile", "more-control-flow.js/testWhile",
"more-control-flow.js/testFor", "more-control-flow.js/testReturn" } } };
@Test
public void testMoreControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -158,30 +157,30 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
verifyGraphAssertions(CG, assertionsForMoreControlflow);
}
private static final Object[][] assertionsForForin = new Object[][] { new Object[] { ROOT, new String[] { "tests/forin.js" } },
new Object[] { "tests/forin.js", new String[] { "tests/forin.js/testForIn" } },
new Object[] { "tests/forin.js/testForIn", new String[] { "tests/forin.js/testForIn1", "tests/forin.js/testForIn2" } } };
private static final Object[][] assertionsForForin = new Object[][] { new Object[] { ROOT, new String[] { "forin.js" } },
new Object[] { "forin.js", new String[] { "forin.js/testForIn" } },
new Object[] { "forin.js/testForIn", new String[] { "forin.js/testForIn1", "forin.js/testForIn2" } } };
@Test
public void testForin() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "forin.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForForin);
}
private static final Object[][] assertionsForSimpleLexical = new Object[][] {
new Object[] { ROOT, new String[] { "tests/simple-lexical.js" } },
new Object[] { "tests/simple-lexical.js", new String[] { "tests/simple-lexical.js/outer" } },
new Object[] { ROOT, new String[] { "simple-lexical.js" } },
new Object[] { "simple-lexical.js", new String[] { "simple-lexical.js/outer" } },
new Object[] {
"tests/simple-lexical.js/outer",
new String[] { "tests/simple-lexical.js/outer/indirect", "tests/simple-lexical.js/outer/inner",
"tests/simple-lexical.js/outer/inner2", "tests/simple-lexical.js/outer/inner3" } },
new Object[] { "tests/simple-lexical.js/outer/inner2",
new String[] { "tests/simple-lexical.js/outer/inner", "tests/simple-lexical.js/outer/inner3" } },
new Object[] { "tests/simple-lexical.js/outer/indirect",
new String[] { "tests/simple-lexical.js/outer/inner", "tests/simple-lexical.js/outer/inner3" } } };
"simple-lexical.js/outer",
new String[] { "simple-lexical.js/outer/indirect", "simple-lexical.js/outer/inner",
"simple-lexical.js/outer/inner2", "simple-lexical.js/outer/inner3" } },
new Object[] { "simple-lexical.js/outer/inner2",
new String[] { "simple-lexical.js/outer/inner", "simple-lexical.js/outer/inner3" } },
new Object[] { "simple-lexical.js/outer/indirect",
new String[] { "simple-lexical.js/outer/inner", "simple-lexical.js/outer/inner3" } } };
@Test
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[][] {
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:reachable2" } }};
@ -208,19 +207,19 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
private static final Object[][] assertionsForTry = new Object[][] {
new Object[] { ROOT, new String[] { "tests/try.js" } },
new Object[] { "tests/try.js",
new String[] { "tests/try.js/tryCatch", "tests/try.js/tryFinally", "tests/try.js/tryCatchFinally" } },
new Object[] { "tests/try.js/tryCatch",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/two" } },
new Object[] { "tests/try.js/tryFinally",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/two" } },
new Object[] { "tests/try.js/tryCatchFinally",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/three", "tests/try.js/two" } },
new Object[] { "tests/try.js/tryCatchTwice",
new String[] { "tests/try.js/targetOne", "tests/try.js/targetTwo", "tests/try.js/three", "tests/try.js/two" } },
new Object[] { "tests/try.js/testRet",
new String[] { "tests/try.js/three", "tests/try.js/two" } }
new Object[] { ROOT, new String[] { "try.js" } },
new Object[] { "try.js",
new String[] { "try.js/tryCatch", "try.js/tryFinally", "try.js/tryCatchFinally" } },
new Object[] { "try.js/tryCatch",
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/two" } },
new Object[] { "try.js/tryFinally",
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/two" } },
new Object[] { "try.js/tryCatchFinally",
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/three", "try.js/two" } },
new Object[] { "try.js/tryCatchTwice",
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/three", "try.js/two" } },
new Object[] { "try.js/testRet",
new String[] { "try.js/three", "try.js/two" } }
};
@Test
@ -237,8 +236,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForStringOp = new Object[][] {
new Object[] { ROOT, new String[] { "tests/string-op.js" } },
new Object[] { "tests/string-op.js", new String[] { "tests/string-op.js/getOp", "tests/string-op.js/plusNum" } } };
new Object[] { ROOT, new String[] { "string-op.js" } },
new Object[] { "string-op.js", new String[] { "string-op.js/getOp", "string-op.js/plusNum" } } };
@Test
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[][] {
new Object[] { ROOT, new String[] { "tests/upward.js" } },
new Object[] { ROOT, new String[] { "upward.js" } },
new Object[] {
"tests/upward.js",
new String[] { "tests/upward.js/Obj/setit", "tests/upward.js/Obj/getit", "tests/upward.js/tester1",
"tests/upward.js/tester2" } } };
"upward.js",
new String[] { "upward.js/Obj/setit", "upward.js/Obj/getit", "upward.js/tester1",
"upward.js/tester2" } } };
@Test
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[][] {
new Object[] { ROOT, new String[] { "tests/string-prims.js" } },
new Object[] { "tests/string-prims.js", new String[] { "prologue.js/String_prototype_split", "prologue.js/String_prototype_toUpperCase" } } };
new Object[] { ROOT, new String[] { "string-prims.js" } },
new Object[] { "string-prims.js", new String[] { "prologue.js/String_prototype_split", "prologue.js/String_prototype_toUpperCase" } } };
@Test
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);
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForStringPrims);
}
private static final Object[][] assertionsForNested = new Object[][] { new Object[] { ROOT, new String[] { "tests/nested.js" } },
new Object[] { "tests/nested.js", new String[] { "tests/nested.js/f", "tests/nested.js/f/ff", "tests/nested.js/f/ff/fff" } } };
private static final Object[][] assertionsForNested = new Object[][] { new Object[] { ROOT, new String[] { "nested.js" } },
new Object[] { "nested.js", new String[] { "nested.js/f", "nested.js/f/ff", "nested.js/f/ff/fff" } } };
@Test
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,
new String[] { "tests/instanceof.js" } } };
new String[] { "instanceof.js" } } };
@Test
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
* Object[] { ROOT, new String[] { "tests/with.js" } } };
* Object[] { ROOT, new String[] { "with.js" } } };
*
* @Test public void testWith() throws IOException, IllegalArgumentException,
* CancelException { PropagationCallGraphBuilder B =
@ -325,8 +324,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForMultivar = new Object[][] {
new Object[] { ROOT, new String[] { "tests/multivar.js" } },
new Object[] { "tests/multivar.js", new String[] { "tests/multivar.js/a", "tests/multivar.js/bf", "tests/multivar.js/c" } } };
new Object[] { ROOT, new String[] { "multivar.js" } },
new Object[] { "multivar.js", new String[] { "multivar.js/a", "multivar.js/bf", "multivar.js/c" } } };
@Test
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[][] {
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: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));
Assert
.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());
}
}
}
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:theTwo" } } };
@ -389,7 +388,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } } };
@Test
@ -399,7 +398,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } } };
@Test
@ -409,7 +408,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } } };
@Test
@ -419,7 +418,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } } };
@Test
@ -429,7 +428,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } } };
@Test
@ -439,7 +438,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } } };
@Test
@ -452,7 +451,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
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" } } };
@Test
@ -462,7 +461,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } } };
@Test
@ -473,21 +472,21 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
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:bar" } } };
@Test
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());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForReturnThis);
}
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:foo" } },
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[][] {
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: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[][] {
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" } } };
@Test
@ -527,7 +526,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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:f", new String[] { "suffix:g" } }
};
@ -544,7 +543,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } }
};
@ -555,7 +554,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
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" } }
};
@ -566,24 +565,24 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForDispatch = new Object[][] {
new Object[] { ROOT, new String[] { "tests/dispatch.js" } },
new Object[] { "tests/dispatch.js", new String[] { "tests/dispatch.js/left_outer", "tests/dispatch.js/right_outer" } },
new Object[] { "tests/dispatch.js/left_outer", new String[]{ "tests/dispatch.js/left_inner" } },
new Object[] { "tests/dispatch.js/right_outer", new String[]{ "tests/dispatch.js/right_inner" } }
new Object[] { ROOT, new String[] { "dispatch.js" } },
new Object[] { "dispatch.js", new String[] { "dispatch.js/left_outer", "dispatch.js/right_outer" } },
new Object[] { "dispatch.js/left_outer", new String[]{ "dispatch.js/left_inner" } },
new Object[] { "dispatch.js/right_outer", new String[]{ "dispatch.js/right_inner" } }
};
@Test
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());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDispatch);
}
private static final Object[][] assertionsForDispatchSameTarget = new Object[][] {
new Object[] { ROOT, new String[] { "tests/dispatch_same_target.js" } },
new Object[] { "tests/dispatch_same_target.js/f3", new String[] { "tests/dispatch_same_target.js/f4" } }
new Object[] { ROOT, new String[] { "dispatch_same_target.js" } },
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[][] {
new Object[] { ROOT, new String[] { "tests/for_in_prototype.js" } },
new Object[] { "tests/for_in_prototype.js", new String[] { "suffix:A",
new Object[] { ROOT, new String[] { "for_in_prototype.js" } },
new Object[] { "for_in_prototype.js", new String[] { "suffix:A",
"suffix:reachable",
"suffix:also_reachable" } }
};
@ -611,8 +610,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForArrayIndexConv = new Object[][] {
new Object[] { ROOT, new String[] { "tests/array_index_conv.js" } },
new Object[] { "tests/array_index_conv.js", new String[] { "suffix:reachable1",
new Object[] { ROOT, new String[] { "array_index_conv.js" } },
new Object[] { "array_index_conv.js", new String[] { "suffix:reachable1",
"suffix:reachable2",
"suffix:reachable3",
"suffix:reachable4" } }
@ -626,8 +625,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForArrayIndexConv2 = new Object[][] {
new Object[] { ROOT, new String[] { "tests/array_index_conv2.js" } },
new Object[] { "tests/array_index_conv2.js", new String[] { "suffix:invokeOnA" } },
new Object[] { ROOT, new String[] { "array_index_conv2.js" } },
new Object[] { "array_index_conv2.js", new String[] { "suffix:invokeOnA" } },
new Object[] { "suffix:invokeOnA", new String[] { "suffix:reachable",
"suffix:also_reachable",
"suffix:reachable_too" } }
@ -644,8 +643,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForDateProperty = new Object[][] {
new Object[] { ROOT, new String[] { "tests/date-property.js" } },
new Object[] { "tests/date-property.js", new String[] { "suffix:_fun" } }
new Object[] { ROOT, new String[] { "date-property.js" } },
new Object[] { "date-property.js", new String[] { "suffix:_fun" } }
};
@Test
@ -657,8 +656,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
verifyGraphAssertions(CG, assertionsForDateProperty);
}
private static final Object[][] assertionsForDeadCode = new Object[][] {
new Object[] { ROOT, new String[] { "tests/dead.js" } },
new Object[] { "tests/dead.js", new String[] { "suffix:twoReturns" } }
new Object[] { ROOT, new String[] { "dead.js" } },
new Object[] { "dead.js", new String[] { "suffix:twoReturns" } }
};
@Test
@ -671,10 +670,10 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForShadow = new Object[][] {
new Object[] { ROOT, new String[] { "tests/shadow_test.js" } },
new Object[] { "tests/shadow_test.js", new String[] { "tests/shadow_test.js/test" } },
new Object[] { "tests/shadow_test.js/test", new String[] { "tests/shadow_test.js/bad" } },
new Object[] { "tests/shadow_test.js/test", new String[] { "tests/shadow_test.js/global_bad" } }
new Object[] { ROOT, new String[] { "shadow_test.js" } },
new Object[] { "shadow_test.js", new String[] { "shadow_test.js/test" } },
new Object[] { "shadow_test.js/test", new String[] { "shadow_test.js/bad" } },
new Object[] { "shadow_test.js/test", new String[] { "shadow_test.js/global_bad" } }
};
@Test
@ -685,8 +684,8 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
}
private static final Object[][] assertionsForExtend = new Object[][] {
new Object[] { ROOT, new String[] { "tests/extend.js" } },
new Object[] { "tests/extend.js", new String[] { "suffix:bar", "!suffix:foo" } }
new Object[] { ROOT, new String[] { "extend.js" } },
new Object[] { "extend.js", new String[] { "suffix:bar", "!suffix:foo" } }
};
@Test
@ -712,7 +711,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean save = CAstCallGraphUtil.AVOID_DUMP;
//CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save;
}
@ -725,56 +724,56 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
monitor.beginTask("build CG", 1);
CallGraph CG = B.makeCallGraph(B.getOptions(), monitor);
monitor.done();
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
}
@Test
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());
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
// verifyGraphAssertions(CG, assertionsForDateProperty);
}
private static final Object[][] assertionsForLoops = new Object[][] {
new Object[] { ROOT, new String[] { "tests/loops.js" } },
new Object[] { "tests/loops.js", new String[] { "tests/loops.js/three", "tests/loops.js/four"} }
new Object[] { ROOT, new String[] { "loops.js" } },
new Object[] { "loops.js", new String[] { "loops.js/three", "loops.js/four"} }
};
@Ignore("need to fix this. bug from Sukyoung's group")
@Test
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());
boolean x = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = x;
verifyGraphAssertions(CG, assertionsForLoops);
}
private static final Object[][] assertionsForPrimitiveStrings = new Object[][] {
new Object[] { ROOT, new String[] { "tests/primitive_strings.js" } },
new Object[] { "tests/primitive_strings.js", new String[] { "tests/primitive_strings.js/f1", "tests/primitive_strings.js/f1"} },
new Object[] { "tests/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[] { ROOT, new String[] { "primitive_strings.js" } },
new Object[] { "primitive_strings.js", new String[] { "primitive_strings.js/f1", "primitive_strings.js/f1"} },
new Object[] { "primitive_strings.js/f2", 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")
@Test
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());
boolean x = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = x;
verifyGraphAssertions(CG, assertionsForPrimitiveStrings);
}
Object[][] renamingAssertions = {
{ "tests/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/f", new Name[]{ new Name(9, 7, "x"), new Name(9, 7, "y") } },
{ "rename-example.js/ff", new Name[]{ new Name(11, 10, "x"), new Name(11, 10, "y"), new Name(11, 10, "z") } }
};
@Test

View File

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

View File

@ -4,6 +4,6 @@
<classpathentry kind="src" path="dat"/>
<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.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"/>
</classpath>

View File

@ -2,9 +2,9 @@ eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
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.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.localVariable=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.unusedPrivateMember=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.alignment_for_arguments_in_allocation_expression=16
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.Context;
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.impl.AbstractRootMethod;
import com.ibm.wala.ipa.callgraph.impl.ContextInsensitiveSelector;
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
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.DelegatingSSAContextInterpreter;
import com.ibm.wala.ipa.callgraph.propagation.cfa.nCFAContextSelector;
@ -70,17 +72,17 @@ public abstract class FieldBasedCallGraphBuilder {
// standard call graph machinery
protected final AnalysisOptions options;
protected final AnalysisCache cache;
protected final IAnalysisCacheView cache;
protected final JavaScriptConstructorFunctions constructors;
protected final MethodTargetSelector targetSelector;
public final MethodTargetSelector targetSelector;
protected final boolean supportFullPointerAnalysis;
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.options = options;
this.cache = cache;
this.cache = iAnalysisCacheView;
this.constructors = new JavaScriptConstructorFunctions(cha);
this.targetSelector = setupMethodTargetSelector(cha, constructors, options);
this.supportFullPointerAnalysis = supportFullPointerAnalysis;
@ -89,7 +91,7 @@ public abstract class FieldBasedCallGraphBuilder {
private MethodTargetSelector setupMethodTargetSelector(IClassHierarchy cha, JavaScriptConstructorFunctions constructors2, AnalysisOptions options) {
MethodTargetSelector result = new JavaScriptConstructTargetSelector(constructors2, options.getMethodTargetSelector());
if (options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply()) {
result = new JavaScriptFunctionApplyTargetSelector(new JavaScriptFunctionDotCallTargetSelector(result));
result = new JavaScriptFunctionApplyTargetSelector(new JavaScriptFunctionDotCallTargetSelector(result, cache));
}
return result;
}
@ -137,14 +139,19 @@ public abstract class FieldBasedCallGraphBuilder {
/**
* Extract a call graph from a given flow graph.
*/
@SuppressWarnings("deprecation")
protected JSCallGraph extract(FlowGraph flowgraph, Iterable<? extends Entrypoint> eps, IProgressMonitor monitor) throws CancelException {
@SuppressWarnings("deprecation")
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
final JSCallGraph cg = new JSCallGraph(cha, options, cache);
cg.init();
// setup context interpreters
DelegatingSSAContextInterpreter interpreter = new DelegatingSSAContextInterpreter(new AstContextInsensitiveSSAContextInterpreter(options, cache), new DefaultSSAInterpreter(options, cache));
if (options instanceof JSAnalysisOptions && ((JSAnalysisOptions)options).handleCallApply()) {
interpreter = new DelegatingSSAContextInterpreter(new JavaScriptFunctionApplyContextInterpreter(options, cache), interpreter);
}
@ -206,7 +213,7 @@ public abstract class FieldBasedCallGraphBuilder {
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,
IMethod target) throws CancelException {
// 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);
System.err.println("adding callees " + reflectiveTargets + " for " + caller);
// 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();
for (FuncVertex f : reflectiveTargets) {
IMethod reflectiveTgtMethod = targetSelector.getCalleeTarget(functionPrototypeCallNode, reflectiveCallSite, f.getConcreteType());
@ -228,7 +236,7 @@ public abstract class FieldBasedCallGraphBuilder {
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 {
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.
*/
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();
final Set<Pair<CallVertex, FuncVertex>> result = HashSetFactory.make();

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