[committed] cobol: Isolate source format for included files
Checks
Commit Message
From: Xavier Del Campo Romero <xdelcampo@symas.com>
Date: Wed, 30 Sep 2026 23:44:15 +0200
Subject: [PATCH] cobol: Isolate source format for included files
When a file was included via the -include command-line option, the
heuristic that determines whether fixed or free format must be applied
was applied first and only on the included file, thus affecting the rest
of the compilation unit.
This could potentially break the compilation of the main source file
because the heuristic would not be applied again, and therefore the
assigned format could differ.
For example, an included file with fixed format could break the
compilation of a main source file written in free format.
Therefore, this commit aims to isolate included files from affecting the
rest of the compilation unit by allocating a source_format_stack_t
object to every included file, and then a separate source_format_stack_t
object for the main source file.
gcc/cobol/ChangeLog:
* lexio.cc (cdftext::lex_open): Split objects for included files
and
main source file.
---
gcc/cobol/lexio.cc | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
name);
@@ -1537,6 +1537,13 @@ cdftext::lex_open( const char filename[] ) {
dbgmsg("lex_open: processed %zu of %zu: '%s'", n,
included_files.size(), name);
cobol_filename_restore(); // process_file restores only for COPY
}
+ source_format_stack_t source_format;
+ source_format_t format; // free-form by default
+ if( command_line_indicator_column || explicit_format ) {
+ format.indicator_column_set(command_line_indicator_column);
+ }
+ source_format.push(format);
+
included_files.clear();
dbgmsg("lex_open: '%s'", filename);
@@ -1507,13 +1507,6 @@ cdftext::lex_open( const char filename[] ) {
* redundant.
*/
- source_format_stack_t source_format;
- source_format_t format; // free-form by default
- if( command_line_indicator_column || explicit_format ) {
- format.indicator_column_set(command_line_indicator_column);
- }
- source_format.push(format);
-
int input = open_input( filename );
if( input == -1 ) return NULL;
@@ -1522,6 +1515,13 @@ cdftext::lex_open( const char filename[] ) {
// Process any files supplied by the -include command-line option.
for( auto name : included_files ) {
+ source_format_stack_t source_format;
+ source_format_t format; // free-form by default
+ if( command_line_indicator_column || explicit_format ) {
+ format.indicator_column_set(command_line_indicator_column);
+ }
+ source_format.push(format);
+
int input; // cppcheck-suppress shadowVariable
if( -1 == (input = open(name, O_RDONLY)) ) {
cbl_message(LexIncludeE, "cannot open %<-include%> file %qs",