Etten Moor
Etten Moor

Reputation: 33

Is there a reliable way or heuristic to determine if a COBOL section does / does not fall through when constructing a control flowgraph?

I'm constructing a control flowgraph for some COBOL code as an exercise. For this question, I consider the following code:

IDENTIFICATION DIVISION.PROGRAM-ID. IRREDUCIBLE-TEST.
 AUTHOR.        MOJO.
 ENVIRONMENT DIVISION.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
   01  TESTING    PIC 9(8) VALUE 100.
 PROCEDURE DIVISION.
 ROOT SECTION.
   PERFORM MAIN-SECTION-01.
   STOP RUN.
 MAIN-SECTION-01 SECTION.
   MAIN-SECTION-01-A.
      IF  TESTING = 5
         GO  TO  MAIN-SECTION-01-Z.
      PERFORM  SUBROUTINE-1.
   MAIN-SECTION-01-Z.
      EXIT.
 SUBROUTINE-1 SECTION.
   SUBROUTINE-1-A.
      EXIT.

It is clear from visual inspection that control flow does not fall through after MAIN-SECTION-01 is executed (i.e., SUBROUTINE-1 is not executed following MAIN-SECTION-01's exit), because MAIN-SECTION-01 is called through a PERFORM. However, indiscriminately connecting sections which are sequential from a syntactic perspective (like MAIN-SECTION-01 to SUBROUTINE-1) results in an irreducible flowgraph (using T1-T2 transforms), like so:

Irreducible flowgraph resulting for indiscriminate linking of serial sections

My question is: is there a reasonable heuristic or graph-theoretic basis for determining unambiguously if a section does not fall through to the next section? I know that there will always be situations where there is not a clear YES/NO answer because of decisions based on computed conditions, but in cases where this is no ambiguity (like in the program above), what would be a reasonable approach?

I'd very much appreciate any pointers to any relevant techniques that I can go off and explore by myself.

One way I've circumvented this problem is to let the developer explicitly specify which sections/paragraphs do not have incoming fallthrough connections. This works, but I'd be happier automating (some) of that decision-making.

Upvotes: 3

Views: 108

Answers (2)

Scott Nelson
Scott Nelson

Reputation: 616

Like what James Anderson said, there is no heuristic other than analysing the code.

Our company has policies: We only perform paragraphs, we do not allow GO TO (except to the paragraph that the GO TO is part of). So, if a programmer followed our policies then you know that only the beginning section falls through (and any ENTRY points). But that only helps if the programmer follows procedure properly. <shrug>

Upvotes: -1

James Anderson
James Anderson

Reputation: 27478

If you "fall into" a SECTION or "GO TO" into a section then the code will fall through to the next paragraph or section.

Basically unless you "PERFORM" a section the implicit exit does not take place and control falls to the next paragraph.

Upvotes: 0

Related Questions