[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-compiler-dev
Subject:    A potential enhancement about switch at JavacParser
From:       Guoxiong Li <lgxbslgx () gmail ! com>
Date:       2021-05-30 13:48:27
Message-ID: CAPSsVqik0Tj7sb+xrHAKZzPYQdE-t9r4YeGGQLz62rREoEpVjA () mail ! gmail ! com
[Download RAW message or body]

Hi all,

Currently, we have the switch statement and switch expression.
They have some different points. For example, the `yield` only can
be enclosed in the switch expression. But in general, they may be
the same in many situations, especially only considering their
syntactic struct.

Please see the following productions excerpted from the JLS.



*SwitchStatement:     switch ( Expression ) SwitchBlock*


*SwitchExpression:      switch ( Expression ) SwitchBlock*

They use the same `SwitchBlock` to construct the AST. But currently,
the parser uses different methods to construct them.

1. The class `JavacParser` uses methods `switchExpressionStatementGroup`
and `switchBlockStatementGroup` to separately construct the `case` subtree
of the switch expression and the switch statement.

2. And  the `case SWITCH` clause of the method `term3` (where the switch
expression is implemented)
and  the method `switchBlockStatementGroups` has the similar code snippet
to construct the switch body.

Maybe the methods of the two aspects above can be merged to clean up the
code
and reduce the complication of the parser.

And the codes mentioned above have other places that need to be adjusted.
For example, the return type of the method `switchExpressionStatementGroup`
and
`switchBlockStatementGroup` could be the `JCCase` instead of the
`List<JCCase>`.

What do you think about this enhancement?
Could someone who implemented the switch expression provide more
information on why the different methods were used?
Any ideas are appreciated.

And considering that the `Pattern matching for switch` may revise these
codes
and the Rampdown Phase One is coming soon, if we confirm this enhancement
is feasible, it is best to complete it at JDK 18 so that the feature of the
`Pattern matching for switch` won't be affected.

Best Regards,
-- Guoxiong

[Attachment #3 (text/html)]

<div dir="ltr">Hi all,<div><br></div><div>Currently, we have the switch statement and \
switch expression.</div><div>They have some different points. For example, the \
`yield` only can  </div><div>be enclosed in the switch expression. But in general, \
they may be  </div><div>the same in many situations, especially only considering \
their  </div><div>syntactic struct.</div><div><br></div><div>Please see the following \
productions excerpted from the JLS.</div><div><br></div><div><b>SwitchStatement:<br>  \
switch ( Expression ) \
SwitchBlock<br></b></div><div><b><br></b></div><div><b>SwitchExpression:<br>         \
switch ( Expression ) SwitchBlock</b><br></div><div><br></div><div>They use the same \
`SwitchBlock` to construct the AST. But currently,  </div><div>the parser uses \
different methods to construct them.</div><div><br></div><div>1. The class \
`JavacParser` uses methods `switchExpressionStatementGroup`  </div><div>and \
`switchBlockStatementGroup` to separately construct the `case` subtree  </div><div>of \
the switch expression and the switch statement.</div><div><br></div><div>2. And   the \
`case SWITCH` clause of the method `term3` (where the switch expression is \
implemented)</div><div>and   the method `switchBlockStatementGroups` has the similar \
code snippet  </div><div>to construct the switch body.</div><div><br></div><div>Maybe \
the methods of the two aspects above can be merged to clean up the code  \
</div><div>and reduce the complication of the parser.</div><div><br></div><div>And \
the codes mentioned above have other places that need to be adjusted.</div><div>For \
example, the return type of the method `switchExpressionStatementGroup` and  \
</div><div>`switchBlockStatementGroup` could be the `JCCase` instead of the \
`List&lt;JCCase&gt;`.</div><div><br></div><div>What do you think about this \
enhancement?</div><div>Could someone who implemented the switch expression provide \
more  </div><div>information on why the different methods were used?</div><div>Any \
ideas are appreciated.</div><div><br></div><div>And considering that the `Pattern \
matching for switch` may revise these codes  </div><div>and the Rampdown Phase One is \
coming soon, if we confirm this enhancement  </div><div>is feasible, it is best to \
complete it at JDK 18 so that the feature of the  </div><div>`Pattern matching for \
switch` won&#39;t be affected.</div><div><br></div><div>Best Regards,</div><div>-- \
Guoxiong</div><div><br></div><div><br></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic