pastojs: fixed anonymous asm proc in mode delphi

git-svn-id: trunk@47060 -
This commit is contained in:
Mattias Gaertner 2020-10-06 21:40:52 +00:00
parent 29b6e4d6de
commit 8ca7446bf0
3 changed files with 52 additions and 5 deletions
packages
fcl-passrc/src
pastojs/tests

View File

@ -451,7 +451,8 @@ type
procedure ParseArgList(Parent: TPasElement;
Args: TFPList; // list of TPasArgument
EndToken: TToken);
procedure ParseProcedureOrFunction(Parent: TPasElement; Element: TPasProcedureType; ProcType: TProcType; OfObjectPossible: Boolean);
procedure ParseProcedureOrFunction(Parent: TPasElement;
Element: TPasProcedureType; ProcType: TProcType; OfObjectPossible: Boolean);
procedure ParseProcedureBody(Parent: TPasElement);
function ParseMethodResolution(Parent: TPasElement): TPasMethodResolution;
// Properties for external access
@ -4998,7 +4999,7 @@ begin
ptAnonymousProcedure,ptAnonymousFunction:
case CurToken of
tkIdentifier, // e.g. procedure assembler
tkbegin,tkvar,tkconst,tktype,tkprocedure,tkfunction:
tkbegin,tkvar,tkconst,tktype,tkprocedure,tkfunction,tkasm:
UngetToken;
tkColon:
if ProcType=ptAnonymousFunction then
@ -5300,7 +5301,7 @@ begin
ResultEl.ResultType := ParseType(ResultEl,CurSourcePos);
end;
else
resultEl:=Nil;
ResultEl:=Nil;
end;
if OfObjectPossible then
begin
@ -5312,7 +5313,7 @@ begin
end
else if (CurToken = tkIs) then
begin
expectToken(tkIdentifier);
ExpectToken(tkIdentifier);
if (lowerCase(CurTokenString)<>'nested') then
ParseExc(nParserExpectedNested,SParserExpectedNested);
Element.IsNested:=True;

View File

@ -2730,7 +2730,7 @@ begin
'implementation',
'generic function Run<T>(a: T): T;',
'var b: T;',
' var i: word;',
' i: word;',
'begin',
' b:=a;',
' Result:=b;',

View File

@ -358,6 +358,7 @@ type
Procedure TestAnonymousProc_NestedAssignResult;
Procedure TestAnonymousProc_Class;
Procedure TestAnonymousProc_ForLoop;
Procedure TestAnonymousProc_AsmDelphi;
// enums, sets
Procedure TestEnum_Name;
@ -5257,6 +5258,51 @@ begin
]));
end;
procedure TTestModule.TestAnonymousProc_AsmDelphi;
begin
StartProgram(false);
Add([
'{$mode delphi}',
'type',
' TProc = reference to procedure;',
' TFunc = reference to function(x: word): word;',
'procedure Run;',
'asm',
'end;',
'procedure Walk(p: TProc; f: TFunc);',
'begin',
' Walk(procedure asm end, function(b:word): word asm return 1+b; end);',
'end;',
'begin',
' Walk(procedure',
' asm',
' console.log("a");',
' end,',
' function(x: word): word asm',
' console.log("c");',
' end);',
'']);
ConvertProgram;
CheckSource('TestAnonymousProc_AsmDelphi',
LinesToStr([ // statements
'this.Run = function () {',
'};',
'this.Walk = function (p, f) {',
' $mod.Walk(function () {',
' }, function (b) {',
' return 1+b;',
' });',
'};',
'']),
LinesToStr([
'$mod.Walk(function () {',
' console.log("a");',
'}, function (x) {',
' console.log("c");',
'});',
'']));
end;
procedure TTestModule.TestEnum_Name;
begin
StartProgram(false);