FileDocCategorySizeDatePackage
RegisterSpecList.javaAPI DocAndroid 1.5 API10451Wed May 06 22:41:02 BST 2009com.android.dx.rop.code

RegisterSpecList

public final class RegisterSpecList extends com.android.dx.util.FixedSizeList implements com.android.dx.rop.type.TypeList
List of {@link RegisterSpec} instances.

Fields Summary
public static final RegisterSpecList
EMPTY
non-null; no-element instance
Constructors Summary
public RegisterSpecList(int size)
Constructs an instance. All indices initially contain null.

param
size the size of the list

        super(size);
    
Methods Summary
public RegisterSpecget(int n)
Gets the indicated element. It is an error to call this with the index for an element which was never set; if you do that, this will throw NullPointerException.

param
n >= 0, < size(); which element
return
non-null; the indicated element

        return (RegisterSpec) get0(n);
    
public intgetRegistersSize()
Gets the minimum required register count implied by this instance. This is equal to the highest register number referred to plus the widest width (largest category) of the type used in that register.

return
>= 0; the required registers size

        int sz = size();
        int result = 0;

        for (int i = 0; i < sz; i++) {
            RegisterSpec spec = (RegisterSpec) get0(i);
            if (spec != null) {
                int min = spec.getNextReg();
                if (min > result) {
                    result = min;
                }
            }
        }

        return result;
    
public com.android.dx.rop.type.TypegetType(int n)
{@inheritDoc}

        return get(n).getType().getType();
    
public intgetWordCount()
{@inheritDoc}

        int sz = size();
        int result = 0;

        for (int i = 0; i < sz; i++) {
            result += getType(i).getCategory();
        }

        return result;
    
public intindexOfRegister(int reg)
Returns the index of a RegisterSpec in this list that uses the specified register, or -1 if none in this list uses the register.

param
reg Register to find
return
index of RegisterSpec or -1

        int sz = size();
        for (int i = 0; i < sz; i++) {
            RegisterSpec rs;

            rs = get(i);

            if (rs.getReg() == reg) {
                return i;
            }
        }

        return -1;        
    
public static com.android.dx.rop.code.RegisterSpecListmake(RegisterSpec spec)
Makes a single-element instance.

param
spec non-null; the element
return
non-null; an appropriately-constructed instance


                        
         
        RegisterSpecList result = new RegisterSpecList(1);
        result.set(0, spec);
        return result;
    
public static com.android.dx.rop.code.RegisterSpecListmake(RegisterSpec spec0, RegisterSpec spec1)
Makes a two-element instance.

param
spec0 non-null; the first element
param
spec1 non-null; the second element
return
non-null; an appropriately-constructed instance

        RegisterSpecList result = new RegisterSpecList(2);
        result.set(0, spec0);
        result.set(1, spec1);
        return result;
    
public static com.android.dx.rop.code.RegisterSpecListmake(RegisterSpec spec0, RegisterSpec spec1, RegisterSpec spec2)
Makes a three-element instance.

param
spec0 non-null; the first element
param
spec1 non-null; the second element
param
spec2 non-null; the third element
return
non-null; an appropriately-constructed instance

        RegisterSpecList result = new RegisterSpecList(3);
        result.set(0, spec0);
        result.set(1, spec1);
        result.set(2, spec2);
        return result;
    
public static com.android.dx.rop.code.RegisterSpecListmake(RegisterSpec spec0, RegisterSpec spec1, RegisterSpec spec2, RegisterSpec spec3)
Makes a four-element instance.

param
spec0 non-null; the first element
param
spec1 non-null; the second element
param
spec2 non-null; the third element
param
spec3 non-null; the fourth element
return
non-null; an appropriately-constructed instance

        RegisterSpecList result = new RegisterSpecList(4);
        result.set(0, spec0);
        result.set(1, spec1);
        result.set(2, spec2);
        result.set(3, spec3);
        return result;
    
public voidset(int n, RegisterSpec spec)
Sets the element at the given index.

param
n >= 0, < size(); which element
param
spec non-null; the value to store

        set0(n, spec);
    
public RegisterSpecspecForRegister(int reg)
Returns a RegisterSpec in this list that uses the specified register, or null if there is none in this list.

param
reg Register to find
return
RegisterSpec that uses argument or null.

        int sz = size();
        for (int i = 0; i < sz; i++) {
            RegisterSpec rs;

            rs = get(i);

            if (rs.getReg() == reg) {
                return rs;
            }
        }

        return null;
    
public com.android.dx.rop.type.TypeListwithAddedType(com.android.dx.rop.type.Type type)
{@inheritDoc}

        throw new UnsupportedOperationException("unsupported");
    
public com.android.dx.rop.code.RegisterSpecListwithFirst(RegisterSpec spec)
Returns a new instance, which is the same as this instance, except that it has an additional element prepended to the original. Mutability of the result is inherited from the original.

param
spec non-null; the new first spec (to prepend)
return
non-null; an appropriately-constructed instance

        int sz = size();
        RegisterSpecList result = new RegisterSpecList(sz + 1);

        for (int i = 0; i < sz; i++) {
            result.set0(i + 1, get0(i));
        }

        result.set0(0, spec);
        if (isImmutable()) {
            result.setImmutable();
        }

        return result;
    
public com.android.dx.rop.code.RegisterSpecListwithOffset(int delta)
Returns an instance that is identical to this one, except that all register numbers are offset by the given amount. Mutability of the result is inherited from the original.

param
delta the amount to offset the register numbers by
return
non-null; an appropriately-constructed instance

        int sz = size();

        if (sz == 0) {
            // Don't bother making a new zero-element instance.
            return this;
        }

        RegisterSpecList result = new RegisterSpecList(sz);

        for (int i = 0; i < sz; i++) {
            RegisterSpec one = (RegisterSpec) get0(i);
            if (one != null) {
                result.set0(i, one.withOffset(delta));
            }
        }

        if (isImmutable()) {
            result.setImmutable();
        }

        return result;
    
public com.android.dx.rop.code.RegisterSpecListwithSequentialRegisters(int base, boolean duplicateFirst)
Returns an instance that is identical to this one, except that all register numbers are renumbered sequentially from the given base, with the first number duplicated if indicated.

param
base the base register number
param
duplicateFirst whether to duplicate the first number
return
non-null; an appropriately-constructed instance

        int sz = size();

        if (sz == 0) {
            // Don't bother making a new zero-element instance.
            return this;
        }

        RegisterSpecList result = new RegisterSpecList(sz);

        for (int i = 0; i < sz; i++) {
            RegisterSpec one = (RegisterSpec) get0(i);
            result.set0(i, one.withReg(base));
            if (duplicateFirst) {
                duplicateFirst = false;
            } else {
                base += one.getCategory();
            }
        }

        if (isImmutable()) {
            result.setImmutable();
        }

        return result;
    
public com.android.dx.rop.code.RegisterSpecListwithoutFirst()
Returns a new instance, which is the same as this instance, except that its first element is removed. Mutability of the result is inherited from the original.

return
non-null; an appropriately-constructed instance

        int newSize = size() - 1;

        if (newSize == 0) {
            return EMPTY;
        }

        RegisterSpecList result = new RegisterSpecList(newSize);

        for (int i = 0; i < newSize; i++) {
            result.set0(i, get0(i + 1));
        }

        if (isImmutable()) {
            result.setImmutable();
        }

        return result;
    
public com.android.dx.rop.code.RegisterSpecListwithoutLast()
Returns a new instance, which is the same as this instance, except that its last element is removed. Mutability of the result is inherited from the original.

return
non-null; an appropriately-constructed instance

        int newSize = size() - 1;

        if (newSize == 0) {
            return EMPTY;
        }

        RegisterSpecList result = new RegisterSpecList(newSize);

        for (int i = 0; i < newSize; i++) {
            result.set0(i, get0(i));
        }

        if (isImmutable()) {
            result.setImmutable();
        }

        return result;