From cd1518057a158c8c4b1c647023c7523bbc444356 Mon Sep 17 00:00:00 2001 From: Irame Date: Wed, 27 Oct 2021 10:16:15 +0200 Subject: [PATCH 1/2] Now supports WinApi calling directive --- Source/SimpleParser/SimpleParser.Lexer.Types.pas | 1 + Source/SimpleParser/SimpleParser.Lexer.pas | 3 ++- Source/SimpleParser/SimpleParser.pas | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/SimpleParser/SimpleParser.Lexer.Types.pas b/Source/SimpleParser/SimpleParser.Lexer.Types.pas index 97843bd..26859cb 100644 --- a/Source/SimpleParser/SimpleParser.Lexer.Types.pas +++ b/Source/SimpleParser/SimpleParser.Lexer.Types.pas @@ -262,6 +262,7 @@ interface ptWhile, ptWideChar, ptWideString, + ptWinApi, ptWith, ptWord, ptWordBool, diff --git a/Source/SimpleParser/SimpleParser.Lexer.pas b/Source/SimpleParser/SimpleParser.Lexer.pas index 444246b..7298064 100644 --- a/Source/SimpleParser/SimpleParser.Lexer.pas +++ b/Source/SimpleParser/SimpleParser.Lexer.pas @@ -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; diff --git a/Source/SimpleParser/SimpleParser.pas b/Source/SimpleParser/SimpleParser.pas index a54e175..dac0679 100644 --- a/Source/SimpleParser/SimpleParser.pas +++ b/Source/SimpleParser/SimpleParser.pas @@ -172,6 +172,7 @@ interface ptSafeCall, ptStdCall, ptVirtual, + ptWinApi, ptDeprecated, ptLibrary, ptPlatform, @@ -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; @@ -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 @@ -3186,6 +3187,10 @@ procedure TmwSimplePasPar.DirectiveCalling; begin NextToken; end; + ptWinApi: + begin + NextToken; + end; else begin SynError(InvalidDirectiveCalling); @@ -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; @@ -4802,7 +4807,7 @@ procedure TmwSimplePasPar.ProceduralDirective; begin DirectiveBinding; end; - ptCdecl, ptPascal, ptRegister, ptSafeCall, ptStdCall: + ptCdecl, ptPascal, ptRegister, ptSafeCall, ptStdCall, ptWinApi: begin DirectiveCalling; end; @@ -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 From 01d733533cde4ec58d57f63d5f23cdeee8caa607 Mon Sep 17 00:00:00 2001 From: Irame Date: Thu, 28 Oct 2021 19:58:48 +0200 Subject: [PATCH 2/2] Added test for WinApi calling directive --- Test/Snippets/winapicallingdirective.pas | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Test/Snippets/winapicallingdirective.pas diff --git a/Test/Snippets/winapicallingdirective.pas b/Test/Snippets/winapicallingdirective.pas new file mode 100644 index 0000000..39411a2 --- /dev/null +++ b/Test/Snippets/winapicallingdirective.pas @@ -0,0 +1,17 @@ +unit winapicallingdirective; + +interface + +type + TMyWinApiFunc = function(): Integer; winapi; + + TMyWinApiProc = procedure(); winapi; + + +function MyWinApiFunc(): Integer; winapi; + +procedure MyWinApiProc(); winapi; + +implementation + +end.