From 4e92b0a0285908cba5f649b63fbb74409691b3be Mon Sep 17 00:00:00 2001 From: mattias Date: Fri, 27 May 2022 00:17:10 +0200 Subject: [PATCH] codetools: removed modeswitch clousers, added functionreferences and anonymousfunctions --- components/codetools/linkscanner.pas | 12 ++++++++---- components/codetools/pascalparsertool.pas | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/components/codetools/linkscanner.pas b/components/codetools/linkscanner.pas index d7283ff98e..f8850d41a7 100644 --- a/components/codetools/linkscanner.pas +++ b/components/codetools/linkscanner.pas @@ -213,7 +213,6 @@ type ansistring; similarly, char becomes unicodechar rather than ansichar } cmsTypeHelpers, { allows the declaration of "type helper" (non-Delphi) or "record helper" (Delphi) for primitive types } - cmsClosures, { Anonymous methods } // not in tmodeswitch / globtype.pas !!! cmsCBlocks, { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) } cmsISOlike_IO, { I/O as it required by an ISO compatible compiler } cmsISOLike_Program_Para, { program parameters as it required by an ISO compatible compiler } @@ -224,6 +223,8 @@ type cmsPrefixedAttributes, { enable attributes that are defined before the type they belong to } cmsUnderscoreisSeparator, { _ can be used as separator to group digits in numbers } cmsImplicitFunctionSpecialization, { infer types on calls of generic functions } + cmsFunctionReferences, { allow "reference to" function types } + cmsAnonymousFunctions, { allow anonymous functions } // not yet in FPC, supported by pas2js: cmsExternalClass, { pas2js: allow class external [pkgname] name [symbol] } @@ -244,14 +245,16 @@ const cmsPointer_2_procedure,cmsAutoderef,cmsTp_procvar,cmsInitfinal,cmsDefault_ansistring, cmsOut,cmsDefault_para,cmsDuplicate_names,cmsHintdirective, cmsProperty,cmsDefault_inline,cmsExcept,cmsAdvancedRecords, - cmsClosures,cmsPrefixedAttributes,cmsArrayOperators], + cmsPrefixedAttributes,cmsArrayOperators,cmsFunctionReferences, + cmsAnonymousFunctions], // cmDELPHIUNICODE [cmsClass,cmsObjpas,cmsResult,cmsString_pchar, cmsPointer_2_procedure,cmsAutoderef,cmsTp_procvar,cmsInitfinal, cmsOut,cmsDefault_para,cmsDuplicate_names,cmsHintdirective, cmsProperty,cmsDefault_inline,cmsExcept,cmsAdvancedRecords, cmsSystemcodepage,cmsDefault_unicodestring, - cmsClosures,cmsPrefixedAttributes,cmsArrayOperators], + cmsPrefixedAttributes,cmsArrayOperators,cmsFunctionReferences, + cmsAnonymousFunctions], // cmGPC [cmsTp_procvar], // cmTP @@ -307,7 +310,6 @@ const 'FINALFIELDS', 'UNICODESTRINGS', 'TYPEHELPERS', - 'CLOSURES', // not in tmodeswitch / globtype.pas 'CBLOCKS', 'ISOIO', 'ISOPROGRAMPARAS', @@ -318,6 +320,8 @@ const 'PREFIXEDATTRIBUTES', 'UNDERSCOREISSEPARATOR', 'IMPLICITFUNCTIONSPECIALIZATION', + 'FUNCTIONREFERENCES', + 'ANONYMOUSFUNCTIONS', // not yet in FPC, supported by pas2js: 'EXTERNALCLASS', 'IGNOREATTRIBUTES', diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 0660908ddb..ed37644b6c 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -252,12 +252,12 @@ type Copying: boolean = false; const Attr: TProcHeadAttributes = []); procedure ReadAnsiStringParams(Extract: boolean = false; Copying: boolean = false; const Attr: TProcHeadAttributes = []); - function ReadClosure(ExceptionOnError: boolean): boolean; + function ReadAnonymousFunction(ExceptionOnError: boolean): boolean; function SkipTypeReference(ExceptionOnError: boolean): boolean; function SkipSpecializeParams(ExceptionOnError: boolean): boolean; function WordIsPropertyEnd: boolean; function AllowAttributes: boolean; inline; - function AllowClosures: boolean; inline; + function AllowAnonymousFunctions: boolean; inline; public CurSection: TCodeTreeNodeDesc; @@ -1094,8 +1094,8 @@ begin SaveRaiseEndOfSourceExpected(20170421195401); end else if UpAtomIs('WITH') then ReadWithStatement(true,true) - else if (UpAtomIs('PROCEDURE') or UpAtomIs('FUNCTION')) and AllowClosures then - ReadClosure(true); + else if (UpAtomIs('PROCEDURE') or UpAtomIs('FUNCTION')) and AllowAnonymousFunctions then + ReadAnonymousFunction(true); until false; except {$IFDEF ShowIgnoreErrorAfter} @@ -3056,8 +3056,8 @@ begin and (TryType=ttExcept) then begin ReadOnStatement(true,CreateNodes); end else if (UpAtomIs('PROCEDURE') or UpAtomIs('FUNCTION')) - and AllowClosures then begin - ReadClosure(true); + and AllowAnonymousFunctions then begin + ReadAnonymousFunction(true); end else begin // check for unexpected keywords case BlockType of @@ -4997,7 +4997,7 @@ end; function TPascalParserTool.KeyWordFuncTypeReferenceTo: boolean; begin - if (Scanner.CompilerModeSwitches*[cmsClosures,cmsCBlocks]<>[]) + if (Scanner.CompilerModeSwitches*[cmsFunctionReferences,cmsCBlocks]<>[]) or (Scanner.PascalCompiler=pcPas2js) then begin CreateChildNode; CurNode.Desc:=ctnReferenceTo; @@ -6132,7 +6132,7 @@ begin until false; end; -function TPascalParserTool.ReadClosure(ExceptionOnError: boolean): boolean; +function TPascalParserTool.ReadAnonymousFunction(ExceptionOnError: boolean): boolean; { parse parameter list, result type, calling convention, begin..end examples: @@ -6301,9 +6301,9 @@ begin Result:=Scanner.CompilerMode in [cmDELPHI,cmDELPHIUNICODE,cmOBJFPC]; end; -function TPascalParserTool.AllowClosures: boolean; +function TPascalParserTool.AllowAnonymousFunctions: boolean; begin - Result:=(cmsClosures in Scanner.CompilerModeSwitches) + Result:=(cmsAnonymousFunctions in Scanner.CompilerModeSwitches) or (Scanner.PascalCompiler=pcPas2js); end;