From 80ad2b225050faabbac77f6410b010224bc10d28 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Thu, 16 Oct 2025 16:54:07 +0900 Subject: [PATCH 01/14] feat: improve output strings concatenated with & --- cobj/codegen.c | 63 ++++++++++++++++++++++++++++++++++++++++++-------- cobj/tree.c | 54 ++++++++++++++++++++++++++++++++++++++++++- cobj/tree.h | 23 +++++++++++++++++- 3 files changed, 128 insertions(+), 12 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index f0242a74..58405b86 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -79,6 +79,8 @@ static const char *excp_current_program_id = NULL; static const char *excp_current_section = NULL; static const char *excp_current_paragraph = NULL; static struct cb_program *current_prog; +static size_t *sgmt_sizes = NULL; +static size_t sgmt_count = 0; extern int cb_default_byte_specified; extern unsigned char cb_default_byte; @@ -463,6 +465,7 @@ struct string_literal_cache { enum cb_string_category category; char *var_name; struct string_literal_cache *next; + size_t *segment_sizes; /* segment sizes for strings concatenated with '&' */ }; int string_literal_id = 0; @@ -531,7 +534,8 @@ static enum cb_string_category get_string_category(const unsigned char *s, } static void joutput_string_write(const unsigned char *s, int size, - enum cb_string_category category) { + enum cb_string_category category, + size_t *tmp_sgmt_sizes) { int i; #ifdef I18N_UTF8 @@ -552,7 +556,11 @@ static void joutput_string_write(const unsigned char *s, int size, } else { joutput("CobolUtil.stringToBytes("); } - + if (tmp_sgmt_sizes) { + joutput_indent_level += 2; + joutput_newline(); + joutput_prefix(); + } joutput("\""); #ifdef I18N_UTF8 @@ -561,13 +569,17 @@ static void joutput_string_write(const unsigned char *s, int size, if (c == '\"' || c == '\\') { joutput("\\%c", c); } else if (c == '\n') { - joutput("\\n"); + joutput_line("\" + "); + joutput_prefix(); + joutput("\""); } else { joutput("%c", c); } } #else int output_multibyte = 0; + int sum_sgmt_size = 0; + int sgmt_index = 0; for (i = 0; i < size; i++) { int c = s[i]; if (!output_multibyte && (c == '\"' || c == '\\')) { @@ -577,10 +589,26 @@ static void joutput_string_write(const unsigned char *s, int size, } else { joutput("%c", c); } + // insert line breaks between segments concatenated with '&' + if (tmp_sgmt_sizes && i < size - 1) { + size_t segment_end_position = + sum_sgmt_size + tmp_sgmt_sizes[sgmt_index] - 1; + if (i == segment_end_position) { + joutput("\" + "); + joutput_newline(); + joutput_prefix(); + joutput("\""); + sum_sgmt_size += tmp_sgmt_sizes[sgmt_index]; + sgmt_index++; + } + } output_multibyte = !output_multibyte && ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xef)); } #endif + if (tmp_sgmt_sizes) { + joutput_indent_level -= 2; + } joutput("\")"); } else { if (param_wrap_string_flag) { @@ -631,6 +659,14 @@ static void joutput_string(const unsigned char *s, int size) { new_literal_cache->var_name[var_name_length + 1 + i] = '\0'; } + // set segment sizes to new cache + if (sgmt_sizes) { + new_literal_cache->segment_sizes = malloc(sizeof(size_t) * sgmt_count); + memcpy(new_literal_cache->segment_sizes, sgmt_sizes, + sizeof(size_t) * sgmt_count); + sgmt_sizes = NULL; + } + // add the new cache to string_literal_list new_literal_cache->next = string_literal_list; string_literal_list = new_literal_cache; @@ -658,7 +694,8 @@ static void joutput_all_string_literals() { joutput_prefix(); joutput("public static final %s %s = ", data_type, l->var_name); param_wrap_string_flag = l->param_wrap_string_flag; - joutput_string_write(l->string_value, l->size, l->category); + joutput_string_write(l->string_value, l->size, l->category, + l->segment_sizes); joutput(";\n"); l = l->next; } @@ -2280,6 +2317,13 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) { /* Initialize by value */ if (p->val && f->values) { cb_tree value = CB_VALUE(f->values); + struct cb_literal *l = CB_LITERAL_P(value) ? CB_LITERAL(value) : NULL; + // save the size information of '&' concatenated segments + if (l && l->segment_count > 0) { + sgmt_sizes = cobc_malloc(sizeof(size_t) * l->segment_count); + memcpy(sgmt_sizes, l->segment_sizes, sizeof(size_t) * l->segment_count); + sgmt_count = l->segment_count; + } /* NATIONAL also needs no editing but mbchar conversion. */ if (CB_TREE_CATEGORY(x) == CB_CATEGORY_NATIONAL) { @@ -2340,7 +2384,6 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) { /* We do not use joutput_move here because we do not want to have the value be edited. */ - struct cb_literal *l = CB_LITERAL(value); static char *buff = NULL; static int lastsize = 0; if (!buff) { @@ -4989,7 +5032,7 @@ static void *list_cache_sort(void *inlist, } /** - * メンバ変数の初期化を行うメソッドinitを出力する + * メンバ変数の初期化を行うメソ�?ドinitを�?�力す�? */ static void joutput_init_method(struct cb_program *prog) { struct literal_list *m; @@ -5014,7 +5057,7 @@ static void joutput_init_method(struct cb_program *prog) { joutput("\n"); } - /* CobolDataStorage型変数の初期化(定数) */ + /* CobolDataStorage型変数の初期�?(定数) */ if (base_cache) { joutput_line("/* Data storage */\n"); joutput_line("cob_unifunc = null;\n"); @@ -6200,7 +6243,7 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, /* Program local stuff */ - // コンストラクタの実装コードを出力 + // コンストラクタの実�?コードを出�? // メンバ変数の初期化を行う joutput_line("public %s()", prog->program_id); joutput_line("{"); @@ -6208,12 +6251,12 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, joutput_line("}"); joutput_newline(); - // メンバ変数の初期化メソッドを出力 + // メンバ変数の初期化メソ�?ドを出�? create_sorted_data_storage_cache(); joutput_init_method(prog); joutput_newline(); - // メンバ変数の出力 + // メンバ変数の出�? joutput_declare_member_variables(prog, prog->parameter_list); joutput("\n"); diff --git a/cobj/tree.c b/cobj/tree.c index 3bd85e75..372f4460 100644 --- a/cobj/tree.c +++ b/cobj/tree.c @@ -455,6 +455,32 @@ struct cb_literal *build_literal(enum cb_category category, return p; } +struct cb_literal *build_concat_literal(enum cb_category category, + const unsigned char *data, size_t size1, + size_t size2, size_t *sgmt_sizes, + size_t sgmt_count) { + struct cb_literal *p; + size_t size = size1 + size2; + p = make_tree(CB_TAG_LITERAL, category, sizeof(struct cb_literal)); + p->data = cobc_malloc((size_t)(size + 1)); + p->size = size; + memcpy(p->data, data, (size_t)size); + + // Set segment sizes + if (!sgmt_sizes) { + p->segment_sizes = cobc_malloc(sizeof(size_t) * 2); + p->segment_sizes[0] = size1; + sgmt_count = 1; + } else { + p->segment_sizes = cobc_malloc(sizeof(size_t) * (sgmt_count + 1)); + memcpy(p->segment_sizes, sgmt_sizes, sizeof(size_t) * sgmt_count); + } + memcpy(p->segment_sizes + sgmt_count, &size2, sizeof(size_t)); + p->segment_count = sgmt_count + 1; + + return p; +} + char *cb_name(cb_tree x) { if (!treenamebuff) { treenamebuff = cobc_malloc(COB_NORMAL_BUFF); @@ -1030,6 +1056,22 @@ cb_tree cb_build_national_literal(const unsigned char *data, size_t size) { return CB_TREE(build_literal(CB_CATEGORY_NATIONAL, data, size)); } +cb_tree cb_build_concat_alphanumeric_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count) { + return CB_TREE(build_concat_literal(CB_CATEGORY_ALPHANUMERIC, data, size1, + size2, sgmt_sizes, sgmt_count)); +} + +cb_tree cb_build_concat_national_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count) { + return CB_TREE(build_concat_literal(CB_CATEGORY_NATIONAL, data, size1, size2, + sgmt_sizes, sgmt_count)); +} + cb_tree cb_concat_literals(cb_tree x1, cb_tree x2) { unsigned char *buff; cb_tree x; @@ -1037,14 +1079,17 @@ cb_tree cb_concat_literals(cb_tree x1, cb_tree x2) { unsigned char *data2; size_t size1; size_t size2; + struct cb_literal *l; if (x1 == cb_error_node || x2 == cb_error_node) { return cb_error_node; } if (CB_LITERAL_P(x1)) { + l = CB_LITERAL(x1); data1 = CB_LITERAL(x1)->data; size1 = CB_LITERAL(x1)->size; } else if (CB_CONST_P(x1)) { + l = CB_LITERAL(x1); size1 = 1; if (x1 == cb_space) { data1 = (unsigned char *)" "; @@ -1090,8 +1135,15 @@ cb_tree cb_concat_literals(cb_tree x1, cb_tree x2) { buff = cobc_malloc(size1 + size2 + 3); memcpy(buff, data1, size1); memcpy(buff + size1, data2, size2); - x = cb_build_alphanumeric_literal(buff, size1 + size2); + if (x1->category == CB_CATEGORY_NATIONAL) { + x = cb_build_concat_national_literal(buff, size1, size2, l->segment_sizes, + l->segment_count); + } else { + x = cb_build_concat_alphanumeric_literal( + buff, size1, size2, l->segment_sizes, l->segment_count); + } free(buff); + return x; } diff --git a/cobj/tree.h b/cobj/tree.h index 167c76b7..c26d45a1 100644 --- a/cobj/tree.h +++ b/cobj/tree.h @@ -467,9 +467,17 @@ extern cb_tree cb_build_system_name(enum cb_system_name_category category, * Literal */ +struct cb_literal_segment { + size_t size; + unsigned char *data; + struct cb_literal_segment *next; +}; + struct cb_literal { struct cb_tree_common common; size_t size; + size_t *segment_sizes; /* segment sizes for strings concatenated with '&' */ + size_t segment_count; unsigned char *data; signed char all; signed char sign; /* unsigned: 0 negative: -1 positive: 1 */ @@ -489,6 +497,14 @@ extern cb_tree cb_build_alphanumeric_literal(const unsigned char *data, extern cb_tree cb_build_national_literal(const unsigned char *data, size_t size); extern cb_tree cb_concat_literals(cb_tree x1, cb_tree x2); +extern cb_tree cb_build_concat_alphanumeric_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count); +extern cb_tree cb_build_concat_national_literal(const unsigned char *data, + size_t size1, size_t size2, + size_t *sgmt_sizes, + size_t sgmt_count); /* * Decimal @@ -566,7 +582,7 @@ struct cb_field { cb_tree key; /* KEY */ cb_tree ref; /* reference used in SEARCH ALL */ cb_tree val; /* value to be compared in SEARCH ALL */ - } *keys; + } * keys; int nkeys; /* the number of keys */ int param_num; /* CHAINING param number */ struct cb_picture *pic; /* PICTURE */ @@ -606,6 +622,7 @@ struct cb_field { unsigned int flag_is_pdiv_parm : 1; /* is PROC DIV USING */ unsigned int flag_local_alloced : 1; /* LOCAL storage is allocated */ unsigned int flag_no_init : 1; /* no initialize unless used */ + // unsigned int flag_sql_str : 1; /* is SQL string */ unsigned int flag_spare : 5; }; @@ -1438,6 +1455,10 @@ extern void level_except_error(cb_tree x, const char *clause); struct cb_literal *build_literal(enum cb_category category, const unsigned char *data, size_t size); +struct cb_literal *build_concat_literal(enum cb_category category, + const unsigned char *data, size_t size1, + size_t size2, size_t *sgmt_sizes, + size_t sgmt_count); /* field.c */ extern size_t cb_needs_01; From 1455b1796a6df8602c0ed64cb665500b657df613 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Thu, 16 Oct 2025 17:15:46 +0900 Subject: [PATCH 02/14] fix: Minor bug fix --- cobj/codegen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cobj/codegen.c b/cobj/codegen.c index 58405b86..b0dd439b 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -589,6 +589,7 @@ static void joutput_string_write(const unsigned char *s, int size, } else { joutput("%c", c); } + // insert line breaks between segments concatenated with '&' if (tmp_sgmt_sizes && i < size - 1) { size_t segment_end_position = From a9dc37f091afe82c7cdbeb6775a220b3a777e41c Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Thu, 16 Oct 2025 17:20:04 +0900 Subject: [PATCH 03/14] fix: Minor bug fix --- cobj/codegen.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index b0dd439b..6c019bff 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -569,9 +569,7 @@ static void joutput_string_write(const unsigned char *s, int size, if (c == '\"' || c == '\\') { joutput("\\%c", c); } else if (c == '\n') { - joutput_line("\" + "); - joutput_prefix(); - joutput("\""); + joutput("\\n"); } else { joutput("%c", c); } @@ -5033,7 +5031,7 @@ static void *list_cache_sort(void *inlist, } /** - * メンバ変数の初期化を行うメソ�?ドinitを�?�力す�? + * メンバ変数の初期化を行うメソッドinitを出力する */ static void joutput_init_method(struct cb_program *prog) { struct literal_list *m; @@ -5058,7 +5056,7 @@ static void joutput_init_method(struct cb_program *prog) { joutput("\n"); } - /* CobolDataStorage型変数の初期�?(定数) */ + /* CobolDataStorage型変数の初期化(定数) */ if (base_cache) { joutput_line("/* Data storage */\n"); joutput_line("cob_unifunc = null;\n"); @@ -6244,7 +6242,7 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, /* Program local stuff */ - // コンストラクタの実�?コードを出�? + // コンストラクタの実装コードを出力 // メンバ変数の初期化を行う joutput_line("public %s()", prog->program_id); joutput_line("{"); @@ -6252,12 +6250,12 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list, joutput_line("}"); joutput_newline(); - // メンバ変数の初期化メソ�?ドを出�? + // メンバ変数の初期化メソッドを出力 create_sorted_data_storage_cache(); joutput_init_method(prog); joutput_newline(); - // メンバ変数の出�? + // メンバ変数の出力 joutput_declare_member_variables(prog, prog->parameter_list); joutput("\n"); From 1507c5b1522bba37449b23a8c459b0441a2b5866 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Fri, 17 Oct 2025 11:13:20 +0900 Subject: [PATCH 04/14] fix: bugfix for memory access error --- cobj/codegen.c | 2 ++ cobj/tree.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index 6c019bff..ec5cf71a 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -664,6 +664,8 @@ static void joutput_string(const unsigned char *s, int size) { memcpy(new_literal_cache->segment_sizes, sgmt_sizes, sizeof(size_t) * sgmt_count); sgmt_sizes = NULL; + } else { + new_literal_cache->segment_sizes = NULL; } // add the new cache to string_literal_list diff --git a/cobj/tree.c b/cobj/tree.c index 372f4460..54efee20 100644 --- a/cobj/tree.c +++ b/cobj/tree.c @@ -466,7 +466,7 @@ struct cb_literal *build_concat_literal(enum cb_category category, p->size = size; memcpy(p->data, data, (size_t)size); - // Set segment sizes + // set segment sizes if (!sgmt_sizes) { p->segment_sizes = cobc_malloc(sizeof(size_t) * 2); p->segment_sizes[0] = size1; From a2db4c183dfc05567efa8c6abae7aac1214d8ba2 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Fri, 17 Oct 2025 15:07:18 +0900 Subject: [PATCH 05/14] fix: remove unneccessary code --- cobj/tree.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cobj/tree.h b/cobj/tree.h index c26d45a1..c652cd63 100644 --- a/cobj/tree.h +++ b/cobj/tree.h @@ -582,7 +582,7 @@ struct cb_field { cb_tree key; /* KEY */ cb_tree ref; /* reference used in SEARCH ALL */ cb_tree val; /* value to be compared in SEARCH ALL */ - } * keys; + } *keys; int nkeys; /* the number of keys */ int param_num; /* CHAINING param number */ struct cb_picture *pic; /* PICTURE */ @@ -622,7 +622,6 @@ struct cb_field { unsigned int flag_is_pdiv_parm : 1; /* is PROC DIV USING */ unsigned int flag_local_alloced : 1; /* LOCAL storage is allocated */ unsigned int flag_no_init : 1; /* no initialize unless used */ - // unsigned int flag_sql_str : 1; /* is SQL string */ unsigned int flag_spare : 5; }; From 5b59277a1fc4370a03c507a2c323f93c2d6bf95c Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Fri, 17 Oct 2025 15:26:43 +0900 Subject: [PATCH 06/14] style: minor refactoring --- cobj/codegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index ec5cf71a..ffd24bb0 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -535,7 +535,7 @@ static enum cb_string_category get_string_category(const unsigned char *s, static void joutput_string_write(const unsigned char *s, int size, enum cb_string_category category, - size_t *tmp_sgmt_sizes) { + const size_t *tmp_sgmt_sizes) { int i; #ifdef I18N_UTF8 From 81b173994a8f7164a4ec284a646dd96566942bde Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Mon, 20 Oct 2025 11:47:40 +0900 Subject: [PATCH 07/14] test add a test --- cobj/codegen.c | 9 +++++++-- tests/Makefile.am | 3 ++- tests/Makefile.in | 3 ++- tests/misc.at | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index ffd24bb0..2e7d9e45 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -606,9 +606,14 @@ static void joutput_string_write(const unsigned char *s, int size, } #endif if (tmp_sgmt_sizes) { + joutput("\""); + joutput_newline(); joutput_indent_level -= 2; + joutput_prefix(); + joutput(")"); + } else { + joutput("\")"); } - joutput("\")"); } else { if (param_wrap_string_flag) { joutput("CobolDataStorage.makeCobolDataStorage("); @@ -2550,7 +2555,7 @@ static void joutput_initialize_compound(struct cb_initialize *p, cb_tree x) { } else { size = ff->offset + ff->size - last_field->offset; } - + joutput_initialize_uniform(c, last_char, (int)size); break; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 0006440a..9e3053e1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -262,7 +262,8 @@ misc_DEPENDENCIES = \ misc.src/display-numeric-NUMERIC-class.at \ misc.src/display-inspect-sign.at \ misc.src/comp1-comp2.at \ - misc.src/variable-length-file.at + misc.src/variable-length-file.at \ + misc.src/convert-string-concat.at \ EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ diff --git a/tests/Makefile.in b/tests/Makefile.in index a37c42d2..fc0413a9 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -801,7 +801,8 @@ misc_DEPENDENCIES = \ misc.src/display-numeric-NUMERIC-class.at \ misc.src/display-inspect-sign.at \ misc.src/comp1-comp2.at \ - misc.src/variable-length-file.at + misc.src/variable-length-file.at \ + misc.src/convert-string-concat.at \ EXTRA_DIST = $(srcdir)/package.m4 \ $(TESTS) \ diff --git a/tests/misc.at b/tests/misc.at index af958f71..1db81ab4 100644 --- a/tests/misc.at +++ b/tests/misc.at @@ -57,3 +57,4 @@ m4_include([display-numeric-NUMERIC-class.at]) m4_include([display-inspect-sign.at]) m4_include([comp1-comp2.at]) m4_include([variable-length-file.at]) +m4_include([convert-string-concat.at]) From 555333c48708696808bd3941bf9762f23f97bf7d Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Mon, 20 Oct 2025 11:50:28 +0900 Subject: [PATCH 08/14] test: add a test --- tests/misc.src/convert-string-concat.at | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/misc.src/convert-string-concat.at diff --git a/tests/misc.src/convert-string-concat.at b/tests/misc.src/convert-string-concat.at new file mode 100644 index 00000000..89cb48bd --- /dev/null +++ b/tests/misc.src/convert-string-concat.at @@ -0,0 +1,40 @@ +AT_SETUP([convert '&' concatenated strings to Java]) + +AT_DATA([prog.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X-CONCAT PIC X(25) VALUE "abcde" + & "fghij" + & "klmno" + & "pqrst" + & "uvwxy". + 01 N-CONCAT PIC N(25) VALUE "" + & "" + & "" + & "‚Ă" + & "Ȃɂʂ˂". + PROCEDURE DIVISION. + MAIN-RTN. + DISPLAY X-CONCAT. + DISPLAY N-CONCAT. + STOP RUN. +]) + +AT_CHECK([${COMPILE} prog.cbl]) +AT_CHECK([java prog], [0], +[abcdefghijklmnopqrstuvwxy +‚ĂƂȂɂʂ˂ +]) +AT_CHECK([grep -q ' \"\" +' prog.java]) +AT_CHECK([grep -q ' \"\" +' prog.java]) +AT_CHECK([grep -q ' \"\" +' prog.java]) +AT_CHECK([grep -q ' \"‚Ă\" +' prog.java]) +AT_CHECK([grep -q ' \"Ȃɂʂ˂\"' prog.java]) +AT_CHECK([grep -q ' \"abcde\" +' prog.java]) +AT_CHECK([grep -q ' \"fghij\" +' prog.java]) +AT_CHECK([grep -q ' \"klmno\" +' prog.java]) +AT_CHECK([grep -q ' \"pqrst\" +' prog.java]) +AT_CHECK([grep -q ' \"uvwxy\"' prog.java]) +AT_CLEANUP From c5f2199206434186fdd781a9a9c9be11bda04bfa Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Mon, 20 Oct 2025 11:55:24 +0900 Subject: [PATCH 09/14] style: format --- cobj/codegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index 2e7d9e45..1cae8639 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -2555,7 +2555,7 @@ static void joutput_initialize_compound(struct cb_initialize *p, cb_tree x) { } else { size = ff->offset + ff->size - last_field->offset; } - + joutput_initialize_uniform(c, last_char, (int)size); break; } From d0af46617f037cc8b69ca2e85fb296a9e5ca5cf5 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Mon, 20 Oct 2025 12:57:48 +0900 Subject: [PATCH 10/14] test: minor fix for added test --- tests/misc.src/convert-string-concat.at | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/misc.src/convert-string-concat.at b/tests/misc.src/convert-string-concat.at index 89cb48bd..84f34d3f 100644 --- a/tests/misc.src/convert-string-concat.at +++ b/tests/misc.src/convert-string-concat.at @@ -27,14 +27,14 @@ AT_CHECK([java prog], [0], [abcdefghijklmnopqrstuvwxy ‚ĂƂȂɂʂ˂ ]) -AT_CHECK([grep -q ' \"\" +' prog.java]) -AT_CHECK([grep -q ' \"\" +' prog.java]) -AT_CHECK([grep -q ' \"\" +' prog.java]) -AT_CHECK([grep -q ' \"‚Ă\" +' prog.java]) -AT_CHECK([grep -q ' \"Ȃɂʂ˂\"' prog.java]) AT_CHECK([grep -q ' \"abcde\" +' prog.java]) AT_CHECK([grep -q ' \"fghij\" +' prog.java]) AT_CHECK([grep -q ' \"klmno\" +' prog.java]) AT_CHECK([grep -q ' \"pqrst\" +' prog.java]) AT_CHECK([grep -q ' \"uvwxy\"' prog.java]) +AT_CHECK([grep -q ' \"\" +' prog.java]) +AT_CHECK([grep -q ' \"\" +' prog.java]) +AT_CHECK([grep -q ' \"\" +' prog.java]) +AT_CHECK([grep -q ' \"‚Ă\" +' prog.java]) +AT_CHECK([grep -q ' \"Ȃɂʂ˂\"' prog.java]) AT_CLEANUP From d0e6aa652c6eac19064c4ce17229479087acd0b6 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Tue, 21 Oct 2025 10:41:43 +0900 Subject: [PATCH 11/14] refactor: minor refactor for handling &-concatinated strings --- cobj/codegen.c | 2 +- cobj/tree.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index 1cae8639..8770cc13 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -665,7 +665,7 @@ static void joutput_string(const unsigned char *s, int size) { // set segment sizes to new cache if (sgmt_sizes) { - new_literal_cache->segment_sizes = malloc(sizeof(size_t) * sgmt_count); + new_literal_cache->segment_sizes = cobc_malloc(sizeof(size_t) * sgmt_count); memcpy(new_literal_cache->segment_sizes, sgmt_sizes, sizeof(size_t) * sgmt_count); sgmt_sizes = NULL; diff --git a/cobj/tree.c b/cobj/tree.c index 54efee20..44471e8e 100644 --- a/cobj/tree.c +++ b/cobj/tree.c @@ -470,7 +470,6 @@ struct cb_literal *build_concat_literal(enum cb_category category, if (!sgmt_sizes) { p->segment_sizes = cobc_malloc(sizeof(size_t) * 2); p->segment_sizes[0] = size1; - sgmt_count = 1; } else { p->segment_sizes = cobc_malloc(sizeof(size_t) * (sgmt_count + 1)); memcpy(p->segment_sizes, sgmt_sizes, sizeof(size_t) * sgmt_count); @@ -1135,6 +1134,9 @@ cb_tree cb_concat_literals(cb_tree x1, cb_tree x2) { buff = cobc_malloc(size1 + size2 + 3); memcpy(buff, data1, size1); memcpy(buff + size1, data2, size2); + if (!l->segment_count) { + l->segment_count = 1; + } if (x1->category == CB_CATEGORY_NATIONAL) { x = cb_build_concat_national_literal(buff, size1, size2, l->segment_sizes, l->segment_count); From fbab533de693d29afcd6b5bb1415bf6d48f0e381 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Tue, 21 Oct 2025 11:42:56 +0900 Subject: [PATCH 12/14] fix: fix warning of a test script for &-concatenated strings --- tests/misc.src/convert-string-concat.at | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/misc.src/convert-string-concat.at b/tests/misc.src/convert-string-concat.at index 84f34d3f..44926293 100644 --- a/tests/misc.src/convert-string-concat.at +++ b/tests/misc.src/convert-string-concat.at @@ -27,14 +27,14 @@ AT_CHECK([java prog], [0], [abcdefghijklmnopqrstuvwxy ‚ĂƂȂɂʂ˂ ]) -AT_CHECK([grep -q ' \"abcde\" +' prog.java]) -AT_CHECK([grep -q ' \"fghij\" +' prog.java]) -AT_CHECK([grep -q ' \"klmno\" +' prog.java]) -AT_CHECK([grep -q ' \"pqrst\" +' prog.java]) -AT_CHECK([grep -q ' \"uvwxy\"' prog.java]) -AT_CHECK([grep -q ' \"\" +' prog.java]) -AT_CHECK([grep -q ' \"\" +' prog.java]) -AT_CHECK([grep -q ' \"\" +' prog.java]) -AT_CHECK([grep -q ' \"‚Ă\" +' prog.java]) -AT_CHECK([grep -q ' \"Ȃɂʂ˂\"' prog.java]) +AT_CHECK([grep -q ' "abcde" +' prog.java]) +AT_CHECK([grep -q ' "fghij" +' prog.java]) +AT_CHECK([grep -q ' "klmno" +' prog.java]) +AT_CHECK([grep -q ' "pqrst" +' prog.java]) +AT_CHECK([grep -q ' "uvwxy"' prog.java]) +AT_CHECK([grep -q ' "" +' prog.java]) +AT_CHECK([grep -q ' "" +' prog.java]) +AT_CHECK([grep -q ' "" +' prog.java]) +AT_CHECK([grep -q ' "‚Ă" +' prog.java]) +AT_CHECK([grep -q ' "Ȃɂʂ˂"' prog.java]) AT_CLEANUP From 721e8e4cf556bbffbd5807899ff52bee2a8dbd3a Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Thu, 23 Oct 2025 17:03:26 +0900 Subject: [PATCH 13/14] refactor: minor refactoring for &-concatenated strings --- cobj/cobj.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cobj/cobj.c b/cobj/cobj.c index 78a5c1c4..7a5c73b7 100644 --- a/cobj/cobj.c +++ b/cobj/cobj.c @@ -1817,6 +1817,7 @@ static void package_name_to_path(char *buff, char *package_name) { *b_p = *p_p; } } + *b_p = '\0'; } static int process_compile(struct filename *fn) { From 1ed9330806bdd4e227415a594cb2654ca64bc738 Mon Sep 17 00:00:00 2001 From: Kio Watanabe Date: Thu, 23 Oct 2025 17:46:28 +0900 Subject: [PATCH 14/14] refactor: minor refactoring for &-concatenated strings --- cobj/cobj.c | 1 - cobj/tree.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cobj/cobj.c b/cobj/cobj.c index 7a5c73b7..78a5c1c4 100644 --- a/cobj/cobj.c +++ b/cobj/cobj.c @@ -1817,7 +1817,6 @@ static void package_name_to_path(char *buff, char *package_name) { *b_p = *p_p; } } - *b_p = '\0'; } static int process_compile(struct filename *fn) { diff --git a/cobj/tree.c b/cobj/tree.c index 44471e8e..d0462bb3 100644 --- a/cobj/tree.c +++ b/cobj/tree.c @@ -474,7 +474,7 @@ struct cb_literal *build_concat_literal(enum cb_category category, p->segment_sizes = cobc_malloc(sizeof(size_t) * (sgmt_count + 1)); memcpy(p->segment_sizes, sgmt_sizes, sizeof(size_t) * sgmt_count); } - memcpy(p->segment_sizes + sgmt_count, &size2, sizeof(size_t)); + p->segment_sizes[sgmt_count] = size2; p->segment_count = sgmt_count + 1; return p;