-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
seastar-json2code: reformat the rendered code and cleanups #2090
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instead of have a giant function for generating the .hh and .cc files from .json, let's extract the loop body out. for better readability. in following-up changes, we will extract some more helper functions out. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
instead of concatenating strings, use Template to generate code for enum types. for better readability. before this change the generated code looks like: ```c++ query_enum str2query_enum(const sstring& str) { static const sstring arr[] = {"VAL1","VAL2","VAL3"}; int i; for (i=0; i < 3; i++) { if (arr[i] == str) {return (query_enum)i;} } return (query_enum)i; } ``` the generated code looks like ```c++ query_enum str2query_enum(const sstring& str) { static const sstring arr[] = { "VAL1", "VAL2", "VAL3" }; int i; for (i = 0; i < 3; i++) { if (arr[i] == str) { return (query_enum)i; } } return (query_enum)i; } ``` Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
move `not_first()` up so it can be reused, and use it for indent. before this change, the rendered code looks like ```c++ query_enum str2query_enum(const sstring& str) { static const sstring arr[] = { "VAL1", "VAL2", "VAL3" }; int i; for (i = 0; i < 3; i++) { if (arr[i] == str) { return (query_enum)i; } } return (query_enum)i; } ``` after this change, the rendered code looks like: ```c++ query_enum str2query_enum(const sstring& str) { static const sstring arr[] = { "VAL1", "VAL2", "VAL3" }; int i; for (i = 0; i < 3; i++) { if (arr[i] == str) { return (query_enum)i; } } return (query_enum)i; } ``` Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
instead of checking for the existence of a key in dict, just go ahead and access it using dict.get(key, []). so that we can reduce the indent level. this should improve the readability a little bit. Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
use `join()` to simplify the implementation to print the names of required query parameters, simpler this way. this change also prepares for scylladb#2082. Refs scylladb#2082 Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
@amnonh hi Amnon, could you help review this change? |
amnonh
approved these changes
Feb 15, 2024
LGTM |
@scylladb/seastar-maint hello maintainers, could you help merge this change? |
graphcareful
pushed a commit
to graphcareful/seastar
that referenced
this pull request
Mar 20, 2024
…rom Kefu Chai this change refactors `seastar-json2code.py` by splitting `create_h_file()` into smaller pieces, and also reformats the rendered code with better formatting. Refs scylladb#2082 Closes scylladb#2090 * github.com:scylladb/seastar: seastar-json2code: collect required_query_params using a list seastar-json2code: reduce the indent level seastar-json2code: indent the enum and array elements seastar-json2code: generate code for enum type using Template seastar-json2code: extract add_operation() out
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this change refactors
seastar-json2code.py
by splittingcreate_h_file()
into smaller pieces, and also reformats the rendered code with better formatting.Refs #2082