-
Notifications
You must be signed in to change notification settings - Fork 265
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
CFR uses numerical literals instead of constants #353
Comments
The name of the constant is not stored in the constant pool in the bytecode. The disassembled code looks like this:
So it's just fetching the value stored at index So the best CFR would be able to do is guess that it's the same as the |
Yes, that's what I'm proposing. Thank you for clarifying that! |
This is (partially) handled in InstanceConstants cfr/src/org/benf/cfr/reader/bytecode/analysis/opgraph/op3rewriters/InstanceConstants.java Line 89 in d6f6758
However, while it's a 'nice' thing, it tends to lead to completely confusing code in all but the most obvious cases; it's been a while so I may be mis remembering, but GUI code in particular uses a lot of magic constants , so the code to do this is very pessimistic. ( while a false negative is annoying, a false positive is downright confusing ). |
Thank you for your explanation. |
It's commonplace that the developers tend to create a multitude of well-named constants that might be used across their projects. And I've found that CFR sometimes intends to omit the constants while using the numerical literals these constants have stood for. At this case, CFR may encounter challenges in retaining these numerical literals to the corresponding constants, thus having a negative impact on the code readability and understandability.
I think that improving the strategy of coping with the relatively special constants defined by source codes might help resolve this problem.
Here is an example:
The following code snippet is from src/main/java/org/bukkit/util/BlockIterator.java in the project Bukkit:
The corresponding code generated by CFR:
As we can see, CFR has replaced the GridSize with a numerical literals, which might make the code less understandable.
The corresponding .class file can be found here
The text was updated successfully, but these errors were encountered: