PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/dalvik/dx/src/com/android/dx/cf/code/LocalsArray.java

https://gitlab.com/brian0218/rk3288_r-box_android4.4.2_sdk
Java | 181 lines | 27 code | 19 blank | 135 comment | 0 complexity | f31ec27c3f3901da3d46879f58e8f519 MD5 | raw file
  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.android.dx.cf.code;
  17. import com.android.dex.util.ExceptionWithContext;
  18. import com.android.dx.rop.code.RegisterSpec;
  19. import com.android.dx.rop.type.Type;
  20. import com.android.dx.rop.type.TypeBearer;
  21. import com.android.dx.util.MutabilityControl;
  22. import com.android.dx.util.ToHuman;
  23. /**
  24. * Representation of an array of local variables, with Java semantics.
  25. *
  26. * <p><b>Note:</b> For the most part, the documentation for this class
  27. * ignores the distinction between {@link Type} and {@link
  28. * TypeBearer}.</p>
  29. */
  30. public abstract class LocalsArray extends MutabilityControl implements ToHuman {
  31. /**
  32. * Constructs an instance, explicitly indicating the mutability.
  33. *
  34. * @param mutable {@code true} if this instance is mutable
  35. */
  36. protected LocalsArray(boolean mutable) {
  37. super(mutable);
  38. }
  39. /**
  40. * Makes and returns a mutable copy of this instance.
  41. *
  42. * @return {@code non-null;} the copy
  43. */
  44. public abstract LocalsArray copy();
  45. /**
  46. * Annotates (adds context to) the given exception with information
  47. * about this instance.
  48. *
  49. * @param ex {@code non-null;} the exception to annotate
  50. */
  51. public abstract void annotate(ExceptionWithContext ex);
  52. /**
  53. * Replaces all the occurrences of the given uninitialized type in
  54. * this array with its initialized equivalent.
  55. *
  56. * @param type {@code non-null;} type to replace
  57. */
  58. public abstract void makeInitialized(Type type);
  59. /**
  60. * Gets the maximum number of locals this instance can refer to.
  61. *
  62. * @return the max locals
  63. */
  64. public abstract int getMaxLocals();
  65. /**
  66. * Sets the type stored at the given local index. If the given type
  67. * is category-2, then (a) the index must be at least two less than
  68. * {@link #getMaxLocals} and (b) the next index gets invalidated
  69. * by the operation. In case of either category, if the <i>previous</i>
  70. * local contains a category-2 value, then it too is invalidated by
  71. * this operation.
  72. *
  73. * @param idx {@code >= 0, < getMaxLocals();} which local
  74. * @param type {@code non-null;} new type for the local at {@code idx}
  75. */
  76. public abstract void set(int idx, TypeBearer type);
  77. /**
  78. * Sets the type for the local indicated by the given register spec
  79. * to that register spec (which includes type and optional name
  80. * information). This is identical to calling
  81. * {@code set(spec.getReg(), spec)}.
  82. *
  83. * @param spec {@code non-null;} register spec to use as the basis for the update
  84. */
  85. public abstract void set(RegisterSpec spec);
  86. /**
  87. * Invalidates the local at the given index.
  88. *
  89. * @param idx {@code >= 0, < getMaxLocals();} which local
  90. */
  91. public abstract void invalidate(int idx);
  92. /**
  93. * Gets the type stored at the given local index, or {@code null}
  94. * if the given local is uninitialized / invalid.
  95. *
  96. * @param idx {@code >= 0, < getMaxLocals();} which local
  97. * @return {@code null-ok;} the type of value stored in that local
  98. */
  99. public abstract TypeBearer getOrNull(int idx);
  100. /**
  101. * Gets the type stored at the given local index, only succeeding if
  102. * the given local contains a valid type (though it is allowed to
  103. * be an uninitialized instance).
  104. *
  105. * @param idx {@code >= 0, < getMaxLocals();} which local
  106. * @return {@code non-null;} the type of value stored in that local
  107. * @throws SimException thrown if {@code idx} is valid, but
  108. * the contents are invalid
  109. */
  110. public abstract TypeBearer get(int idx);
  111. /**
  112. * Gets the type stored at the given local index, which is expected
  113. * to be an initialized category-1 value.
  114. *
  115. * @param idx {@code >= 0, < getMaxLocals();} which local
  116. * @return {@code non-null;} the type of value stored in that local
  117. * @throws SimException thrown if {@code idx} is valid, but
  118. * one of the following holds: (a) the local is invalid; (b) the local
  119. * contains an uninitialized instance; (c) the local contains a
  120. * category-2 value
  121. */
  122. public abstract TypeBearer getCategory1(int idx);
  123. /**
  124. * Gets the type stored at the given local index, which is expected
  125. * to be a category-2 value.
  126. *
  127. * @param idx {@code >= 0, < getMaxLocals();} which local
  128. * @return {@code non-null;} the type of value stored in that local
  129. * @throws SimException thrown if {@code idx} is valid, but
  130. * one of the following holds: (a) the local is invalid; (b) the local
  131. * contains a category-1 value
  132. */
  133. public abstract TypeBearer getCategory2(int idx);
  134. /**
  135. * Merges this instance with {@code other}. If the merged result is
  136. * the same as this instance, then this is returned (not a copy).
  137. *
  138. * @param other {@code non-null;} another LocalsArray
  139. * @return {@code non-null;} the merge result, a new instance or this
  140. */
  141. public abstract LocalsArray merge(LocalsArray other);
  142. /**
  143. * Merges this instance with a {@code LocalsSet} from a subroutine
  144. * caller. To be used when merging in the first block of a subroutine.
  145. *
  146. * @param other {@code other non-null;} another LocalsArray. The final locals
  147. * state of a subroutine caller.
  148. * @param predLabel the label of the subroutine caller block.
  149. * @return {@code non-null;} the merge result, a new instance or this
  150. */
  151. public abstract LocalsArraySet mergeWithSubroutineCaller
  152. (LocalsArray other, int predLabel);
  153. /**
  154. * Gets the locals set appropriate for the current execution context.
  155. * That is, if this is a {@code OneLocalsArray} instance, then return
  156. * {@code this}, otherwise return {@code LocalsArraySet}'s
  157. * primary.
  158. *
  159. * @return locals for this execution context.
  160. */
  161. protected abstract OneLocalsArray getPrimary();
  162. }