Class LocalsArray

java.lang.Object
com.android.dx.util.MutabilityControl
com.android.dx.cf.code.LocalsArray
All Implemented Interfaces:
ToHuman
Direct Known Subclasses:
LocalsArraySet, OneLocalsArray

public abstract class LocalsArray extends MutabilityControl implements ToHuman
Representation of an array of local variables, with Java semantics.

Note: For the most part, the documentation for this class ignores the distinction between Type and TypeBearer.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    LocalsArray(boolean mutable)
    Constructs an instance, explicitly indicating the mutability.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Annotates (adds context to) the given exception with information about this instance.
    abstract LocalsArray
    Makes and returns a mutable copy of this instance.
    abstract TypeBearer
    get(int idx)
    Gets the type stored at the given local index, only succeeding if the given local contains a valid type (though it is allowed to be an uninitialized instance).
    abstract TypeBearer
    getCategory1(int idx)
    Gets the type stored at the given local index, which is expected to be an initialized category-1 value.
    abstract TypeBearer
    getCategory2(int idx)
    Gets the type stored at the given local index, which is expected to be a category-2 value.
    abstract int
    Gets the maximum number of locals this instance can refer to.
    abstract TypeBearer
    getOrNull(int idx)
    Gets the type stored at the given local index, or null if the given local is uninitialized / invalid.
    protected abstract OneLocalsArray
    Gets the locals set appropriate for the current execution context.
    abstract void
    invalidate(int idx)
    Invalidates the local at the given index.
    abstract void
    Replaces all the occurrences of the given uninitialized type in this array with its initialized equivalent.
    abstract LocalsArray
    Merges this instance with other.
    mergeWithSubroutineCaller(LocalsArray other, int predLabel)
    Merges this instance with a LocalsSet from a subroutine caller.
    abstract void
    set(int idx, TypeBearer type)
    Sets the type stored at the given local index.
    abstract void
    Sets the type for the local indicated by the given register spec to that register spec (which includes type and optional name information).

    Methods inherited from class com.android.dx.util.MutabilityControl

    isImmutable, isMutable, setImmutable, throwIfImmutable, throwIfMutable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.android.dx.util.ToHuman

    toHuman
  • Constructor Details

    • LocalsArray

      protected LocalsArray(boolean mutable)
      Constructs an instance, explicitly indicating the mutability.
      Parameters:
      mutable - true if this instance is mutable
  • Method Details

    • copy

      public abstract LocalsArray copy()
      Makes and returns a mutable copy of this instance.
      Returns:
      non-null; the copy
    • annotate

      public abstract void annotate(ExceptionWithContext ex)
      Annotates (adds context to) the given exception with information about this instance.
      Parameters:
      ex - non-null; the exception to annotate
    • makeInitialized

      public abstract void makeInitialized(Type type)
      Replaces all the occurrences of the given uninitialized type in this array with its initialized equivalent.
      Parameters:
      type - non-null; type to replace
    • getMaxLocals

      public abstract int getMaxLocals()
      Gets the maximum number of locals this instance can refer to.
      Returns:
      the max locals
    • set

      public abstract void set(int idx, TypeBearer type)
      Sets the type stored at the given local index. If the given type is category-2, then (a) the index must be at least two less than getMaxLocals() and (b) the next index gets invalidated by the operation. In case of either category, if the previous local contains a category-2 value, then it too is invalidated by this operation.
      Parameters:
      idx - >= 0, < getMaxLocals(); which local
      type - non-null; new type for the local at idx
    • set

      public abstract void set(RegisterSpec spec)
      Sets the type for the local indicated by the given register spec to that register spec (which includes type and optional name information). This is identical to calling set(spec.getReg(), spec).
      Parameters:
      spec - non-null; register spec to use as the basis for the update
    • invalidate

      public abstract void invalidate(int idx)
      Invalidates the local at the given index.
      Parameters:
      idx - >= 0, < getMaxLocals(); which local
    • getOrNull

      public abstract TypeBearer getOrNull(int idx)
      Gets the type stored at the given local index, or null if the given local is uninitialized / invalid.
      Parameters:
      idx - >= 0, < getMaxLocals(); which local
      Returns:
      null-ok; the type of value stored in that local
    • get

      public abstract TypeBearer get(int idx)
      Gets the type stored at the given local index, only succeeding if the given local contains a valid type (though it is allowed to be an uninitialized instance).
      Parameters:
      idx - >= 0, < getMaxLocals(); which local
      Returns:
      non-null; the type of value stored in that local
      Throws:
      SimException - thrown if idx is valid, but the contents are invalid
    • getCategory1

      public abstract TypeBearer getCategory1(int idx)
      Gets the type stored at the given local index, which is expected to be an initialized category-1 value.
      Parameters:
      idx - >= 0, < getMaxLocals(); which local
      Returns:
      non-null; the type of value stored in that local
      Throws:
      SimException - thrown if idx is valid, but one of the following holds: (a) the local is invalid; (b) the local contains an uninitialized instance; (c) the local contains a category-2 value
    • getCategory2

      public abstract TypeBearer getCategory2(int idx)
      Gets the type stored at the given local index, which is expected to be a category-2 value.
      Parameters:
      idx - >= 0, < getMaxLocals(); which local
      Returns:
      non-null; the type of value stored in that local
      Throws:
      SimException - thrown if idx is valid, but one of the following holds: (a) the local is invalid; (b) the local contains a category-1 value
    • merge

      public abstract LocalsArray merge(LocalsArray other)
      Merges this instance with other. If the merged result is the same as this instance, then this is returned (not a copy).
      Parameters:
      other - non-null; another LocalsArray
      Returns:
      non-null; the merge result, a new instance or this
    • mergeWithSubroutineCaller

      public abstract LocalsArraySet mergeWithSubroutineCaller(LocalsArray other, int predLabel)
      Merges this instance with a LocalsSet from a subroutine caller. To be used when merging in the first block of a subroutine.
      Parameters:
      other - other non-null; another LocalsArray. The final locals state of a subroutine caller.
      predLabel - the label of the subroutine caller block.
      Returns:
      non-null; the merge result, a new instance or this
    • getPrimary

      protected abstract OneLocalsArray getPrimary()
      Gets the locals set appropriate for the current execution context. That is, if this is a OneLocalsArray instance, then return this, otherwise return LocalsArraySet's primary.
      Returns:
      locals for this execution context.