Allow to submit method during dependency check

This commit is contained in:
Alexey Andreev 2015-10-21 21:35:22 +03:00
parent db364f2adc
commit f3a4d3737b

View File

@ -166,34 +166,46 @@ public class DependencyChecker implements DependencyInfo {
public void submitMethod(MethodReference methodRef, Program program) { public void submitMethod(MethodReference methodRef, Program program) {
if (!completing) { if (!completing) {
throw new IllegalStateException("Can't submit class during check phase"); ClassHolder cls = classSource.get(methodRef.getClassName());
}
MethodDependency dep = getMethod(methodRef); if (cls == null) {
if (dep == null) { throw new IllegalArgumentException("Class not found: " + methodRef.getClassName());
throw new IllegalArgumentException("Method was not reached: " + methodRef); }
} if (cls.getMethod(methodRef.getDescriptor()) != null) {
MethodHolder method = dep.method; throw new IllegalArgumentException("Method already exists: " + methodRef.getClassName());
}
MethodHolder method = new MethodHolder(methodRef.getDescriptor());
method.getModifiers().add(ElementModifier.STATIC);
method.setProgram(ProgramUtils.copy(program));
new UnreachableBasicBlockEliminator().optimize(program);
cls.addMethod(method);
} else {
MethodDependency dep = getMethod(methodRef);
if (dep == null) {
throw new IllegalArgumentException("Method was not reached: " + methodRef);
}
MethodHolder method = dep.method;
if (!method.hasModifier(ElementModifier.NATIVE)) { if (!method.hasModifier(ElementModifier.NATIVE)) {
throw new IllegalArgumentException("Method is not native: " + methodRef); throw new IllegalArgumentException("Method is not native: " + methodRef);
} }
if (!dep.used) { if (!dep.used) {
return; return;
} }
method.getModifiers().remove(ElementModifier.NATIVE); method.getModifiers().remove(ElementModifier.NATIVE);
method.setProgram(ProgramUtils.copy(program)); method.setProgram(ProgramUtils.copy(program));
new UnreachableBasicBlockEliminator().optimize(method.getProgram()); new UnreachableBasicBlockEliminator().optimize(method.getProgram());
dep.used = false; dep.used = false;
lock(dep, false); lock(dep, false);
tasks.add(() -> { tasks.add(() -> {
DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyChecker.this); DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyChecker.this);
graphBuilder.buildGraph(dep); graphBuilder.buildGraph(dep);
dep.used = true; dep.used = true;
}); });
processQueue(); processQueue();
}
} }
public void addDependencyListener(DependencyListener listener) { public void addDependencyListener(DependencyListener listener) {