RFR: 8287236: Reorganize AST related to pattern matching for switch [v3]
Jan Lahoda
jlahoda at openjdk.java.net
Thu Jun 2 10:55:44 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:
Reflecting review comments.
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/8959/files
- new: https://git.openjdk.java.net/jdk/pull/8959/files/7a147c2f..a952c48d
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=8959&range=02
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=8959&range=01-02
Stats: 26 lines in 3 files changed: 2 ins; 1 del; 23 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