[code-reflection] RFR: 8337158: Modeling and lowering of switch statement [v13]
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Aug 16 14:10:02 UTC 2024
On Fri, 16 Aug 2024 12:02:19 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:
>> Modeling and lowering of switch statement.
>
> Mourad Abbay has updated the pull request incrementally with two additional commits since the last revision:
>
> - Add a test case of switch statement model
> - Runtime tests of switch statement
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ReflectMethods.java line 1676:
> 1674:
> 1675: @Override
> 1676: public void visitSwitch(JCTree.JCSwitch tree) {
This method seems 90% the same as the one for switch expression, we should try to consolidate. I've left a comment on how to maybe simplify the logic to add a throwing default - let's see where we are after that's addressed.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ReflectMethods.java line 1822:
> 1820: // if enhanced switch and no default label
> 1821: // enhanced: target type not byte, char short, int, String, or, has case pattern or case null
> 1822: boolean enhancedSw = !List.of(JavaType.BYTE, JavaType.CHAR, JavaType.SHORT, JavaType.INT,
In `Lower` the code corresponding to this is:
public void visitSwitch(JCSwitch tree) {
List<JCCase> cases = tree.patternSwitch ? addDefaultIfNeeded(tree.patternSwitch,
tree.wasEnumSelector,
tree.cases)
: tree.cases;
handleSwitch(tree, tree.selector, cases);
}
So, I don't think you need all this state tracking and you can probably simplify all this.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/211#discussion_r1719895548
PR Review Comment: https://git.openjdk.org/babylon/pull/211#discussion_r1719894382
More information about the babylon-dev
mailing list