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

Allow @ModifyVariable to capture locals #649

Open
ctrlaltmilk opened this issue Dec 1, 2023 · 1 comment
Open

Allow @ModifyVariable to capture locals #649

ctrlaltmilk opened this issue Dec 1, 2023 · 1 comment

Comments

@ctrlaltmilk
Copy link

I have a function with the structure

void foo() {
    int a = bar();
    int b = baz();

    if (a == 0) {
        doSomethingNontrivial();
    }
}

I would like to use Mixins to rewrite the function a bit:

void foo() {
    int a = bar();
    int b = baz();

    if (a == 0 || b == 0) {
        baz();
    }
}

To do this, the best option seems to be a @ModifyVariable on the value of a, but to do that I would need to capture the value of b as well. Currently, this is not possible. If the a == 0 was a method call, it would be possible to use an @Inject just before the comparison and set a to 0 if b is 0, but as the comparison becomes an IF_ICMPEQ it's impossible to target for an injection. @ModifyVariable already examines the LVT to determine the accesses it needs to inject bytecode at, so adding another local capture shouldn't make it any more fragile than it already is.

@LlamaLad7
Copy link
Contributor

Consider using https://github.com/LlamaLad7/MixinExtras/wiki/Local in the meantime.

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