Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for WinApi calling directive #316

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/SimpleParser/SimpleParser.Lexer.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ interface
ptWhile,
ptWideChar,
ptWideString,
ptWinApi,
ptWith,
ptWord,
ptWordBool,
Expand Down
3 changes: 2 additions & 1 deletion Source/SimpleParser/SimpleParser.Lexer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,8 @@ function TmwBasePasLex.Func71: TptTokenKind;
function TmwBasePasLex.Func72: TptTokenKind;
begin
Result := ptIdentifier;
if KeyComp('Static') then FExID := ptStatic;
if KeyComp('Static') then FExID := ptStatic else
if KeyComp('WinApi') then FExID := ptWinApi;
end;

function TmwBasePasLex.Func73: TptTokenKind;
Expand Down
15 changes: 10 additions & 5 deletions Source/SimpleParser/SimpleParser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ interface
ptSafeCall,
ptStdCall,
ptVirtual,
ptWinApi,
ptDeprecated,
ptLibrary,
ptPlatform,
Expand Down Expand Up @@ -1837,7 +1838,7 @@ procedure TmwSimplePasPar.ObjectMethodDirective;
begin
while ExID in [ptAbstract, ptCdecl, ptDynamic, ptExport, ptExternal, ptFar,
ptMessage, ptNear, ptOverload, ptPascal, ptRegister, ptSafeCall, ptStdCall,
ptVirtual, ptDeprecated, ptLibrary, ptPlatform, ptStatic, ptInline] do
ptVirtual, ptWinApi, ptDeprecated, ptLibrary, ptPlatform, ptStatic, ptInline] do
begin
ProceduralDirective;
if TokenID = ptSemiColon then Semicolon;
Expand Down Expand Up @@ -2127,7 +2128,7 @@ procedure TmwSimplePasPar.FunctionProcedureBlock;

while ExID in [ptAbstract, ptCdecl, ptDynamic, ptExport, ptExternal, ptDelayed, ptFar,
ptMessage, ptNear, ptOverload, ptOverride, ptPascal, ptRegister,
ptReintroduce, ptSafeCall, ptStdCall, ptVirtual, ptLibrary,
ptReintroduce, ptSafeCall, ptStdCall, ptVirtual, ptWinApi, ptLibrary,
ptPlatform, ptLocal, ptVarargs, ptAssembler, ptStatic, ptInline, ptForward,
ptExperimental, ptDeprecated] do
begin
Expand Down Expand Up @@ -3186,6 +3187,10 @@ procedure TmwSimplePasPar.DirectiveCalling;
begin
NextToken;
end;
ptWinApi:
begin
NextToken;
end;
else
begin
SynError(InvalidDirectiveCalling);
Expand Down Expand Up @@ -4164,7 +4169,7 @@ procedure TmwSimplePasPar.ProceduralType;
end;
while TheTokenID in [ptAbstract, ptCdecl, ptDynamic, ptExport, ptExternal, ptFar,
ptMessage, ptNear, ptOverload, ptOverride, ptPascal, ptRegister,
ptReintroduce, ptSafeCall, ptStdCall, ptVirtual, ptStatic, ptInline, ptVarargs] do
ptReintroduce, ptSafeCall, ptStdCall, ptVirtual, ptWinApi, ptStatic, ptInline, ptVarargs] do
// DR 2001-11-14 no checking for deprecated etc. since it's captured by the typedecl
begin
if TokenID = ptSemiColon then Semicolon;
Expand Down Expand Up @@ -4802,7 +4807,7 @@ procedure TmwSimplePasPar.ProceduralDirective;
begin
DirectiveBinding;
end;
ptCdecl, ptPascal, ptRegister, ptSafeCall, ptStdCall:
ptCdecl, ptPascal, ptRegister, ptSafeCall, ptStdCall, ptWinApi:
begin
DirectiveCalling;
end;
Expand Down Expand Up @@ -4870,7 +4875,7 @@ procedure TmwSimplePasPar.ExportedHeading;
//TODO: Add FINAL
while ExID in [ptAbstract, ptCdecl, ptDynamic, ptExport, ptExternal, ptFar,
ptMessage, ptNear, ptOverload, ptOverride, ptPascal, ptRegister,
ptReintroduce, ptSafeCall, ptStdCall, ptVirtual,
ptReintroduce, ptSafeCall, ptStdCall, ptVirtual, ptWinApi,
ptDeprecated, ptLibrary, ptPlatform, ptLocal, ptVarargs,
ptStatic, ptInline, ptAssembler, ptForward, ptDelayed] do
begin
Expand Down
17 changes: 17 additions & 0 deletions Test/Snippets/winapicallingdirective.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
unit winapicallingdirective;

interface

type
TMyWinApiFunc = function(): Integer; winapi;

TMyWinApiProc = procedure(); winapi;


function MyWinApiFunc(): Integer; winapi;

procedure MyWinApiProc(); winapi;

implementation

end.