Merge branch 'master' into maven

This commit is contained in:
Manu Sridharan 2013-05-02 10:58:55 -07:00
commit e6bef253ff
14 changed files with 74 additions and 88 deletions

View File

@ -7,6 +7,7 @@
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.debug.ui.ATTR_CAPTURE_IN_FILE" value="/tmp/console.txt"/>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="com.ibm.wala.cast.java.test.data" default="getSources" basedir=".">
<project name="com.ibm.wala.cast.java.test.data" default="jar" basedir=".">
<property name="basews" value="${ws}"/>
<property name="baseos" value="${os}"/>

View File

@ -9,20 +9,20 @@
* IBM Corporation - initial API and implementation
*****************************************************************************/
public class Scoping2 {
public static void main(String[] args) {
Scoping2 s2= new Scoping2();
{
final int x= 5;
System.out.println(x);
(new Object() {
public void foo() {
System.out.println("x = " + x);
}
}).foo();
}
{
double x= 3.14;
System.out.println(x);
}
public static void main(String[] args) {
Scoping2 s2 = new Scoping2();
{
final int x = 5;
System.out.println(x);
(new Object() {
public void foo() {
System.out.println("x = " + x);
}
}).foo();
}
{
double x = 3.14;
System.out.println(x);
}
}
}

View File

@ -220,7 +220,7 @@ public abstract class JavaIRTests extends IRTests {
MethodReference mref = descriptorToMethodRef("Source#ArrayLiteral1#main#([Ljava/lang/String;)V", cg.getClassHierarchy());
CGNode node = cg.getNodes(mref).iterator().next();
SSAInstruction s = node.getIR().getInstructions()[3];
SSAInstruction s = node.getIR().getInstructions()[2];
Assert.assertTrue("Did not find new array instruction.", s instanceof SSANewInstruction);
Assert.assertTrue("", ((SSANewInstruction) s).getNewSite().getDeclaredType().isArrayType());
}
@ -245,7 +245,7 @@ public abstract class JavaIRTests extends IRTests {
final SSAInstruction[] instructions = node.getIR().getInstructions();
// test 1
{
SSAInstruction s1 = instructions[3];
SSAInstruction s1 = instructions[2];
if (s1 instanceof SSANewInstruction) {
Assert.assertTrue("", ((SSANewInstruction) s1).getNewSite().getDeclaredType().isArrayType());
} else {
@ -254,7 +254,7 @@ public abstract class JavaIRTests extends IRTests {
}
// test 2
{
SSAInstruction s2 = instructions[4];
SSAInstruction s2 = instructions[3];
if (s2 instanceof SSANewInstruction) {
Assert.assertTrue("", ((SSANewInstruction) s2).getNewSite().getDeclaredType().isArrayType());
} else {
@ -264,7 +264,7 @@ public abstract class JavaIRTests extends IRTests {
// test 3: the last 4 instructions are of the form y[i] = i+1;
{
final SymbolTable symbolTable = node.getIR().getSymbolTable();
for (int i = 5; i <= 8; i++) {
for (int i = 4; i <= 7; i++) {
Assert.assertTrue("Expected only array stores.", instructions[i] instanceof SSAArrayStoreInstruction);
SSAArrayStoreInstruction as = (SSAArrayStoreInstruction) instructions[i];
@ -302,7 +302,7 @@ public abstract class JavaIRTests extends IRTests {
MethodReference mref = descriptorToMethodRef("Source#QualifiedStatic#main#([Ljava/lang/String;)V", cg.getClassHierarchy());
CGNode node = cg.getNodes(mref).iterator().next();
SSAInstruction s = node.getIR().getInstructions()[5];
SSAInstruction s = node.getIR().getInstructions()[4];
Assert.assertTrue("Did not find a getstatic instruction.", s instanceof SSAGetInstruction
&& ((SSAGetInstruction) s).isStatic());

View File

@ -34,6 +34,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSANewInstruction;
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.intset.IntSetAction;
@ -279,4 +280,12 @@ public class AstJavaSSAPropagationCallGraphBuilder extends AstSSAPropagationCall
protected ConstraintVisitor makeVisitor(CGNode node) {
return new AstJavaConstraintVisitor(this, node);
}
@Override
protected boolean sameMethod(CGNode opNode, String definingMethod) {
MethodReference reference = opNode.getMethod().getReference();
String selector = reference.getSelector().toString();
String containingClass = reference.getDeclaringClass().getName().toString();
return definingMethod.equals(containingClass + "/" + selector);
}
}

View File

@ -91,7 +91,7 @@ public class JavaCAst2IRTranslator extends AstTranslator {
}
protected boolean useLocalValuesForLexicalVars() {
return true;
return false;
}
protected void doThrow(WalkContext context, int exception) {

View File

@ -25,10 +25,12 @@ import com.ibm.wala.cast.js.html.WebPageLoaderFactory;
import com.ibm.wala.cast.js.html.WebUtil;
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.loader.JavaScriptLoader;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.loader.CAstAbstractLoader;
import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule;
@ -79,7 +81,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
}
public static JSCFABuilder makeScriptCGBuilder(String dir, String name, CGBuilderType builderType) throws IOException, WalaException {
JavaScriptLoaderFactory loaders = JSCallGraphBuilderUtil.makeLoaders();
JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders();
AnalysisScope scope = makeScriptScope(dir, name, loaders);
@ -92,7 +94,6 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + "/" + name);
}
assert script != null : "cannot find " + dir + " and " + name;
AnalysisScope scope;
if (script.openConnection() instanceof JarURLConnection) {
scope = makeScope(new URL[] { script }, loaders, JavaScriptLoader.JS);
@ -119,7 +120,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
return CG;
}
public static CallGraph makeScriptCG(SourceModule[] scripts, CGBuilderType builderType, IRFactory irFactory) throws IOException, IllegalArgumentException,
public static CallGraph makeScriptCG(SourceModule[] scripts, CGBuilderType builderType, IRFactory<IMethod> irFactory) throws IOException, IllegalArgumentException,
CancelException, WalaException {
PropagationCallGraphBuilder b = makeCGBuilder(makeLoaders(), scripts, builderType, irFactory);
CallGraph CG = b.makeCallGraph(b.getOptions());
@ -134,7 +135,7 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
public static JSCFABuilder makeHTMLCGBuilder(URL url, CGBuilderType builderType) throws IOException, WalaException {
JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
SourceModule[] scripts;
IRFactory irFactory = AstIRFactory.makeDefaultFactory();
IRFactory<IMethod> irFactory = AstIRFactory.makeDefaultFactory();
JavaScriptLoaderFactory loaders = new WebPageLoaderFactory(translatorFactory, preprocessor);
try {
Set<MappedSourceModule> script = WebUtil.extractScriptFromHTML(url).fst;
@ -163,12 +164,12 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
return CG;
}
public static JSCFABuilder makeCGBuilder(JavaScriptLoaderFactory loaders, SourceModule[] scripts, CGBuilderType builderType, IRFactory irFactory) throws IOException, WalaException {
public static JSCFABuilder makeCGBuilder(JavaScriptLoaderFactory loaders, SourceModule[] scripts, CGBuilderType builderType, IRFactory<IMethod> irFactory) throws IOException, WalaException {
AnalysisScope scope = makeScope(scripts, loaders, JavaScriptLoader.JS);
return makeCG(loaders, scope, builderType, irFactory);
}
protected static JSCFABuilder makeCG(JavaScriptLoaderFactory loaders, AnalysisScope scope, CGBuilderType builderType, IRFactory irFactory) throws IOException, WalaException {
protected static JSCFABuilder makeCG(JavaScriptLoaderFactory loaders, AnalysisScope scope, CGBuilderType builderType, IRFactory<IMethod> irFactory) throws IOException, WalaException {
try {
IClassHierarchy cha = makeHierarchy(scope, loaders);
com.ibm.wala.cast.js.util.Util.checkForFrontEndErrors(cha);

View File

@ -1036,6 +1036,11 @@ public class JSSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraph
} else {
PointerKey EA = getPointerKeyForLocal(caller, instruction.getDef(1));
system.newConstraint(EA, assignOperator, EF);
}
}
}
@Override
protected boolean sameMethod(CGNode opNode, String definingMethod) {
return definingMethod.equals(opNode.getMethod().getReference().getDeclaringClass().getName().toString());
}
}

View File

@ -693,7 +693,7 @@ public abstract class AstSSAPropagationCallGraphBuilder extends SSAPropagationCa
private Set<CGNode> getLexicalDefiners(final CGNode opNode, final Pair<String, String> definer) {
if (definer == null) {
return Collections.singleton(getBuilder().getCallGraph().getFakeRootNode());
} else if (definer.snd.equals(opNode.getMethod().getReference().getDeclaringClass().getName().toString())) {
} else if (getBuilder().sameMethod(opNode, definer.snd)) {
// lexical access to a variable declared in opNode itself
assert AstTranslator.NEW_LEXICAL;
return Collections.singleton(opNode);
@ -1361,4 +1361,13 @@ public abstract class AstSSAPropagationCallGraphBuilder extends SSAPropagationCa
});
}
}
/**
*
* Is definingMethod the same as the method represented by opNode? We need this since the names for
* methods in some languages don't map in the straightforward way to the CGNode
*/
protected abstract boolean sameMethod(final CGNode opNode, final String definingMethod);
}

View File

@ -19,7 +19,7 @@ import java.net.URL;
import com.ibm.wala.util.io.FileSuffixes;
/**
* A {@link Module} which is a wrapper around a .java file
* A {@link Module} which is a wrapper around a source file
*/
public class SourceFileModule extends FileModule implements Module, ModuleEntry, SourceModule {

View File

@ -103,6 +103,7 @@ public class ContainerContextSelector implements ContextSelector {
* com.ibm.wala.classLoader.CallSiteReference, com.ibm.wala.classLoader.IMethod,
* com.ibm.wala.ipa.callgraph.propagation.InstanceKey)
*/
@Override
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] keys) {
if (DEBUG) {
System.err.println("ContainerContextSelector: getCalleeTarget " + callee);
@ -170,7 +171,8 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* return true iff m represents one of the well-known methods in java.lang.reflect.Arrays that do some sort of arraycopy
* return true iff m represents one of the well-known methods in
* java.lang.reflect.Arrays that do some sort of arraycopy
*/
private static boolean isArrayCopyMethod(MethodReference m) {
if (m.getDeclaringClass().equals(Arrays)) {
@ -194,8 +196,9 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C a) includes
* the method M. or b) includes the method in which the receiver was allocated
* This method walks recursively up the definition of a context C, to see if
* the chain of contexts that give rise to C a) includes the method M. or b)
* includes the method in which the receiver was allocated
*
* @return the matching context if found, null otherwise
*/
@ -218,10 +221,11 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C includes
* the method M.
* This method walks recursively up the definition of a context C, to see if
* the chain of contexts that give rise to C includes the method M.
*
* If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N. Else return
* If C is a ReceiverInstanceContext, Let N be the node that allocated
* C.instance. If N.method == M, return N. Else return
* findRecursiveMatchingContext(M, N.context) Else return null
*/
public static CGNode findNodeRecursiveMatchingContext(IMethod m, Context c) {
@ -254,10 +258,11 @@ public class ContainerContextSelector implements ContextSelector {
}
/**
* This method walks recursively up the definition of a context C, to see if the chain of contexts that give rise to C includes
* the method M.
* This method walks recursively up the definition of a context C, to see if
* the chain of contexts that give rise to C includes the method M.
*
* If C is a ReceiverInstanceContext, Let N be the node that allocated C.instance. If N.method == M, return N.context. Else return
* If C is a ReceiverInstanceContext, Let N be the node that allocated
* C.instance. If N.method == M, return N.context. Else return
* findRecursiveMatchingContext(M, N.context) Else return null
*/
public static Context findRecursiveMatchingContext(IMethod M, Context C) {
@ -333,6 +338,7 @@ public class ContainerContextSelector implements ContextSelector {
private static final IntSet thisParameter = IntSetUtil.make(new int[]{0});
@Override
public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) {
if (site.isDispatch() || site.getDeclaredTarget().getNumberOfParameters() > 0) {
return thisParameter;

View File

@ -30,7 +30,7 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.ide.jdt.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcom.ibm.wala.tracefile=/tmp/jdt15tests.txt -Xmx2048M -XX:MaxPermSize=256M -ea"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcom.ibm.wala.tracefile=/tmp/jdt15tests.txt -Xmx1024M -XX:MaxPermSize=256M -ea"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
<booleanAttribute key="run_in_ui_thread" value="true"/>

File diff suppressed because one or more lines are too long

View File

@ -25,12 +25,12 @@
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JDK 1.6"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.cast.java.test.JDTJavaIRTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.ide.jdt.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcom.ibm.wala.tracefile=/tmp/jdttests.txt -Xmx2048M -XX:MaxPermSize=256M -ea"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcom.ibm.wala.tracefile=/tmp/jdttests.txt -Xmx1024M -XX:MaxPermSize=256M -ea"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
<booleanAttribute key="run_in_ui_thread" value="true"/>