FileDocCategorySizeDatePackage
OneLocalsArray.javaAPI DocAndroid 1.5 API6981Wed May 06 22:41:02 BST 2009com.android.dx.cf.code

OneLocalsArray

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 {@link com.android.dx.rop.type.Type} and {@link com.android.dx.rop.type.TypeBearer}.

Fields Summary
private final com.android.dx.rop.type.TypeBearer[]
locals
non-null; actual array
Constructors Summary
public OneLocalsArray(int maxLocals)
Constructs an instance. The locals array initially consists of all-uninitialized values (represented as nulls).

param
maxLocals >= 0; the maximum number of locals this instance can refer to

        super(maxLocals != 0);
        locals = new TypeBearer[maxLocals];
    
Methods Summary
public voidannotate(com.android.dx.util.ExceptionWithContext ex)

inheritDoc

        for (int i = 0; i < locals.length; i++) {
            TypeBearer type = locals[i];
            String s = (type == null) ? "<invalid>" : type.toString();
            ex.addContext("locals[" + Hex.u2(i) + "]: " + s);
        }
    
public com.android.dx.cf.code.OneLocalsArraycopy()

inheritDoc

        OneLocalsArray result = new OneLocalsArray(locals.length);

        System.arraycopy(locals, 0, result.locals, 0, locals.length);

        return result;
    
public com.android.dx.rop.type.TypeBearerget(int idx)

inheritDoc

        TypeBearer result = locals[idx];

        if (result == null) {
            return throwSimException(idx, "invalid");
        }

        return result;
    
public com.android.dx.rop.type.TypeBearergetCategory1(int idx)

inheritDoc

        TypeBearer result = get(idx);
        Type type = result.getType();

        if (type.isUninitialized()) {
            return throwSimException(idx, "uninitialized instance");
        }

        if (type.isCategory2()) {
            return throwSimException(idx, "category-2");
        }

        return result;
    
public com.android.dx.rop.type.TypeBearergetCategory2(int idx)

inheritDoc

        TypeBearer result = get(idx);

        if (result.getType().isCategory1()) {
            return throwSimException(idx, "category-1");
        }

        return result;
    
public intgetMaxLocals()

inheritDoc

        return locals.length;
    
public com.android.dx.rop.type.TypeBearergetOrNull(int idx)

inheritDoc

        return locals[idx];
    
protected com.android.dx.cf.code.OneLocalsArraygetPrimary()
{@inheritDoc}

        return this;
    
public voidinvalidate(int idx)

inheritDoc

        throwIfImmutable();
        locals[idx] = null;
    
public voidmakeInitialized(com.android.dx.rop.type.Type type)

inheritDoc

        int len = locals.length;

        if (len == 0) {
            // We have to check for this before checking for immutability.
            return;
        }

        throwIfImmutable();

        Type initializedType = type.getInitializedType();

        for (int i = 0; i < len; i++) {
            if (locals[i] == type) {
                locals[i] = initializedType;
            }
        }
    
public LocalsArraymerge(LocalsArray other)

inheritDoc

        if (other instanceof OneLocalsArray) {
            return merge((OneLocalsArray)other);
        } else { //LocalsArraySet
            // LocalsArraySet knows how to merge me.
            return other.merge(this);
        }
    
public com.android.dx.cf.code.OneLocalsArraymerge(com.android.dx.cf.code.OneLocalsArray other)
Merges this OneLocalsArray instance with another OneLocalsArray instance. A more-refined version of {@link #merge(LocalsArray) merge} which is called by that method when appropriate.

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

        try {
            return Merger.mergeLocals(this, other);
        } catch (SimException ex) {
            ex.addContext("underlay locals:");
            annotate(ex);
            ex.addContext("overlay locals:");
            other.annotate(ex);
            throw ex;
        }
    
public LocalsArraySetmergeWithSubroutineCaller(LocalsArray other, int predLabel)

inheritDoc


        LocalsArraySet result = new LocalsArraySet(getMaxLocals());
        return result.mergeWithSubroutineCaller(other, predLabel);
    
public voidset(int idx, com.android.dx.rop.type.TypeBearer type)

inheritDoc

        throwIfImmutable();

        try {
            type = type.getFrameType();
        } catch (NullPointerException ex) {
            // Elucidate the exception
            throw new NullPointerException("type == null");
        }

        if (idx < 0) {
            throw new IndexOutOfBoundsException("idx < 0");
        }

        // Make highest possible out-of-bounds check happen first.
        if (type.getType().isCategory2()) {
            locals[idx + 1] = null;
        }

        locals[idx] = type;

        if (idx != 0) {
            TypeBearer prev = locals[idx - 1];
            if ((prev != null) && prev.getType().isCategory2()) {
                locals[idx - 1] = null;
            }
        }
    
public voidset(com.android.dx.rop.code.RegisterSpec spec)

inheritDoc

        set(spec.getReg(), spec);
    
private static com.android.dx.rop.type.TypeBearerthrowSimException(int idx, java.lang.String msg)
Throws a properly-formatted exception.

param
idx the salient local index
param
msg non-null; useful message
return
never (keeps compiler happy)

        throw new SimException("local " + Hex.u2(idx) + ": " + msg);
    
public java.lang.StringtoHuman()
{@inheritDoc

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < locals.length; i++) {
            TypeBearer type = locals[i];
            String s = (type == null) ? "<invalid>" : type.toString();
            sb.append("locals[" + Hex.u2(i) + "]: " + s + "\n");
        }

        return sb.toString();