Skip to content
Closed
6 changes: 5 additions & 1 deletion gitgalaxy/core/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from gitgalaxy.core.java_arg_types import param_types as java_param_types
from gitgalaxy.core.java_arg_types import site_arg_types as java_site_arg_types
from gitgalaxy.core.network_risk_sensor import CASE_INSENSITIVE_IMPORT_LANGS
from gitgalaxy.core.pli_calls import blank_sequence_fields
from gitgalaxy.core.preproc_toggles import toggle_condition_value
from gitgalaxy.core.prism import CPP_CHAR_LITERAL_PATTERN, CPP_DIGIT_SEPARATED_NUMBER_PATTERN, CPP_LANG_IDS
from gitgalaxy.core.receiver_types import TYPED_LANGS, file_field_types
Expand Down Expand Up @@ -7169,7 +7170,10 @@ def _structural_unit_end(self, sandbox: str, header_end: int, match: re.Match[st
m = end_re.search(sandbox, header_end)
if m:
return m.end()
return len(sandbox)
# No labelled END (a procedure closed by a bare `END;`, or one run into the next header): the unit ends at its
# last line that holds anything, not at the lines that carry only a columns 73-80 sequence number (DSF).
kept = len(blank_sequence_fields(sandbox).rstrip())
return max(kept, header_end)

def _slice_by_labels(
self,
Expand Down
54 changes: 3 additions & 51 deletions tests/cobol_mainframe/ground_truth_ledger.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"engine_unit_end_counts_noncode_lines": {
"issue": 4300,
"kind": "defect",
"summary": "A unit that ends at the next header runs over the trailing lines that hold no code: a sequence number alone (CardDemo cols 1-6, 91 units; DSF PL/I cols 73-80, 8 outer procedures) or a col-7 D debugging line while WITH DEBUGGING MODE is commented out (CBSA BANKDATA CDW010). Same root as #4300 (the sequence area is not blanked in the stream the slicer reads); the key ends a unit at its last code line."
"summary": "A unit that ends at the next header still runs over the comment block written above that header (DSF R001NN11 P105_BEHANDLE_A1); the key ends a unit at its last code line. The sequence-number-only tails are fixed (#4300); whether header comments belong to the unit above or the one below is a design question."
},
"forge_reads_first_program_data_division": {
"issue": 4244,
Expand Down Expand Up @@ -3079,56 +3079,8 @@
"engine | intra-program edges | src/GML/FO04F1X1.cobol | LES-KORT -> GO TO LES-KORT | fn": "engine_drops_self_transfer",
"engine | intra-program edges | src/GML/FO04F1X1.cobol | LES-PARAM -> GO TO LES-PARAM | fn": "engine_drops_self_transfer",
"engine | intra-program edges | src/GML/R001BYDL.cobol | 1000 -> GO TO 1000 | fn": "engine_drops_self_transfer",
"engine | unit extents | src/GML/R0010422.pli | R001B1 L23-177 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010422.pli | R001B1 L23-181 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010423.pli | R001B1 L22-253 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010423.pli | R001B1 L22-255 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010424.pli | R001B1 L22-254 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010424.pli | R001B1 L22-256 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010425.pli | R001B1 L22-266 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010425.pli | R001B1 L22-268 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R00104BP.pli | R001041 L43-92 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R00104BP.pli | R001041 L43-93 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R00104E3.pli | R001041 L47-125 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R00104E3.pli | R001041 L47-127 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R00104U3.pli | R001041 L44-138 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R00104U3.pli | R001041 L44-139 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010701.pli | R00107 L74-217 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0010701.pli | R00107 L74-218 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0011430.pli | MELDING_OM_GIFTEM\u00c5L L34-287 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0011430.pli | MELDING_OM_GIFTEM\u00c5L L34-292 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0012201.pli | R001220 L44-122 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0012201.pli | R001220 L44-123 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0013101.pli | R001310 L28-808 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0013101.pli | R001310 L28-814 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0014601.pli | R001460 L23-128 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0014601.pli | R001460 L23-129 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0015502.pli | R001550 L17-191 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0015502.pli | R001550 L17-197 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0019928.pli | R001992 L25-234 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0019928.pli | R001992 L25-254 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0019961.pli | OMREGNING_PGA_FNRENDRING L36-109 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R0019961.pli | OMREGNING_PGA_FNRENDRING L36-111 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R001I801.pli | R001I80 L4-265 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R001I801.pli | R001I80 L4-283 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R001N501.pli | R001N5 L74-350 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R001N501.pli | R001N5 L74-351 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R001NN11.pli | P105_BEHANDLE_A1 L43-69 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/GML/R001NN11.pli | P105_BEHANDLE_A1 L43-77 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R0010422.pli | R001B1 L21-175 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R0010422.pli | R001B1 L21-179 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R0010424.pli | R001B1 L21-253 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R0010424.pli | R001B1 L21-255 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R00104BP.pli | R001041 L40-89 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R00104BP.pli | R001041 L40-90 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R00104F7.pli | R001041 L40-94 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R00104F7.pli | R001041 L40-95 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R0015602.pli | R001560 L23-219 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R0015602.pli | R001560 L23-225 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R001TK06.pli | R001TK6 L32-420 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R001TK06.pli | R001TK6 L32-424 | fp": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R001TK61.pli | R001T61 L32-310 | fn": "engine_unit_end_counts_noncode_lines",
"engine | unit extents | src/R001TK61.pli | R001T61 L32-311 | fp": "engine_unit_end_counts_noncode_lines"
"engine | unit extents | src/GML/R001NN11.pli | P105_BEHANDLE_A1 L43-77 | fp": "engine_unit_end_counts_noncode_lines"
},
"scoreboard": {
"BMS screen fields": {
Expand Down Expand Up @@ -3517,7 +3469,7 @@
"engine": {
"got": 423,
"outside": 0,
"tp": 398,
"tp": 422,
"truth": 423
},
"forge": null,
Expand Down
41 changes: 41 additions & 0 deletions tests/core_engine/test_pli_unit_end_sequence_tail_4300.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""#4300: a PL/I unit with no labelled `END name;` ran to the next header and so took the lines that hold only a
columns 73-80 sequence number (navikt/DSF: 16 of 25 mis-ended procedures). It now ends at its last line with content.
Trailing comments stay with the unit: that is a separate question (the key ends a unit at its last code line)."""

from gitgalaxy.core.detector import StructuralExtractor
from gitgalaxy.standards.language_standards import LANGUAGE_DEFINITIONS


def _seq(lines: list[str]) -> str:
"""Lines with an ISPF-style sequence number in columns 73-80."""
return "\n".join(line.ljust(72) + f"{(i + 1) * 10:08d}" for i, line in enumerate(lines)) + "\n"


def _extents(src: str) -> list[tuple[str, int, int]]:
result = StructuralExtractor("pli", LANGUAGE_DEFINITIONS).splice(src, "")
return [(f["name"], f["start_line"], f["end_line"]) for f in result["functions"]]


def test_a_unit_closed_by_a_bare_end_stops_before_the_sequence_only_lines():
src = _seq([" A: PROC;", " X = 1;", " RETURN;", " END;", "", "", "", " B: PROC;", " Y = 2;", " END B;"])
assert _extents(src) == [("A", 1, 4), ("B", 8, 10)]


def test_a_labelled_end_still_ends_the_unit_exactly_there():
src = _seq([" A: PROC;", " X = 1;", " END A;", "", "", " B: PROC;", " Y = 2;", " END B;"])
assert _extents(src) == [("A", 1, 3), ("B", 6, 8)]


def test_a_trailing_comment_stays_with_the_unit():
src = _seq([" A: PROC;", " X = 1;", " END;", "/* NOTE ON B */", "", " B: PROC;", " Y = 2;", " END B;"])
assert _extents(src) == [("A", 1, 4), ("B", 6, 8)]


def test_a_source_without_sequence_numbers_is_unchanged():
src = "\n".join([" A: PROC;", " X = 1;", " END;", "", " B: PROC;", " Y = 2;", " END B;"]) + "\n"
assert _extents(src) == [("A", 1, 3), ("B", 5, 7)]


def test_the_last_unit_of_a_file_also_drops_a_sequence_only_tail():
src = _seq([" A: PROC;", " X = 1;", " END;", "", ""])
assert _extents(src) == [("A", 1, 3)]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading