mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-08 12:39:39 +02:00
pastojs: type helper set
git-svn-id: trunk@41295 -
This commit is contained in:
parent
1b6c69e079
commit
a12ca1c1a0
@ -388,12 +388,16 @@ Works:
|
|||||||
- record helpers:
|
- record helpers:
|
||||||
- in function allow assign Self
|
- in function allow assign Self
|
||||||
- type helpers:
|
- type helpers:
|
||||||
- var, const, read only const
|
- pass var, const, read only const
|
||||||
- arg default, arg const, arg var, arg out
|
- pass arg default, arg const, arg var, arg out
|
||||||
- result element
|
- pass result element
|
||||||
|
- pass function result
|
||||||
|
- pass field, class field
|
||||||
|
- pass property getter field, property getter function,
|
||||||
|
- pass class property, static class property
|
||||||
|
- pass array property
|
||||||
|
|
||||||
ToDos:
|
ToDos:
|
||||||
- class helpers, type helpers, record helpers
|
|
||||||
- cmd line param to set modeswitch
|
- cmd line param to set modeswitch
|
||||||
- Result:=inherited;
|
- Result:=inherited;
|
||||||
- asm-block annotate/reference
|
- asm-block annotate/reference
|
||||||
@ -12265,9 +12269,38 @@ Var
|
|||||||
Procedure AddReturnThis;
|
Procedure AddReturnThis;
|
||||||
var
|
var
|
||||||
RetSt: TJSReturnStatement;
|
RetSt: TJSReturnStatement;
|
||||||
|
HelperForType: TPasType;
|
||||||
|
Call: TJSCallExpression;
|
||||||
|
Proc: TPasProcedure;
|
||||||
|
aResolver: TPas2JSResolver;
|
||||||
|
ClassOrRec: TPasMembersType;
|
||||||
begin
|
begin
|
||||||
|
// "return this"
|
||||||
RetSt:=TJSReturnStatement(CreateElement(TJSReturnStatement,El));
|
RetSt:=TJSReturnStatement(CreateElement(TJSReturnStatement,El));
|
||||||
RetSt.Expr:=TJSPrimaryExpressionThis(CreateElement(TJSPrimaryExpressionThis,El));
|
RetSt.Expr:=TJSPrimaryExpressionThis(CreateElement(TJSPrimaryExpressionThis,El));
|
||||||
|
aResolver:=AContext.Resolver;
|
||||||
|
if aResolver<>nil then
|
||||||
|
begin
|
||||||
|
Proc:=TPasProcedure(El.Parent);
|
||||||
|
ProcScope:=Proc.CustomData as TPas2JSProcedureScope;
|
||||||
|
ClassOrRec:=ProcScope.ClassRecScope.Element as TPasMembersType;
|
||||||
|
if (ClassOrRec.ClassType=TPasClassType)
|
||||||
|
and (TPasClassType(ClassOrRec).HelperForType<>nil) then
|
||||||
|
begin
|
||||||
|
HelperForType:=AContext.Resolver.ResolveAliasType(TPasClassType(ClassOrRec).HelperForType);
|
||||||
|
if HelperForType is TPasMembersType then
|
||||||
|
// helper constructor for class or record -> "this" is the class/record
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
// helper constructor for a simpletype -> "this" is a reference
|
||||||
|
// -> return this.get()
|
||||||
|
Call:=CreateCallExpression(El);
|
||||||
|
Call.Expr:=CreateDotExpression(El,RetSt.Expr,
|
||||||
|
CreatePrimitiveDotExpr(TempRefObjGetterName,El));
|
||||||
|
RetSt.Expr:=Call;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
Add(RetSt,El);
|
Add(RetSt,El);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -672,7 +672,7 @@ type
|
|||||||
Procedure TestTypeHelper_StringChar;
|
Procedure TestTypeHelper_StringChar;
|
||||||
Procedure TestTypeHelper_Array;
|
Procedure TestTypeHelper_Array;
|
||||||
Procedure TestTypeHelper_EnumType;
|
Procedure TestTypeHelper_EnumType;
|
||||||
Procedure TestTypeHelper_SetType; // ToDo
|
Procedure TestTypeHelper_SetType;
|
||||||
|
|
||||||
// proc types
|
// proc types
|
||||||
Procedure TestProcType;
|
Procedure TestProcType;
|
||||||
@ -22694,6 +22694,7 @@ begin
|
|||||||
' THelper = type helper for TSetOfEnum',
|
' THelper = type helper for TSetOfEnum',
|
||||||
' procedure DoIt(e: byte = 123);',
|
' procedure DoIt(e: byte = 123);',
|
||||||
' constructor Init(e: TEnum);',
|
' constructor Init(e: TEnum);',
|
||||||
|
' constructor InitEmpty;',
|
||||||
' end;',
|
' end;',
|
||||||
'procedure THelper.DoIt(e: byte);',
|
'procedure THelper.DoIt(e: byte);',
|
||||||
'begin',
|
'begin',
|
||||||
@ -22707,14 +22708,17 @@ begin
|
|||||||
' Self:=[e];',
|
' Self:=[e];',
|
||||||
' Include(Self,blue);',
|
' Include(Self,blue);',
|
||||||
'end;',
|
'end;',
|
||||||
|
'constructor THelper.InitEmpty;',
|
||||||
|
'begin',
|
||||||
|
'end;',
|
||||||
'var s: TSetOfEnum;',
|
'var s: TSetOfEnum;',
|
||||||
'begin',
|
'begin',
|
||||||
//' s.DoIt;',
|
' s.DoIt;',
|
||||||
//' [red].DoIt;',
|
//' [red].DoIt;',
|
||||||
//' with s do DoIt;',
|
//' with s do DoIt;',
|
||||||
//' with [red,blue] do DoIt;',
|
//' with [red,blue] do DoIt;',
|
||||||
//' s:=TSetOfEnum.Init(blue);',
|
' s:=TSetOfEnum.Init(blue);',
|
||||||
//' s:=s.Init(blue);',
|
' s:=s.Init(blue);',
|
||||||
'']);
|
'']);
|
||||||
ConvertProgram;
|
ConvertProgram;
|
||||||
CheckSource('TestTypeHelper_SetType',
|
CheckSource('TestTypeHelper_SetType',
|
||||||
@ -22735,7 +22739,10 @@ begin
|
|||||||
' this.set({});',
|
' this.set({});',
|
||||||
' this.set(rtl.createSet(e));',
|
' this.set(rtl.createSet(e));',
|
||||||
' this.set(rtl.includeSet(this.get(), $mod.TEnum.blue));',
|
' this.set(rtl.includeSet(this.get(), $mod.TEnum.blue));',
|
||||||
' return this;',
|
' return this.get();',
|
||||||
|
' };',
|
||||||
|
' this.InitEmpty = function () {',
|
||||||
|
' return this.get();',
|
||||||
' };',
|
' };',
|
||||||
' this.$new = function (fn, args) {',
|
' this.$new = function (fn, args) {',
|
||||||
' return this[fn].call({',
|
' return this[fn].call({',
|
||||||
@ -22752,6 +22759,25 @@ begin
|
|||||||
'this.s = {};',
|
'this.s = {};',
|
||||||
'']),
|
'']),
|
||||||
LinesToStr([ // $mod.$main
|
LinesToStr([ // $mod.$main
|
||||||
|
'$mod.THelper.DoIt.apply({',
|
||||||
|
' p: $mod,',
|
||||||
|
' get: function () {',
|
||||||
|
' return this.p.s;',
|
||||||
|
' },',
|
||||||
|
' set: function (v) {',
|
||||||
|
' this.p.s = v;',
|
||||||
|
' }',
|
||||||
|
'}, 123);',
|
||||||
|
'$mod.s = rtl.refSet($mod.THelper.$new("Init", [$mod.TEnum.blue]));',
|
||||||
|
'$mod.s = rtl.refSet($mod.THelper.Init.apply({',
|
||||||
|
' p: $mod,',
|
||||||
|
' get: function () {',
|
||||||
|
' return this.p.s;',
|
||||||
|
' },',
|
||||||
|
' set: function (v) {',
|
||||||
|
' this.p.s = v;',
|
||||||
|
' }',
|
||||||
|
'}, $mod.TEnum.blue));',
|
||||||
'']));
|
'']));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user