|
@@ -1806,7 +1806,7 @@ type
|
|
Procedure AddRTLVersionCheck(FuncContext: TFunctionContext; PosEl: TPasElement);
|
|
Procedure AddRTLVersionCheck(FuncContext: TFunctionContext; PosEl: TPasElement);
|
|
// create elements for helpers
|
|
// create elements for helpers
|
|
Function CreateCallHelperMethod(Proc: TPasProcedure; Expr: TPasExpr;
|
|
Function CreateCallHelperMethod(Proc: TPasProcedure; Expr: TPasExpr;
|
|
- AContext: TConvertContext): TJSElement; virtual;
|
|
|
|
|
|
+ AContext: TConvertContext): TJSCallExpression; virtual;
|
|
// Statements
|
|
// Statements
|
|
Function ConvertImplBlockElements(El: TPasImplBlock; AContext: TConvertContext; NilIfEmpty: boolean): TJSElement; virtual;
|
|
Function ConvertImplBlockElements(El: TPasImplBlock; AContext: TConvertContext; NilIfEmpty: boolean): TJSElement; virtual;
|
|
Function ConvertBeginEndStatement(El: TPasImplBeginBlock; AContext: TConvertContext; NilIfEmpty: boolean): TJSElement; virtual;
|
|
Function ConvertBeginEndStatement(El: TPasImplBeginBlock; AContext: TConvertContext; NilIfEmpty: boolean): TJSElement; virtual;
|
|
@@ -7301,8 +7301,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
LeftJS:=nil;
|
|
LeftJS:=nil;
|
|
- if (RightRefDecl.Parent.ClassType=TPasClassType)
|
|
|
|
- and (TPasClassType(RightRefDecl.Parent).HelperForType<>nil) then
|
|
|
|
|
|
+ if aResolver.IsHelper(RightRefDecl.Parent) then
|
|
begin
|
|
begin
|
|
// LeftJS.HelperMember
|
|
// LeftJS.HelperMember
|
|
if RightRefDecl is TPasVariable then
|
|
if RightRefDecl is TPasVariable then
|
|
@@ -7702,8 +7701,7 @@ begin
|
|
Decl:=aResolver.GetPasPropertySetter(Prop);
|
|
Decl:=aResolver.GetPasPropertySetter(Prop);
|
|
if Decl is TPasProcedure then
|
|
if Decl is TPasProcedure then
|
|
begin
|
|
begin
|
|
- if (Decl.Parent is TPasClassType)
|
|
|
|
- and (TPasClassType(Decl.Parent).HelperForType<>nil) then
|
|
|
|
|
|
+ if aResolver.IsHelper(Decl.Parent) then
|
|
begin
|
|
begin
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),El,AContext);
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),El,AContext);
|
|
exit;
|
|
exit;
|
|
@@ -7772,8 +7770,7 @@ begin
|
|
Call.AddArg(CreateLiteralString(El,TransformVariableName(Decl,AContext)));
|
|
Call.AddArg(CreateLiteralString(El,TransformVariableName(Decl,AContext)));
|
|
exit;
|
|
exit;
|
|
end
|
|
end
|
|
- else if (Decl is TPasProcedure) and (Decl.Parent is TPasClassType)
|
|
|
|
- and (TPasClassType(Decl.Parent).HelperForType<>nil)
|
|
|
|
|
|
+ else if aResolver.IsHelperMethod(Decl)
|
|
and not (rrfNoImplicitCallWithoutParams in Ref.Flags) then
|
|
and not (rrfNoImplicitCallWithoutParams in Ref.Flags) then
|
|
begin
|
|
begin
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),El,AContext);
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),El,AContext);
|
|
@@ -8712,17 +8709,18 @@ var
|
|
Result:=nil;
|
|
Result:=nil;
|
|
AssignContext:=nil;
|
|
AssignContext:=nil;
|
|
aResolver:=AContext.Resolver;
|
|
aResolver:=AContext.Resolver;
|
|
- Call:=CreateCallExpression(El);
|
|
|
|
|
|
+ Call:=nil;
|
|
try
|
|
try
|
|
case AContext.Access of
|
|
case AContext.Access of
|
|
caAssign:
|
|
caAssign:
|
|
begin
|
|
begin
|
|
AccessEl:=aResolver.GetPasPropertySetter(Prop);
|
|
AccessEl:=aResolver.GetPasPropertySetter(Prop);
|
|
if IsJSBracketAccessorAndConvert(Prop,AccessEl,AContext,true) then
|
|
if IsJSBracketAccessorAndConvert(Prop,AccessEl,AContext,true) then
|
|
- begin
|
|
|
|
- FreeAndNil(Call);
|
|
|
|
exit;
|
|
exit;
|
|
- end;
|
|
|
|
|
|
+ if aResolver.IsHelperMethod(AccessEl) then
|
|
|
|
+ Call:=CreateCallHelperMethod(TPasProcedure(AccessEl),El.Value,AContext)
|
|
|
|
+ else
|
|
|
|
+ Call:=CreateCallExpression(El);
|
|
AssignContext:=AContext.AccessContext as TAssignContext;
|
|
AssignContext:=AContext.AccessContext as TAssignContext;
|
|
AssignContext.PropertyEl:=Prop;
|
|
AssignContext.PropertyEl:=Prop;
|
|
AssignContext.Call:=Call;
|
|
AssignContext.Call:=Call;
|
|
@@ -8731,16 +8729,17 @@ var
|
|
begin
|
|
begin
|
|
AccessEl:=aResolver.GetPasPropertyGetter(Prop);
|
|
AccessEl:=aResolver.GetPasPropertyGetter(Prop);
|
|
if IsJSBracketAccessorAndConvert(Prop,AccessEl,AContext,true) then
|
|
if IsJSBracketAccessorAndConvert(Prop,AccessEl,AContext,true) then
|
|
- begin
|
|
|
|
- FreeAndNil(Call);
|
|
|
|
exit;
|
|
exit;
|
|
- end;
|
|
|
|
|
|
+ if aResolver.IsHelperMethod(AccessEl) then
|
|
|
|
+ Call:=CreateCallHelperMethod(TPasProcedure(AccessEl),El.Value,AContext)
|
|
|
|
+ else
|
|
|
|
+ Call:=CreateCallExpression(El);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
RaiseNotSupported(El,AContext,20170213213317);
|
|
RaiseNotSupported(El,AContext,20170213213317);
|
|
end;
|
|
end;
|
|
|
|
|
|
- if CheckPath then
|
|
|
|
|
|
+ if CheckPath and (Call.Expr=nil) then
|
|
if aResolver.IsNameExpr(El.Value) then
|
|
if aResolver.IsNameExpr(El.Value) then
|
|
// no special context
|
|
// no special context
|
|
else if El.Value is TBinaryExpr then
|
|
else if El.Value is TBinaryExpr then
|
|
@@ -8953,12 +8952,11 @@ begin
|
|
writeln('TPasToJSConverter.ConvertArrayParams Value=',GetResolverResultDbg(ResolvedEl));
|
|
writeln('TPasToJSConverter.ConvertArrayParams Value=',GetResolverResultDbg(ResolvedEl));
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
if ResolvedEl.BaseType in btAllJSStrings then
|
|
if ResolvedEl.BaseType in btAllJSStrings then
|
|
- // astring[]
|
|
|
|
|
|
+ // aString[]
|
|
ConvertStringBracket(ResolvedEl)
|
|
ConvertStringBracket(ResolvedEl)
|
|
else if (ResolvedEl.IdentEl is TPasProperty)
|
|
else if (ResolvedEl.IdentEl is TPasProperty)
|
|
- and (aResolver.IsNameExpr(El.Value) or (El.Value is TBinaryExpr))
|
|
|
|
and (aResolver.GetPasPropertyArgs(TPasProperty(ResolvedEl.IdentEl)).Count>0) then
|
|
and (aResolver.GetPasPropertyArgs(TPasProperty(ResolvedEl.IdentEl)).Count>0) then
|
|
- // aproperty[]
|
|
|
|
|
|
+ // aProperty[]
|
|
ConvertIndexedProperty(TPasProperty(ResolvedEl.IdentEl),AContext,true)
|
|
ConvertIndexedProperty(TPasProperty(ResolvedEl.IdentEl),AContext,true)
|
|
else if ResolvedEl.BaseType=btContext then
|
|
else if ResolvedEl.BaseType=btContext then
|
|
begin
|
|
begin
|
|
@@ -9167,8 +9165,7 @@ begin
|
|
end
|
|
end
|
|
else if C.InheritsFrom(TPasProcedure) then
|
|
else if C.InheritsFrom(TPasProcedure) then
|
|
begin
|
|
begin
|
|
- if (Decl.Parent is TPasClassType)
|
|
|
|
- and (TPasClassType(Decl.Parent).HelperForType<>nil) then
|
|
|
|
|
|
+ if aResolver.IsHelper(Decl.Parent) then
|
|
begin
|
|
begin
|
|
// calling a helper method
|
|
// calling a helper method
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),El.Value,AContext);
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),El.Value,AContext);
|
|
@@ -14038,8 +14035,7 @@ begin
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
ThisPas:=ProcScope.ClassRecScope.Element;
|
|
ThisPas:=ProcScope.ClassRecScope.Element;
|
|
- if (ThisPas.ClassType=TPasClassType)
|
|
|
|
- and (TPasClassType(ThisPas).HelperForType<>nil) then
|
|
|
|
|
|
+ if aResolver.IsHelper(ThisPas) then
|
|
begin
|
|
begin
|
|
// helper method
|
|
// helper method
|
|
HelperForType:=aResolver.ResolveAliasType(TPasClassType(ThisPas).HelperForType);
|
|
HelperForType:=aResolver.ResolveAliasType(TPasClassType(ThisPas).HelperForType);
|
|
@@ -15471,8 +15467,7 @@ begin
|
|
Result:=CreateReferencePathExpr(Proc,AContext);
|
|
Result:=CreateReferencePathExpr(Proc,AContext);
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
- IsHelper:=(Proc.Parent.ClassType=TPasClassType)
|
|
|
|
- and (TPasClassType(Proc.Parent).HelperForType<>nil);
|
|
|
|
|
|
+ IsHelper:=aResolver.IsHelper(Proc.Parent);
|
|
NeedClass:=aResolver.IsClassMethod(Proc);
|
|
NeedClass:=aResolver.IsClassMethod(Proc);
|
|
|
|
|
|
// an of-object method -> create "rtl.createCallback(Target,func)"
|
|
// an of-object method -> create "rtl.createCallback(Target,func)"
|
|
@@ -15870,8 +15865,7 @@ begin
|
|
if (Expr<>nil) then
|
|
if (Expr<>nil) then
|
|
begin
|
|
begin
|
|
// explicit property read
|
|
// explicit property read
|
|
- if (Decl.Parent is TPasClassType)
|
|
|
|
- and (TPasClassType(Decl.Parent).HelperForType<>nil) then
|
|
|
|
|
|
+ if aResolver.IsHelper(Decl.Parent) then
|
|
begin
|
|
begin
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),Expr,AContext);
|
|
Result:=CreateCallHelperMethod(TPasProcedure(Decl),Expr,AContext);
|
|
exit;
|
|
exit;
|
|
@@ -16919,7 +16913,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
function TPasToJSConverter.CreateCallHelperMethod(Proc: TPasProcedure;
|
|
function TPasToJSConverter.CreateCallHelperMethod(Proc: TPasProcedure;
|
|
- Expr: TPasExpr; AContext: TConvertContext): TJSElement;
|
|
|
|
|
|
+ Expr: TPasExpr; AContext: TConvertContext): TJSCallExpression;
|
|
var
|
|
var
|
|
Left: TPasExpr;
|
|
Left: TPasExpr;
|
|
WithExprScope: TPas2JSWithExprScope;
|
|
WithExprScope: TPas2JSWithExprScope;
|
|
@@ -17202,6 +17196,13 @@ begin
|
|
|
|
|
|
if Prop<>nil then
|
|
if Prop<>nil then
|
|
begin
|
|
begin
|
|
|
|
+ if aResolver.GetPasPropertyArgs(Prop).Count>0 then
|
|
|
|
+ begin
|
|
|
|
+ // arguments are passed by ConvertParamsExpr
|
|
|
|
+ Result:=Call;
|
|
|
|
+ Call:=nil;
|
|
|
|
+ exit;
|
|
|
|
+ end;
|
|
case AContext.Access of
|
|
case AContext.Access of
|
|
caAssign:
|
|
caAssign:
|
|
begin
|
|
begin
|