Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2026-03-03 Ramy George <ramygeorge19@gmail.com>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please start with a newline (that helps with a bunch of diff algrothms for some reason)


* parser.y (constant_section, _constant_section): Add parsing
rules for Fujitsu CONSTANT SECTION extension. Route parsed
items to CB_STORAGE_CONSTANT.
* typeck.c (cb_validate_field): Enforced VALUE clause requirement
for items defined in the CONSTANT SECTION. Added CB_UNFINISHED
marker for code generation.

2025-12-29 Roger Bowler <rbowler@snipix.net>

Expand Down
8 changes: 7 additions & 1 deletion cobc/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -3408,11 +3408,17 @@ cb_validate_field (struct cb_field *f)
f->flag_invalid = 1;
return;
}
if (f->flag_item_78) {
if (f->flag_item_78) {
f->flag_is_verified = 1;
return;
}

if (f->storage == CB_STORAGE_CONSTANT) {
if (!f->values) {
cb_error_x (CB_TREE(f),("item in CONSTANT SECTION must have a VALUE clause"));
}
}

/* Set up parameters */
if (f->storage == CB_STORAGE_LOCAL ||
f->storage == CB_STORAGE_LINKAGE ||
Expand Down
30 changes: 26 additions & 4 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,11 @@ enum cobc_hd {
COBC_HD_WORKING_STORAGE_SECTION = (1U << 12),
COBC_HD_COMMUNICATION_SECTION = (1U << 13),
COBC_HD_LOCAL_STORAGE_SECTION = (1U << 14),
COBC_HD_LINKAGE_SECTION = (1U << 15),
COBC_HD_REPORT_SECTION = (1U << 16),
COBC_HD_SCREEN_SECTION = (1U << 17),
COBC_HD_PROCEDURE_DIVISION = (1U << 18)
COBC_HD_CONSTANT_SECTION = (1U << 15),
COBC_HD_LINKAGE_SECTION = (1U << 16),
COBC_HD_REPORT_SECTION = (1U << 17),
COBC_HD_SCREEN_SECTION = (1U << 18),
COBC_HD_PROCEDURE_DIVISION = (1U << 19)
};

/* Static functions */
Expand Down Expand Up @@ -6437,6 +6438,7 @@ _data_division:
_working_storage_section
_communication_section
_local_storage_section
_constant_section
_linkage_section
_report_section
_screen_section
Expand Down Expand Up @@ -9077,6 +9079,26 @@ _local_storage_section:
}
;

/* CONSTANT SECTION */

constant_section: CONSTANT {check_area_a_of("CONSTANT SECTION");};
_constant_section:

| constant_section SECTION _dot
{
check_headers_present(COBC_HD_DATA_DIVISION,0,0,0);
header_check |= COBC_HD_CONSTANT_SECTION;
current_storage = CB_STORAGE_CONSTANT;
}
_record_description_list
{
if ($5){
CB_FIELD_ADD (current_program->constant_storage, CB_FIELD($5));
}
}
;



/* LINKAGE SECTION */

Expand Down
1 change: 1 addition & 0 deletions cobc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,7 @@ struct cb_program {
struct cb_field *linkage_storage; /* LINKAGE */
struct cb_field *screen_storage; /* SCREEN */
struct cb_field *report_storage; /* REPORT */
struct cb_field *constant_storage; /* CONSTANT */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is the right thing to add - but you'd have to add the fields to that as well and then "read" the fields from there later on (have a look how that is done with working_storage)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I'm not exactly sure what should be added. I thought this is mainly for building the AST so I'm not particularly sure what is missing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When producing AST we have a "current storage" where fields are added to (a linked list of 01/77 fields) - I think while the current_storage is setup correctly, the assignment to add fields to that list isn't.
For other storage elements those are already used for the symbol printing (have a look at code for -tsymbols - it actually should be added there) and at the end for the codegen.
The new storage will also be added (but just for the -fdump part) into codegen by starting from that linked list.

When you add the new storage to those two places, you'll likely see that they are "empty".

cb_tree local_file_list; /* Local files */
cb_tree global_file_list; /* Global files */
struct handler_struct global_handler[5]; /* Global handlers */
Expand Down
9 changes: 8 additions & 1 deletion cobc/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,9 @@ cb_build_generic_register (const char *name, const char *external_definition,
}

if (current_program) {
if (field->storage == CB_STORAGE_CONSTANT) {
CB_FIELD_ADD(current_program->constant_storage, field);
}
if (field->storage == CB_STORAGE_LINKAGE) {
CB_FIELD_ADD (current_program->linkage_storage, field);
} else
Expand Down Expand Up @@ -5076,6 +5079,10 @@ cb_validate_program_data (struct cb_program *prog)
}
}
}

if (prog->constant_storage) {
CB_UNFINISHED ("CONSTANT SECTION code generation");
}
}


Expand Down Expand Up @@ -6157,7 +6164,7 @@ enum_explain_storage (const enum cb_storage storage)
{
switch (storage) {
case CB_STORAGE_CONSTANT:
return "Constants";
return "CONSTANT SECTION";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants may should be lower-cased (not sure), but CONSTANT SECTION is wrong here as other constants have the same storage but are not "living" in that section

case CB_STORAGE_FILE:
return "FILE SECTION";
case CB_STORAGE_WORKING:
Expand Down
23 changes: 23 additions & 0 deletions tests/testsuite.src/syn_definition.at
Original file line number Diff line number Diff line change
Expand Up @@ -2947,3 +2947,26 @@ AT_DATA([prog.cob], [

AT_CHECK([$COMPILE_ONLY -Wno-unfinished prog.cob], [0], [], [])
AT_CLEANUP


AT_SETUP([CONSTANT SECTION syntax])
AT_KEYWORDS([extension constant VALUE])

AT_DATA([prog.cob],[
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
CONSTANT SECTION.
01 NUM-CONST PIC 9(3).
01 OTHER-CONST PIC 9(3) VALUE 123.
PROCEDURE DIVISION.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a third constant with a constant record

STOP RUN.

])

AT_CHECK([$COMPILE_ONLY prog.cob], [1], [],
[prog.cob:6: error: item in CONSTANT SECTION must have a VALUE clause
prog.cob:7: warning: handling of CONSTANT SECTION code generation is unfinished; implementation is likely to be changed
])
AT_CLEANUP

43 changes: 43 additions & 0 deletions tests/testsuite.src/syn_move.at
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,46 @@ prog.cob:7: note: 'BIGFLT' defined here as USAGE FLOAT

AT_CLEANUP


AT_SETUP([MOVE to CONSTANT SECTION item])
AT_KEYWORDS([extension constant move])

# To be implemented.
AT_XFAIL_IF([true])

AT_DATA([prog.cob],[
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
CONSTANT SECTION.
01 NUM-CONST PIC 9(3) VALUE 123.
PROCEDURE DIVISION.
MOVE 456 TO NUM-CONST.
STOP RUN.
])

AT_CHECK([$COMPILE prog.cob], [1], [],[ignore])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may add -Wno-unfinished to the command line - please add the expected error into stderr instead of ignore (see tests above how to split the AT_CHECK into multiple lines for that

AT_CLEANUP


AT_SETUP([MOVE CONSTANT SECTION to field])
AT_KEYWORDS([extension constant move])

AT_XFAIL_IF([true])

AT_DATA([prog.cob],[
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
CONSTANT SECTION.
01 MY-CONST PIC 9(3) VALUE 123.
WORKING-STORAGE SECTION.
01 RESULT-FLD PIC 9(3).
PROCEDURE DIVISION.
MOVE MY-CONST TO RESULT-FLD.
DISPLAY RESULT-FLD.
STOP RUN.
])
# This is also not implemented yet but should help towards the bigger issue with CONSTANTs being replaced by literals
AT_CHECK([$COMPILE prog.cob], [0], [], [])
AT_CLEANUP
Comment on lines +777 to +797
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test should be moved to run_extensions (with -Wno-unfinished in the compilation) and should include testing the actual result (which I guess will be fine);
please add another runtime test into run_extensions.at that has an alphanumeric constant and uses refererence modification [substring], like MOVE MY-CONST (2:2) TO RESULT-FLD. - I guess that will currently fail during compile.

Loading