// Copyright (c) 2022, 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.shaking;

import com.android.tools.r8.androidapi.AndroidApiLevelCompute;
import com.android.tools.r8.androidapi.ComputedApiLevel;
import com.android.tools.r8.dex.code.CfOrDexInstruction;
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.DexMethodHandle;
import com.android.tools.r8.graph.DexReference;
import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.graph.ProgramMethod;
import com.android.tools.r8.graph.UseRegistry;
import java.util.ListIterator;

public class ComputeApiLevelUseRegistry extends UseRegistry<ProgramMethod> {

  protected final AppView<?> appView;
  private final AndroidApiLevelCompute apiLevelCompute;
  private final boolean isEnabled;
  private ComputedApiLevel maxApiReferenceLevel;

  public ComputeApiLevelUseRegistry(
      AppView<?> appView, ProgramMethod context, AndroidApiLevelCompute apiLevelCompute) {
    super(appView, context);
    this.appView = appView;
    this.apiLevelCompute = apiLevelCompute;
    isEnabled = apiLevelCompute.isEnabled();
    maxApiReferenceLevel = appView.computedMinApiLevel();
  }

  @Override
  public void registerInitClass(DexType clazz) {
    // Intentionally empty since init class as synthesized.
  }

  @Override
  public void registerInvokeVirtual(DexMethod invokedMethod) {
    setMaxApiReferenceLevel(invokedMethod);
  }

  @Override
  public void registerInvokeDirect(DexMethod invokedMethod) {
    setMaxApiReferenceLevel(invokedMethod);
  }

  @Override
  public void registerInvokeStatic(DexMethod invokedMethod) {
    setMaxApiReferenceLevel(invokedMethod);
  }

  @Override
  public void registerInvokeInterface(DexMethod invokedMethod) {
    setMaxApiReferenceLevel(invokedMethod);
  }

  @Override
  public void registerInvokeSuper(DexMethod invokedMethod) {
    setMaxApiReferenceLevel(invokedMethod);
  }

  @Override
  public void registerInstanceFieldRead(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerInstanceFieldReadFromMethodHandle(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerInstanceFieldWrite(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerInstanceFieldWriteFromMethodHandle(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerNewInstance(DexType type) {
    setMaxApiReferenceLevel(type);
  }

  @Override
  public void registerStaticFieldRead(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerStaticFieldReadFromMethodHandle(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerStaticFieldWrite(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerStaticFieldWriteFromMethodHandle(DexField field) {
    setMaxApiReferenceLevel(field);
  }

  @Override
  public void registerConstClass(
      DexType type,
      ListIterator<? extends CfOrDexInstruction> iterator,
      boolean ignoreCompatRules) {
    setMaxApiReferenceLevel(type);
  }

  @Override
  public void registerCheckCast(DexType type, boolean ignoreCompatRules) {
    // CheckCast are not causing soft verification issues
  }

  @Override
  public void registerSafeCheckCast(DexType type) {
    // CheckCast are not causing soft verification issues
  }

  @Override
  public void registerTypeReference(DexType type) {
    // Type references are OK as long as we do not have a use on them
  }

  @Override
  public void registerInstanceOf(DexType type) {
    // InstanceOf are not causing soft verification issues
  }

  @Override
  public void registerExceptionGuard(DexType guard) {
    setMaxApiReferenceLevel(guard);
  }

  @Override
  public void registerMethodHandle(DexMethodHandle methodHandle, MethodHandleUse use) {
    super.registerMethodHandle(methodHandle, use);
  }

  private void setMaxApiReferenceLevel(DexReference reference) {
    if (isEnabled) {
      maxApiReferenceLevel =
          maxApiReferenceLevel.max(
              apiLevelCompute.computeApiLevelForLibraryReference(
                  reference, apiLevelCompute.getPlatformApiLevelOrUnknown(appView)));
    }
  }

  public ComputedApiLevel getMaxApiReferenceLevel() {
    return maxApiReferenceLevel;
  }
}
