blob: 4f381133f838361edded6aa3e7d43d5cce5bac3a [file] [log] [blame]
// Copyright (c) 2020, 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.kotlin;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteList;
import static com.android.tools.r8.utils.FunctionUtils.forEachApply;
import com.android.tools.r8.graph.AppView;
import com.android.tools.r8.graph.DexDefinitionSupplier;
import com.android.tools.r8.graph.DexItemFactory;
import com.android.tools.r8.shaking.EnqueuerMetadataTraceable;
import com.android.tools.r8.utils.Reporter;
import java.util.List;
import java.util.function.Consumer;
import kotlinx.metadata.KmEffect;
import kotlinx.metadata.KmEffectInvocationKind;
import kotlinx.metadata.KmEffectType;
public class KotlinEffectInfo implements EnqueuerMetadataTraceable {
private final KmEffectType type;
private final KmEffectInvocationKind invocationKind;
private final List<KotlinEffectExpressionInfo> constructorArguments;
private final KotlinEffectExpressionInfo conclusion;
public KotlinEffectInfo(
KmEffectType type,
KmEffectInvocationKind invocationKind,
List<KotlinEffectExpressionInfo> constructorArguments,
KotlinEffectExpressionInfo conclusion) {
this.type = type;
this.invocationKind = invocationKind;
this.constructorArguments = constructorArguments;
this.conclusion = conclusion;
}
static KotlinEffectInfo create(KmEffect effect, DexItemFactory factory, Reporter reporter) {
return new KotlinEffectInfo(
effect.getType(),
effect.getInvocationKind(),
KotlinEffectExpressionInfo.create(effect.getConstructorArguments(), factory, reporter),
KotlinEffectExpressionInfo.create(effect.getConclusion(), factory, reporter));
}
@Override
public void trace(DexDefinitionSupplier definitionSupplier) {
forEachApply(constructorArguments, arg -> arg::trace, definitionSupplier);
conclusion.trace(definitionSupplier);
}
boolean rewrite(Consumer<KmEffect> consumer, AppView<?> appView) {
KmEffect kmEffect = consume(new KmEffect(type, invocationKind), consumer);
boolean rewritten = conclusion.rewrite(kmEffect::setConclusion, appView);
rewritten |=
rewriteList(
appView,
constructorArguments,
kmEffect.getConstructorArguments(),
KotlinEffectExpressionInfo::rewrite);
return rewritten;
}
}