All Downloads are FREE. Search and download functionalities are using the official Maven repository.

proguard.evaluation.util.jsonprinter.InstructionRecord Maven / Gradle / Ivy

Go to download

ProGuardCORE is a free library to read, analyze, modify, and write Java class files.

There is a newer version: 9.1.6
Show newest version
/*
 * ProGuardCORE -- library to process Java bytecode.
 *
 * Copyright (c) 2002-2023 Guardsquare NV
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package proguard.evaluation.util.jsonprinter;

import java.util.List;
import org.jetbrains.annotations.NotNull;

/** DTO to track a single instruction. */
class InstructionRecord implements JsonSerializable {
  /** The offset of the instruction. */
  private final int offset;

  /** String representation of the instruction. */
  @NotNull private final String instruction;

  /**
   * Contains the final result computations from the partial evaluator regarding the variables of
   * this instruction.
   */
  private List finalVariablesBefore;

  /**
   * Contains the final result computations from the partial evaluator regarding the stack of this
   * instruction.
   */
  private List finalStackBefore;

  /**
   * Contains the final result computations from the partial evaluator regarding the target
   * instructions of this instruction.
   */
  private List finalTargetInstructions;

  /**
   * Contains the final result computations from the partial evaluator regarding the source
   * instructions of this instruction.
   */
  private List finalOriginInstructions;

  public InstructionRecord(int offset, @NotNull String instruction) {
    this.offset = offset;
    this.instruction = instruction;
  }

  @Override
  public StringBuilder toJson(StringBuilder builder) {
    builder.append("{");
    JsonPrinter.toJson("offset", offset, builder).append(",");
    JsonPrinter.toJson("instruction", instruction, builder);
    if (finalVariablesBefore != null) {
      builder.append(",");
      JsonPrinter.stringListToJson("finalVariablesBefore", finalVariablesBefore, builder);
    }
    if (finalStackBefore != null) {
      builder.append(",");
      JsonPrinter.stringListToJson("finalStackBefore", finalStackBefore, builder);
    }
    if (finalTargetInstructions != null) {
      builder.append(",");
      JsonPrinter.intListToJson("finalTargetInstructions", finalTargetInstructions, builder);
    }
    if (finalOriginInstructions != null) {
      builder.append(",");
      JsonPrinter.intListToJson("finalOriginInstructions", finalOriginInstructions, builder);
    }
    return builder.append("}");
  }

  public List getFinalStackBefore() {
    return finalStackBefore;
  }

  public void setFinalStackBefore(List finalStackBefore) {
    this.finalStackBefore = finalStackBefore;
  }

  public List getFinalVariablesBefore() {
    return finalVariablesBefore;
  }

  public void setFinalVariablesBefore(List finalVariablesBefore) {
    this.finalVariablesBefore = finalVariablesBefore;
  }

  public List getFinalTargetInstructions() {
    return finalTargetInstructions;
  }

  public void setFinalTargetInstructions(List finalTargetInstructions) {
    this.finalTargetInstructions = finalTargetInstructions;
  }

  public List getFinalOriginInstructions() {
    return finalOriginInstructions;
  }

  public void setFinalOriginInstructions(List finalOriginInstructions) {
    this.finalOriginInstructions = finalOriginInstructions;
  }

  public int getOffset() {
    return offset;
  }

  @NotNull
  public String getInstruction() {
    return instruction;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy