Menu

#32 Prototypes

Test
pending
6
2021-09-19
2016-08-31
Edward Hart
No

Attached is a draft patch for program and function prototypes. It only adds support for the PROTOTYPE format of programs and functions and checks that prototypes and definition agree with each other. It lacks the following important features:

  • checks for parameter conformance and
  • the external repository.

Also missing is:

  • a ChangeLog entry
  • allowing the use of prototypes-name in ADDRESS OF items.

By the time this patch is complete, all of these features should be implemented.

1 Attachments

Related

Bugs: #350
Commit: [r5278]
Discussion: USER DEFINED FUNCTIONS 3 questions

Discussion

  • Edward Hart

    Edward Hart - 2016-09-22

    This update adds checks for parameter conformance.

    Here is an example.

    :::cobol
           IDENTIFICATION DIVISION.
           PROGRAM-ID. prog1 PROTOTYPE.
    
           DATA DIVISION.
           LINKAGE SECTION.
           01  x PIC X(10).
           01  y PIC 9(5) USAGE COMP-3.
    
           PROCEDURE DIVISION USING x, VALUE y.
           END PROGRAM prog1.
    
           IDENTIFICATION   DIVISION.
           PROGRAM-ID.      caller.
    
           ENVIRONMENT DIVISION.
           CONFIGURATION SECTION.
           REPOSITORY.
               PROGRAM prog1. 
    
           DATA             DIVISION.
           WORKING-STORAGE  SECTION.
           01  x PIC X(10).
           01  y FLOAT-SHORT.
           01  z PIC X.
    
           PROCEDURE        DIVISION.
               *> Valid
               CALL prog1 USING x, y
               *> TO-DO: Warn on BY VALUE without prototype (unless system function and even if we have seen the program)
               CALL "prog1" USING REFERENCE x, VALUE y
               CALL prog1 USING CONTENT z, y
               CALL prog1 USING "hello", 5
               CALL "cob_max_int" USING VALUE 4, 1
    
               *> Invalid
               CALL prog1 USING x, CONTENT y
               CALL "prog1" USING x, CONTENT y
               CALL prog1 USING x
               CALL prog1 USING x, y, z
               CALL prog1 USING x, y RETURNING z
               CALL prog1 USING x, z
               CALL prog1 USING z, y
               CALL prog1 USING OMITTED, OMITTED
               CALL prog1 USING 5, "hello"
               .
    

    The above program causes the following errors (the first error is a bug) :

    ./test.cob: 3: error: prototypes must be come before any program/function definitions
    ./test.cob: 10: warning: handling of parameters passed BY VALUE is unfinished; implementation is likely to be changed
    ./test.cob: 34: warning: BY VALUE used with unseen program; COMP-5 parameter will be assumed
    ./test.cob: 37: error: expected argument #2, y, to be passed BY VALUE
    ./test.cob: 38: error: expected argument #2, y, to be passed BY VALUE
    ./test.cob: 39: error: argument #2 is not optional
    ./test.cob: 40: error: expecting up to 2 arguments, but found 4
    ./test.cob: 41: error: unexpected RETURNING item
    ./test.cob: 41: error: invalid RETURNING field
    ./test.cob: 42: error: 'z' is not a numeric value
    ./test.cob: 42: error: argument #2, z, does not conform to the parameter definition
    ./test.cob: 43: error: argument #1, z, does not conform to the parameter definition
    ./test.cob: 45: error: argument #1 is not optional
    ./test.cob: 45: error: argument #1, NULL, does not conform to the parameter definition
    ./test.cob: 45: error: '"hello"' is not a numeric value
    ./test.cob: 45: error: argument #2, "hello", does not conform to the parameter definition
    
     
    • Edward Hart

      Edward Hart - 2017-10-07

      Patch updated to [r2120] (otherwise unchanged).

       
  • Simon Sobisch

    Simon Sobisch - 2016-09-24

    Thank you for your work on this. Current questions for this work-in-progress:

    • "40: error: expecting up to 2 arguments, but found 4" why four - I only see three?
    • "41: error: unexpected RETURNING item" - shouldn't a returning item be always possible (with an implicit move of the RETURN-CODE if the prototype doesn't have the RETURNING clause?

    Please upload a patch without the generated man entries, bison/flex testsuite and a first draft of the Changelogs, this helps to understand better what part of the patch is doing what.

     
  • Simon Sobisch

    Simon Sobisch - 2021-09-19
    • labels: COBOL 2002 --> COBOL 2002, PROTOTYPE, CALL
    • status: accepted --> pending
     
  • Simon Sobisch

    Simon Sobisch - 2021-09-19

    I'm really sorry that it took so long to recheck this. While the patch had a bunch of TODOs, general open points and some issues it was already a good bunch of work.

    I've included most of the last patch with [r4358] (fixing added errors in [r4360]), taking care of updating it to the current codebase, fixed the numbered parameter check (needed to inspect PROCEDURE DIVISION USING parameters, not LINKAGE items) and made the prototype checks depend on a warning (defaulting to on) instead of an error, allowing it to be suppressed.

    It would be really nice to get an updated version of the patch with the missing pieces, also nice: testsuite entries (could be directly committed with skip/xfail, too).

     

    Related

    Commit: [r4358]
    Commit: [r4360]


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.