fix for missing Java 8 feature
This commit is contained in:
parent
583cf37e59
commit
7b393a7da2
|
@ -0,0 +1,30 @@
|
||||||
|
package special;
|
||||||
|
|
||||||
|
class A {
|
||||||
|
String name;
|
||||||
|
|
||||||
|
A() {
|
||||||
|
setX("silly");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Ctor<T> {
|
||||||
|
T make();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Ctor<A> o = A::new;
|
||||||
|
Object a = o.make();
|
||||||
|
a.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -41,6 +41,26 @@ import com.ibm.wala.util.strings.Atom;
|
||||||
*/
|
*/
|
||||||
public class LambdaTest extends WalaTestCase {
|
public class LambdaTest extends WalaTestCase {
|
||||||
|
|
||||||
|
@Test public void testStreamExample_137() throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException {
|
||||||
|
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
|
||||||
|
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
|
||||||
|
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
|
||||||
|
"Lspecial/A");
|
||||||
|
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
|
||||||
|
|
||||||
|
CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(), cha, scope, false);
|
||||||
|
|
||||||
|
TypeReference A = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lspecial/A");
|
||||||
|
|
||||||
|
MethodReference ct = MethodReference.findOrCreate(A, Atom.findOrCreateUnicodeAtom("<init>"), Descriptor.findOrCreateUTF8("()V"));
|
||||||
|
Set<CGNode> ctnodes = cg.getNodes(ct);
|
||||||
|
Assert.assertEquals(1, ctnodes.size());
|
||||||
|
|
||||||
|
MethodReference ts = MethodReference.findOrCreate(A, Atom.findOrCreateUnicodeAtom("toString"), Descriptor.findOrCreateUTF8("()Ljava/lang/String;"));
|
||||||
|
Set<CGNode> tsnodes = cg.getNodes(ts);
|
||||||
|
Assert.assertEquals(1, tsnodes.size());
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void testSortingExample() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
|
@Test public void testSortingExample() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
|
||||||
|
|
||||||
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
|
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.ibm.wala.classLoader.CallSiteReference;
|
||||||
import com.ibm.wala.classLoader.IClass;
|
import com.ibm.wala.classLoader.IClass;
|
||||||
import com.ibm.wala.classLoader.IField;
|
import com.ibm.wala.classLoader.IField;
|
||||||
import com.ibm.wala.classLoader.IMethod;
|
import com.ibm.wala.classLoader.IMethod;
|
||||||
|
import com.ibm.wala.classLoader.NewSiteReference;
|
||||||
import com.ibm.wala.classLoader.SyntheticClass;
|
import com.ibm.wala.classLoader.SyntheticClass;
|
||||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||||
|
@ -257,11 +258,14 @@ public class LambdaSummaryClass extends SyntheticClass {
|
||||||
MethodReference callee = MethodReference.findOrCreate(ClassLoaderReference.Application, getLambdaCalleeClass(), getLambdaCalleeName(), getLambdaCalleeSignature());
|
MethodReference callee = MethodReference.findOrCreate(ClassLoaderReference.Application, getLambdaCalleeClass(), getLambdaCalleeName(), getLambdaCalleeSignature());
|
||||||
|
|
||||||
Dispatch code;
|
Dispatch code;
|
||||||
|
boolean isNew = false;
|
||||||
|
int new_v = -1;
|
||||||
int kind = getLambdaCalleeKind();
|
int kind = getLambdaCalleeKind();
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case 5: code = Dispatch.VIRTUAL; break;
|
case 5: code = Dispatch.VIRTUAL; break;
|
||||||
case 6: code = Dispatch.STATIC; break;
|
case 6: code = Dispatch.STATIC; break;
|
||||||
case 7: code = Dispatch.SPECIAL; break;
|
case 7: code = Dispatch.SPECIAL; break;
|
||||||
|
case 8: code = Dispatch.SPECIAL; isNew = true; break;
|
||||||
case 9: code = Dispatch.INTERFACE; break;
|
case 9: code = Dispatch.INTERFACE; break;
|
||||||
default:
|
default:
|
||||||
throw new Error("unexpected dynamic invoke type " + kind);
|
throw new Error("unexpected dynamic invoke type " + kind);
|
||||||
|
@ -269,15 +273,24 @@ public class LambdaSummaryClass extends SyntheticClass {
|
||||||
|
|
||||||
int numParams = getClassHierarchy().resolveMethod(callee).getNumberOfParameters();
|
int numParams = getClassHierarchy().resolveMethod(callee).getNumberOfParameters();
|
||||||
int params[] = new int[ numParams ];
|
int params[] = new int[ numParams ];
|
||||||
for(int i = 0; i < invoke.getNumberOfParameters(); i++) {
|
for(int i = isNew? 1: 0; i < invoke.getNumberOfParameters(); i++) {
|
||||||
params[i] = args + i + 1;
|
params[i] = args + i + 1;
|
||||||
}
|
}
|
||||||
for(int n = 2, i = invoke.getNumberOfParameters(); i < numParams; i++) {
|
for(int n = 2, i = invoke.getNumberOfParameters(); i < numParams; i++) {
|
||||||
params[i] = n++;
|
params[i] = n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNew) {
|
||||||
|
v++;
|
||||||
|
summary.addStatement(insts.NewInstruction(inst++, new_v=v++, NewSiteReference.make(inst, callee.getDeclaringClass())));
|
||||||
|
params[0] = new_v;
|
||||||
|
}
|
||||||
|
|
||||||
if (callee.getReturnType().equals(TypeReference.Void)) {
|
if (callee.getReturnType().equals(TypeReference.Void)) {
|
||||||
summary.addStatement(insts.InvokeInstruction(inst++, params, v++, CallSiteReference.make(inst, callee, code), null));
|
summary.addStatement(insts.InvokeInstruction(inst++, params, v++, CallSiteReference.make(inst, callee, code), null));
|
||||||
|
if (isNew) {
|
||||||
|
summary.addStatement(insts.ReturnInstruction(inst++, new_v, false));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int ret = v++;
|
int ret = v++;
|
||||||
summary.addStatement(insts.InvokeInstruction(inst++, ret, params, v++, CallSiteReference.make(inst, callee, code), null));
|
summary.addStatement(insts.InvokeInstruction(inst++, ret, params, v++, CallSiteReference.make(inst, callee, code), null));
|
||||||
|
|
Loading…
Reference in New Issue