mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 01:29:21 +02:00
pastojs: rename overloads in interface when intf finished
git-svn-id: trunk@38518 -
This commit is contained in:
parent
602dd31a45
commit
b24b2ee6fc
@ -982,6 +982,7 @@ type
|
|||||||
procedure ResolveImplAsm(El: TPasImplAsmStatement); override;
|
procedure ResolveImplAsm(El: TPasImplAsmStatement); override;
|
||||||
procedure ResolveNameExpr(El: TPasExpr; const aName: string;
|
procedure ResolveNameExpr(El: TPasExpr; const aName: string;
|
||||||
Access: TResolvedRefAccess); override;
|
Access: TResolvedRefAccess); override;
|
||||||
|
procedure FinishInterfaceSection(Section: TPasSection); override;
|
||||||
procedure FinishModule(CurModule: TPasModule); override;
|
procedure FinishModule(CurModule: TPasModule); override;
|
||||||
procedure FinishEnumType(El: TPasEnumType); override;
|
procedure FinishEnumType(El: TPasEnumType); override;
|
||||||
procedure FinishSetType(El: TPasSetType); override;
|
procedure FinishSetType(El: TPasSetType); override;
|
||||||
@ -1827,37 +1828,20 @@ end;
|
|||||||
|
|
||||||
procedure TPas2JSResolver.RenameOverloadsInSection(aSection: TPasSection);
|
procedure TPas2JSResolver.RenameOverloadsInSection(aSection: TPasSection);
|
||||||
var
|
var
|
||||||
ImplSection: TImplementationSection;
|
IntfSection: TInterfaceSection;
|
||||||
SectionClass: TClass;
|
|
||||||
begin
|
begin
|
||||||
if aSection=nil then exit;
|
if aSection=nil then exit;
|
||||||
|
IntfSection:=nil;
|
||||||
|
if aSection.ClassType=TImplementationSection then
|
||||||
|
begin
|
||||||
|
IntfSection:=RootElement.InterfaceSection;
|
||||||
|
PushOverloadScope(IntfSection.CustomData as TPasIdentifierScope);
|
||||||
|
end;
|
||||||
PushOverloadScope(aSection.CustomData as TPasIdentifierScope);
|
PushOverloadScope(aSection.CustomData as TPasIdentifierScope);
|
||||||
RenameOverloads(aSection,aSection.Declarations);
|
RenameOverloads(aSection,aSection.Declarations);
|
||||||
SectionClass:=aSection.ClassType;
|
|
||||||
if SectionClass=TInterfaceSection then
|
|
||||||
begin
|
|
||||||
// unit interface
|
|
||||||
// first rename all overloads in interface and implementation
|
|
||||||
ImplSection:=(aSection.Parent as TPasModule).ImplementationSection;
|
|
||||||
if ImplSection<>nil then
|
|
||||||
begin
|
|
||||||
PushOverloadScope(ImplSection.CustomData as TPasIdentifierScope);
|
|
||||||
RenameOverloads(ImplSection,ImplSection.Declarations);
|
|
||||||
end;
|
|
||||||
// and then rename all nested overloads (e.g. methods)
|
|
||||||
// Important: nested overloads must check both interface and implementation
|
|
||||||
RenameSubOverloads(aSection.Declarations);
|
RenameSubOverloads(aSection.Declarations);
|
||||||
if ImplSection<>nil then
|
|
||||||
begin
|
|
||||||
RenameSubOverloads(ImplSection.Declarations);
|
|
||||||
PopOverloadScope;
|
PopOverloadScope;
|
||||||
end;
|
if IntfSection<>nil then
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
// program or library
|
|
||||||
RenameSubOverloads(aSection.Declarations);
|
|
||||||
end;
|
|
||||||
PopOverloadScope;
|
PopOverloadScope;
|
||||||
{$IFDEF VerbosePas2JS}
|
{$IFDEF VerbosePas2JS}
|
||||||
//writeln('TPas2JSResolver.RenameOverloadsInSection END ',GetObjName(aSection));
|
//writeln('TPas2JSResolver.RenameOverloadsInSection END ',GetObjName(aSection));
|
||||||
@ -1887,6 +1871,7 @@ begin
|
|||||||
if ProcScope.ImplProc<>nil then
|
if ProcScope.ImplProc<>nil then
|
||||||
RaiseInternalError(20170221110853);
|
RaiseInternalError(20170221110853);
|
||||||
// proc implementation (not forward) -> skip
|
// proc implementation (not forward) -> skip
|
||||||
|
Proc.Name:=ProcScope.DeclarationProc.Name;
|
||||||
continue;
|
continue;
|
||||||
end;
|
end;
|
||||||
if Proc.IsOverride then
|
if Proc.IsOverride then
|
||||||
@ -1899,7 +1884,7 @@ begin
|
|||||||
if ProcScope.ImplProc<>nil then
|
if ProcScope.ImplProc<>nil then
|
||||||
ProcScope.ImplProc.Name:=Proc.Name;
|
ProcScope.ImplProc.Name:=Proc.Name;
|
||||||
end;
|
end;
|
||||||
Continue;
|
continue;
|
||||||
end
|
end
|
||||||
else if Proc.IsExternal then
|
else if Proc.IsExternal then
|
||||||
begin
|
begin
|
||||||
@ -1922,7 +1907,7 @@ procedure TPas2JSResolver.RenameSubOverloads(Declarations: TFPList);
|
|||||||
var
|
var
|
||||||
i, OldScopeCount: Integer;
|
i, OldScopeCount: Integer;
|
||||||
El: TPasElement;
|
El: TPasElement;
|
||||||
Proc, ImplProc: TPasProcedure;
|
Proc: TPasProcedure;
|
||||||
ProcScope: TPasProcedureScope;
|
ProcScope: TPasProcedureScope;
|
||||||
ClassScope, aScope: TPasClassScope;
|
ClassScope, aScope: TPasClassScope;
|
||||||
ClassEl: TPasClassType;
|
ClassEl: TPasClassType;
|
||||||
@ -1935,28 +1920,19 @@ begin
|
|||||||
if C.InheritsFrom(TPasProcedure) then
|
if C.InheritsFrom(TPasProcedure) then
|
||||||
begin
|
begin
|
||||||
Proc:=TPasProcedure(El);
|
Proc:=TPasProcedure(El);
|
||||||
if Proc.IsAbstract or Proc.IsExternal then continue;
|
|
||||||
ProcScope:=Proc.CustomData as TPasProcedureScope;
|
ProcScope:=Proc.CustomData as TPasProcedureScope;
|
||||||
{$IFDEF VerbosePas2JS}
|
{$IFDEF VerbosePas2JS}
|
||||||
writeln('TPas2JSResolver.RenameSubOverloads Proc=',Proc.Name,' DeclarationProc=',GetObjName(ProcScope.DeclarationProc),' ImplProc=',GetObjName(ProcScope.ImplProc),' ClassScope=',GetObjName(ProcScope.ClassScope));
|
writeln('TPas2JSResolver.RenameSubOverloads Proc=',Proc.Name,' DeclarationProc=',GetObjName(ProcScope.DeclarationProc),' ImplProc=',GetObjName(ProcScope.ImplProc),' ClassScope=',GetObjName(ProcScope.ClassScope));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if ProcScope.DeclarationProc<>nil then
|
if Proc.Body<>nil then
|
||||||
// proc implementation (not forward) -> skip
|
|
||||||
continue;
|
|
||||||
ImplProc:=Proc;
|
|
||||||
if ProcScope.ImplProc<>nil then
|
|
||||||
begin
|
begin
|
||||||
// this proc has a separate implementation
|
|
||||||
// -> switch to implementation
|
|
||||||
ImplProc:=ProcScope.ImplProc;
|
|
||||||
ProcScope:=ImplProc.CustomData as TPasProcedureScope;
|
|
||||||
end;
|
|
||||||
PushOverloadScope(ProcScope);
|
PushOverloadScope(ProcScope);
|
||||||
// first rename all overloads on this level
|
// first rename all overloads on this level
|
||||||
RenameOverloads(ImplProc.Body,ImplProc.Body.Declarations);
|
RenameOverloads(Proc.Body,Proc.Body.Declarations);
|
||||||
// then process nested procedures
|
// then process nested procedures
|
||||||
RenameSubOverloads(ImplProc.Body.Declarations);
|
RenameSubOverloads(Proc.Body.Declarations);
|
||||||
PopOverloadScope;
|
PopOverloadScope;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else if C=TPasClassType then
|
else if C=TPasClassType then
|
||||||
begin
|
begin
|
||||||
@ -2146,19 +2122,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPas2JSResolver.FinishInterfaceSection(Section: TPasSection);
|
||||||
|
begin
|
||||||
|
inherited FinishInterfaceSection(Section);
|
||||||
|
if FOverloadScopes=nil then
|
||||||
|
begin
|
||||||
|
FOverloadScopes:=TFPList.Create;
|
||||||
|
RenameOverloadsInSection(Section);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPas2JSResolver.FinishModule(CurModule: TPasModule);
|
procedure TPas2JSResolver.FinishModule(CurModule: TPasModule);
|
||||||
var
|
var
|
||||||
ModuleClass: TClass;
|
ModuleClass: TClass;
|
||||||
begin
|
begin
|
||||||
inherited FinishModule(CurModule);
|
inherited FinishModule(CurModule);
|
||||||
|
if FOverloadScopes=nil then
|
||||||
FOverloadScopes:=TFPList.Create;
|
FOverloadScopes:=TFPList.Create;
|
||||||
try
|
try
|
||||||
ModuleClass:=CurModule.ClassType;
|
ModuleClass:=CurModule.ClassType;
|
||||||
if ModuleClass=TPasModule then
|
if ModuleClass=TPasModule then
|
||||||
begin
|
RenameOverloadsInSection(CurModule.ImplementationSection)
|
||||||
RenameOverloadsInSection(CurModule.InterfaceSection);
|
|
||||||
// Note: ImplementationSection is child of InterfaceSection
|
|
||||||
end
|
|
||||||
else if ModuleClass=TPasProgram then
|
else if ModuleClass=TPasProgram then
|
||||||
RenameOverloadsInSection(TPasProgram(CurModule).ProgramSection)
|
RenameOverloadsInSection(TPasProgram(CurModule).ProgramSection)
|
||||||
else if CurModule.ClassType=TPasLibrary then
|
else if CurModule.ClassType=TPasLibrary then
|
||||||
@ -2166,7 +2150,7 @@ begin
|
|||||||
else
|
else
|
||||||
RaiseNotYetImplemented(20170221000032,CurModule);
|
RaiseNotYetImplemented(20170221000032,CurModule);
|
||||||
finally
|
finally
|
||||||
FOverloadScopes.Free;
|
FreeAndNil(FOverloadScopes);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3095,6 +3079,7 @@ destructor TPas2JSResolver.Destroy;
|
|||||||
begin
|
begin
|
||||||
ClearElementData;
|
ClearElementData;
|
||||||
FreeAndNil(FExternalNames);
|
FreeAndNil(FExternalNames);
|
||||||
|
FreeAndNil(FOverloadScopes);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -270,8 +270,9 @@ type
|
|||||||
Procedure TestProc_VarParamV;
|
Procedure TestProc_VarParamV;
|
||||||
Procedure TestProc_Overload;
|
Procedure TestProc_Overload;
|
||||||
Procedure TestProc_OverloadForward;
|
Procedure TestProc_OverloadForward;
|
||||||
Procedure TestProc_OverloadUnit;
|
Procedure TestProc_OverloadIntfImpl;
|
||||||
Procedure TestProc_OverloadNested;
|
Procedure TestProc_OverloadNested;
|
||||||
|
Procedure TestProc_OverloadUnitCycle;
|
||||||
Procedure TestProc_Varargs;
|
Procedure TestProc_Varargs;
|
||||||
Procedure TestProc_ConstOrder;
|
Procedure TestProc_ConstOrder;
|
||||||
Procedure TestProc_LocalVarAbsolute;
|
Procedure TestProc_LocalVarAbsolute;
|
||||||
@ -3091,7 +3092,7 @@ begin
|
|||||||
'']));
|
'']));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestModule.TestProc_OverloadUnit;
|
procedure TTestModule.TestProc_OverloadIntfImpl;
|
||||||
begin
|
begin
|
||||||
StartUnit(false);
|
StartUnit(false);
|
||||||
Add('interface');
|
Add('interface');
|
||||||
@ -3242,6 +3243,45 @@ begin
|
|||||||
'']));
|
'']));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestModule.TestProc_OverloadUnitCycle;
|
||||||
|
begin
|
||||||
|
AddModuleWithIntfImplSrc('Unit2.pas',
|
||||||
|
LinesToStr([
|
||||||
|
'type',
|
||||||
|
' TObject = class',
|
||||||
|
' procedure DoIt(b: boolean); virtual; abstract;',
|
||||||
|
' procedure DoIt(i: longint); virtual; abstract;',
|
||||||
|
' end;',
|
||||||
|
'']),
|
||||||
|
'uses test1;');
|
||||||
|
StartUnit(true);
|
||||||
|
Add([
|
||||||
|
'interface',
|
||||||
|
'uses unit2;',
|
||||||
|
'type',
|
||||||
|
' TEagle = class(TObject)',
|
||||||
|
' procedure DoIt(b: boolean); override;',
|
||||||
|
' procedure DoIt(i: longint); override;',
|
||||||
|
' end;',
|
||||||
|
'implementation',
|
||||||
|
'procedure TEagle.DoIt(b: boolean); begin end;',
|
||||||
|
'procedure TEagle.DoIt(i: longint); begin end;',
|
||||||
|
'']);
|
||||||
|
ConvertUnit;
|
||||||
|
CheckSource('TestProc_OverloadUnitCycle',
|
||||||
|
LinesToStr([ // statements
|
||||||
|
'rtl.createClass($mod, "TEagle", pas.Unit2.TObject, function () {',
|
||||||
|
' this.DoIt = function (b) {',
|
||||||
|
' };',
|
||||||
|
' this.DoIt$1 = function (i) {',
|
||||||
|
' };',
|
||||||
|
'});',
|
||||||
|
'']),
|
||||||
|
'',
|
||||||
|
LinesToStr([
|
||||||
|
'']));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestModule.TestProc_Varargs;
|
procedure TTestModule.TestProc_Varargs;
|
||||||
begin
|
begin
|
||||||
StartProgram(false);
|
StartProgram(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user