RomanYankovsky / DelphiAST

Abstract syntax tree builder for Delphi
Mozilla Public License 2.0
271 stars 116 forks source link

Procedure declaration with varargs directive is not fully supported #303

Closed kvrabec closed 4 years ago

kvrabec commented 4 years ago

The following line can't be parsed by SimpleParser:

Tzstr_sendx_fn = function(dest : Winapi.Windows.PVOID; const &string : System.PAnsiChar) : System.Int32; cdecl varargs;

Even though Delphi allowes it and compiles. It works as intended when semicolon (";") is added between directives like in following example:

Tzstr_sendx_fn = function(dest : Winapi.Windows.PVOID; const &string : System.PAnsiChar) : System.Int32; cdecl; varargs;

In our case, 2nd example doesn't compile.

Workaround:

  1. Add a custom define like in following example:

{$IFNDEF CUSTOM_TAG } Tzstr_sendx_fn = function(dest : Winapi.Windows.PVOID; const &string : System.PAnsiChar) : System.Int32; cdecl varargs; {$ENDIF}

  1. Ensure to add custom tag to Syntax tree builder.

builder := TPasSyntaxTreeBuilder.Create(); builder.AddDefine('CUSTOM_TAG');

Related issue where it was allegedly solved: #246