RFR: 8287236: Reorganize AST related to pattern matching for switch [v2]
Jan Lahoda
jlahoda at openjdk.java.net
Tue May 31 17:08:32 UTC 2022
> Under JEP 427, case label elements may be: a) expressions; b) patterns; c) the default. Currently, this is modeled in the Trees API in a way where all expressions and patterns extend `CaseLabelTree`.
>
> When guarded patterns were removed in favor of guards on pattern case label element, it was necessary to augment all patterns with a guard, which is only used when the pattern is used as a case label element. This is somewhat inconsistent for the Trees API.
>
> A use a layer of indirection is proposed here: - the `CaseLabelTree` has three subtypes: `ConstantCaseLabelTree`, which contains `ExpressionTree` as a subnode; `PatternCaseLabelTree`, which contains `PatternTree` and a guard (`ExpressionTree`) as subnodes; and the `DefaultCaseLabelTree` for the default clause.
>
> This patch also fixes `TreeScanner.visitCase`, which currently iterates only over `CaseTree.getExpressions()`, ignoring patterns. It is changed to iterate over `CaseTree.getLabels()`, to get all labels.
Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
Fixing test.
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/8959/files
- new: https://git.openjdk.java.net/jdk/pull/8959/files/7746c9fd..7a147c2f
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=8959&range=01
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=8959&range=00-01
Stats: 2 lines in 1 file changed: 0 ins; 0 del; 2 mod
Patch: https://git.openjdk.java.net/jdk/pull/8959.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/8959/head:pull/8959
PR: https://git.openjdk.java.net/jdk/pull/8959
More information about the compiler-dev
mailing list