com.android.dx.cf.code
Class OneLocalsArray

java.lang.Object
  extended by com.android.dx.util.MutabilityControl
      extended by com.android.dx.cf.code.LocalsArray
          extended by com.android.dx.cf.code.OneLocalsArray
All Implemented Interfaces:
ToHuman

public class OneLocalsArray
extends LocalsArray

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
OneLocalsArray(int maxLocals)
          Constructs an instance.
 
Method Summary
 void annotate(com.android.dex.util.ExceptionWithContext ex)
          Annotates (adds context to) the given exception with information about this instance.
 OneLocalsArray copy()
          Makes and returns a mutable copy of this instance.
 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).
 TypeBearer getCategory1(int idx)
          Gets the type stored at the given local index, which is expected to be an initialized category-1 value.
 TypeBearer getCategory2(int idx)
          Gets the type stored at the given local index, which is expected to be a category-2 value.
 int getMaxLocals()
          Gets the maximum number of locals this instance can refer to.
 TypeBearer getOrNull(int idx)
          Gets the type stored at the given local index, or null if the given local is uninitialized / invalid.
protected  OneLocalsArray getPrimary()
          Gets the locals set appropriate for the current execution context.
 void invalidate(int idx)
          Invalidates the local at the given index.
 void makeInitialized(Type type)
          Replaces all the occurrences of the given uninitialized type in this array with its initialized equivalent.
 LocalsArray merge(LocalsArray other)
          Merges this instance with other.
 OneLocalsArray merge(OneLocalsArray other)
          Merges this OneLocalsArray instance with another OneLocalsArray instance.
 LocalsArraySet mergeWithSubroutineCaller(LocalsArray other, int predLabel)
          Merges this instance with a LocalsSet from a subroutine caller.
 void set(int idx, TypeBearer type)
          Sets the type stored at the given local index.
 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).
 String toHuman()
          {@inheritDoc
 
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
 

Constructor Detail

OneLocalsArray

public OneLocalsArray(int maxLocals)
Constructs an instance. The locals array initially consists of all-uninitialized values (represented as nulls).

Parameters:
maxLocals - >= 0; the maximum number of locals this instance can refer to
Method Detail

copy

public OneLocalsArray copy()
Description copied from class: LocalsArray
Makes and returns a mutable copy of this instance.

Specified by:
copy in class LocalsArray
Returns:
non-null; the copy

annotate

public void annotate(com.android.dex.util.ExceptionWithContext ex)
Description copied from class: LocalsArray
Annotates (adds context to) the given exception with information about this instance.

Specified by:
annotate in class LocalsArray
Parameters:
ex - non-null; the exception to annotate

toHuman

public String toHuman()
{@inheritDoc

Returns:
non-null; the human string form

makeInitialized

public void makeInitialized(Type type)
Description copied from class: LocalsArray
Replaces all the occurrences of the given uninitialized type in this array with its initialized equivalent.

Specified by:
makeInitialized in class LocalsArray
Parameters:
type - non-null; type to replace

getMaxLocals

public int getMaxLocals()
Description copied from class: LocalsArray
Gets the maximum number of locals this instance can refer to.

Specified by:
getMaxLocals in class LocalsArray
Returns:
the max locals

set

public void set(int idx,
                TypeBearer type)
Description copied from class: LocalsArray
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 LocalsArray.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.

Specified by:
set in class LocalsArray
Parameters:
idx - >= 0, < getMaxLocals(); which local
type - non-null; new type for the local at idx

set

public void set(RegisterSpec spec)
Description copied from class: LocalsArray
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).

Specified by:
set in class LocalsArray
Parameters:
spec - non-null; register spec to use as the basis for the update

invalidate

public void invalidate(int idx)
Description copied from class: LocalsArray
Invalidates the local at the given index.

Specified by:
invalidate in class LocalsArray
Parameters:
idx - >= 0, < getMaxLocals(); which local

getOrNull

public TypeBearer getOrNull(int idx)
Description copied from class: LocalsArray
Gets the type stored at the given local index, or null if the given local is uninitialized / invalid.

Specified by:
getOrNull in class LocalsArray
Parameters:
idx - >= 0, < getMaxLocals(); which local
Returns:
null-ok; the type of value stored in that local

get

public TypeBearer get(int idx)
Description copied from class: LocalsArray
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).

Specified by:
get in class LocalsArray
Parameters:
idx - >= 0, < getMaxLocals(); which local
Returns:
non-null; the type of value stored in that local

getCategory1

public TypeBearer getCategory1(int idx)
Description copied from class: LocalsArray
Gets the type stored at the given local index, which is expected to be an initialized category-1 value.

Specified by:
getCategory1 in class LocalsArray
Parameters:
idx - >= 0, < getMaxLocals(); which local
Returns:
non-null; the type of value stored in that local

getCategory2

public TypeBearer getCategory2(int idx)
Description copied from class: LocalsArray
Gets the type stored at the given local index, which is expected to be a category-2 value.

Specified by:
getCategory2 in class LocalsArray
Parameters:
idx - >= 0, < getMaxLocals(); which local
Returns:
non-null; the type of value stored in that local

merge

public LocalsArray merge(LocalsArray other)
Description copied from class: LocalsArray
Merges this instance with other. If the merged result is the same as this instance, then this is returned (not a copy).

Specified by:
merge in class LocalsArray
Parameters:
other - non-null; another LocalsArray
Returns:
non-null; the merge result, a new instance or this

merge

public OneLocalsArray merge(OneLocalsArray other)
Merges this OneLocalsArray instance with another OneLocalsArray instance. A more-refined version of merge which is called by that method when appropriate.

Parameters:
other - locals array with which to merge
Returns:
this instance if merge was a no-op, or a new instance if the merge resulted in a change.

mergeWithSubroutineCaller

public LocalsArraySet mergeWithSubroutineCaller(LocalsArray other,
                                                int predLabel)
Description copied from class: LocalsArray
Merges this instance with a LocalsSet from a subroutine caller. To be used when merging in the first block of a subroutine.

Specified by:
mergeWithSubroutineCaller in class LocalsArray
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 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.

Specified by:
getPrimary in class LocalsArray
Returns:
locals for this execution context.


Copyright © 2015. All rights reserved.