Skip to content
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

[Enhanced Switch] "Retrofit" some design into code generation for switch statement #3430

Open
srikanth-sankaran opened this issue Dec 10, 2024 · 0 comments · May be fixed by #3410
Open

[Enhanced Switch] "Retrofit" some design into code generation for switch statement #3430

srikanth-sankaran opened this issue Dec 10, 2024 · 0 comments · May be fixed by #3410
Assignees
Milestone

Comments

@srikanth-sankaran
Copy link
Contributor

As of Java 24, there are 5 kinds of switches namely, "Classic" integer selector switches, enum switches, string switches, type switches with patterns and primitive switches.

Code generation for each of these involves some abstractable steps such as (a) Prologue (all preparatory steps including and upto the case selection) (b) Code generation for the switch block (c) generation of injected default case - where applicable (d) epilogue - any and all actions to wrap up.

ATM, there is no clear design that is worth speaking of - there is some faint half/quarter hearted attempt at differentiating prologues, but this is inconsistently followed through, resulting in two big "blobs" of code - one for switching on strings and one for all other switches.

There is no attempt at code reuse - see the duplication between org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCodeForStringSwitch(BlockScope, CodeStream) and org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCode(BlockScope, CodeStream) - bottom half of each could be extracted as common code.

There is also no clear separation of concerns - resulting in spaghetti style intertwining of disparate concerns.

We can certainly do better by retrofitting some design that would promote readability, code organization and reuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant