Skip to content

Commit 85c7080

Browse files
committed
Merge remote-tracking branch 'upstream/gnucobol-3.x' into gcos4gnucobol-3.x
2 parents 369eb24 + bba2a4e commit 85c7080

File tree

11 files changed

+214
-29
lines changed

11 files changed

+214
-29
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ NEWS - user visible changes -*- outline -*-
5454
calls to externals. The files are put into quotes, unless they start by
5555
'<'. Quoted files are expected to have absolute paths, as the C compiler
5656
is called in a temp directory instead of the project directory.
57+
The directive >>IMP INCLUDE "file.h", >>IMP INCLUDE "<file.h>",
58+
>>IMP INCLUDE <file.h> or >>IMP INCLUDE file.h can be used as an alternative
59+
to this compiler option.
5760

5861
** output of unlimited errors may be requested by -fmax-errors=0,
5962
to stop compiliation at first error use -Wfatal-errors

cobc/ChangeLog

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,21 @@
152152
internally disabling it for generation of libraries/executable after
153153
first program as we only need that code once, fixing Win32 build errors
154154
and duplication warnings in other environments
155-
* flag.def: don't suppress the help of -fwinmain under Win32
155+
* flag.def: don't suppress the help of -fwinmain under Win32 and Cygwin
156156
* typeck.c (build_expr_finish): use fallback error position token, fixing
157157
compiler aborts on broken expressions, bugs #933, #938 and #966
158158
* typeck.c: minor refactoring within functions
159159

160+
2024-04-25 Boris Eng <[email protected]>
161+
162+
FR #176: "Implementation of GC directive to include .h (c/c++) files"
163+
* pplex.l, ppparse.y, cobc.h, codegen.c (output_gnucobol_defines):
164+
new >>IMP INCLUDE directive to include one or multiple header files in the
165+
generated C code (same behavior as the --include but with one directive per
166+
file)
167+
* scanner.l: the leading space for all internal directives is removed in the
168+
lexer. Source previously preprocessed may need to be adjusted
169+
160170
2024-04-24 Fabrice Le Fessant <[email protected]>
161171

162172
* replace.c: optimize speed and memory usage. For speed, we add two

cobc/cobc.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ enum cb_sub_check {
276276
struct cb_text_list {
277277
struct cb_text_list *next; /* next pointer */
278278
struct cb_text_list *last;
279-
const char *text;
279+
char *text;
280280
};
281281

282282
/* Structure for extended filenames */
@@ -478,7 +478,8 @@ extern int cb_depend_keep_missing;
478478
extern int cb_flag_copybook_deps;
479479
extern struct cb_text_list *cb_depend_list;
480480
extern struct cb_text_list *cb_copy_list;
481-
extern struct cb_text_list *cb_include_file_list;
481+
extern struct cb_text_list *cb_include_file_list; /* global */
482+
extern struct cb_text_list *cb_include_file_list_directive; /* temporary */
482483
extern struct cb_text_list *cb_include_list;
483484
extern struct cb_text_list *cb_intrinsic_list;
484485
extern struct cb_text_list *cb_extension_list;

cobc/codegen.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,7 @@ static void
18011801
output_gnucobol_defines (const char *formatted_date)
18021802
{
18031803
int i;
1804+
struct cb_text_list *l;
18041805

18051806
if (!strrchr (cb_source_file, '\\')
18061807
&& !strrchr (cb_source_file, '"')) {
@@ -1832,17 +1833,23 @@ output_gnucobol_defines (const char *formatted_date)
18321833
current_compile_tm.tm_sec;
18331834
output_line ("#define COB_MODULE_TIME\t\t%d", i);
18341835

1835-
{
1836-
struct cb_text_list *l = cb_include_file_list ;
1837-
for (;l;l=l->next){
1838-
if (l->text[0] == '<'){
1839-
output_line ("#include %s", l->text);
1840-
} else {
1841-
output_line ("#include \"%s\"", l->text);
1842-
}
1836+
for (l = cb_include_file_list; l; l = l->next) {
1837+
if (l->text[0] == '<') {
1838+
output_line ("#include %s", l->text);
1839+
} else {
1840+
output_line ("#include \"%s\"", l->text);
1841+
}
1842+
}
1843+
1844+
for (l = cb_include_file_list_directive; l; l = l->next) {
1845+
if (l->text[0] == '<') {
1846+
output_line ("#include %s", l->text);
1847+
} else {
1848+
output_line ("#include \"%s\"", l->text);
18431849
}
18441850
}
18451851

1852+
cb_include_file_list_directive = NULL;
18461853
}
18471854

18481855
/* CALL cache */

cobc/flag.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ CB_FLAG_NQ (1, "default-file-colseq", CB_FLAG_GETOPT_DEFAULT_FILE_COLSEQ,
109109
" * default: NATIVE"))
110110

111111
/* Binary flags, partially with suppressed help */
112-
#ifdef _WIN32
112+
#if defined (_WIN32) || defined (__CYGWIN__)
113113
#define COB_SHOW 1
114114
#else
115115
#define COB_SHOW 0

cobc/pplex.l

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ ALNUM_LITERAL_A "\'"([^''\n]|("\'"[0-9][0-9, ]+"\'"))*"\'"
201201
ALNUM_LITERAL {ALNUM_LITERAL_Q}|{ALNUM_LITERAL_A}
202202
SET_PAREN_LIT \([^()\n]*\)
203203
DEFNUM_LITERAL [+-]?[0-9]*[\.]*[0-9]+
204+
RAW_SEQ [^ \n]+
204205

205206
AREA_A [ ]?#
206207
MAYBE_AREA_A [ ]?#?
@@ -224,6 +225,7 @@ MAYBE_AREA_A [ ]?#?
224225
%x ALNUM_LITERAL_STATE
225226
%x CONTROL_STATEMENT_STATE
226227
%x DISPLAY_DIRECTIVE_STATE
228+
%x IMP_DIRECTIVE_STATE
227229

228230
%%
229231

@@ -357,6 +359,11 @@ MAYBE_AREA_A [ ]?#?
357359
return CALL_DIRECTIVE;
358360
}
359361

362+
^{MAYBE_AREA_A}[ ]*">>"[ ]?"IMP" {
363+
BEGIN IMP_DIRECTIVE_STATE;
364+
return IMP_DIRECTIVE;
365+
}
366+
360367
^{MAYBE_AREA_A}[ ]*">>"[ ]*\n {
361368
/* empty 2002+ style directive */
362369
cb_plex_warning (COBC_WARN_FILLER, newline_count,
@@ -721,6 +728,7 @@ ELSE_DIRECTIVE_STATE,
721728
ENDIF_DIRECTIVE_STATE,
722729
ALNUM_LITERAL_STATE,
723730
CONTROL_STATEMENT_STATE,
731+
IMP_DIRECTIVE_STATE,
724732
COBOL_WORDS_DIRECTIVE_STATE>{
725733
\n {
726734
BEGIN INITIAL;
@@ -990,6 +998,14 @@ ENDIF_DIRECTIVE_STATE>{
990998
}
991999
}
9921000

1001+
<IMP_DIRECTIVE_STATE>{
1002+
"INCLUDE" { return INCLUDE; } /* GnuCOBOL 3.3 extension */
1003+
{RAW_SEQ} {
1004+
pplval.s = cobc_plex_strdup (yytext);
1005+
return TOKEN;
1006+
}
1007+
}
1008+
9931009
<IF_DIRECTIVE_STATE>{
9941010
"IS" { return IS; }
9951011
"NOT" { return NOT; }

cobc/ppparse.y

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,9 @@ ppparse_clear_vars (const struct cb_define_struct *p)
741741
%token WITH
742742
%token LOCATION
743743

744+
%token IMP_DIRECTIVE
745+
%token INCLUDE
746+
744747
%token TERMINATOR "end of line"
745748

746749
%token <s> TOKEN "Word or Literal"
@@ -768,6 +771,7 @@ ppparse_clear_vars (const struct cb_define_struct *p)
768771
%type <l> alnum_equality_list
769772
%type <l> ec_list
770773
%type <s> unquoted_literal
774+
%type <l> imp_include_sources
771775

772776
%type <r> _copy_replacing
773777
%type <r> replacing_list
@@ -838,6 +842,7 @@ directive:
838842
| TURN_DIRECTIVE turn_directive
839843
| LISTING_DIRECTIVE listing_directive
840844
| LEAP_SECOND_DIRECTIVE leap_second_directive
845+
| IMP_DIRECTIVE imp_directive
841846
| IF_DIRECTIVE
842847
{
843848
current_cmd = PLEX_ACT_IF;
@@ -1368,6 +1373,34 @@ leap_second_directive:
13681373
| OFF
13691374
;
13701375

1376+
imp_directive:
1377+
/* GnuCOBOL 3.3 extension */
1378+
INCLUDE
1379+
{
1380+
cb_error (_("invalid %s directive"), "IMP INCLUDE");
1381+
yyerrok;
1382+
}
1383+
| INCLUDE imp_include_sources
1384+
{
1385+
struct cb_text_list *p = $2;
1386+
while (p != NULL) {
1387+
fprintf (ppout, "#INCLUDE %s\n", p->text);
1388+
p = p->next;
1389+
}
1390+
}
1391+
;
1392+
1393+
imp_include_sources:
1394+
TOKEN
1395+
{
1396+
$$ = ppp_list_add (NULL, fix_filename ($1));
1397+
}
1398+
| imp_include_sources TOKEN
1399+
{
1400+
$$ = ppp_list_add ($1, fix_filename ($2));
1401+
}
1402+
;
1403+
13711404
turn_directive:
13721405
ec_list CHECKING on_or_off
13731406
{

cobc/scanner.l

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ static size_t pic2_size;
172172
static unsigned int inside_bracket = 0;
173173
static char err_msg[COB_MINI_BUFF];
174174

175+
struct cb_text_list *cb_include_file_list_directive = NULL;
176+
175177
/* Function declarations */
176178
static void read_literal (const char, const enum cb_literal_type);
177179
static int scan_x (const char *, const char *);
@@ -189,6 +191,7 @@ static void copy_two_words_in_quotes (char ** const, char ** const);
189191
static void add_synonym (const int, const int);
190192
static void make_synonym (void);
191193
static void clear_constants (void);
194+
static struct cb_text_list *scan_list_add (struct cb_text_list *, const char *);
192195

193196
%}
194197

@@ -217,7 +220,7 @@ AREA_A "#AREA_A"\n
217220
cobc_in_area_a = 0;
218221
%}
219222

220-
<*>^[ ]?"#CALLFH".*\n {
223+
<*>^"#CALLFH".*\n {
221224
if (current_program) {
222225
const char *p1;
223226
char *p2;
@@ -240,37 +243,37 @@ AREA_A "#AREA_A"\n
240243
}
241244

242245

243-
<*>^[ ]?"#DEFLIT".*\n {
246+
<*>^"#DEFLIT".*\n {
244247
scan_define_options (yytext);
245248
}
246249

247-
<*>^[ ]?"#ADDRSV".*\n {
250+
<*>^"#ADDRSV".*\n {
248251
char *word;
249252

250253
copy_word_in_quotes (&word);
251254
add_reserved_word_now (word, NULL);
252255
cobc_free (word);
253256
}
254257

255-
<*>^[ ]?"#ADDSYN-STD".*\n {
258+
<*>^"#ADDSYN-STD".*\n {
256259
add_synonym (1, 0);
257260
}
258-
<*>^[ ]?"#ADDSYN".*\n {
261+
<*>^"#ADDSYN".*\n {
259262
add_synonym (0, 0);
260263
}
261264

262-
<*>^[ ]?"#MAKESYN".*\n {
265+
<*>^"#MAKESYN".*\n {
263266
make_synonym ();
264267
}
265268

266-
<*>^[ ]?"#OVERRIDE-STD".*\n {
269+
<*>^"#OVERRIDE-STD".*\n {
267270
add_synonym (1, 1);
268271
}
269-
<*>^[ ]?"#OVERRIDE".*\n {
272+
<*>^"#OVERRIDE".*\n {
270273
add_synonym (0, 1);
271274
}
272275

273-
<*>^[ ]?"#REMOVE-STD".*\n {
276+
<*>^"#REMOVE-STD".*\n {
274277
char *word;
275278

276279
copy_word_in_quotes (&word);
@@ -283,27 +286,27 @@ AREA_A "#AREA_A"\n
283286
cobc_free (word);
284287
}
285288

286-
<*>^[ ]?"#REMOVE".*\n {
289+
<*>^"#REMOVE".*\n {
287290
char *word;
288291

289292
copy_word_in_quotes (&word);
290293
remove_reserved_word_now (word);
291294
cobc_free (word);
292295
}
293296

294-
<*>^[ ]?"#REFMOD_ZERO "[0-9]\n {
297+
<*>^"#REFMOD_ZERO "[0-9]\n {
295298
cb_ref_mod_zero_length = (yytext[13] - '0');
296299
}
297300

298-
<*>^[ ]?"#ODOSLIDE "[0-1]\n {
301+
<*>^"#ODOSLIDE "[0-1]\n {
299302
cb_odoslide = (yytext[10] - '0');
300303
}
301304

302-
<*>^[ ]?"#ASSIGN "[0-9]\n {
305+
<*>^"#ASSIGN "[0-9]\n {
303306
cb_assign_type_default = (enum cb_assign_type)(yytext[8] - '0');
304307
}
305308

306-
<*>^[ ]?"#TURN".*\n {
309+
<*>^"#TURN".*\n {
307310
struct cb_turn_list *l;
308311

309312
for (l = cb_turn_list; l && l->line != -1; l = l->next);
@@ -312,14 +315,21 @@ AREA_A "#AREA_A"\n
312315
}
313316
}
314317

315-
<*>^[ ]?"#AREACHECK"\n {
318+
<*>^"#AREACHECK"\n {
316319
cobc_areacheck = 1;
317320
}
318321

319-
<*>^[ ]?"#NOAREACHECK"\n {
322+
<*>^"#NOAREACHECK"\n {
320323
cobc_areacheck = 0;
321324
}
322325

326+
<*>^"#INCLUDE".*/\n {
327+
cb_include_file_list_directive = scan_list_add (
328+
cb_include_file_list_directive,
329+
yytext + 9
330+
);
331+
}
332+
323333
<*>^{AREA_A}[ ]*/"." {
324334
count_lines (yytext + 9); /* skip "\n#area_a\n" */
325335
if (cobc_in_procedure && cobc_areacheck) {
@@ -2580,6 +2590,22 @@ clear_constants (void)
25802590
top_78_ptr = NULL;
25812591
}
25822592

2593+
static struct cb_text_list *
2594+
scan_list_add (struct cb_text_list *list, const char *text)
2595+
{
2596+
struct cb_text_list *p;
2597+
2598+
p = cobc_parse_malloc (sizeof (struct cb_text_list));
2599+
p->text = cobc_parse_strdup (text);
2600+
if (!list) {
2601+
p->last = p;
2602+
return p;
2603+
}
2604+
list->last->next = p;
2605+
list->last = p;
2606+
return list;
2607+
}
2608+
25832609
/* Global functions */
25842610

25852611
void

doc/gnucobol.texi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ Add a @code{#include} @file{file.h} at the beginning of the generated
386386
C source file. The file name is put into quotes, unless it starts by
387387
@code{<}. Quoted files should be absolute paths, since C files are compiled
388388
in temporary directories.
389+
The directive @code{>>IMP INCLUDE "FILE.h"} or @code{>>IMP INCLUDE <FILE.h>}
390+
can be used as an alternative to this compiler option.
389391
The option also implies @option{-fno-gen-c-decl-static-call}.
390392
This option can be used to check function prototypes when
391393
static calls are used. When this option is used, the source file is

0 commit comments

Comments
 (0)