mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 10:39:09 +02:00
codetools: parse proc modifier async, built-in function await
git-svn-id: trunk@63192 -
This commit is contained in:
parent
c2d27ff505
commit
7c7f225d4f
@ -5274,7 +5274,9 @@ function TDefineTree.GetDirDefinesForVirtualDirectory: TDirectoryDefines;
|
|||||||
begin
|
begin
|
||||||
DoPrepareTree;
|
DoPrepareTree;
|
||||||
if FVirtualDirCache=nil then begin
|
if FVirtualDirCache=nil then begin
|
||||||
//DebugLn('################ TDefineTree.GetDirDefinesForVirtualDirectory');
|
{$IFDEF VerboseDefineCache}
|
||||||
|
DebugLn('################ TDefineTree.GetDirDefinesForVirtualDirectory');
|
||||||
|
{$ENDIF}
|
||||||
FVirtualDirCache:=TDirectoryDefines.Create;
|
FVirtualDirCache:=TDirectoryDefines.Create;
|
||||||
FVirtualDirCache.Path:=VirtualDirectory;
|
FVirtualDirCache.Path:=VirtualDirectory;
|
||||||
if Calculate(FVirtualDirCache) then begin
|
if Calculate(FVirtualDirCache) then begin
|
||||||
|
@ -1502,6 +1502,11 @@ begin
|
|||||||
AddCompilerProcedure('Write','Args:Arguments');
|
AddCompilerProcedure('Write','Args:Arguments');
|
||||||
AddCompilerProcedure('WriteLn','Args:Arguments');
|
AddCompilerProcedure('WriteLn','Args:Arguments');
|
||||||
AddCompilerProcedure('WriteStr','var S:String;Args:Arguments');
|
AddCompilerProcedure('WriteStr','var S:String;Args:Arguments');
|
||||||
|
if Scanner.PascalCompiler=pcPas2js then begin
|
||||||
|
AddCompilerFunction('Str','const X[:Width[:Decimals]]','string');
|
||||||
|
AddCompilerFunction('AWait','const Expr: T','T');
|
||||||
|
AddCompilerFunction('AWait','aType; p: TJSPromise','aType');
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (ilcfStartOfOperand in CurrentIdentifierList.ContextFlags) and
|
if (ilcfStartOfOperand in CurrentIdentifierList.ContextFlags) and
|
||||||
|
@ -871,6 +871,7 @@ begin
|
|||||||
with IsKeyWordMethodSpecifier do begin
|
with IsKeyWordMethodSpecifier do begin
|
||||||
Add('ABSTRACT' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('ABSTRACT' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
|
Add('ASYNC' ,{$ifdef FPC}@{$endif}AllwaysTrue); // pas2js
|
||||||
Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('EXTDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue); // often used for macros
|
Add('EXTDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue); // often used for macros
|
||||||
ADD('MWPASCAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
ADD('MWPASCAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
@ -907,6 +908,7 @@ begin
|
|||||||
with IsKeyWordProcedureSpecifier do begin
|
with IsKeyWordProcedureSpecifier do begin
|
||||||
Add('ALIAS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('ALIAS' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
|
Add('ASYNC' ,{$ifdef FPC}@{$endif}AllwaysTrue); // pas2js
|
||||||
Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('COMPILERPROC' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('COMPILERPROC' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('DEPRECATED' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('DEPRECATED' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
@ -973,6 +975,7 @@ begin
|
|||||||
KeyWordLists.Add(IsKeyWordProcedureAnonymousSpecifier);
|
KeyWordLists.Add(IsKeyWordProcedureAnonymousSpecifier);
|
||||||
with IsKeyWordProcedureAnonymousSpecifier do begin
|
with IsKeyWordProcedureAnonymousSpecifier do begin
|
||||||
Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('ASSEMBLER' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
|
Add('ASYNC' ,{$ifdef FPC}@{$endif}AllwaysTrue); // pas2js
|
||||||
Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('CDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('EXTDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue); // used often for macros
|
Add('EXTDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue); // used often for macros
|
||||||
Add('FAR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('FAR' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
@ -997,6 +1000,7 @@ begin
|
|||||||
Add('EXTDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('EXTDECL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('MWPASCAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('MWPASCAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('POPSTACK' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('POPSTACK' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
|
Add('SAFECALL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
Add('VECTORCALL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
Add('VECTORCALL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
|
||||||
// Note: 'inline' and 'is nested' are not a calling specifiers
|
// Note: 'inline' and 'is nested' are not a calling specifiers
|
||||||
end;
|
end;
|
||||||
|
@ -13,16 +13,17 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, CodeToolManager, FileProcs, DefineTemplates, LinkScanner,
|
Classes, SysUtils, CodeToolManager, FileProcs, DefineTemplates, LinkScanner,
|
||||||
CodeCache, TestGlobals, LazLogger, LazFileUtils, LazUTF8, fpcunit,
|
CodeCache, ExprEval, TestGlobals, LazLogger, LazFileUtils, LazUTF8, fpcunit,
|
||||||
testregistry;
|
testregistry, TestFindDeclaration;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TCustomTestPas2js }
|
{ TCustomTestPas2js }
|
||||||
|
|
||||||
TCustomTestPas2js = class(TTestCase)
|
TCustomTestPas2js = class(TCustomTestFindDeclaration)
|
||||||
private
|
private
|
||||||
FAutoSearchPas2js: boolean;
|
FAutoSearchPas2js: boolean;
|
||||||
|
FBaseDir: string;
|
||||||
FCode: TCodeBuffer;
|
FCode: TCodeBuffer;
|
||||||
FPas2jsFilename: string;
|
FPas2jsFilename: string;
|
||||||
FUnitSetCache: TFPCUnitSetCache;
|
FUnitSetCache: TFPCUnitSetCache;
|
||||||
@ -36,15 +37,16 @@ type
|
|||||||
procedure Add(const s: string);
|
procedure Add(const s: string);
|
||||||
procedure Add(Args: array of const);
|
procedure Add(Args: array of const);
|
||||||
function FindPas2js: string;
|
function FindPas2js: string;
|
||||||
function StartProgram: boolean; virtual;
|
function StartProgram: boolean; override;
|
||||||
procedure ParseModule; virtual;
|
procedure ParseModule; virtual;
|
||||||
procedure WriteSource(CleanPos: integer; Tool: TCodeTool);
|
procedure WriteSource(CleanPos: integer; Tool: TCodeTool);
|
||||||
procedure WriteSource(const CursorPos: TCodeXYPosition);
|
procedure WriteSource(const CursorPos: TCodeXYPosition);
|
||||||
property AutoSearchPas2js: boolean read FAutoSearchPas2js write FAutoSearchPas2js;
|
property AutoSearchPas2js: boolean read FAutoSearchPas2js write FAutoSearchPas2js;
|
||||||
property Code: TCodeBuffer read FCode;
|
property Code: TCodeBuffer read FCode;
|
||||||
property Pas2jsFilename: string read FPas2jsFilename write FPas2jsFilename;
|
property Pas2jsFilename: string read FPas2jsFilename write FPas2jsFilename; // compiler filename
|
||||||
property UnitSetCache: TFPCUnitSetCache read FUnitSetCache write FUnitSetCache;
|
property UnitSetCache: TFPCUnitSetCache read FUnitSetCache write FUnitSetCache;
|
||||||
property VirtualDirDefines: TDefineTemplate read FVirtualDirDefines write FVirtualDirDefines;
|
property VirtualDirDefines: TDefineTemplate read FVirtualDirDefines write FVirtualDirDefines;
|
||||||
|
property BaseDir: string read FBaseDir write FBaseDir;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTestPas2js }
|
{ TTestPas2js }
|
||||||
@ -53,6 +55,7 @@ type
|
|||||||
published
|
published
|
||||||
procedure TestPas2js_ReadSettings;
|
procedure TestPas2js_ReadSettings;
|
||||||
procedure TestPas2js_FindDeclaration;
|
procedure TestPas2js_FindDeclaration;
|
||||||
|
procedure TestPas2js_FindDeclaration_AWait;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -63,6 +66,7 @@ procedure TCustomTestPas2js.SetUp;
|
|||||||
var
|
var
|
||||||
CurUnitSet: TFPCUnitSetCache;
|
CurUnitSet: TFPCUnitSetCache;
|
||||||
UnitSetID: String;
|
UnitSetID: String;
|
||||||
|
CompilerDefines: TDefineTemplate;
|
||||||
begin
|
begin
|
||||||
inherited SetUp;
|
inherited SetUp;
|
||||||
if (Pas2jsFilename='') and AutoSearchPas2js then begin
|
if (Pas2jsFilename='') and AutoSearchPas2js then begin
|
||||||
@ -83,10 +87,12 @@ begin
|
|||||||
VirtualDirDefines:=TDefineTemplate.Create(
|
VirtualDirDefines:=TDefineTemplate.Create(
|
||||||
'VirtualDirPas2js', 'set pas2js as compiler for virtual directory',
|
'VirtualDirPas2js', 'set pas2js as compiler for virtual directory',
|
||||||
'',VirtualDirectory,da_Directory);
|
'',VirtualDirectory,da_Directory);
|
||||||
VirtualDirDefines.AddChild(TDefineTemplate.Create('UnitSet','UnitSet identifier',
|
VirtualDirDefines.AddChild(TDefineTemplate.Create('Reset','','','',da_UndefineAll));
|
||||||
UnitSetMacroName,UnitSetID,da_DefineRecurse));
|
// create template for Pas2js settings
|
||||||
CodeToolBoss.DefineTree.Add(VirtualDirDefines);
|
CompilerDefines:=CreateFPCTemplate(UnitSetCache,nil);
|
||||||
|
VirtualDirDefines.AddChild(CompilerDefines);
|
||||||
end;
|
end;
|
||||||
|
CodeToolBoss.DefineTree.Add(VirtualDirDefines);
|
||||||
|
|
||||||
// check
|
// check
|
||||||
CurUnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
|
CurUnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
|
||||||
@ -94,6 +100,11 @@ begin
|
|||||||
Fail('CodeToolBoss.GetUnitSetForDirectory=nil');
|
Fail('CodeToolBoss.GetUnitSetForDirectory=nil');
|
||||||
if CurUnitSet<>UnitSetCache then
|
if CurUnitSet<>UnitSetCache then
|
||||||
AssertEquals('UnitSet VirtualDirectory should be pas2js',UnitSetID,CurUnitSet.GetUnitSetID);
|
AssertEquals('UnitSet VirtualDirectory should be pas2js',UnitSetID,CurUnitSet.GetUnitSetID);
|
||||||
|
|
||||||
|
if CodeToolBoss.GetPascalCompilerForDirectory('')<>pcPas2js then
|
||||||
|
AssertEquals('VirtualDirectory compiler should be pas2js',
|
||||||
|
PascalCompilerNames[pcPas2js],
|
||||||
|
PascalCompilerNames[CodeToolBoss.GetPascalCompilerForDirectory('')]);
|
||||||
end;
|
end;
|
||||||
FCode:=CodeToolBoss.CreateFile('test1.pas');
|
FCode:=CodeToolBoss.CreateFile('test1.pas');
|
||||||
end;
|
end;
|
||||||
@ -129,6 +140,7 @@ constructor TCustomTestPas2js.Create;
|
|||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FAutoSearchPas2js:=true;
|
FAutoSearchPas2js:=true;
|
||||||
|
FBaseDir:='pas2js';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomTestPas2js.Add(const s: string);
|
procedure TCustomTestPas2js.Add(const s: string);
|
||||||
@ -241,6 +253,32 @@ begin
|
|||||||
//FindDeclarations(Code);
|
//FindDeclarations(Code);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestPas2js.TestPas2js_FindDeclaration_AWait;
|
||||||
|
begin
|
||||||
|
if not StartProgram then exit;
|
||||||
|
Add([
|
||||||
|
'{$modeswitch externalclass}',
|
||||||
|
'type',
|
||||||
|
' TJSPromise = class external name ''Promise''',
|
||||||
|
' end;',
|
||||||
|
'function Crawl(d: double = 1.3): word; ',
|
||||||
|
'begin',
|
||||||
|
'end;',
|
||||||
|
'function Run(d: double): word; async;',
|
||||||
|
'var',
|
||||||
|
' p: TJSPromise;',
|
||||||
|
'begin',
|
||||||
|
' Result:=await(word,p{declaration:Run.p});',
|
||||||
|
' Result:=await(1);',
|
||||||
|
' Result:=await(Crawl{declaration:Crawl});',
|
||||||
|
' Result:=await(Crawl{declaration:Crawl}(4.5));',
|
||||||
|
'end;',
|
||||||
|
'begin',
|
||||||
|
' Run{declaration:run}(3);',
|
||||||
|
'end.']);
|
||||||
|
FindDeclarations(Code);
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisterTest(TTestPas2js);
|
RegisterTest(TTestPas2js);
|
||||||
end.
|
end.
|
||||||
|
@ -30,7 +30,7 @@ type
|
|||||||
procedure Add(const s: string);
|
procedure Add(const s: string);
|
||||||
procedure Add(Args: array of const);
|
procedure Add(Args: array of const);
|
||||||
procedure StartUnit;
|
procedure StartUnit;
|
||||||
procedure StartProgram;
|
function StartProgram: boolean; virtual;
|
||||||
procedure ParseModule;
|
procedure ParseModule;
|
||||||
procedure CheckParseError(const CursorPos: TCodeXYPosition; Msg: string);
|
procedure CheckParseError(const CursorPos: TCodeXYPosition; Msg: string);
|
||||||
procedure WriteSource(CleanPos: integer; Tool: TCodeTool);
|
procedure WriteSource(CleanPos: integer; Tool: TCodeTool);
|
||||||
@ -110,8 +110,9 @@ begin
|
|||||||
Add('');
|
Add('');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomTestPascalParser.StartProgram;
|
function TCustomTestPascalParser.StartProgram: boolean;
|
||||||
begin
|
begin
|
||||||
|
Result:=true;
|
||||||
Add('program test1;');
|
Add('program test1;');
|
||||||
Add('');
|
Add('');
|
||||||
Add('{$mode objfpc}{$H+}');
|
Add('{$mode objfpc}{$H+}');
|
||||||
|
Loading…
Reference in New Issue
Block a user