-
Notifications
You must be signed in to change notification settings - Fork 38
Improve Java code output for string literals concatenated with '&' #731
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
Improve Java code output for string literals concatenated with '&' #731
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Improves Java code output formatting for COBOL string literals concatenated with '&' by preserving the original segment structure and adding appropriate line breaks in the generated code. This change enhances readability when SQL statements and other multi-line strings are converted from COBOL to Java.
- Modified literal handling structures to track segment sizes and counts for concatenated strings
- Updated code generation to output each segment on a separate line with proper indentation
- Added comprehensive tests to verify the formatting improvements
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/misc.src/convert-string-concat.at | New test file verifying Java output formatting for '&'-concatenated strings |
| tests/misc.at | Includes the new test file in the test suite |
| tests/Makefile.in | Updates build configuration to include the new test |
| tests/Makefile.am | Updates automake configuration to include the new test |
| cobj/tree.h | Adds segment tracking fields to cb_literal struct and new function declarations |
| cobj/tree.c | Implements segment tracking logic and new concatenation functions |
| cobj/codegen.c | Updates Java code generation to format concatenated strings with line breaks |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
@yutaro-sakamoto |
Overview
&delimiter when string literals are concatenated with&in the COBOL program.&-concatenated strings in the generated Java code.Details
Improvement of Generated Java Code for &-Concatenated String Literals
struct cb_literal_segment:size_t *segment_sizes: Stores the length of each segment in the&-concatenated string. For example, for"abcde" & "fghijkl" & "mno", it holds{5, 7, 3}.size_t segment_count: Stores the number of segments in the&-concatenated string. For example, for"ab" & "cd" & "ef", it holds3.size_t *segment_sizestostruct string_literal_cache. Its purpose is the same as instruct cb_literal_segment.tree.ccb_tree cb_concat_literalsfunction:cb_build_alphanumeric_literalto call the newly added functionscb_build_concat_alphanumeric_literalorcb_build_concat_national_literalinstead.cb_tree cb_build_concat_alphanumeric_literalandcb_tree cb_build_concat_national_literalfunctions:build_concat_literalfunction.cb_literal *build_concat_literalfunction:build_literalfunction by adding logic to populatesegment_sizes(with segment lengths) andsegment_count(with the number of segments).codegen.csize_t *sgmt_sizesandsize_t sgmt_count:static void joutput_initialize_onefunction to temporarily storesegment_sizesandsegment_count.static void joutput_stringfunction:size_t *sgmt_sizesandsize_t sgmt_countand stores them innew_literal_cache->segment_sizes. Thisnew_literal_cache->segment_sizesis then passed as an argument to thestatic void joutput_string_writefunction.static void joutput_string_writefunction:size_t *tmp_sgmt_sizesas an argument.size_t *tmp_sgmt_sizesis notNULL, it outputs line breaks in the Java code according to the string lengths stored insize_t *tmp_sgmt_sizes.Test Addition
convert-string-concat.attomisc.srcPIC XandPIC Nthat have&-concatenated strings in theirVALUEclause.Operation Check with Open COBOL ESQL4J Integration