[code-reflection] RFR: Implement bitwise/shift assignment operations [v2]
Paul Sandoz
psandoz at openjdk.org
Wed May 15 16:19:17 UTC 2024
On Wed, 15 May 2024 08:25:56 GMT, Hannes Greule <hgreule at openjdk.org> wrote:
>> This change adds support for compound assignments for bitwise operations and shift operations. Tests are also enhanced to cover those cases.
>>
>> As with already existing operations, input types `byte`, `char`, `short` are not converted to `int`. Again, we have the special case of shift operations where the spec dictates unary promotion. That's why currently the rhs is promoted to `int` even in shift compound assignments.
>>
>> The additional methods in `InvokableLeafOps` are needed in the current design.
>
> Hannes Greule has updated the pull request incrementally with one additional commit since the last revision:
>
> Fix missed change from rebase
Looks good, thanks for adding these.
test/jdk/java/lang/reflect/code/CoreBinaryOpsTest.java line 66:
> 64:
> 65: @CodeReflection
> 66: @SupportedTypes(types = {int.class, long.class, byte.class, short.class, char.class, boolean.class})
Alas we cannot have constant array values, hence the duplication. But, we can use enums:
enum Types {
INTEGRAL_BOOLEAN(
new Class<?>[]{int.class, long.class, byte.class, short.class, char.class, boolean.class}),
INTEGRAL_FLOATING_POINT(
new Class<?>[]{int.class, long.class, byte.class, short.class, char.class, float.class, double.class}
);
final Class<?>[] types;
PrimitiveTypeList(Class<?>[] types) {
this.types = types;
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface SupportedTypes {
PrimitiveTypeList[] value();
}
...
@CodeReflection
@SupportedTypes(Types.INTEGRAL_BOOLEAN)
static int add(int left, int right) {
return left + right;
}
Up to you.
-------------
Marked as reviewed by psandoz (Lead).
PR Review: https://git.openjdk.org/babylon/pull/77#pullrequestreview-2058479960
PR Review Comment: https://git.openjdk.org/babylon/pull/77#discussion_r1601923390
More information about the babylon-dev
mailing list