From edc9c0feab0ee71eff6546bca62ed48dd81c5ff7 Mon Sep 17 00:00:00 2001 From: Mattias Gaertner Date: Sun, 28 Feb 2021 21:26:56 +0000 Subject: [PATCH] pastojs: fixed calling Instance.StaticMethod git-svn-id: trunk@48842 - (cherry picked from commit ce3edc8c95736568b51b73bd9ddb3ffb8af652c0) --- packages/pastojs/src/fppas2js.pp | 13 +++--- packages/pastojs/tests/tcgenerics.pas | 6 +-- packages/pastojs/tests/tcmodules.pas | 64 ++++++++++++++++++--------- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/packages/pastojs/src/fppas2js.pp b/packages/pastojs/src/fppas2js.pp index 0eb5feb3f0..2865296ddc 100644 --- a/packages/pastojs/src/fppas2js.pp +++ b/packages/pastojs/src/fppas2js.pp @@ -9789,15 +9789,12 @@ begin if RightRefDecl is TPasProcedure then begin Proc:=TPasProcedure(RightRefDecl); - if coShortRefGlobals in Options then + if not aResolver.ProcHasSelf(Proc) then begin - if not aResolver.ProcHasSelf(Proc) then - begin - // a.StaticProc -> $lp(defaultargs) - // ToDo: check if left side has only types (no call nor field) - Result:=ConvertIdentifierExpr(RightEl,TPrimitiveExpr(RightEl).Value,aContext); - exit; - end; + // a.StaticProc -> pas.unit1.aclass.StaticProc(defaultargs) + // ToDo: check if left side has only types (no call nor field) + Result:=ConvertIdentifierExpr(RightEl,TPrimitiveExpr(RightEl).Value,aContext); + exit; end; end; diff --git a/packages/pastojs/tests/tcgenerics.pas b/packages/pastojs/tests/tcgenerics.pas index 317e4fd758..e7a2f72f13 100644 --- a/packages/pastojs/tests/tcgenerics.pas +++ b/packages/pastojs/tests/tcgenerics.pas @@ -170,8 +170,8 @@ begin '']), LinesToStr([ // $mod.$main '$mod.TPoint$G1.x = $mod.p.x + 10;', - '$mod.p.Fly();', - '$mod.p.Fly();', + '$mod.TPoint$G1.Fly();', + '$mod.TPoint$G1.Fly();', ''])); end; @@ -757,7 +757,7 @@ begin ' $mod.TPoint$G1.x = this.x + 5;', ' $mod.TPoint$G1.x = $mod.TPoint$G1.x + 6;', ' this.Fly();', - ' $mod.TPoint$G1.Fly();', + ' this.Fly();', ' this.Run();', ' $mod.TPoint$G1.Run();', ' };', diff --git a/packages/pastojs/tests/tcmodules.pas b/packages/pastojs/tests/tcmodules.pas index 60235b39b2..1092da987a 100644 --- a/packages/pastojs/tests/tcmodules.pas +++ b/packages/pastojs/tests/tcmodules.pas @@ -12136,9 +12136,9 @@ begin '$mod.TRec.SetInt($mod.TRec.GetInt() + 2);', '$mod.TRec.SetInt($mod.TRec.Fx);', '$mod.TRec.Fy = $mod.r.Fx + 1;', - 'if ($mod.r.GetInt() === 2) ;', - '$mod.r.SetInt($mod.r.GetInt() + 2);', - '$mod.r.SetInt($mod.r.Fx);', + 'if ($mod.TRec.GetInt() === 2) ;', + '$mod.TRec.SetInt($mod.TRec.GetInt() + 2);', + '$mod.TRec.SetInt($mod.r.Fx);', ''])); end; @@ -12602,8 +12602,8 @@ begin ' $mod.TPoint.Fly();', '})();', '$mod.TPoint.x = $mod.r.x + 10;', - '$mod.r.Fly();', - '$mod.r.Fly();', + '$mod.TPoint.Fly();', + '$mod.TPoint.Fly();', ''])); end; @@ -13521,36 +13521,58 @@ end; procedure TTestModule.TestClass_CallClassMethodStatic; begin - exit; - StartProgram(false); Add([ 'type', ' TObject = class', ' public', - ' class var w: word;', - ' class function GetIt: tobject; static;', + ' class function Fly: tobject; static;', ' end;', - 'class function tobject.getit: tobject;', + 'class function tobject.Fly: tobject;', 'begin', - ' Result.GetIt;', - ' w:=3;', - ' w:=w+3;', + ' Result.Fly;', + ' Result.Fly();', + ' Fly;', + ' Fly();', + ' Fly.Fly;', + ' Fly.Fly();', 'end;', 'var Obj: tobject;', 'begin', - ' obj.GetIt;', - ' obj.w:=obj.w+4;', + ' obj.Fly;', + ' obj.Fly();', ' with obj do begin', - ' w:=w-5;', + ' Fly;', + ' Fly();', ' end;', '']); ConvertProgram; CheckSource('TestClass_CallClassMethodStatic', LinesToStr([ // statements + 'rtl.createClass(this, "TObject", null, function () {', + ' this.$init = function () {', + ' };', + ' this.$final = function () {', + ' };', + ' this.Fly = function () {', + ' var Result = null;', + ' $mod.TObject.Fly();', + ' $mod.TObject.Fly();', + ' $mod.TObject.Fly();', + ' $mod.TObject.Fly();', + ' $mod.TObject.Fly();', + ' $mod.TObject.Fly();', + ' return Result;', + ' };', + '});', 'this.Obj = null;' ]), LinesToStr([ // $mod.$main + '$mod.TObject.Fly();', + '$mod.TObject.Fly();', + 'var $with = $mod.Obj;', + '$with.Fly();', + '$with.Fly();', ''])); end; @@ -22690,21 +22712,21 @@ begin 'this.c = null;', '']), LinesToStr([ // $mod.$main - '$mod.b.SetSpeed($mod.b.GetSpeed() + 12);', + '$mod.TObject.SetSpeed($mod.TObject.GetSpeed() + 12);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 13);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 14);', 'var $with = $mod.b;', '$with.SetSpeed($with.GetSpeed() + 32);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 33);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 34);', - '$mod.c.SetSpeed($mod.c.GetSpeed() + 12);', + '$mod.TObject.SetSpeed($mod.TObject.GetSpeed() + 12);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 13);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 14);', 'var $with1 = $mod.c;', '$with1.SetSpeed($with1.GetSpeed() + 32);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 33);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 34);', - '$mod.TBird.SetSpeed($mod.TBird.GetSpeed() + 12);', + '$mod.TObject.SetSpeed($mod.TObject.GetSpeed() + 12);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 13);', '$mod.TObjHelper.SetLeft($mod.TObjHelper.GetLeft() + 14);', 'var $with2 = $mod.TBird;', @@ -24490,7 +24512,7 @@ begin '']), LinesToStr([ // $mod.$main '$mod.THelper.Fly.call({', - ' p: $mod.o.GetField(),', + ' p: $mod.TObject.GetField(),', ' get: function () {', ' return this.p;', ' },', @@ -24508,7 +24530,7 @@ begin ' this.p = v;', ' }', '}, 12);', - 'var $with1 = $mod.o.GetField();', + 'var $with1 = $mod.TObject.GetField();', '$mod.THelper.Fly.call({', ' get: function () {', ' return $with1;',