Skip to content

cobol func_start: free-format source reads data items as paragraphs and misses PROGRAM-ID units (CobolCraft) #4203

Closed

Description

@squid-protocol

Problem

In free-format COBOL (GnuCOBOL -free, *> comments, no sequence area), func_start reads data definitions as paragraphs and misses the program units. The rule's own comments (cobol.py, the CEE3DMP shield) note that "a real structural fix needs file-level fixed/free-format detection"; #2538 and #3197 deferred it.

Repro

CobolCraft (github.com/meyfa/CobolCraft @ e8c420df7a90, MIT), scanned with galaxyscope at main:

File PROGRAM-IDs func_start rows What they are
src/util/coordinates.cob 3 (Facing-GetRelative, Facing-ToString, Facing-FromString) 1 LK-POSITION (a LINKAGE item), spanning all 3 programs
src/encoding/decode.cob 13 12 VALUE-BYTES ×9, BYTE-ALPHA, LK-VALUE, LK-SLOT: all data items

Free-format data lines like 01 VALUE-BYTES. match as paragraph headers once the optional sequence-area slot swallows the indent. Meanwhile PROGRAM-ID. X. / END PROGRAM X. units, which carry CobolCraft's structure, aren't counted. Other readings (doc lines, calls/ipc) matched the source in the files checked.

Proposal

  • Detect the format per file: >>SOURCE FORMAT FREE / >>SOURCE FREE, *> comment density, lines with code in columns 1–6, or code past column 72.
  • For free-format files, anchor paragraph and section headers to a lone NAME. sentence in the PROCEDURE DIVISION only. Count nested or consecutive PROGRAM-ID units as function boundaries, and never count level-number data lines.
  • Add CobolCraft-shaped valid and invalid fixtures to the COBOL tests.

Activity

  1. added
    bug
    core-engine
    legacy-modernization
    on Oct 3, 2026
  2. squid-protocol commented on Oct 3, 2026

    @squid-protocol
    OwnerAuthor

    Follow-up from PR #4227 (which landed the free-format half): the PROGRAM-ID / END PROGRAM unit-boundary half remains open and needs a design call. It changes func_start counts for every COBOL file, and PROGRAM-IDs are already counted in class_count, so counting them as functions as well makes each program both a class and a function. Decision needed before implementing: (a) keep PROGRAM-ID as class only, (b) also count as func_start, (c) only for multi-program sources. Labelling this question. Also see multi-program issues #4243 and #4245.

  3. added
    question
    on Oct 3, 2026
  4. squid-protocol commented on Oct 4, 2026

    @squid-protocol
    OwnerAuthor

    Another shape of this issue (estate-crucible horror H-0028):

    Found by estate-crucible v0.2.0 (#4317); planted in squid-protocol/estate-crucible, scored by tests/tools/estate_crucible.py on main (#4337 has the full scorecard). The horror flips to pass when this is fixed.

  5. squid-protocol commented on Oct 5, 2026

    @squid-protocol
    OwnerAuthor

    The first half (free-format data lines read as paragraph headers) no longer reproduces on main.

    I re-scanned the issue's two CobolCraft files at e8c420df7a90 with galaxyscope --db-only on main e514b4d62 (after #4227, #4264, #4306 and #4371):

    File PROGRAM-IDs function_data rows now in the issue
    src/util/coordinates.cob 3 0 1 (LK-POSITION, a LINKAGE item)
    src/encoding/decode.cob 13 0 12 (VALUE-BYTES ×9, BYTE-ALPHA, LK-VALUE, LK-SLOT)

    Neither file has a procedure paragraph or section; each program's PROCEDURE DIVISION runs straight to GOBACK.. So zero units is the correct reading, and no data item is read as a paragraph any more. The free-format data-entry shield (#4227) and the "units only inside the PROCEDURE DIVISION" rule (#4306) both cover this shape.

    The column-1 hyphen shape (H-0028) was fixed separately in #4371.

    What is left of this issue is the PROGRAM-ID-as-unit half (should a nested or batch-compiled program count as a function boundary?). That is the owner's design question and is untouched here.

    🤖 Generated with Claude Code

  6. squid-protocol commented on Oct 5, 2026

    @squid-protocol
    OwnerAuthor

    Closing.

  7. added
    scope:core
    on Oct 16, 2026
  8. added 2 commits that reference this issue on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginelegacy-modernizationpriority: mediumquestionscope:core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions