Skip to content

getType of JArrayRef#1083

Merged
swissiety merged 2 commits intosoot-oss:developfrom
Liyw979:getType
Sep 24, 2024
Merged

getType of JArrayRef#1083
swissiety merged 2 commits intosoot-oss:developfrom
Liyw979:getType

Conversation

@Liyw979
Copy link
Copy Markdown
Contributor

@Liyw979 Liyw979 commented Sep 24, 2024

fix #1076

Copy link
Copy Markdown
Collaborator

@swissiety swissiety left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

if (baseType.equals(NullType.getInstance())) {
return NullType.getInstance();
} else if (baseType instanceof ArrayType) {
return ((ArrayType) baseType).getElementType();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this if we have a multidimensional array e.g. int[ ][ ] this would return int instead of int[ ] ? we need to reduce the amount of dimensions / unwrap as it was done in Soot.
Why they check for NullType and return UnknownType instead of the actual baseType is not clear to me (maybe sanitization but in SootUp we rather would trow an error than silently trying to fix problems introduced/not handled earlier)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

((ArrayType) baseType).getElementType(); handles the int[ ][ ] case I guess

public Type getElementType() {
if (dimension > 1) {
return new ArrayType(baseType, dimension - 1);
} else {
return this.baseType;
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base.getType() is UnknownType when TypeAssigner is not enabled.
I feel it hard to use if we throw errors inside getType. We have to do try-catch every where.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But baseType would already be unknown, so we can return it directly / same for NullType - Im wondering if handling just ArrayType/return baseType otherwise would be enough?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation is correct you want to have the type of a entry in an array. if the array is multidimensional you should get an array as return value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the point.
else return base.getType() is equivalent from the value perspective.
But this code would imply that the return type of jarrayref is just the array itself, this could be confusing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation is correct you want to have the type of a entry in an array. if the array is multidimensional you should get an array as return value.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes sense.. as these two would be the only valid other base types as the ArrayRef should not point anywhere else than to an Array which is of ArrayType.

Copy link
Copy Markdown
Collaborator

@JonasKlauke JonasKlauke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no issue in the implementation.
Thanks 👍

if (baseType.equals(NullType.getInstance())) {
return NullType.getInstance();
} else if (baseType instanceof ArrayType) {
return ((ArrayType) baseType).getElementType();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation is correct you want to have the type of a entry in an array. if the array is multidimensional you should get an array as return value.

Copy link
Copy Markdown
Collaborator

@swissiety swissiety left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets reorder the ifelse so that the ArrayType is the first check as usually someone would use the TypeAssigner

Copy link
Copy Markdown
Collaborator

@swissiety swissiety left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your contribution!

@swissiety swissiety merged commit c2dd57a into soot-oss:develop Sep 24, 2024
@Liyw979 Liyw979 deleted the getType branch January 23, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: getType of JArrayRef is not element's type

3 participants