Class LocalsArraySet
java.lang.Object
com.android.dx.util.MutabilityControl
com.android.dx.cf.code.LocalsArray
com.android.dx.cf.code.LocalsArraySet
- All Implemented Interfaces:
ToHuman
Representation of a set of local variable arrays, with Java semantics.
This peculiar case is to support in-method subroutines, which can
have different locals sets for each caller.
Note: For the most part, the documentation for this class
ignores the distinction between Type and TypeBearer.
-
Constructor Summary
ConstructorsConstructorDescriptionLocalsArraySet(int maxLocals) Constructs an instance.LocalsArraySet(OneLocalsArray primary, ArrayList<LocalsArray> secondaries) Constructs an instance with the specified primary and secondaries set. -
Method Summary
Modifier and TypeMethodDescriptionvoidAnnotates (adds context to) the given exception with information about this instance.copy()Makes and returns a mutable copy of this instance.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).getCategory1(int idx) Gets the type stored at the given local index, which is expected to be an initialized category-1 value.getCategory2(int idx) Gets the type stored at the given local index, which is expected to be a category-2 value.intGets the maximum number of locals this instance can refer to.getOrNull(int idx) Gets the type stored at the given local index, ornullif the given local is uninitialized / invalid.protected OneLocalsArrayGets the locals set appropriate for the current execution context.voidinvalidate(int idx) Invalidates the local at the given index.voidmakeInitialized(Type type) Replaces all the occurrences of the given uninitialized type in this array with its initialized equivalent.merge(LocalsArray other) Merges this instance withother.mergeWithSubroutineCaller(LocalsArray other, int predLabel) Merges this instance with aLocalsSetfrom a subroutine caller.voidset(int idx, TypeBearer type) Sets the type stored at the given local index.voidset(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).voidMakes this instance immutable.subArrayForLabel(int subLabel) Returns a LocalsArray instance representing the locals state that should be used when returning to a subroutine caller.toHuman()Return the "human" string form of this instance.Methods inherited from class MutabilityControl
isImmutable, isMutable, throwIfImmutable, throwIfMutable
-
Constructor Details
-
LocalsArraySet
public LocalsArraySet(int maxLocals) Constructs an instance. The locals array initially consists of all-uninitialized values (represented asnulls).- Parameters:
maxLocals->= 0;the maximum number of locals this instance can refer to
-
LocalsArraySet
Constructs an instance with the specified primary and secondaries set.- Parameters:
primary-non-null;primary locals to usesecondaries-non-null;secondaries set, indexed by subroutine caller label.
-
-
Method Details
-
setImmutable
public void setImmutable()Makes this instance immutable.- Overrides:
setImmutablein classMutabilityControl
-
copy
Makes and returns a mutable copy of this instance.- Specified by:
copyin classLocalsArray- Returns:
non-null;the copy
-
annotate
Annotates (adds context to) the given exception with information about this instance.- Specified by:
annotatein classLocalsArray- Parameters:
ex-non-null;the exception to annotate
-
toHuman
Return the "human" string form of this instance. This is generally less "debuggy" thantoString().- Returns:
non-null;the human string form
-
makeInitialized
Replaces all the occurrences of the given uninitialized type in this array with its initialized equivalent.- Specified by:
makeInitializedin classLocalsArray- Parameters:
type-non-null;type to replace
-
getMaxLocals
public int getMaxLocals()Gets the maximum number of locals this instance can refer to.- Specified by:
getMaxLocalsin classLocalsArray- Returns:
- the max locals
-
set
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 thanLocalsArray.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:
setin classLocalsArray- Parameters:
idx->= 0, < getMaxLocals();which localtype-non-null;new type for the local atidx
-
set
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 callingset(spec.getReg(), spec).- Specified by:
setin classLocalsArray- Parameters:
spec-non-null;register spec to use as the basis for the update
-
invalidate
public void invalidate(int idx) Invalidates the local at the given index.- Specified by:
invalidatein classLocalsArray- Parameters:
idx->= 0, < getMaxLocals();which local
-
getOrNull
Gets the type stored at the given local index, ornullif the given local is uninitialized / invalid.- Specified by:
getOrNullin classLocalsArray- Parameters:
idx->= 0, < getMaxLocals();which local- Returns:
null-ok;the type of value stored in that local
-
get
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:
getin classLocalsArray- Parameters:
idx->= 0, < getMaxLocals();which local- Returns:
non-null;the type of value stored in that local
-
getCategory1
Gets the type stored at the given local index, which is expected to be an initialized category-1 value.- Specified by:
getCategory1in classLocalsArray- Parameters:
idx->= 0, < getMaxLocals();which local- Returns:
non-null;the type of value stored in that local
-
getCategory2
Gets the type stored at the given local index, which is expected to be a category-2 value.- Specified by:
getCategory2in classLocalsArray- Parameters:
idx->= 0, < getMaxLocals();which local- Returns:
non-null;the type of value stored in that local
-
merge
Merges this instance withother. If the merged result is the same as this instance, then this is returned (not a copy).- Specified by:
mergein classLocalsArray- Parameters:
other-non-null;another LocalsArray- Returns:
non-null;the merge result, a new instance or this
-
mergeWithSubroutineCaller
Merges this instance with aLocalsSetfrom a subroutine caller. To be used when merging in the first block of a subroutine.- Specified by:
mergeWithSubroutineCallerin classLocalsArray- 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
-
subArrayForLabel
Returns a LocalsArray instance representing the locals state that should be used when returning to a subroutine caller.- Parameters:
subLabel->= 0;A calling label of a subroutine- Returns:
null-ok;an instance for this subroutine, or null if subroutine is not in this set.
-
getPrimary
Gets the locals set appropriate for the current execution context. That is, if this is aOneLocalsArrayinstance, then returnthis, otherwise returnLocalsArraySet's primary.- Specified by:
getPrimaryin classLocalsArray- Returns:
- locals for this execution context.
-