blob: 8a7d1aac091c6c9f7d047124c8a4a8df96e3f084 [file] [log] [blame]
// Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.optimize;
import com.android.tools.r8.graph.AppInfo;
import com.android.tools.r8.graph.AppView;
import com.android.tools.r8.graph.DexField;
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.graph.GraphLense;
import com.android.tools.r8.graph.GraphLense.NestedGraphLense;
import com.android.tools.r8.ir.code.Invoke.Type;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
public class MemberRebindingLense extends NestedGraphLense {
public static class Builder extends NestedGraphLense.Builder {
private final AppView<? extends AppInfo> appView;
protected Builder(AppView<? extends AppInfo> appView) {
this.appView = appView;
}
public GraphLense build(GraphLense previousLense) {
assert typeMap.isEmpty();
if (methodMap.isEmpty() && fieldMap.isEmpty()) {
return previousLense;
}
return new MemberRebindingLense(appView, methodMap, fieldMap, previousLense);
}
}
private final AppView<? extends AppInfo> appView;
public MemberRebindingLense(
AppView<? extends AppInfo> appView,
Map<DexMethod, DexMethod> methodMap,
Map<DexField, DexField> fieldMap,
GraphLense previousLense) {
super(
ImmutableMap.of(),
methodMap,
fieldMap,
null,
null,
previousLense,
appView.dexItemFactory());
this.appView = appView;
}
public static Builder builder(AppView<? extends AppInfo> appView) {
return new Builder(appView);
}
@Override
protected Type mapInvocationType(DexMethod newMethod, DexMethod originalMethod, Type type) {
return super.mapVirtualInterfaceInvocationTypes(appView, newMethod, originalMethod, type);
}
}