fesch / Structorizer.Desktop

Structorizer is a little tool which you can use to create Nassi-Schneiderman Diagrams (NSD).
https://structorizer.fisch.lu
GNU General Public License v3.0
65 stars 20 forks source link

COBOL export aspects #1170

Open codemanyak opened 1 month ago

codemanyak commented 1 month ago

I just wonder what happened to the export,

Originally posted by @GitMensch in https://github.com/fesch/Structorizer.Desktop/issues/1148#issuecomment-2117084115

codemanyak commented 1 month ago

@GitMensch

Note: I guess the CODE SECTION. is intended to be output directly before the first instruction, not after every one.

I found out that the lines "CODE SECTION." and "GO BACK." were produced by the Generator method generateResult(), which is supposed to implement the function result mechanism at a routines end. "CODE SECTION." was an arbitrarily chosen section name, possibly intended for adressability of the return code (i.e., to allow to jump there from some other part of the subroutine), The "GO BACK." generation seems misplaced in generateResult() as it should always be added at the end of a diagram (except perhaps from Includables) und should therefore be produced by generateFooter(). Hence, for diagrams not representing a function, the method should not produce anything. For functions returning an integer value, it should apparently move the result value to variable RETURN-CODE (or the identifier specified by the "RETURNING" clause of the procedure division). But my question would be: what to do with a non-integer result? How do non-integral user-defined functions work in COBOL, or are they to be implemented as procedures that fill either a "globally" or "externally" declared variable or some reference argument? What is the preferrable way to export a general function diagram to COBOL?

EDIT (2024-05-27): I guess the declaration of an "BY REFERENCE" argument in the respective CALL might be the preferrable way to pass a non-integral result since it provides the best chance of name independence. In the generator draft the discussed mechanisms have indeed already been prepared, just not quite completely.