BrianGarland / vscode-rpgfree

Visual Studio Code extension to convert fixed format RPGLE to free format
MIT License
18 stars 11 forks source link

Conversion of CALL Statements Placed in Wrong Location and Lose Values Assigned to Parameters #87

Open BrianGodsend opened 1 year ago

BrianGodsend commented 1 year ago

When a CALL statement is converted to **FREE format, the CALL is converted to a procedure style call. There are a few problems:

Fixed format RPG:

     D idx             s              5p 0 inz
     C                   ADD       1             idx
     C                   CALL      'QCMDEXC'
     C                   PARM      'DSPLIBL'     cmd               7  
     C     RTNVALUE      PARM      7             cmdLen           15 5
       *inLR = *ON;
       return;

Wrong output:

**FREE
       Dcl-S idx          Packed(5:0) inz;
       QCMDEXC(cmd:cmdLen);
         idx = idx + 1;
       *inLR = *ON;
       return;

Expected output:

**FREE
       Dcl-S idx          Packed(5:0) inz;
         idx = idx + 1;
     C                   CALL      'QCMDEXC'
     C                   PARM      'DSPLIBL'     cmd               7  
     C     RTNVALUE      PARM      7             cmdLen           15 5
       *inLR = *ON;
       return;

If a CALL specifies variables in factor 1 (return values), the CALL statement cannot be converted to FREE. There is no equivalent syntax in FREE that would support this. The closest approximation would be to set the factor 1 variable to the contents of the result field, then pass the factor 1 as the parameter. This would require adding additional lines before the call. Also additional lines would also be needed if any initialization value was being passed as well.

For example, assume QCMDEXC passed back something to do with the command length, the following RPG could be used:

Fixed format RPG:

     D idx             s              5p 0 inz
     C                   ADD       1             idx
     C                   CALL      'QCMDEXC'
     C                   PARM      'DSPLIBL'     cmd               7  
     C     RTNVALUE      PARM      7             cmdLen           15 5
       *inLR = *ON;
       return;

Expected output:

**FREE
       Dcl-S idx          Packed(5:0) inz;
         idx = idx + 1;
         cmd = 'DSPLIBL';
         cmdLen = 7;
         RTNVALUE = cmdLen;
         QCMD(cmd:RNTVALUE);
       *inLR = *ON;
       return;
BrianGodsend commented 1 year ago

Note, the moving the CALL statement appears to be inconsistent. A trigger to make something bad happen seems to be:

The odd behaviors include:

BrianGodsend commented 1 year ago

This is may be a duplicate of #6.