[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: soot.ArrayType
There are three things that one might want to know about an array:
What is the base type of the array? That is, for an array of type
A[][][], how do I find out what the A is? The accepted way of doing this
has always been to look at the public field baseType in ArrayType, ever
since the very beginning of Soot.
If I get an element of the array, what will be its type? That is, if I
have an array a of type A[][][], what is the type of a[] (it's A[][])?
The getElementType() method in ArrayType was introduced much later to
answer this question.
If I have a variable x of declared type t, what is a good declared type
for the expression ((Object[]) x)[i]? The getArrayElementType() method
in RefLikeType was introduced even later to answer this question for
all classes implementing RefLikeType. If t is an array, then the answer
is the same as getElementType(). But t could also be Object,
Serializable, or Cloneable, which can all hold any array, so then the
answer is Object.
I guess it's unfortunate that the last two aren't handled by methods
with the same name. I've at least put the above descriptions in the
javadocs to avoid confusing people in the future.
Ondrej
On Sat, Nov 29, 2003 at 12:07:35AM -0500, Navindra Umanee wrote:
> Ankush Varma <ankush@eng.umd.edu> wrote:
> > What's the difference between
> > getArrayElementType() and getElementType()
> >
> > in soot.ArrayType ?
>
> That does indeed look bizarre. My guess is that getElementType() was
> kept for backwards compatibility with previous code, because
> getArrayElementType() and getElementType() return exactly the same
> thing. getElementType() will probably be phased out.
>
> getArrayElementType() seems to have been introduced with the
> RefLikeType super interface:
>
> http://www.sable.mcgill.ca/soot/doc/soot/RefLikeType.html
>
> RefType (subclass of RefLikeType) also implements
> getArrayElementType() although I'm not at all sure why that's needed:
>
> public Type getArrayElementType() {
> if( className.equals( "java.lang.Object" )
> || className.equals( "java.io.Serializable" )
> || className.equals( "java.lang.Cloneable" ) ) {
> return RefType.v( "java.lang.Object" );
> }
> throw new RuntimeException( "Attempt to get array base type of a non-array" );
> }
>
> Maybe for when the typing algorithm can't figure out that an Object is
> of array type? Ondrej can probably tell us.
>
> Cheers,
> Navin.
>