codefori / vscode-rpgle

RPGLE language tools for VS Code
MIT License
39 stars 20 forks source link

Error is Incorrectly Flagged on use of %PADDR #250

Closed BrianGodsend closed 1 year ago

BrianGodsend commented 1 year ago

The %PADDR BIF accepts either a string or a prototype as its one and only parameter. If a prototype is used and the RPG lint setting RequiresParameter is enabled, the line is flagged with the Procedure calls require brackets.. In the context of the %PADDR BIF, parentheses cannot be used on the prototype (subprocedure) name.

The RPG linter should not be flagging prototype names used in %PADDR as needing parentheses.

For example:

**FREE
ctl-opt dftactgrp(*NO);
dcl-s callback  pointer(*PROC);
callback = %paddr('SOMEOTHERFUNCTION');

.///
// The following line will incorrectly be flagged in error.
///
callback = %paddr(someFunction);

*inLR = *ON;
return;
dcl-proc someFunction;
  dcl-pi *N int(10);
    value1                    char(10) const;
    value2                    char(10) const;
  end-pi;
  if value1 < value2;
    return -1;
  endif;
  if value1 > value2;
    return 1;
  endif;
  return 0;
end-proc;
dcl-proc someOtherFunction;
  dcl-pi *N int(10);
    value1                    int(10) const;
    value2                    int(10) const;
  end-pi;
  if value1 < value2;
    return -1;
  endif;
  if value1 > value2;
    return 1;
  endif;
  return 0;
end-proc;
worksofliam commented 1 year ago

@BrianGodsend What other procedures accept a raw procedure name like %PADDR?

BrianGodsend commented 1 year ago

There are a few places a procedure name (or prototype) may be specified. Just clicking through them in my head, I get the following:

Control options (Ctl-Opt):

Data definitions:

BIFs:

Looking at the list, I think you will potentially have problems primarily with MAIN, LIKE, OVERLOAD, and %paddr(). On second thought, you may have problems with them all. I believe the EXTPROC, EXPORT, and IMPORT do not require the values to be quoted ... this may be limited to fixed format (traditional syntax) source.

This may be just useless trivia as I do not think it will impact the linter, but be aware that at times a procedure name may be determined by a constant value as apposed to a literal value. IBM does this quite often when defining prototypes for the C/C++ functions. For example:

/IF DEFINED(LARGE_FILES)
  dcl-c open_function 'open64';
/ELSE
  dcl-c open_function 'open';
/ENDIF
dcl-pr open int(10) extproc(*CWIDEN : open_function);
  path           pointer    value options(*STRING);
end-pr;
worksofliam commented 1 year ago

@BrianGodsend Thanks foe the great list. I believe the control options and data definition keywords already handle this case, just not %PADDR! I will do this today or this weekend.

Thank you!

BrianGodsend commented 1 year ago

Thank YOU!

I also thought about snd-msg. It has the optional parameter %target() which, of course, accepts a program or procedure name. However, as with other unmentioned uses, the procedure name in %target() is required to be quoted and so will not come into play.

worksofliam commented 1 year ago

Released with 0.21.4.