From 6760a54c9f3e96f5794f02d808867acb1bc1c24f Mon Sep 17 00:00:00 2001 From: engboris Date: Thu, 25 Apr 2024 19:15:43 +0200 Subject: [PATCH 1/9] Add >>IMP INCLUDE directive --- NEWS | 3 ++ cobc/ChangeLog | 12 ++++++ cobc/cobc.h | 3 +- cobc/codegen.c | 21 +++++++-- cobc/pplex.l | 16 +++++++ cobc/ppparse.y | 28 ++++++++++++ cobc/scanner.l | 26 +++++++++++ doc/gnucobol.texi | 2 + tests/testsuite.src/syn_misc.at | 64 ++++++++++++++++++++++++++++ tests/testsuite.src/used_binaries.at | 16 ++++++- 10 files changed, 185 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 97f62186c..54c2ac622 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,9 @@ NEWS - user visible changes -*- outline -*- calls to externals. The files are put into quotes, unless they start by '<'. Quoted files are expected to have absolute paths, as the C compiler is called in a temp directory instead of the project directory. + The directive >>IMP INCLUDE "file.h", >>IMP INCLUDE "", + >>IMP INCLUDE or >>IMP INCLUDE file.h can be used as an alternative + to this compiler option. ** output of unlimited errors may be requested by -fmax-errors=0, to stop compiliation at first error use -Wfatal-errors diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 7b55fddf3..33bd27c0d 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -28,6 +28,12 @@ compiler aborts on broken expressions, bugs #933, #938 and #966 * typeck.c: minor refactoring within functions +2024-04-25 Boris Eng + + * cobc.h, pplex.l, ppparse.y: new >>IMP INCLUDE directive to include + multiple header files in the C generated code. Has the same behavior as the + --include compiler option. + 2024-04-24 Fabrice Le Fessant * replace.c: optimize speed and memory usage. For speed, we add two @@ -38,6 +44,12 @@ replace stream) and we use a circular buffer for the temporary queue of tokens instead of a list. +2024-04-25 Boris Eng + + * pplex.l, ppparse.y, scanner.l, cobc.h, codegen.c: + new >>IMP INCLUDE directive to include one or multiple header files in + the generated C code (same behavior as the --include compiler option) + 2024-03-17 Fabrice Le Fessant Emilien Lemaire diff --git a/cobc/cobc.h b/cobc/cobc.h index 822f7381e..15d8463a3 100644 --- a/cobc/cobc.h +++ b/cobc/cobc.h @@ -276,7 +276,7 @@ enum cb_sub_check { struct cb_text_list { struct cb_text_list *next; /* next pointer */ struct cb_text_list *last; - const char *text; + char *text; }; /* Structure for extended filenames */ @@ -477,6 +477,7 @@ extern struct cb_text_list *cb_depend_list; extern struct cb_text_list *cb_copy_list; extern struct cb_text_list *cb_include_file_list; extern struct cb_text_list *cb_include_list; +extern struct cb_text_list *cb_include_file_list_directive; extern struct cb_text_list *cb_intrinsic_list; extern struct cb_text_list *cb_extension_list; extern struct cb_text_list *cb_static_call_list; diff --git a/cobc/codegen.c b/cobc/codegen.c index a9ba045b0..a99bbbba0 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -1830,16 +1830,29 @@ output_gnucobol_defines (const char *formatted_date) output_line ("#define COB_MODULE_TIME\t\t%d", i); { - struct cb_text_list *l = cb_include_file_list ; - for (;l;l=l->next){ - if (l->text[0] == '<'){ + struct cb_text_list *l; + struct cb_text_list *last = NULL; + for (l = cb_include_file_list; l; l = l->next) { + if (l->text[0] == '<') { output_line ("#include %s", l->text); } else { output_line ("#include \"%s\"", l->text); } } - } + for (l = cb_include_file_list_directive; l; l = l->next) { + if (last != NULL) { + cobc_free (last->text); + cobc_free (last); + } + last = l; + if (l->text[0] == '<') { + output_line ("#include %s", l->text); + } else { + output_line ("#include \"%s\"", l->text); + } + } + } } /* CALL cache */ diff --git a/cobc/pplex.l b/cobc/pplex.l index 02bb2640c..ada22042c 100644 --- a/cobc/pplex.l +++ b/cobc/pplex.l @@ -204,6 +204,7 @@ ALNUM_LITERAL_A "\'"([^''\n]|("\'"[0-9][0-9, ]+"\'"))*"\'" ALNUM_LITERAL {ALNUM_LITERAL_Q}|{ALNUM_LITERAL_A} SET_PAREN_LIT \([^()\n]*\) DEFNUM_LITERAL [+-]?[0-9]*[\.]*[0-9]+ +RAW_SEQ [^ \n]+ AREA_A [ ]?# MAYBE_AREA_A [ ]?#? @@ -227,6 +228,7 @@ MAYBE_AREA_A [ ]?#? %x ALNUM_LITERAL_STATE %x CONTROL_STATEMENT_STATE %x DISPLAY_DIRECTIVE_STATE +%x IMP_DIRECTIVE_STATE %% @@ -360,6 +362,11 @@ MAYBE_AREA_A [ ]?#? return CALL_DIRECTIVE; } +^{MAYBE_AREA_A}[ ]*">>"[ ]?"IMP" { + BEGIN IMP_DIRECTIVE_STATE; + return IMP_DIRECTIVE; +} + ^{MAYBE_AREA_A}[ ]*">>"[ ]*\n { /* empty 2002+ style directive */ cb_plex_warning (COBC_WARN_FILLER, newline_count, @@ -724,6 +731,7 @@ ELSE_DIRECTIVE_STATE, ENDIF_DIRECTIVE_STATE, ALNUM_LITERAL_STATE, CONTROL_STATEMENT_STATE, +IMP_DIRECTIVE_STATE, COBOL_WORDS_DIRECTIVE_STATE>{ \n { BEGIN INITIAL; @@ -993,6 +1001,14 @@ ENDIF_DIRECTIVE_STATE>{ } } +{ + "INCLUDE" { return INCLUDE; } /* GnuCOBOL 3.3 extension */ + {RAW_SEQ} { + pplval.s = cobc_plex_strdup (yytext); + return TOKEN; + } +} + { "IS" { return IS; } "NOT" { return NOT; } diff --git a/cobc/ppparse.y b/cobc/ppparse.y index 76b3c9a58..267044679 100644 --- a/cobc/ppparse.y +++ b/cobc/ppparse.y @@ -741,6 +741,9 @@ ppparse_clear_vars (const struct cb_define_struct *p) %token WITH %token LOCATION +%token IMP_DIRECTIVE +%token INCLUDE + %token TERMINATOR "end of line" %token TOKEN "Word or Literal" @@ -768,6 +771,7 @@ ppparse_clear_vars (const struct cb_define_struct *p) %type alnum_equality_list %type ec_list %type unquoted_literal +%type imp_include_sources %type _copy_replacing %type replacing_list @@ -838,6 +842,7 @@ directive: | TURN_DIRECTIVE turn_directive | LISTING_DIRECTIVE listing_directive | LEAP_SECOND_DIRECTIVE leap_second_directive +| IMP_DIRECTIVE imp_directive | IF_DIRECTIVE { current_cmd = PLEX_ACT_IF; @@ -1368,6 +1373,29 @@ leap_second_directive: | OFF ; +imp_directive: + /* GnuCOBOL 3.3 extension */ + INCLUDE imp_include_sources + { + struct cb_text_list *p = $2; + while (p != NULL) { + fprintf (ppout, "#INCLUDE %s\n", p->text); + p = p->next; + } + } +; + +imp_include_sources: + TOKEN + { + $$ = ppp_list_add (NULL, fix_filename ($1)); + } +| imp_include_sources TOKEN + { + $$ = ppp_list_add ($1, fix_filename ($2)); + } +; + turn_directive: ec_list CHECKING on_or_off { diff --git a/cobc/scanner.l b/cobc/scanner.l index 15f3d1871..034ac42b6 100644 --- a/cobc/scanner.l +++ b/cobc/scanner.l @@ -175,6 +175,8 @@ static size_t pic2_size; static unsigned int inside_bracket = 0; static char err_msg[COB_MINI_BUFF]; +struct cb_text_list *cb_include_file_list_directive = NULL; + /* Function declarations */ static void read_literal (const char, const enum cb_literal_type); static int scan_x (const char *, const char *); @@ -192,6 +194,7 @@ static void copy_two_words_in_quotes (char ** const, char ** const); static void add_synonym (const int, const int); static void make_synonym (void); static void clear_constants (void); +static struct cb_text_list *scan_list_add (struct cb_text_list *, const char *); %} @@ -323,6 +326,13 @@ AREA_A "#AREA_A"\n cobc_areacheck = 0; } +<*>^[ ]?"#INCLUDE".*/\n { + cb_include_file_list_directive = scan_list_add ( + cb_include_file_list_directive, + yytext + 9 + ); +} + <*>^{AREA_A}[ ]*/"." { count_lines (yytext + 9); /* skip "\n#area_a\n" */ if (cobc_in_procedure && cobc_areacheck) { @@ -2583,6 +2593,22 @@ clear_constants (void) top_78_ptr = NULL; } +static struct cb_text_list * +scan_list_add (struct cb_text_list *list, const char *text) +{ + struct cb_text_list *p; + + p = cobc_malloc (sizeof (struct cb_text_list)); + p->text = cobc_strdup (text); + if (!list) { + p->last = p; + return p; + } + list->last->next = p; + list->last = p; + return list; +} + /* Global functions */ void diff --git a/doc/gnucobol.texi b/doc/gnucobol.texi index af4eb9fd2..dea8111ae 100644 --- a/doc/gnucobol.texi +++ b/doc/gnucobol.texi @@ -383,6 +383,8 @@ Add a @code{#include} @file{file.h} at the beginning of the generated C source file. The file name is put into quotes, unless it starts by @code{<}. Quoted files should be absolute paths, since C files are compiled in temporary directories. +The directive @code{>>IMP INCLUDE "FILE.h"} or @code{>>IMP INCLUDE } +can be used as an alternative to this compiler option. The option also implies @option{-fno-gen-c-decl-static-call}. This option can be used to check function prototypes when static calls are used. When this option is used, the source file is diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index c3c7091f7..aa69e32ab 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -8405,3 +8405,67 @@ prog.cob:18: error: ANY LENGTH items may only be BY REFERENCE formal parameters AT_CLEANUP + +AT_SETUP([IMP INCLUDE directive]) +AT_KEYWORDS([IMP INCLUDE]) + +AT_DATA([prog.cob], [ + >>IMP INCLUDE "file.h" + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + GOBACK. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [0], [], []) + +AT_DATA([prog.cob], [ +>>IMP INCLUDE "file.h" +identification division. +program-id. prog. +procedure division. + goback. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=free prog.cob], [0], [], []) + +AT_DATA([prog.cob], [ + >>IMP INCLUDE + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + GOBACK. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [0], [], []) + +AT_DATA([prog.cob], [ + >>IMP INCLUDE + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + GOBACK. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [1], [], +[prog.cob:2: error: syntax error, unexpected end of line, expecting Word or Literal +prog.cob:2: error: PROGRAM-ID header missing +]) + +AT_CLEANUP + + +AT_SETUP([IMP INCLUDE directive multiple files]) +AT_KEYWORDS([IMP INCLUDE]) + +AT_DATA([prog.cob], [ +>>IMP INCLUDE "file1.h" file2.h "" +identification division. +program-id. prog. +procedure division. + goback. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=free prog.cob], [0], [], []) + +AT_CLEANUP diff --git a/tests/testsuite.src/used_binaries.at b/tests/testsuite.src/used_binaries.at index 50d8a1867..7e71e0f76 100644 --- a/tests/testsuite.src/used_binaries.at +++ b/tests/testsuite.src/used_binaries.at @@ -1095,7 +1095,7 @@ AT_CLEANUP AT_SETUP([check include header file]) -#AT_KEYWORDS([cobc copy]) +#AT_KEYWORDS([cobc copy include imp]) AT_DATA([filec.h], [ /* COB_EXT_IMPORT will be defined by libcob.h up-front */ @@ -1171,4 +1171,18 @@ AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call prog2.co AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call -L. -lfilec prog2.cob -o prog2c], [0], ignore, ignore)] ) +AT_DATA([prog3.cob], [ + >> IMP INCLUDE "file.h" + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 long USAGE BINARY-C-LONG. + PROCEDURE DIVISION. + CALL "f" USING "Hello" BY VALUE long RETURNING NOTHING. +]) + +# static build with correct function signature +# AT_CHECK([$COBC -m -I . -fstatic-call prog3.cob], [0], [], []) + AT_CLEANUP From cd6cbfcc7aee9a133103ce113cd8e8a57903e5db Mon Sep 17 00:00:00 2001 From: engboris Date: Thu, 25 Apr 2024 19:15:43 +0200 Subject: [PATCH 2/9] Add >>IMP INCLUDE directive --- NEWS | 3 ++ cobc/ChangeLog | 12 ++++++ cobc/cobc.h | 3 +- cobc/codegen.c | 21 +++++++-- cobc/pplex.l | 16 +++++++ cobc/ppparse.y | 28 ++++++++++++ cobc/scanner.l | 26 +++++++++++ doc/gnucobol.texi | 2 + tests/testsuite.src/syn_misc.at | 64 ++++++++++++++++++++++++++++ tests/testsuite.src/used_binaries.at | 16 ++++++- 10 files changed, 185 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 97f62186c..54c2ac622 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,9 @@ NEWS - user visible changes -*- outline -*- calls to externals. The files are put into quotes, unless they start by '<'. Quoted files are expected to have absolute paths, as the C compiler is called in a temp directory instead of the project directory. + The directive >>IMP INCLUDE "file.h", >>IMP INCLUDE "", + >>IMP INCLUDE or >>IMP INCLUDE file.h can be used as an alternative + to this compiler option. ** output of unlimited errors may be requested by -fmax-errors=0, to stop compiliation at first error use -Wfatal-errors diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 50fbd7507..41e1b19ba 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -40,6 +40,12 @@ compiler aborts on broken expressions, bugs #933, #938 and #966 * typeck.c: minor refactoring within functions +2024-04-25 Boris Eng + + * cobc.h, pplex.l, ppparse.y: new >>IMP INCLUDE directive to include + multiple header files in the C generated code. Has the same behavior as the + --include compiler option. + 2024-04-24 Fabrice Le Fessant * replace.c: optimize speed and memory usage. For speed, we add two @@ -50,6 +56,12 @@ replace stream) and we use a circular buffer for the temporary queue of tokens instead of a list. +2024-04-25 Boris Eng + + * pplex.l, ppparse.y, scanner.l, cobc.h, codegen.c: + new >>IMP INCLUDE directive to include one or multiple header files in + the generated C code (same behavior as the --include compiler option) + 2024-03-17 Fabrice Le Fessant Emilien Lemaire diff --git a/cobc/cobc.h b/cobc/cobc.h index 822f7381e..15d8463a3 100644 --- a/cobc/cobc.h +++ b/cobc/cobc.h @@ -276,7 +276,7 @@ enum cb_sub_check { struct cb_text_list { struct cb_text_list *next; /* next pointer */ struct cb_text_list *last; - const char *text; + char *text; }; /* Structure for extended filenames */ @@ -477,6 +477,7 @@ extern struct cb_text_list *cb_depend_list; extern struct cb_text_list *cb_copy_list; extern struct cb_text_list *cb_include_file_list; extern struct cb_text_list *cb_include_list; +extern struct cb_text_list *cb_include_file_list_directive; extern struct cb_text_list *cb_intrinsic_list; extern struct cb_text_list *cb_extension_list; extern struct cb_text_list *cb_static_call_list; diff --git a/cobc/codegen.c b/cobc/codegen.c index a9ba045b0..a99bbbba0 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -1830,16 +1830,29 @@ output_gnucobol_defines (const char *formatted_date) output_line ("#define COB_MODULE_TIME\t\t%d", i); { - struct cb_text_list *l = cb_include_file_list ; - for (;l;l=l->next){ - if (l->text[0] == '<'){ + struct cb_text_list *l; + struct cb_text_list *last = NULL; + for (l = cb_include_file_list; l; l = l->next) { + if (l->text[0] == '<') { output_line ("#include %s", l->text); } else { output_line ("#include \"%s\"", l->text); } } - } + for (l = cb_include_file_list_directive; l; l = l->next) { + if (last != NULL) { + cobc_free (last->text); + cobc_free (last); + } + last = l; + if (l->text[0] == '<') { + output_line ("#include %s", l->text); + } else { + output_line ("#include \"%s\"", l->text); + } + } + } } /* CALL cache */ diff --git a/cobc/pplex.l b/cobc/pplex.l index 02bb2640c..ada22042c 100644 --- a/cobc/pplex.l +++ b/cobc/pplex.l @@ -204,6 +204,7 @@ ALNUM_LITERAL_A "\'"([^''\n]|("\'"[0-9][0-9, ]+"\'"))*"\'" ALNUM_LITERAL {ALNUM_LITERAL_Q}|{ALNUM_LITERAL_A} SET_PAREN_LIT \([^()\n]*\) DEFNUM_LITERAL [+-]?[0-9]*[\.]*[0-9]+ +RAW_SEQ [^ \n]+ AREA_A [ ]?# MAYBE_AREA_A [ ]?#? @@ -227,6 +228,7 @@ MAYBE_AREA_A [ ]?#? %x ALNUM_LITERAL_STATE %x CONTROL_STATEMENT_STATE %x DISPLAY_DIRECTIVE_STATE +%x IMP_DIRECTIVE_STATE %% @@ -360,6 +362,11 @@ MAYBE_AREA_A [ ]?#? return CALL_DIRECTIVE; } +^{MAYBE_AREA_A}[ ]*">>"[ ]?"IMP" { + BEGIN IMP_DIRECTIVE_STATE; + return IMP_DIRECTIVE; +} + ^{MAYBE_AREA_A}[ ]*">>"[ ]*\n { /* empty 2002+ style directive */ cb_plex_warning (COBC_WARN_FILLER, newline_count, @@ -724,6 +731,7 @@ ELSE_DIRECTIVE_STATE, ENDIF_DIRECTIVE_STATE, ALNUM_LITERAL_STATE, CONTROL_STATEMENT_STATE, +IMP_DIRECTIVE_STATE, COBOL_WORDS_DIRECTIVE_STATE>{ \n { BEGIN INITIAL; @@ -993,6 +1001,14 @@ ENDIF_DIRECTIVE_STATE>{ } } +{ + "INCLUDE" { return INCLUDE; } /* GnuCOBOL 3.3 extension */ + {RAW_SEQ} { + pplval.s = cobc_plex_strdup (yytext); + return TOKEN; + } +} + { "IS" { return IS; } "NOT" { return NOT; } diff --git a/cobc/ppparse.y b/cobc/ppparse.y index 76b3c9a58..267044679 100644 --- a/cobc/ppparse.y +++ b/cobc/ppparse.y @@ -741,6 +741,9 @@ ppparse_clear_vars (const struct cb_define_struct *p) %token WITH %token LOCATION +%token IMP_DIRECTIVE +%token INCLUDE + %token TERMINATOR "end of line" %token TOKEN "Word or Literal" @@ -768,6 +771,7 @@ ppparse_clear_vars (const struct cb_define_struct *p) %type alnum_equality_list %type ec_list %type unquoted_literal +%type imp_include_sources %type _copy_replacing %type replacing_list @@ -838,6 +842,7 @@ directive: | TURN_DIRECTIVE turn_directive | LISTING_DIRECTIVE listing_directive | LEAP_SECOND_DIRECTIVE leap_second_directive +| IMP_DIRECTIVE imp_directive | IF_DIRECTIVE { current_cmd = PLEX_ACT_IF; @@ -1368,6 +1373,29 @@ leap_second_directive: | OFF ; +imp_directive: + /* GnuCOBOL 3.3 extension */ + INCLUDE imp_include_sources + { + struct cb_text_list *p = $2; + while (p != NULL) { + fprintf (ppout, "#INCLUDE %s\n", p->text); + p = p->next; + } + } +; + +imp_include_sources: + TOKEN + { + $$ = ppp_list_add (NULL, fix_filename ($1)); + } +| imp_include_sources TOKEN + { + $$ = ppp_list_add ($1, fix_filename ($2)); + } +; + turn_directive: ec_list CHECKING on_or_off { diff --git a/cobc/scanner.l b/cobc/scanner.l index 15f3d1871..034ac42b6 100644 --- a/cobc/scanner.l +++ b/cobc/scanner.l @@ -175,6 +175,8 @@ static size_t pic2_size; static unsigned int inside_bracket = 0; static char err_msg[COB_MINI_BUFF]; +struct cb_text_list *cb_include_file_list_directive = NULL; + /* Function declarations */ static void read_literal (const char, const enum cb_literal_type); static int scan_x (const char *, const char *); @@ -192,6 +194,7 @@ static void copy_two_words_in_quotes (char ** const, char ** const); static void add_synonym (const int, const int); static void make_synonym (void); static void clear_constants (void); +static struct cb_text_list *scan_list_add (struct cb_text_list *, const char *); %} @@ -323,6 +326,13 @@ AREA_A "#AREA_A"\n cobc_areacheck = 0; } +<*>^[ ]?"#INCLUDE".*/\n { + cb_include_file_list_directive = scan_list_add ( + cb_include_file_list_directive, + yytext + 9 + ); +} + <*>^{AREA_A}[ ]*/"." { count_lines (yytext + 9); /* skip "\n#area_a\n" */ if (cobc_in_procedure && cobc_areacheck) { @@ -2583,6 +2593,22 @@ clear_constants (void) top_78_ptr = NULL; } +static struct cb_text_list * +scan_list_add (struct cb_text_list *list, const char *text) +{ + struct cb_text_list *p; + + p = cobc_malloc (sizeof (struct cb_text_list)); + p->text = cobc_strdup (text); + if (!list) { + p->last = p; + return p; + } + list->last->next = p; + list->last = p; + return list; +} + /* Global functions */ void diff --git a/doc/gnucobol.texi b/doc/gnucobol.texi index af4eb9fd2..dea8111ae 100644 --- a/doc/gnucobol.texi +++ b/doc/gnucobol.texi @@ -383,6 +383,8 @@ Add a @code{#include} @file{file.h} at the beginning of the generated C source file. The file name is put into quotes, unless it starts by @code{<}. Quoted files should be absolute paths, since C files are compiled in temporary directories. +The directive @code{>>IMP INCLUDE "FILE.h"} or @code{>>IMP INCLUDE } +can be used as an alternative to this compiler option. The option also implies @option{-fno-gen-c-decl-static-call}. This option can be used to check function prototypes when static calls are used. When this option is used, the source file is diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index c3c7091f7..aa69e32ab 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -8405,3 +8405,67 @@ prog.cob:18: error: ANY LENGTH items may only be BY REFERENCE formal parameters AT_CLEANUP + +AT_SETUP([IMP INCLUDE directive]) +AT_KEYWORDS([IMP INCLUDE]) + +AT_DATA([prog.cob], [ + >>IMP INCLUDE "file.h" + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + GOBACK. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [0], [], []) + +AT_DATA([prog.cob], [ +>>IMP INCLUDE "file.h" +identification division. +program-id. prog. +procedure division. + goback. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=free prog.cob], [0], [], []) + +AT_DATA([prog.cob], [ + >>IMP INCLUDE + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + GOBACK. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [0], [], []) + +AT_DATA([prog.cob], [ + >>IMP INCLUDE + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + PROCEDURE DIVISION. + GOBACK. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [1], [], +[prog.cob:2: error: syntax error, unexpected end of line, expecting Word or Literal +prog.cob:2: error: PROGRAM-ID header missing +]) + +AT_CLEANUP + + +AT_SETUP([IMP INCLUDE directive multiple files]) +AT_KEYWORDS([IMP INCLUDE]) + +AT_DATA([prog.cob], [ +>>IMP INCLUDE "file1.h" file2.h "" +identification division. +program-id. prog. +procedure division. + goback. +]) + +AT_CHECK([$COMPILE_ONLY -fformat=free prog.cob], [0], [], []) + +AT_CLEANUP diff --git a/tests/testsuite.src/used_binaries.at b/tests/testsuite.src/used_binaries.at index 50d8a1867..7e71e0f76 100644 --- a/tests/testsuite.src/used_binaries.at +++ b/tests/testsuite.src/used_binaries.at @@ -1095,7 +1095,7 @@ AT_CLEANUP AT_SETUP([check include header file]) -#AT_KEYWORDS([cobc copy]) +#AT_KEYWORDS([cobc copy include imp]) AT_DATA([filec.h], [ /* COB_EXT_IMPORT will be defined by libcob.h up-front */ @@ -1171,4 +1171,18 @@ AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call prog2.co AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call -L. -lfilec prog2.cob -o prog2c], [0], ignore, ignore)] ) +AT_DATA([prog3.cob], [ + >> IMP INCLUDE "file.h" + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 long USAGE BINARY-C-LONG. + PROCEDURE DIVISION. + CALL "f" USING "Hello" BY VALUE long RETURNING NOTHING. +]) + +# static build with correct function signature +# AT_CHECK([$COBC -m -I . -fstatic-call prog3.cob], [0], [], []) + AT_CLEANUP From 0bf53800b28ebbf988f1b288e5789cd93a0275bd Mon Sep 17 00:00:00 2001 From: Simon Sobisch Date: Thu, 25 Jul 2024 13:27:28 +0000 Subject: [PATCH 3/9] testing IMP INCLUDE directive --- tests/testsuite.src/used_binaries.at | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/testsuite.src/used_binaries.at b/tests/testsuite.src/used_binaries.at index 7e71e0f76..eff1c06b9 100644 --- a/tests/testsuite.src/used_binaries.at +++ b/tests/testsuite.src/used_binaries.at @@ -1095,7 +1095,7 @@ AT_CLEANUP AT_SETUP([check include header file]) -#AT_KEYWORDS([cobc copy include imp]) +AT_KEYWORDS([cobc copy directive imp]) AT_DATA([filec.h], [ /* COB_EXT_IMPORT will be defined by libcob.h up-front */ @@ -1171,8 +1171,9 @@ AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call prog2.co AT_CHECK([$COMPILE_MODULE -Wno-unfinished --copy "f.copy" -fstatic-call -L. -lfilec prog2.cob -o prog2c], [0], ignore, ignore)] ) +# additional check via directive AT_DATA([prog3.cob], [ - >> IMP INCLUDE "file.h" + >> IMP INCLUDE "filec.h" IDENTIFICATION DIVISION. PROGRAM-ID. prog. DATA DIVISION. @@ -1182,6 +1183,12 @@ AT_DATA([prog3.cob], [ CALL "f" USING "Hello" BY VALUE long RETURNING NOTHING. ]) +# static build with correct function signature +AT_CHECK([$COMPILE_MODULE -I . -fstatic-call prog3.cob], [0], [], [], [ + # Previous test "failed" --> retry with import library + AT_CHECK([$COMPILE_MODULE -I . -fstatic-call -L. -lfilec prog3.cob], [0], ignore, ignore)] +) + # static build with correct function signature # AT_CHECK([$COBC -m -I . -fstatic-call prog3.cob], [0], [], []) From 0b1709045602b9d6cd5ce6048036cd43d0fb77d8 Mon Sep 17 00:00:00 2001 From: engboris Date: Mon, 29 Jul 2024 17:14:34 +0200 Subject: [PATCH 4/9] Remove useless tests and change error message --- cobc/ChangeLog | 12 +++--------- cobc/cobc.h | 4 ++-- cobc/pplex.l | 2 +- cobc/ppparse.y | 6 +++++- cobc/scanner.l | 4 ++-- tests/testsuite.src/syn_misc.at | 34 ++++++++++++--------------------- 6 files changed, 25 insertions(+), 37 deletions(-) diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 33bd27c0d..0310b8c7b 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -30,9 +30,9 @@ 2024-04-25 Boris Eng - * cobc.h, pplex.l, ppparse.y: new >>IMP INCLUDE directive to include - multiple header files in the C generated code. Has the same behavior as the - --include compiler option. + * pplex.l, ppparse.y, scanner.l, cobc.h, codegen.c: + new >>IMP INCLUDE directive to include one or multiple header files in + the generated C code (same behavior as the --include compiler option) 2024-04-24 Fabrice Le Fessant @@ -44,12 +44,6 @@ replace stream) and we use a circular buffer for the temporary queue of tokens instead of a list. -2024-04-25 Boris Eng - - * pplex.l, ppparse.y, scanner.l, cobc.h, codegen.c: - new >>IMP INCLUDE directive to include one or multiple header files in - the generated C code (same behavior as the --include compiler option) - 2024-03-17 Fabrice Le Fessant Emilien Lemaire diff --git a/cobc/cobc.h b/cobc/cobc.h index 15d8463a3..f0c74281c 100644 --- a/cobc/cobc.h +++ b/cobc/cobc.h @@ -475,9 +475,9 @@ extern FILE *cb_src_list_file; extern FILE *cb_depend_file; extern struct cb_text_list *cb_depend_list; extern struct cb_text_list *cb_copy_list; -extern struct cb_text_list *cb_include_file_list; +extern struct cb_text_list *cb_include_file_list; /* global */ +extern struct cb_text_list *cb_include_file_list_directive; /* temporary */ extern struct cb_text_list *cb_include_list; -extern struct cb_text_list *cb_include_file_list_directive; extern struct cb_text_list *cb_intrinsic_list; extern struct cb_text_list *cb_extension_list; extern struct cb_text_list *cb_static_call_list; diff --git a/cobc/pplex.l b/cobc/pplex.l index ada22042c..17fdcd97d 100644 --- a/cobc/pplex.l +++ b/cobc/pplex.l @@ -204,7 +204,7 @@ ALNUM_LITERAL_A "\'"([^''\n]|("\'"[0-9][0-9, ]+"\'"))*"\'" ALNUM_LITERAL {ALNUM_LITERAL_Q}|{ALNUM_LITERAL_A} SET_PAREN_LIT \([^()\n]*\) DEFNUM_LITERAL [+-]?[0-9]*[\.]*[0-9]+ -RAW_SEQ [^ \n]+ +RAW_SEQ [^ \n]+ AREA_A [ ]?# MAYBE_AREA_A [ ]?#? diff --git a/cobc/ppparse.y b/cobc/ppparse.y index 267044679..fe6e2553e 100644 --- a/cobc/ppparse.y +++ b/cobc/ppparse.y @@ -1375,7 +1375,11 @@ leap_second_directive: imp_directive: /* GnuCOBOL 3.3 extension */ - INCLUDE imp_include_sources + INCLUDE + { + ppparse_error (_("Missing argument for IMP INCLUDE directive")); + } +| INCLUDE imp_include_sources { struct cb_text_list *p = $2; while (p != NULL) { diff --git a/cobc/scanner.l b/cobc/scanner.l index 034ac42b6..5e49e75b2 100644 --- a/cobc/scanner.l +++ b/cobc/scanner.l @@ -2598,8 +2598,8 @@ scan_list_add (struct cb_text_list *list, const char *text) { struct cb_text_list *p; - p = cobc_malloc (sizeof (struct cb_text_list)); - p->text = cobc_strdup (text); + p = cobc_parse_malloc (sizeof (struct cb_text_list)); + p->text = cobc_parse_strdup (text); if (!list) { p->last = p; return p; diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index aa69e32ab..88c2ee6b5 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -8417,17 +8417,7 @@ AT_DATA([prog.cob], [ GOBACK. ]) -AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [0], [], []) - -AT_DATA([prog.cob], [ ->>IMP INCLUDE "file.h" -identification division. -program-id. prog. -procedure division. - goback. -]) - -AT_CHECK([$COMPILE_ONLY -fformat=free prog.cob], [0], [], []) +AT_CHECK([$COMPILE_ONLY prog.cob], [0], [], []) AT_DATA([prog.cob], [ >>IMP INCLUDE @@ -8437,9 +8427,9 @@ AT_DATA([prog.cob], [ GOBACK. ]) -AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [0], [], []) +AT_CHECK([$COMPILE_ONLY prog.cob], [0], [], []) -AT_DATA([prog.cob], [ +AT_DATA([prog2.cob], [ >>IMP INCLUDE IDENTIFICATION DIVISION. PROGRAM-ID. prog. @@ -8447,9 +8437,9 @@ AT_DATA([prog.cob], [ GOBACK. ]) -AT_CHECK([$COMPILE_ONLY -fformat=fixed prog.cob], [1], [], -[prog.cob:2: error: syntax error, unexpected end of line, expecting Word or Literal -prog.cob:2: error: PROGRAM-ID header missing +AT_CHECK([$COMPILE_ONLY prog2.cob], [1], [], +[prog2.cob:2: error: syntax error, unexpected end of line, expecting Word or Literal +prog2.cob:2: error: PROGRAM-ID header missing ]) AT_CLEANUP @@ -8459,13 +8449,13 @@ AT_SETUP([IMP INCLUDE directive multiple files]) AT_KEYWORDS([IMP INCLUDE]) AT_DATA([prog.cob], [ ->>IMP INCLUDE "file1.h" file2.h "" -identification division. -program-id. prog. -procedure division. - goback. + >>IMP INCLUDE "file1.h" file2.h "" + IDENTIFICATION DIVISION. + PROGRAM-ID. PROG. + PROCEDURE DIVISION. + GOBACK. ]) -AT_CHECK([$COMPILE_ONLY -fformat=free prog.cob], [0], [], []) +AT_CHECK([$COMPILE_ONLY prog.cob], [0], [], []) AT_CLEANUP From fbade2f08afeda560206bdc044782b6c60484678 Mon Sep 17 00:00:00 2001 From: engboris Date: Mon, 29 Jul 2024 17:31:02 +0200 Subject: [PATCH 5/9] Fix indent --- cobc/ppparse.y | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cobc/ppparse.y b/cobc/ppparse.y index fe6e2553e..131007741 100644 --- a/cobc/ppparse.y +++ b/cobc/ppparse.y @@ -1376,9 +1376,9 @@ leap_second_directive: imp_directive: /* GnuCOBOL 3.3 extension */ INCLUDE - { - ppparse_error (_("Missing argument for IMP INCLUDE directive")); - } + { + ppparse_error (_("Missing argument for IMP INCLUDE directive")); + } | INCLUDE imp_include_sources { struct cb_text_list *p = $2; From 9c112042d637cd2b2ec7b7fe56cb3ca40ce2ce5e Mon Sep 17 00:00:00 2001 From: engboris Date: Mon, 29 Jul 2024 17:33:30 +0200 Subject: [PATCH 6/9] Fix error message of test syn_misc.at --- tests/testsuite.src/syn_misc.at | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index 88c2ee6b5..de4e3164a 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -8438,8 +8438,7 @@ AT_DATA([prog2.cob], [ ]) AT_CHECK([$COMPILE_ONLY prog2.cob], [1], [], -[prog2.cob:2: error: syntax error, unexpected end of line, expecting Word or Literal -prog2.cob:2: error: PROGRAM-ID header missing +[prog2.cob:2: error: prog2.cob:2: error: PROGRAM-ID header missing ]) AT_CLEANUP From f87c1c44fbf2873dbd0e891c90dda53705c747a6 Mon Sep 17 00:00:00 2001 From: engboris Date: Mon, 29 Jul 2024 17:35:12 +0200 Subject: [PATCH 7/9] Fix indent --- cobc/ppparse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobc/ppparse.y b/cobc/ppparse.y index 131007741..fd157e7db 100644 --- a/cobc/ppparse.y +++ b/cobc/ppparse.y @@ -1375,7 +1375,7 @@ leap_second_directive: imp_directive: /* GnuCOBOL 3.3 extension */ - INCLUDE + INCLUDE { ppparse_error (_("Missing argument for IMP INCLUDE directive")); } From 179870396a010c793e2be560674183abee6e6e62 Mon Sep 17 00:00:00 2001 From: engboris Date: Mon, 29 Jul 2024 17:59:40 +0200 Subject: [PATCH 8/9] Fix tests (error message for syn_misc.at) --- tests/testsuite.src/syn_misc.at | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index de4e3164a..909b077ee 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -8438,7 +8438,7 @@ AT_DATA([prog2.cob], [ ]) AT_CHECK([$COMPILE_ONLY prog2.cob], [1], [], -[prog2.cob:2: error: prog2.cob:2: error: PROGRAM-ID header missing +[prog2.cob:2: error: Missing argument for IMP INCLUDE directive ]) AT_CLEANUP From c21b035bf87a1dea6bc6a423c8627a754f5bdc58 Mon Sep 17 00:00:00 2001 From: engboris Date: Tue, 8 Oct 2024 18:00:34 +0200 Subject: [PATCH 9/9] Several fixes --- NEWS | 4 ++++ cobc/cobc.h | 2 +- cobc/codegen.c | 6 ------ cobc/ppparse.y | 3 ++- cobc/scanner.l | 34 ++++++++++++++++----------------- tests/testsuite.src/syn_misc.at | 8 ++++++-- 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/NEWS b/NEWS index 54c2ac622..e52aeec16 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ NEWS - user visible changes -*- outline -*- * New GnuCOBOL features +** the leading space for all internal directives is removed in the lexer. + Source previously processed may need to be ajusted to be processed by + GnuCOBOL 3.3. + ** cobc now checks for binary files and early exit parsing those; the error output for format errors (for example invalid indicator column) is now limitted to 5 per source file diff --git a/cobc/cobc.h b/cobc/cobc.h index 461cbcf5a..4af9b6610 100644 --- a/cobc/cobc.h +++ b/cobc/cobc.h @@ -478,7 +478,7 @@ extern struct cb_text_list *cb_copy_list; extern struct cb_text_list *cb_include_file_list; /* global */ extern struct cb_text_list *cb_include_file_list_directive; /* temporary */ extern struct cb_text_list *cb_include_list; -extern struct cb_text_list *cb_include_file_list_directive; +extern struct cb_text_list *cb_include_file_list_directive; extern struct cb_text_list *cb_intrinsic_list; extern struct cb_text_list *cb_extension_list; extern struct cb_text_list *cb_static_call_list; diff --git a/cobc/codegen.c b/cobc/codegen.c index a99bbbba0..9096da615 100644 --- a/cobc/codegen.c +++ b/cobc/codegen.c @@ -1831,7 +1831,6 @@ output_gnucobol_defines (const char *formatted_date) { struct cb_text_list *l; - struct cb_text_list *last = NULL; for (l = cb_include_file_list; l; l = l->next) { if (l->text[0] == '<') { output_line ("#include %s", l->text); @@ -1841,11 +1840,6 @@ output_gnucobol_defines (const char *formatted_date) } for (l = cb_include_file_list_directive; l; l = l->next) { - if (last != NULL) { - cobc_free (last->text); - cobc_free (last); - } - last = l; if (l->text[0] == '<') { output_line ("#include %s", l->text); } else { diff --git a/cobc/ppparse.y b/cobc/ppparse.y index fd157e7db..7779186ed 100644 --- a/cobc/ppparse.y +++ b/cobc/ppparse.y @@ -1377,7 +1377,8 @@ imp_directive: /* GnuCOBOL 3.3 extension */ INCLUDE { - ppparse_error (_("Missing argument for IMP INCLUDE directive")); + cb_error (_("invalid %s directive"), "IMP INCLUDE"); + yyerrok; } | INCLUDE imp_include_sources { diff --git a/cobc/scanner.l b/cobc/scanner.l index 5e49e75b2..83062309b 100644 --- a/cobc/scanner.l +++ b/cobc/scanner.l @@ -223,7 +223,7 @@ AREA_A "#AREA_A"\n cobc_in_area_a = 0; %} -<*>^[ ]?"#CALLFH".*\n { +<*>^"#CALLFH".*\n { if (current_program) { const char *p1; char *p2; @@ -246,11 +246,11 @@ AREA_A "#AREA_A"\n } -<*>^[ ]?"#DEFLIT".*\n { +<*>^"#DEFLIT".*\n { scan_define_options (yytext); } -<*>^[ ]?"#ADDRSV".*\n { +<*>^"#ADDRSV".*\n { char *word; copy_word_in_quotes (&word); @@ -258,25 +258,25 @@ AREA_A "#AREA_A"\n cobc_free (word); } -<*>^[ ]?"#ADDSYN-STD".*\n { +<*>^"#ADDSYN-STD".*\n { add_synonym (1, 0); } -<*>^[ ]?"#ADDSYN".*\n { +<*>^"#ADDSYN".*\n { add_synonym (0, 0); } -<*>^[ ]?"#MAKESYN".*\n { +<*>^"#MAKESYN".*\n { make_synonym (); } -<*>^[ ]?"#OVERRIDE-STD".*\n { +<*>^"#OVERRIDE-STD".*\n { add_synonym (1, 1); } -<*>^[ ]?"#OVERRIDE".*\n { +<*>^"#OVERRIDE".*\n { add_synonym (0, 1); } -<*>^[ ]?"#REMOVE-STD".*\n { +<*>^"#REMOVE-STD".*\n { char *word; copy_word_in_quotes (&word); @@ -289,7 +289,7 @@ AREA_A "#AREA_A"\n cobc_free (word); } -<*>^[ ]?"#REMOVE".*\n { +<*>^"#REMOVE".*\n { char *word; copy_word_in_quotes (&word); @@ -297,19 +297,19 @@ AREA_A "#AREA_A"\n cobc_free (word); } -<*>^[ ]?"#REFMOD_ZERO "[0-9]\n { +<*>^"#REFMOD_ZERO "[0-9]\n { cb_ref_mod_zero_length = (yytext[13] - '0'); } -<*>^[ ]?"#ODOSLIDE "[0-1]\n { +<*>^"#ODOSLIDE "[0-1]\n { cb_odoslide = (yytext[10] - '0'); } -<*>^[ ]?"#ASSIGN "[0-9]\n { +<*>^"#ASSIGN "[0-9]\n { cb_assign_type_default = (enum cb_assign_type)(yytext[8] - '0'); } -<*>^[ ]?"#TURN".*\n { +<*>^"#TURN".*\n { struct cb_turn_list *l; for (l = cb_turn_list; l && l->line != -1; l = l->next); @@ -318,15 +318,15 @@ AREA_A "#AREA_A"\n } } -<*>^[ ]?"#AREACHECK"\n { +<*>^"#AREACHECK"\n { cobc_areacheck = 1; } -<*>^[ ]?"#NOAREACHECK"\n { +<*>^"#NOAREACHECK"\n { cobc_areacheck = 0; } -<*>^[ ]?"#INCLUDE".*/\n { +<*>^"#INCLUDE".*/\n { cb_include_file_list_directive = scan_list_add ( cb_include_file_list_directive, yytext + 9 diff --git a/tests/testsuite.src/syn_misc.at b/tests/testsuite.src/syn_misc.at index 909b077ee..15d42d48b 100644 --- a/tests/testsuite.src/syn_misc.at +++ b/tests/testsuite.src/syn_misc.at @@ -8438,7 +8438,7 @@ AT_DATA([prog2.cob], [ ]) AT_CHECK([$COMPILE_ONLY prog2.cob], [1], [], -[prog2.cob:2: error: Missing argument for IMP INCLUDE directive +[prog2.cob:2: error: invalid IMP INCLUDE directive ]) AT_CLEANUP @@ -8455,6 +8455,10 @@ AT_DATA([prog.cob], [ GOBACK. ]) -AT_CHECK([$COMPILE_ONLY prog.cob], [0], [], []) +AT_CHECK([$COMPILE --save-temps -E -o prog.i prog.cob], [0], [], []) +AT_CHECK([$GREP "#INCLUDE file1.h" prog.i], [0], ignore, []) +AT_CHECK([$GREP "#INCLUDE file2.h" prog.i], [0], ignore, []) +AT_CHECK([$GREP "#INCLUDE " prog.i], [0], ignore, []) +AT_CHECK([$GREP "#INCLUDE " prog.i], [0], ignore, []) AT_CLEANUP