|
@@ -1329,7 +1329,7 @@ type
|
|
coRTLVersionCheckMain, // insert rtl version check into main
|
|
coRTLVersionCheckMain, // insert rtl version check into main
|
|
coRTLVersionCheckSystem, // insert rtl version check into system unit init
|
|
coRTLVersionCheckSystem, // insert rtl version check into system unit init
|
|
coRTLVersionCheckUnit, // insert rtl version check into every unit init
|
|
coRTLVersionCheckUnit, // insert rtl version check into every unit init
|
|
- coAliaslobals // use short alias variables for global identifiers
|
|
|
|
|
|
+ coAliasGlobals // use short alias variables for global identifiers
|
|
);
|
|
);
|
|
TPasToJsConverterOptions = set of TPasToJsConverterOption;
|
|
TPasToJsConverterOptions = set of TPasToJsConverterOption;
|
|
const
|
|
const
|
|
@@ -1595,7 +1595,6 @@ type
|
|
function GetContextOfPasElement(El: TPasElement): TConvertContext;
|
|
function GetContextOfPasElement(El: TPasElement): TConvertContext;
|
|
function GetFuncContextOfPasElement(El: TPasElement): TFunctionContext;
|
|
function GetFuncContextOfPasElement(El: TPasElement): TFunctionContext;
|
|
function GetContextOfType(aType: TConvertContextClass): TConvertContext;
|
|
function GetContextOfType(aType: TConvertContextClass): TConvertContext;
|
|
- function CreateLocalIdentifier(const Prefix: string): string;
|
|
|
|
function CurrentModeSwitches: TModeSwitches;
|
|
function CurrentModeSwitches: TModeSwitches;
|
|
function GetGlobalFunc: TFunctionContext;
|
|
function GetGlobalFunc: TFunctionContext;
|
|
procedure WriteStack;
|
|
procedure WriteStack;
|
|
@@ -1647,14 +1646,15 @@ type
|
|
TrySt: TJSTryFinallyStatement;
|
|
TrySt: TJSTryFinallyStatement;
|
|
FinallyFirst, FinallyLast: TJSStatementList;
|
|
FinallyFirst, FinallyLast: TJSStatementList;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
- procedure AddLocalVar(const aName: string; El: TPasElement);
|
|
|
|
|
|
+ function AddLocalVar(aName: string; El: TPasElement; AutoUnique: boolean): TFCLocalIdentifier;
|
|
procedure Add_InterfaceRelease(El: TPasElement);
|
|
procedure Add_InterfaceRelease(El: TPasElement);
|
|
|
|
+ //function CreateLocalIdentifier(const Prefix: string): TFCLocalIdentifier;
|
|
function ToString: string; override;
|
|
function ToString: string; override;
|
|
function GetLocalName(El: TPasElement): string; override;
|
|
function GetLocalName(El: TPasElement): string; override;
|
|
function IndexOfLocalVar(const aName: string): integer;
|
|
function IndexOfLocalVar(const aName: string): integer;
|
|
function IndexOfLocalVar(El: TPasElement): integer;
|
|
function IndexOfLocalVar(El: TPasElement): integer;
|
|
- function FindLocalVar(const aName: string): TFCLocalIdentifier;
|
|
|
|
- function FindLocalIdentifier(El: TPasElement): TFCLocalIdentifier;
|
|
|
|
|
|
+ function FindLocalVar(const aName: string; WithParents: boolean): TFCLocalIdentifier;
|
|
|
|
+ function FindLocalIdentifier(El: TPasElement; WithParents: boolean): TFCLocalIdentifier;
|
|
procedure DoWriteStack(Index: integer); override;
|
|
procedure DoWriteStack(Index: integer); override;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -2681,7 +2681,7 @@ procedure TPas2jsPasScanner.DoHandleOptimization(OptName, OptValue: string);
|
|
begin
|
|
begin
|
|
case lowercase(OptName) of
|
|
case lowercase(OptName) of
|
|
'aliasglobals':
|
|
'aliasglobals':
|
|
- HandleBoolean(coAliaslobals,true);
|
|
|
|
|
|
+ HandleBoolean(coAliasGlobals,true);
|
|
else
|
|
else
|
|
DoLog(mtWarning,nWarnIllegalCompilerDirectiveX,sWarnIllegalCompilerDirectiveX,['optimization '+OptName]);
|
|
DoLog(mtWarning,nWarnIllegalCompilerDirectiveX,sWarnIllegalCompilerDirectiveX,['optimization '+OptName]);
|
|
end;
|
|
end;
|
|
@@ -6877,13 +6877,36 @@ begin
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TFunctionContext.AddLocalVar(const aName: string; El: TPasElement);
|
|
|
|
|
|
+function TFunctionContext.AddLocalVar(aName: string; El: TPasElement;
|
|
|
|
+ AutoUnique: boolean): TFCLocalIdentifier;
|
|
var
|
|
var
|
|
l: Integer;
|
|
l: Integer;
|
|
|
|
+ Ident: TFCLocalIdentifier;
|
|
begin
|
|
begin
|
|
|
|
+ Ident:=FindLocalVar(aName,true);
|
|
|
|
+ if Ident<>nil then
|
|
|
|
+ begin
|
|
|
|
+ if AutoUnique then
|
|
|
|
+ begin
|
|
|
|
+ l:=1;
|
|
|
|
+ while FindLocalVar(aName+IntToStr(l),true)<>nil do
|
|
|
|
+ inc(l);
|
|
|
|
+ aName:=aName+IntToStr(l);
|
|
|
|
+ end
|
|
|
|
+ else if (El=nil) or (Ident.Element<>El) then
|
|
|
|
+ // add alias, same name for two different TPasElements
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ {$IFDEF VerbosePas2JS}
|
|
|
|
+ writeln('TFunctionContext.AddLocalVar [20200608131330] "'+aName+'" El='+GetObjPath(El));
|
|
|
|
+ {$ENDIF}
|
|
|
|
+ raise EPas2JS.Create('[20200608131330] "'+aName+'" El='+GetObjPath(El));
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
l:=length(LocalVars);
|
|
l:=length(LocalVars);
|
|
SetLength(LocalVars,l+1);
|
|
SetLength(LocalVars,l+1);
|
|
- LocalVars[l]:=TFCLocalIdentifier.Create(aName,El);
|
|
|
|
|
|
+ Result:=TFCLocalIdentifier.Create(aName,El);
|
|
|
|
+ LocalVars[l]:=Result;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TFunctionContext.Add_InterfaceRelease(El: TPasElement);
|
|
procedure TFunctionContext.Add_InterfaceRelease(El: TPasElement);
|
|
@@ -6902,7 +6925,7 @@ begin
|
|
if ThisPas<>nil then
|
|
if ThisPas<>nil then
|
|
begin
|
|
begin
|
|
Result:=Result+' this';
|
|
Result:=Result+' this';
|
|
- V:=FindLocalIdentifier(ThisPas);
|
|
|
|
|
|
+ V:=FindLocalIdentifier(ThisPas,false);
|
|
if V<>nil then
|
|
if V<>nil then
|
|
Result:=Result+'="'+V.Name+'"';
|
|
Result:=Result+'="'+V.Name+'"';
|
|
Result:=Result+'='+GetObjName(ThisPas);
|
|
Result:=Result+'='+GetObjName(ThisPas);
|
|
@@ -6914,7 +6937,7 @@ var
|
|
V: TFCLocalIdentifier;
|
|
V: TFCLocalIdentifier;
|
|
begin
|
|
begin
|
|
if El=nil then exit('');
|
|
if El=nil then exit('');
|
|
- V:=FindLocalIdentifier(El);
|
|
|
|
|
|
+ V:=FindLocalIdentifier(El,false);
|
|
if V<>nil then
|
|
if V<>nil then
|
|
begin
|
|
begin
|
|
Result:=V.Name;
|
|
Result:=V.Name;
|
|
@@ -6950,26 +6973,38 @@ begin
|
|
Result:=-1;
|
|
Result:=-1;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TFunctionContext.FindLocalVar(const aName: string): TFCLocalIdentifier;
|
|
|
|
|
|
+function TFunctionContext.FindLocalVar(const aName: string; WithParents: boolean
|
|
|
|
+ ): TFCLocalIdentifier;
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
|
|
+ ParentFC: TFunctionContext;
|
|
begin
|
|
begin
|
|
i:=IndexOfLocalVar(aName);
|
|
i:=IndexOfLocalVar(aName);
|
|
if i>=0 then
|
|
if i>=0 then
|
|
- Result:=LocalVars[i]
|
|
|
|
- else
|
|
|
|
- Result:=nil;
|
|
|
|
|
|
+ exit(LocalVars[i]);
|
|
|
|
+ if (not WithParents) or (Parent=nil) then
|
|
|
|
+ exit(nil);
|
|
|
|
+ ParentFC:=Parent.GetFunctionContext;
|
|
|
|
+ if ParentFC=nil then
|
|
|
|
+ exit(nil);
|
|
|
|
+ Result:=ParentFC.FindLocalVar(aName,true);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TFunctionContext.FindLocalIdentifier(El: TPasElement): TFCLocalIdentifier;
|
|
|
|
|
|
+function TFunctionContext.FindLocalIdentifier(El: TPasElement;
|
|
|
|
+ WithParents: boolean): TFCLocalIdentifier;
|
|
var
|
|
var
|
|
i: Integer;
|
|
i: Integer;
|
|
|
|
+ ParentFC: TFunctionContext;
|
|
begin
|
|
begin
|
|
i:=IndexOfLocalVar(El);
|
|
i:=IndexOfLocalVar(El);
|
|
if i>=0 then
|
|
if i>=0 then
|
|
- Result:=LocalVars[i]
|
|
|
|
- else
|
|
|
|
- Result:=nil;
|
|
|
|
|
|
+ exit(LocalVars[i]);
|
|
|
|
+ if (not WithParents) or (Parent=nil) then
|
|
|
|
+ exit(nil);
|
|
|
|
+ ParentFC:=Parent.GetFunctionContext;
|
|
|
|
+ if ParentFC=nil then
|
|
|
|
+ exit(nil);
|
|
|
|
+ Result:=ParentFC.FindLocalIdentifier(El,true);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TFunctionContext.DoWriteStack(Index: integer);
|
|
procedure TFunctionContext.DoWriteStack(Index: integer);
|
|
@@ -7109,12 +7144,6 @@ begin
|
|
until ctx=nil;
|
|
until ctx=nil;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TConvertContext.CreateLocalIdentifier(const Prefix: string): string;
|
|
|
|
-begin
|
|
|
|
- inc(TmpVarCount);
|
|
|
|
- Result:=Prefix+IntToStr(TmpVarCount);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
function TConvertContext.CurrentModeSwitches: TModeSwitches;
|
|
function TConvertContext.CurrentModeSwitches: TModeSwitches;
|
|
begin
|
|
begin
|
|
if Resolver=nil then
|
|
if Resolver=nil then
|
|
@@ -7371,7 +7400,7 @@ begin
|
|
if El.CustomData is TPasModuleScope then
|
|
if El.CustomData is TPasModuleScope then
|
|
IntfContext.ScannerBoolSwitches:=TPasModuleScope(El.CustomData).BoolSwitches;
|
|
IntfContext.ScannerBoolSwitches:=TPasModuleScope(El.CustomData).BoolSwitches;
|
|
ModVarName:=GetBIName(pbivnModule);
|
|
ModVarName:=GetBIName(pbivnModule);
|
|
- IntfContext.AddLocalVar(ModVarName,El);
|
|
|
|
|
|
+ IntfContext.AddLocalVar(ModVarName,El,false);
|
|
AddToSourceElements(Src,CreateVarStatement(ModVarName,
|
|
AddToSourceElements(Src,CreateVarStatement(ModVarName,
|
|
CreatePrimitiveDotExpr('this',El),El));
|
|
CreatePrimitiveDotExpr('this',El),El));
|
|
|
|
|
|
@@ -7396,7 +7425,7 @@ begin
|
|
CreateMemberExpression([ModVarName,GetBIName(pbivnImplementation)]),El);
|
|
CreateMemberExpression([ModVarName,GetBIName(pbivnImplementation)]),El);
|
|
AddToSourceElements(Src,ImplVarSt);
|
|
AddToSourceElements(Src,ImplVarSt);
|
|
// register local var $impl
|
|
// register local var $impl
|
|
- IntfContext.AddLocalVar(GetBIName(pbivnImplementation),El.ImplementationSection);
|
|
|
|
|
|
+ IntfContext.AddLocalVar(GetBIName(pbivnImplementation),El.ImplementationSection,false);
|
|
end;
|
|
end;
|
|
if Assigned(El.InterfaceSection) then
|
|
if Assigned(El.InterfaceSection) then
|
|
AddToSourceElements(Src,ConvertDeclarations(El.InterfaceSection,IntfContext));
|
|
AddToSourceElements(Src,ConvertDeclarations(El.InterfaceSection,IntfContext));
|
|
@@ -15656,7 +15685,7 @@ begin
|
|
begin
|
|
begin
|
|
// has nested procs -> add "var $Self = this;"
|
|
// has nested procs -> add "var $Self = this;"
|
|
if ThisPas<>nil then
|
|
if ThisPas<>nil then
|
|
- FuncContext.AddLocalVar(GetBIName(pbivnSelf),ThisPas)
|
|
|
|
|
|
+ FuncContext.AddLocalVar(GetBIName(pbivnSelf),ThisPas,false)
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
// e.g. in a type helper, where 'this' is a not a Pascal element, but a temp JS getter/setter object
|
|
// e.g. in a type helper, where 'this' is a not a Pascal element, but a temp JS getter/setter object
|
|
@@ -15664,16 +15693,16 @@ begin
|
|
SelfSt:=CreateVarStatement(GetBIName(pbivnSelf),
|
|
SelfSt:=CreateVarStatement(GetBIName(pbivnSelf),
|
|
CreatePrimitiveDotExpr('this',ImplProc),ImplProc);
|
|
CreatePrimitiveDotExpr('this',ImplProc),ImplProc);
|
|
AddBodyStatement(SelfSt,PosEl);
|
|
AddBodyStatement(SelfSt,PosEl);
|
|
- if ImplProcScope.SelfArg<>nil then
|
|
|
|
|
|
+ if (ImplProcScope.SelfArg<>nil) and (ImplProcScope.SelfArg<>ThisPas) then
|
|
begin
|
|
begin
|
|
// redirect Pascal-Self to JS-Self
|
|
// redirect Pascal-Self to JS-Self
|
|
- FuncContext.AddLocalVar(GetBIName(pbivnSelf),ImplProcScope.SelfArg);
|
|
|
|
|
|
+ FuncContext.AddLocalVar(GetBIName(pbivnSelf),ImplProcScope.SelfArg,false);
|
|
end;
|
|
end;
|
|
end
|
|
end
|
|
else if ImplProcScope.SelfArg<>nil then
|
|
else if ImplProcScope.SelfArg<>nil then
|
|
begin
|
|
begin
|
|
// no nested procs -> redirect Pascal-Self to JS-this
|
|
// no nested procs -> redirect Pascal-Self to JS-this
|
|
- FuncContext.AddLocalVar('this',ImplProcScope.SelfArg);
|
|
|
|
|
|
+ FuncContext.AddLocalVar('this',ImplProcScope.SelfArg,false);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -15983,7 +16012,7 @@ var
|
|
StList: TJSStatementList;
|
|
StList: TJSStatementList;
|
|
Expr: TPasExpr;
|
|
Expr: TPasExpr;
|
|
IfSt, LastIfSt: TJSIfStatement;
|
|
IfSt, LastIfSt: TJSIfStatement;
|
|
- TmpVarName: String;
|
|
|
|
|
|
+ TmpVar: TFCLocalIdentifier;
|
|
VarDecl: TJSVarDeclaration;
|
|
VarDecl: TJSVarDeclaration;
|
|
VarSt: TJSVariableStatement;
|
|
VarSt: TJSVariableStatement;
|
|
JSOrExpr: TJSLogicalOrExpression;
|
|
JSOrExpr: TJSLogicalOrExpression;
|
|
@@ -15993,6 +16022,7 @@ var
|
|
JSEQExpr: TJSEqualityExpressionSEQ;
|
|
JSEQExpr: TJSEqualityExpressionSEQ;
|
|
aResolver: TPas2JSResolver;
|
|
aResolver: TPas2JSResolver;
|
|
CaseResolved: TPasResolverResult;
|
|
CaseResolved: TPasResolverResult;
|
|
|
|
+ FuncCtx: TFunctionContext;
|
|
begin
|
|
begin
|
|
Result:=nil;
|
|
Result:=nil;
|
|
aResolver:=AContext.Resolver;
|
|
aResolver:=AContext.Resolver;
|
|
@@ -16038,13 +16068,16 @@ begin
|
|
StList:=TJSStatementList(CreateElement(TJSStatementList,El));
|
|
StList:=TJSStatementList(CreateElement(TJSStatementList,El));
|
|
ok:=false;
|
|
ok:=false;
|
|
try
|
|
try
|
|
- // create var $tmp=CaseExpr;
|
|
|
|
- TmpVarName:=AContext.CreateLocalIdentifier('$tmp');
|
|
|
|
|
|
+ // create var $tmp1=CaseExpr;
|
|
|
|
+ FuncCtx:=AContext.GetFunctionContext;
|
|
|
|
+ if FuncCtx=nil then
|
|
|
|
+ RaiseNotSupported(El,AContext,20200608132048);
|
|
|
|
+ TmpVar:=FuncCtx.AddLocalVar('$tmp',El.CaseExpr,true);
|
|
VarSt:=TJSVariableStatement(CreateElement(TJSVariableStatement,El.CaseExpr));
|
|
VarSt:=TJSVariableStatement(CreateElement(TJSVariableStatement,El.CaseExpr));
|
|
StList.A:=VarSt;
|
|
StList.A:=VarSt;
|
|
VarDecl:=TJSVarDeclaration(CreateElement(TJSVarDeclaration,El.CaseExpr));
|
|
VarDecl:=TJSVarDeclaration(CreateElement(TJSVarDeclaration,El.CaseExpr));
|
|
VarSt.A:=VarDecl;
|
|
VarSt.A:=VarDecl;
|
|
- VarDecl.Name:=TmpVarName;
|
|
|
|
|
|
+ VarDecl.Name:=TmpVar.Name;
|
|
VarDecl.Init:=ConvertExpression(El.CaseExpr,AContext);
|
|
VarDecl.Init:=ConvertExpression(El.CaseExpr,AContext);
|
|
|
|
|
|
LastIfSt:=nil;
|
|
LastIfSt:=nil;
|
|
@@ -16074,19 +16107,19 @@ begin
|
|
// create "tmp>=left"
|
|
// create "tmp>=left"
|
|
JSGEExpr:=TJSRelationalExpressionGE(CreateElement(TJSRelationalExpressionGE,Expr));
|
|
JSGEExpr:=TJSRelationalExpressionGE(CreateElement(TJSRelationalExpressionGE,Expr));
|
|
JSAndExpr.A:=JSGEExpr;
|
|
JSAndExpr.A:=JSGEExpr;
|
|
- JSGEExpr.A:=CreatePrimitiveDotExpr(TmpVarName,El.CaseExpr);
|
|
|
|
|
|
+ JSGEExpr.A:=CreatePrimitiveDotExpr(TmpVar.Name,El.CaseExpr);
|
|
JSGEExpr.B:=ConvertExpression(TBinaryExpr(Expr).left,AContext);
|
|
JSGEExpr.B:=ConvertExpression(TBinaryExpr(Expr).left,AContext);
|
|
// create "tmp<=right"
|
|
// create "tmp<=right"
|
|
JSLEExpr:=TJSRelationalExpressionLE(CreateElement(TJSRelationalExpressionLE,Expr));
|
|
JSLEExpr:=TJSRelationalExpressionLE(CreateElement(TJSRelationalExpressionLE,Expr));
|
|
JSAndExpr.B:=JSLEExpr;
|
|
JSAndExpr.B:=JSLEExpr;
|
|
- JSLEExpr.A:=CreatePrimitiveDotExpr(TmpVarName,El.CaseExpr);
|
|
|
|
|
|
+ JSLEExpr.A:=CreatePrimitiveDotExpr(TmpVar.Name,El.CaseExpr);
|
|
JSLEExpr.B:=ConvertExpression(TBinaryExpr(Expr).right,AContext);
|
|
JSLEExpr.B:=ConvertExpression(TBinaryExpr(Expr).right,AContext);
|
|
if IsCaseOfString then
|
|
if IsCaseOfString then
|
|
begin
|
|
begin
|
|
// case of string, range -> "(tmp.length===1) &&"
|
|
// case of string, range -> "(tmp.length===1) &&"
|
|
JSEQExpr:=TJSEqualityExpressionSEQ(CreateElement(TJSEqualityExpressionSEQ,Expr));
|
|
JSEQExpr:=TJSEqualityExpressionSEQ(CreateElement(TJSEqualityExpressionSEQ,Expr));
|
|
JSEQExpr.A:=CreateDotNameExpr(Expr,
|
|
JSEQExpr.A:=CreateDotNameExpr(Expr,
|
|
- CreatePrimitiveDotExpr(TmpVarName,El.CaseExpr),
|
|
|
|
|
|
+ CreatePrimitiveDotExpr(TmpVar.Name,El.CaseExpr),
|
|
'length');
|
|
'length');
|
|
JSEQExpr.B:=CreateLiteralNumber(Expr,1);
|
|
JSEQExpr.B:=CreateLiteralNumber(Expr,1);
|
|
JSAndExpr:=TJSLogicalAndExpression(CreateElement(TJSLogicalAndExpression,Expr));
|
|
JSAndExpr:=TJSLogicalAndExpression(CreateElement(TJSLogicalAndExpression,Expr));
|
|
@@ -16100,7 +16133,7 @@ begin
|
|
// value -> create (tmp===Expr)
|
|
// value -> create (tmp===Expr)
|
|
JSEQExpr:=TJSEqualityExpressionSEQ(CreateElement(TJSEqualityExpressionSEQ,Expr));
|
|
JSEQExpr:=TJSEqualityExpressionSEQ(CreateElement(TJSEqualityExpressionSEQ,Expr));
|
|
JSExpr:=JSEQExpr;
|
|
JSExpr:=JSEQExpr;
|
|
- JSEQExpr.A:=CreatePrimitiveDotExpr(TmpVarName,El.CaseExpr);
|
|
|
|
|
|
+ JSEQExpr.A:=CreatePrimitiveDotExpr(TmpVar.Name,El.CaseExpr);
|
|
JSEQExpr.B:=ConvertExpression(Expr,AContext);
|
|
JSEQExpr.B:=ConvertExpression(Expr,AContext);
|
|
end;
|
|
end;
|
|
if IfSt.Cond=nil then
|
|
if IfSt.Cond=nil then
|
|
@@ -16271,14 +16304,14 @@ begin
|
|
ModVarName:=GetBIName(pbivnModule);
|
|
ModVarName:=GetBIName(pbivnModule);
|
|
AddToSourceElements(Src,CreateVarStatement(ModVarName,
|
|
AddToSourceElements(Src,CreateVarStatement(ModVarName,
|
|
CreatePrimitiveDotExpr('this',El),El));
|
|
CreatePrimitiveDotExpr('this',El),El));
|
|
- ImplContext.AddLocalVar(ModVarName,El);
|
|
|
|
|
|
+ ImplContext.AddLocalVar(ModVarName,El,false);
|
|
|
|
|
|
// add var $impl = $mod.$impl
|
|
// add var $impl = $mod.$impl
|
|
ImplVarName:=GetBIName(pbivnImplementation);
|
|
ImplVarName:=GetBIName(pbivnImplementation);
|
|
ImplVarSt:=CreateVarStatement(ImplVarName,
|
|
ImplVarSt:=CreateVarStatement(ImplVarName,
|
|
CreateMemberExpression([ModVarName,ImplVarName]),El.ImplementationSection);
|
|
CreateMemberExpression([ModVarName,ImplVarName]),El.ImplementationSection);
|
|
AddToSourceElements(Src,ImplVarSt);
|
|
AddToSourceElements(Src,ImplVarSt);
|
|
- ImplContext.AddLocalVar(ImplVarName,El.ImplementationSection);
|
|
|
|
|
|
+ ImplContext.AddLocalVar(ImplVarName,El.ImplementationSection,false);
|
|
|
|
|
|
// create implementation declarations
|
|
// create implementation declarations
|
|
ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext);
|
|
ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext);
|
|
@@ -17766,14 +17799,14 @@ function TPasToJSConverter.CreateGetEnumeratorLoop(El: TPasImplForLoop;
|
|
// };
|
|
// };
|
|
var
|
|
var
|
|
PosEl: TPasElement;
|
|
PosEl: TPasElement;
|
|
- CurInVarName: String;
|
|
|
|
|
|
+ CurInVar: TFCLocalIdentifier;
|
|
|
|
|
|
function CreateInName: TJSElement;
|
|
function CreateInName: TJSElement;
|
|
var
|
|
var
|
|
Ident: TJSPrimaryExpressionIdent;
|
|
Ident: TJSPrimaryExpressionIdent;
|
|
begin
|
|
begin
|
|
Ident:=TJSPrimaryExpressionIdent(CreateElement(TJSPrimaryExpressionIdent,PosEl));
|
|
Ident:=TJSPrimaryExpressionIdent(CreateElement(TJSPrimaryExpressionIdent,PosEl));
|
|
- Ident.Name:=TJSString(CurInVarName); // do not lowercase
|
|
|
|
|
|
+ Ident.Name:=TJSString(CurInVar.Name); // do not lowercase
|
|
Result:=Ident;
|
|
Result:=Ident;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -17782,7 +17815,7 @@ var
|
|
ForScope: TPasForLoopScope;
|
|
ForScope: TPasForLoopScope;
|
|
Statements: TJSStatementList;
|
|
Statements: TJSStatementList;
|
|
VarSt: TJSVariableStatement;
|
|
VarSt: TJSVariableStatement;
|
|
- FuncContext: TConvertContext;
|
|
|
|
|
|
+ FuncContext: TFunctionContext;
|
|
List, GetCurrent, J: TJSElement;
|
|
List, GetCurrent, J: TJSElement;
|
|
Call: TJSCallExpression;
|
|
Call: TJSCallExpression;
|
|
TrySt: TJSTryFinallyStatement;
|
|
TrySt: TJSTryFinallyStatement;
|
|
@@ -17845,9 +17878,7 @@ begin
|
|
RaiseNotSupported(El,AContext,20190208154003);
|
|
RaiseNotSupported(El,AContext,20190208154003);
|
|
|
|
|
|
// get function context
|
|
// get function context
|
|
- FuncContext:=AContext;
|
|
|
|
- while (FuncContext.Parent<>nil) and (not (FuncContext is TFunctionContext)) do
|
|
|
|
- FuncContext:=FuncContext.Parent;
|
|
|
|
|
|
+ FuncContext:=AContext.GetFunctionContext;
|
|
|
|
|
|
PosEl:=El;
|
|
PosEl:=El;
|
|
Statements:=TJSStatementList(CreateElement(TJSStatementList,PosEl));
|
|
Statements:=TJSStatementList(CreateElement(TJSStatementList,PosEl));
|
|
@@ -17869,8 +17900,8 @@ begin
|
|
CreateIdentifierExpr(GetEnumeratorFunc,AContext),true);
|
|
CreateIdentifierExpr(GetEnumeratorFunc,AContext),true);
|
|
end;
|
|
end;
|
|
// var $in=
|
|
// var $in=
|
|
- CurInVarName:=FuncContext.CreateLocalIdentifier(GetBIName(pbivnLoopIn));
|
|
|
|
- VarSt.A:=CreateVarDecl(CurInVarName,Call,PosEl);
|
|
|
|
|
|
+ CurInVar:=FuncContext.AddLocalVar(GetBIName(pbivnLoopIn),El.VariableName,true);
|
|
|
|
+ VarSt.A:=CreateVarDecl(CurInVar.Name,Call,PosEl);
|
|
|
|
|
|
PosEl:=El.VariableName;
|
|
PosEl:=El.VariableName;
|
|
TrySt:=nil;
|
|
TrySt:=nil;
|
|
@@ -18118,7 +18149,6 @@ function TPasToJSConverter.CreateTypeInfoRef(El: TPasType;
|
|
AContext: TConvertContext; ErrorEl: TPasElement): TJSElement;
|
|
AContext: TConvertContext; ErrorEl: TPasElement): TJSElement;
|
|
var
|
|
var
|
|
aName, aModName: String;
|
|
aName, aModName: String;
|
|
- CurEl: TPasElement;
|
|
|
|
aModule: TPasModule;
|
|
aModule: TPasModule;
|
|
Bracket: TJSBracketMemberExpression;
|
|
Bracket: TJSBracketMemberExpression;
|
|
begin
|
|
begin
|
|
@@ -18130,26 +18160,12 @@ begin
|
|
Result:=CreatePrimitiveDotExpr(aName,El)
|
|
Result:=CreatePrimitiveDotExpr(aName,El)
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
- CurEl:=El;
|
|
|
|
- while CurEl<>nil do
|
|
|
|
- begin
|
|
|
|
- if CurEl is TPasSection then
|
|
|
|
- begin
|
|
|
|
- aModule:=CurEl.Parent as TPasModule;
|
|
|
|
- aModName:=TransformModuleName(aModule,true,AContext);
|
|
|
|
- Bracket:=TJSBracketMemberExpression(CreateElement(TJSBracketMemberExpression,El));
|
|
|
|
- Bracket.MExpr:=CreateMemberExpression([aModName,GetBIName(pbivnRTTI)]);
|
|
|
|
- Bracket.Name:=CreateLiteralString(El,aName);
|
|
|
|
- Result:=Bracket;
|
|
|
|
- exit;
|
|
|
|
- end;
|
|
|
|
- CurEl:=CurEl.Parent;
|
|
|
|
- end;
|
|
|
|
- // not supported
|
|
|
|
- aName:=El.Name;
|
|
|
|
- if aName='' then aName:=El.ClassName;
|
|
|
|
- DoError(20170905152041,nTypeXCannotBePublished,sTypeXCannotBePublished,
|
|
|
|
- [aName],ErrorEl);
|
|
|
|
|
|
+ aModule:=El.GetModule;
|
|
|
|
+ aModName:=TransformModuleName(aModule,true,AContext);
|
|
|
|
+ Bracket:=TJSBracketMemberExpression(CreateElement(TJSBracketMemberExpression,El));
|
|
|
|
+ Bracket.MExpr:=CreateMemberExpression([aModName,GetBIName(pbivnRTTI)]);
|
|
|
|
+ Bracket.Name:=CreateLiteralString(El,aName);
|
|
|
|
+ Result:=Bracket;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -18831,7 +18847,7 @@ begin
|
|
RaiseNotSupported(El,FuncContext,20190223211808,GetObjName(El));
|
|
RaiseNotSupported(El,FuncContext,20190223211808,GetObjName(El));
|
|
|
|
|
|
// add $r to local vars, to avoid name clashes and for nicer debugging
|
|
// add $r to local vars, to avoid name clashes and for nicer debugging
|
|
- FuncContext.AddLocalVar(GetBIName(pbivnRTTILocal),nil);
|
|
|
|
|
|
+ FuncContext.AddLocalVar(GetBIName(pbivnRTTILocal),nil,false);
|
|
|
|
|
|
if NeedLocalVar then
|
|
if NeedLocalVar then
|
|
CreateLocalvar;
|
|
CreateLocalvar;
|
|
@@ -20934,7 +20950,7 @@ var
|
|
end;
|
|
end;
|
|
|
|
|
|
var
|
|
var
|
|
- FuncContext: TConvertContext;
|
|
|
|
|
|
+ FuncContext: TFunctionContext;
|
|
VarResolved, InResolved: TPasResolverResult;
|
|
VarResolved, InResolved: TPasResolverResult;
|
|
StartValue, EndValue, InValue: TResEvalValue;
|
|
StartValue, EndValue, InValue: TResEvalValue;
|
|
StartInt, EndInt: TMaxPrecInt;
|
|
StartInt, EndInt: TMaxPrecInt;
|
|
@@ -21222,9 +21238,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
// get function context
|
|
// get function context
|
|
- FuncContext:=AContext;
|
|
|
|
- while (FuncContext.Parent<>nil) and (not (FuncContext is TFunctionContext)) do
|
|
|
|
- FuncContext:=FuncContext.Parent;
|
|
|
|
|
|
+ FuncContext:=AContext.GetFunctionContext;
|
|
|
|
|
|
StartValue:=nil;
|
|
StartValue:=nil;
|
|
StartInt:=0;
|
|
StartInt:=0;
|
|
@@ -21241,18 +21255,27 @@ begin
|
|
exit;
|
|
exit;
|
|
|
|
|
|
// create unique var names $l, $end, $in
|
|
// create unique var names $l, $end, $in
|
|
- if HasInVar then
|
|
|
|
- CurInVarName:=FuncContext.CreateLocalIdentifier(GetBIName(pbivnLoopIn))
|
|
|
|
- else
|
|
|
|
- CurInVarName:='';
|
|
|
|
- if HasLoopVar then
|
|
|
|
- CurLoopVarName:=FuncContext.CreateLocalIdentifier(GetBIName(pbivnLoop))
|
|
|
|
- else
|
|
|
|
- CurLoopVarName:='';
|
|
|
|
- if HasEndVar then
|
|
|
|
- CurEndVarName:=FuncContext.CreateLocalIdentifier(GetBIName(pbivnLoopEnd))
|
|
|
|
|
|
+ if FuncContext=nil then
|
|
|
|
+ begin
|
|
|
|
+ CurInVarName:='$in';
|
|
|
|
+ CurLoopVarName:='$l';
|
|
|
|
+ CurEndVarName:='$end';
|
|
|
|
+ end
|
|
else
|
|
else
|
|
- CurEndVarName:='';
|
|
|
|
|
|
+ begin
|
|
|
|
+ if HasInVar then
|
|
|
|
+ CurInVarName:=FuncContext.AddLocalVar(GetBIName(pbivnLoopIn),nil,true).Name
|
|
|
|
+ else
|
|
|
|
+ CurInVarName:='';
|
|
|
|
+ if HasLoopVar then
|
|
|
|
+ CurLoopVarName:=FuncContext.AddLocalVar(GetBIName(pbivnLoop),nil,true).Name
|
|
|
|
+ else
|
|
|
|
+ CurLoopVarName:='';
|
|
|
|
+ if HasEndVar then
|
|
|
|
+ CurEndVarName:=FuncContext.AddLocalVar(GetBIName(pbivnLoopEnd),nil,true).Name
|
|
|
|
+ else
|
|
|
|
+ CurEndVarName:='';
|
|
|
|
+ end;
|
|
|
|
|
|
// add "for()"
|
|
// add "for()"
|
|
if InKind in [ikSetInt,ikSetBool,ikSetChar,ikSetString] then
|
|
if InKind in [ikSetInt,ikSetBool,ikSetChar,ikSetString] then
|
|
@@ -21588,7 +21611,7 @@ begin
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
// create unique local var name
|
|
// create unique local var name
|
|
- WithExprScope.WithVarName:=FuncContext.CreateLocalIdentifier(GetBIName(pbivnWith));
|
|
|
|
|
|
+ WithExprScope.WithVarName:=FuncContext.AddLocalVar(GetBIName(pbivnWith),nil,true).Name;
|
|
// create local "var $with1 = expr;"
|
|
// create local "var $with1 = expr;"
|
|
V:=CreateVarStatement(WithExprScope.WithVarName,Expr,PasExpr);
|
|
V:=CreateVarStatement(WithExprScope.WithVarName,Expr,PasExpr);
|
|
AddToStatementList(FirstSt,LastSt,V,PasExpr);
|
|
AddToStatementList(FirstSt,LastSt,V,PasExpr);
|
|
@@ -24730,6 +24753,11 @@ begin
|
|
Result:=GetBIName(pbivnModules)+'["'+Result+'"]'
|
|
Result:=GetBIName(pbivnModules)+'["'+Result+'"]'
|
|
else
|
|
else
|
|
Result:=GetBIName(pbivnModules)+'.'+Result;
|
|
Result:=GetBIName(pbivnModules)+'.'+Result;
|
|
|
|
+
|
|
|
|
+ if coAliasGlobals in Options then
|
|
|
|
+ begin
|
|
|
|
+
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|