Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] @ModifyComparisonArg #21

Open
xanderstuff opened this issue Dec 30, 2022 · 4 comments
Open

[Suggestion] @ModifyComparisonArg #21

xanderstuff opened this issue Dec 30, 2022 · 4 comments

Comments

@xanderstuff
Copy link

xanderstuff commented Dec 30, 2022

This would wrap the entire left-hand or right-hand side of a comparison, which could be chained by multiple mixins.

Example:

@ModifyComparisonArg(
    method = "targetMethod", 
    comparison = "LESS_THAN_OR_EQUAL",
    argument = "SECOND" //or maybe side = "RIGHT_SIDE"?
)
private TargetType wrapExpression(TargetType expression){
    //TargetType is either int, long, float, double, boolean(?)
    return expression + 5;
}

Code diff:

- if(x * i <= foo.get() * 4){
+ if(x * i <= wrapExpression(foo.get() * 4)){
    // stuff
}

Note: in this example code diff, there is no way to add 5 to either side. If you used a @ModifyExpressionValue on foo.get(), then any value you add gets multiplied by 4 (which will not be the same result). And if you used a @ModifyConstant or @Redirect on the field access, then (in this example) any change you make will also get multiplied by the other values in the expression (again, not the same result), while also not being compatible with any other mixins using the same target.

@xanderstuff
Copy link
Author

xanderstuff commented Dec 30, 2022

Question: would it be beneficial to do something similar for logical operations (AND, OR)? or does @ModifyExpressionValue cover every possible use-case scenario (since logical operations are much simpler)?

@xanderstuff
Copy link
Author

xanderstuff commented Dec 30, 2022

I haven't put much thought into the name yet, so here's some alternative names: @WrapComparisonArg, @ModifyComparisonExpression, @WrapComparisonExpression.

@LlamaLad7
Copy link
Owner

The trouble is that targeting such operations is inherently brittle because the instructions are so generic. Slices make it a bit better but it's still not ideal. I may implement something along these lines in the future but it's not a priority because the situations are fairly esoteric (I've yet to encounter anything like you've described in the wild). If there's any specific scenarios you'd like this for, feel free to ask about them.

@LlamaLad7
Copy link
Owner

I do have a plan for this now.

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

No branches or pull requests

2 participants