mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 09:26:15 +02:00
pastojs: remove empty $impl
git-svn-id: trunk@35736 -
This commit is contained in:
parent
2afaeb60de
commit
4bce2e2b4d
@ -214,8 +214,6 @@ Works:
|
|||||||
- use 0o for octal literals
|
- use 0o for octal literals
|
||||||
|
|
||||||
ToDos:
|
ToDos:
|
||||||
- codetools: external class not using TObject as ancestor
|
|
||||||
- remove empty $impl
|
|
||||||
- using external class must not mark the unit as used
|
- using external class must not mark the unit as used
|
||||||
- compiler error code only when option -Jsomething given for fpc compatibility
|
- compiler error code only when option -Jsomething given for fpc compatibility
|
||||||
- -Jirtl.js-
|
- -Jirtl.js-
|
||||||
@ -907,6 +905,8 @@ type
|
|||||||
Function CreateTypeDecl(El: TPasType; AContext: TConvertContext): TJSElement;
|
Function CreateTypeDecl(El: TPasType; AContext: TConvertContext): TJSElement;
|
||||||
Function CreateVarDecl(El: TPasVariable; AContext: TConvertContext): TJSElement;
|
Function CreateVarDecl(El: TPasVariable; AContext: TConvertContext): TJSElement;
|
||||||
Procedure AddToSourceElements(Src: TJSSourceElements; El: TJSElement);
|
Procedure AddToSourceElements(Src: TJSSourceElements; El: TJSElement);
|
||||||
|
procedure RemoveFromSourceElements(Src: TJSSourceElements;
|
||||||
|
El: TJSElement);
|
||||||
function GetBuildInNames(bin: TPas2JSBuiltInName): string;
|
function GetBuildInNames(bin: TPas2JSBuiltInName): string;
|
||||||
procedure SetBuildInNames(bin: TPas2JSBuiltInName; const AValue: string);
|
procedure SetBuildInNames(bin: TPas2JSBuiltInName; const AValue: string);
|
||||||
procedure SetPreservedWords(const AValue: TJSReservedWordList);
|
procedure SetPreservedWords(const AValue: TJSReservedWordList);
|
||||||
@ -967,7 +967,7 @@ type
|
|||||||
Function CreateReferencePath(El: TPasElement; AContext : TConvertContext;
|
Function CreateReferencePath(El: TPasElement; AContext : TConvertContext;
|
||||||
Kind: TRefPathKind; Full: boolean = false; Ref: TResolvedReference = nil): string; virtual;
|
Kind: TRefPathKind; Full: boolean = false; Ref: TResolvedReference = nil): string; virtual;
|
||||||
Function CreateReferencePathExpr(El: TPasElement; AContext : TConvertContext; Full: boolean = false; Ref: TResolvedReference = nil): TJSPrimaryExpressionIdent; virtual;
|
Function CreateReferencePathExpr(El: TPasElement; AContext : TConvertContext; Full: boolean = false; Ref: TResolvedReference = nil): TJSPrimaryExpressionIdent; virtual;
|
||||||
Procedure CreateImplementationSection(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext);
|
Function CreateImplementationSection(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext): TJSElement;
|
||||||
Procedure CreateInitSection(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext);
|
Procedure CreateInitSection(El: TPasModule; Src: TJSSourceElements; AContext: TConvertContext);
|
||||||
Function CreateDotExpression(aParent: TPasElement; Left, Right: TJSElement): TJSElement; virtual;
|
Function CreateDotExpression(aParent: TPasElement; Left, Right: TJSElement): TJSElement; virtual;
|
||||||
Function CreateReferencedSet(El: TPasElement; SetExpr: TJSElement): TJSElement; virtual;
|
Function CreateReferencedSet(El: TPasElement; SetExpr: TJSElement): TJSElement; virtual;
|
||||||
@ -2707,6 +2707,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPasToJSConverter.RemoveFromSourceElements(Src: TJSSourceElements;
|
||||||
|
El: TJSElement);
|
||||||
|
var
|
||||||
|
Statements: TJSElementNodes;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Statements:=Src.Statements;
|
||||||
|
for i:=Statements.Count-1 downto 0 do
|
||||||
|
if Statements[i].Node=El then
|
||||||
|
Statements.Delete(i);
|
||||||
|
end;
|
||||||
|
|
||||||
function TPasToJSConverter.GetBuildInNames(bin: TPas2JSBuiltInName): string;
|
function TPasToJSConverter.GetBuildInNames(bin: TPas2JSBuiltInName): string;
|
||||||
begin
|
begin
|
||||||
Result:=FBuiltInNames[bin];
|
Result:=FBuiltInNames[bin];
|
||||||
@ -2755,9 +2767,10 @@ Var
|
|||||||
UsesSection: TPasSection;
|
UsesSection: TPasSection;
|
||||||
ModuleName: String;
|
ModuleName: String;
|
||||||
IntfContext: TInterfaceContext;
|
IntfContext: TInterfaceContext;
|
||||||
VarSt: TJSVariableStatement;
|
ImplVarSt: TJSVariableStatement;
|
||||||
VarDecl: TJSVarDeclaration;
|
VarDecl: TJSVarDeclaration;
|
||||||
AssignSt: TJSSimpleAssignStatement;
|
ImplAssignSt: TJSSimpleAssignStatement;
|
||||||
|
ImplDecl: TJSElement;
|
||||||
begin
|
begin
|
||||||
Result:=Nil;
|
Result:=Nil;
|
||||||
OuterSrc:=TJSSourceElements(CreateElement(TJSSourceElements, El));
|
OuterSrc:=TJSSourceElements(CreateElement(TJSSourceElements, El));
|
||||||
@ -2815,25 +2828,38 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin // unit
|
begin // unit
|
||||||
// add interface section
|
// add implementation object at top, so the interface elemwnts can add stuff
|
||||||
if (FBuiltInNames[pbivnImplementation]<>'') and Assigned(El.ImplementationSection) then
|
if (FBuiltInNames[pbivnImplementation]<>'') and Assigned(El.ImplementationSection) then
|
||||||
begin
|
begin
|
||||||
// add 'var $impl = {};'
|
// add 'var $impl = {};'
|
||||||
VarSt:=TJSVariableStatement(CreateElement(TJSVariableStatement,El));
|
ImplVarSt:=TJSVariableStatement(CreateElement(TJSVariableStatement,El));
|
||||||
AddToSourceElements(Src,VarSt);
|
AddToSourceElements(Src,ImplVarSt);
|
||||||
VarDecl:=TJSVarDeclaration(CreateElement(TJSVarDeclaration,El));
|
VarDecl:=TJSVarDeclaration(CreateElement(TJSVarDeclaration,El));
|
||||||
VarSt.A:=VarDecl;
|
ImplVarSt.A:=VarDecl;
|
||||||
VarDecl.Name:=FBuiltInNames[pbivnImplementation];
|
VarDecl.Name:=FBuiltInNames[pbivnImplementation];
|
||||||
VarDecl.Init:=TJSEmptyBlockStatement(CreateElement(TJSEmptyBlockStatement,El.ImplementationSection));
|
VarDecl.Init:=TJSEmptyBlockStatement(CreateElement(TJSEmptyBlockStatement,El.ImplementationSection));
|
||||||
// add 'this.$impl = $impl;'
|
// add 'this.$impl = $impl;'
|
||||||
AssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El));
|
ImplAssignSt:=TJSSimpleAssignStatement(CreateElement(TJSSimpleAssignStatement,El));
|
||||||
AddToSourceElements(Src,AssignSt);
|
AddToSourceElements(Src,ImplAssignSt);
|
||||||
AssignSt.LHS:=CreateBuiltInIdentifierExpr('this.'+FBuiltInNames[pbivnImplementation]);
|
ImplAssignSt.LHS:=CreateBuiltInIdentifierExpr('this.'+FBuiltInNames[pbivnImplementation]);
|
||||||
AssignSt.Expr:=CreateBuiltInIdentifierExpr(FBuiltInNames[pbivnImplementation]);
|
ImplAssignSt.Expr:=CreateBuiltInIdentifierExpr(FBuiltInNames[pbivnImplementation]);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
ImplVarSt:=nil;
|
||||||
|
ImplAssignSt:=nil;
|
||||||
end;
|
end;
|
||||||
if Assigned(El.InterfaceSection) then
|
if Assigned(El.InterfaceSection) then
|
||||||
AddToSourceElements(Src,ConvertDeclarations(El.InterfaceSection,IntfContext));
|
AddToSourceElements(Src,ConvertDeclarations(El.InterfaceSection,IntfContext));
|
||||||
CreateImplementationSection(El,Src,IntfContext);
|
if ImplVarSt<>nil then
|
||||||
|
begin
|
||||||
|
ImplDecl:=CreateImplementationSection(El,Src,IntfContext);
|
||||||
|
if ImplDecl=nil then
|
||||||
|
begin
|
||||||
|
RemoveFromSourceElements(Src,ImplVarSt);
|
||||||
|
RemoveFromSourceElements(Src,ImplAssignSt);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
CreateInitSection(El,Src,IntfContext);
|
CreateInitSection(El,Src,IntfContext);
|
||||||
|
|
||||||
// add optional implementation uses list: [<implementation uses1>,<uses2>, ...]
|
// add optional implementation uses list: [<implementation uses1>,<uses2>, ...]
|
||||||
@ -7170,17 +7196,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPasToJSConverter.CreateImplementationSection(El: TPasModule;
|
function TPasToJSConverter.CreateImplementationSection(El: TPasModule;
|
||||||
Src: TJSSourceElements; AContext: TConvertContext);
|
Src: TJSSourceElements; AContext: TConvertContext): TJSElement;
|
||||||
var
|
var
|
||||||
Section: TImplementationSection;
|
Section: TImplementationSection;
|
||||||
begin
|
begin
|
||||||
|
Result:=nil;
|
||||||
if not Assigned(El.ImplementationSection) then
|
if not Assigned(El.ImplementationSection) then
|
||||||
exit;
|
exit;
|
||||||
Section:=El.ImplementationSection;
|
Section:=El.ImplementationSection;
|
||||||
// add implementation section
|
// add implementation section
|
||||||
// merge interface and implementation
|
// merge interface and implementation
|
||||||
AddToSourceElements(Src,ConvertDeclarations(Section,AContext));
|
Result:=ConvertDeclarations(Section,AContext);
|
||||||
|
AddToSourceElements(Src,Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPasToJSConverter.CreateInitSection(El: TPasModule;
|
procedure TPasToJSConverter.CreateInitSection(El: TPasModule;
|
||||||
|
@ -766,6 +766,7 @@ var
|
|||||||
InitAssign: TJSSimpleAssignStatement;
|
InitAssign: TJSSimpleAssignStatement;
|
||||||
FunBody: TJSFunctionBody;
|
FunBody: TJSFunctionBody;
|
||||||
InitName: String;
|
InitName: String;
|
||||||
|
LastNode: TJSElement;
|
||||||
begin
|
begin
|
||||||
if SkipTests then exit;
|
if SkipTests then exit;
|
||||||
try
|
try
|
||||||
@ -840,14 +841,18 @@ begin
|
|||||||
FJSInitBody:=nil;
|
FJSInitBody:=nil;
|
||||||
if JSModuleSrc.Statements.Count>0 then
|
if JSModuleSrc.Statements.Count>0 then
|
||||||
begin
|
begin
|
||||||
InitAssign:=JSModuleSrc.Statements.Nodes[JSModuleSrc.Statements.Count-1].Node as TJSSimpleAssignStatement;
|
LastNode:=JSModuleSrc.Statements.Nodes[JSModuleSrc.Statements.Count-1].Node;
|
||||||
if GetDottedIdentifier(InitAssign.LHS)='this.'+InitName then
|
if LastNode is TJSSimpleAssignStatement then
|
||||||
begin
|
begin
|
||||||
InitFunction:=InitAssign.Expr as TJSFunctionDeclarationStatement;
|
InitAssign:=LastNode as TJSSimpleAssignStatement;
|
||||||
FJSInitBody:=InitFunction.AFunction.Body as TJSFunctionBody;
|
if GetDottedIdentifier(InitAssign.LHS)='this.'+InitName then
|
||||||
end
|
begin
|
||||||
else if Module is TPasProgram then
|
InitFunction:=InitAssign.Expr as TJSFunctionDeclarationStatement;
|
||||||
CheckDottedIdentifier('init function',InitAssign.LHS,'this.'+InitName);
|
FJSInitBody:=InitFunction.AFunction.Body as TJSFunctionBody;
|
||||||
|
end
|
||||||
|
else if Module is TPasProgram then
|
||||||
|
CheckDottedIdentifier('init function',InitAssign.LHS,'this.'+InitName);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1183,9 +1188,6 @@ begin
|
|||||||
ConvertUnit;
|
ConvertUnit;
|
||||||
CheckSource('TestEmptyUnit',
|
CheckSource('TestEmptyUnit',
|
||||||
LinesToStr([
|
LinesToStr([
|
||||||
'var $impl = {',
|
|
||||||
'};',
|
|
||||||
'this.$impl = $impl;'
|
|
||||||
]),
|
]),
|
||||||
'');
|
'');
|
||||||
end;
|
end;
|
||||||
@ -1199,10 +1201,7 @@ begin
|
|||||||
ConvertUnit;
|
ConvertUnit;
|
||||||
CheckSource('TestEmptyUnitUseStrict',
|
CheckSource('TestEmptyUnitUseStrict',
|
||||||
LinesToStr([
|
LinesToStr([
|
||||||
'"use strict";',
|
'"use strict";'
|
||||||
'var $impl = {',
|
|
||||||
'};',
|
|
||||||
'this.$impl = $impl;'
|
|
||||||
]),
|
]),
|
||||||
'');
|
'');
|
||||||
end;
|
end;
|
||||||
@ -2051,10 +2050,7 @@ begin
|
|||||||
ConvertUnit;
|
ConvertUnit;
|
||||||
CheckSource('TestProcedureExternalOtherUnit',
|
CheckSource('TestProcedureExternalOtherUnit',
|
||||||
LinesToStr([
|
LinesToStr([
|
||||||
'var $impl = {',
|
'']),
|
||||||
'};',
|
|
||||||
'this.$impl = $impl;'
|
|
||||||
]),
|
|
||||||
LinesToStr([
|
LinesToStr([
|
||||||
'Date.now();',
|
'Date.now();',
|
||||||
'Date.now();',
|
'Date.now();',
|
||||||
@ -8066,9 +8062,6 @@ begin
|
|||||||
ConvertUnit;
|
ConvertUnit;
|
||||||
CheckSource('TestExternalClass_ClassOtherUnit',
|
CheckSource('TestExternalClass_ClassOtherUnit',
|
||||||
LinesToStr([
|
LinesToStr([
|
||||||
'var $impl = {',
|
|
||||||
'};',
|
|
||||||
'this.$impl = $impl;',
|
|
||||||
'']),
|
'']),
|
||||||
LinesToStr([
|
LinesToStr([
|
||||||
'ExtA.Id = ExtA.Id + 1;',
|
'ExtA.Id = ExtA.Id + 1;',
|
||||||
|
Loading…
Reference in New Issue
Block a user