blob: 029ccdd3b0d87883b0b76afd68af1af52bb4c6dc [file] [log] [blame]
// Copyright (c) 2023, 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.graph.lens;
import com.android.tools.r8.errors.Unreachable;
import com.android.tools.r8.graph.DexField;
import com.android.tools.r8.graph.DexItemFactory;
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.graph.proto.RewrittenPrototypeDescription;
import com.android.tools.r8.ir.code.InvokeType;
// This lens clears all code rewriting (lookup methods mimics identity lens behavior) but still
// relies on the previous lens for names (getRenamed/Original methods).
public class ClearCodeRewritingGraphLens extends NonIdentityGraphLens {
public ClearCodeRewritingGraphLens(DexItemFactory dexItemFactory, GraphLens previousLens) {
super(dexItemFactory, previousLens);
}
@Override
public DexType getOriginalType(DexType type) {
return getPrevious().getOriginalType(type);
}
@Override
public Iterable<DexType> getOriginalTypes(DexType type) {
return getPrevious().getOriginalTypes(type);
}
@Override
public DexField getOriginalFieldSignature(DexField field) {
return getPrevious().getOriginalFieldSignature(field);
}
@Override
public DexField getRenamedFieldSignature(DexField originalField, GraphLens codeLens) {
return this != codeLens ? getPrevious().getRenamedFieldSignature(originalField) : originalField;
}
@Override
public DexMethod getRenamedMethodSignature(DexMethod originalMethod, GraphLens applied) {
return this != applied
? getPrevious().getRenamedMethodSignature(originalMethod, applied)
: originalMethod;
}
@Override
public boolean isClearCodeRewritingLens() {
return true;
}
@Override
public RewrittenPrototypeDescription lookupPrototypeChangesForMethodDefinition(
DexMethod method, GraphLens codeLens) {
return getIdentityLens().lookupPrototypeChangesForMethodDefinition(method, codeLens);
}
@Override
public final DexType internalDescribeLookupClassType(DexType previous) {
return previous;
}
@Override
protected FieldLookupResult internalLookupField(
DexField reference, GraphLens codeLens, LookupFieldContinuation continuation) {
return getIdentityLens().internalLookupField(reference, codeLens, continuation);
}
@Override
protected FieldLookupResult internalDescribeLookupField(FieldLookupResult previous) {
throw new Unreachable();
}
@Override
protected MethodLookupResult internalLookupMethod(
DexMethod reference,
DexMethod context,
InvokeType type,
GraphLens codeLens,
LookupMethodContinuation continuation) {
assert codeLens == null || codeLens == this;
GraphLens identityLens = getIdentityLens();
return identityLens.internalLookupMethod(reference, context, type, identityLens, continuation);
}
@Override
public MethodLookupResult internalDescribeLookupMethod(
MethodLookupResult previous, DexMethod context) {
throw new Unreachable();
}
@Override
public DexMethod getPreviousMethodSignature(DexMethod method) {
return method;
}
@Override
public DexMethod getNextMethodSignature(DexMethod method) {
return method;
}
@Override
public boolean isContextFreeForMethods() {
return getIdentityLens().isContextFreeForMethods();
}
}