summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authormattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-01-16 21:23:15 +0000
committermattias <mattias@3ad0048d-3df7-0310-abae-a5850022a9f2>2020-01-16 21:23:15 +0000
commit91c2b0eaad3491a0fe7d6a59c26ab282208492df (patch)
tree3a566d1f42043d350f776b4c29f5f3401d1636db /packages
parentdc728680b1db235a5e7877df728049b4db89a9b6 (diff)
downloadfpc-91c2b0eaad3491a0fe7d6a59c26ab282208492df.tar.gz
pastojs: filer: generic class
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@43960 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages')
-rw-r--r--packages/fcl-passrc/src/pasresolver.pp3
-rw-r--r--packages/fcl-passrc/src/pasuseanalyzer.pas22
-rw-r--r--packages/pastojs/src/pas2jsfiler.pp5
-rw-r--r--packages/pastojs/tests/tcfiler.pas20
4 files changed, 38 insertions, 12 deletions
diff --git a/packages/fcl-passrc/src/pasresolver.pp b/packages/fcl-passrc/src/pasresolver.pp
index a77e8bdc6a..44278d62a6 100644
--- a/packages/fcl-passrc/src/pasresolver.pp
+++ b/packages/fcl-passrc/src/pasresolver.pp
@@ -27915,7 +27915,8 @@ begin
Templates:=GetProcTemplateTypes(Proc);
if (Templates<>nil) and (Templates.Count>0) then
exit(false);
- if ProcScope.SpecializedFromItem=nil then exit(true);
+ if ProcScope.SpecializedFromItem=nil then
+ exit(true);
Params:=ProcScope.SpecializedFromItem.Params;
for i:=0 to length(Params)-1 do
if Params[i] is TPasGenericTemplateType then exit(false);
diff --git a/packages/fcl-passrc/src/pasuseanalyzer.pas b/packages/fcl-passrc/src/pasuseanalyzer.pas
index d63431b5c7..15fab81629 100644
--- a/packages/fcl-passrc/src/pasuseanalyzer.pas
+++ b/packages/fcl-passrc/src/pasuseanalyzer.pas
@@ -1079,6 +1079,7 @@ function TPasAnalyzer.CanSkipGenericProc(DeclProc: TPasProcedure): boolean;
var
Templates: TFPList;
+ Parent: TPasElement;
begin
Result:=false;
if ScopeModule=nil then
@@ -1093,14 +1094,29 @@ begin
Templates:=Resolver.GetProcTemplateTypes(DeclProc);
if (Templates<>nil) and (Templates.Count>0) then
begin
- // generic template
+ // generic procedure
if paoSkipGenericProc in Options then
- exit(true); //
+ exit(true); // emit no hints for generic proc
// -> analyze
end
else if not Resolver.IsFullySpecialized(DeclProc) then
// half specialized -> skip
- exit(true);
+ exit(true)
+ else if paoSkipGenericProc in Options then
+ begin
+ Parent:=DeclProc.Parent;
+ while Parent<>nil do
+ begin
+ if (Parent is TPasGenericType) then
+ begin
+ Templates:=TPasGenericType(Parent).GenericTemplateTypes;
+ if (Templates<>nil) and (Templates.Count>0) then
+ // procedure of a generic parent -> emit no hints
+ exit(true);
+ end;
+ Parent:=Parent.Parent;
+ end;
+ end;
end;
end;
diff --git a/packages/pastojs/src/pas2jsfiler.pp b/packages/pastojs/src/pas2jsfiler.pp
index 4d53137b02..8175bd8ea9 100644
--- a/packages/pastojs/src/pas2jsfiler.pp
+++ b/packages/pastojs/src/pas2jsfiler.pp
@@ -3721,7 +3721,7 @@ begin
Templ:=TPasGenericTemplateType(GenericTemplateTypes[i]);
TemplObj:=TJSONObject.Create;
Arr.Add(TemplObj);
- TemplObj.Add('Name',Templ.Name);
+ WritePasElement(TemplObj,Templ,aContext);
WriteElementArray(TemplObj,Parent,'Constraints',Templ.Constraints,aContext,true);
end;
end;
@@ -6300,7 +6300,7 @@ var
begin
if not ReadArray(Obj,'Declarations',Arr,Decls) then exit;
{$IFDEF VerbosePCUFiler}
- writeln('TPCUReader.ReadDeclarations ',GetObjName(Section),' ',Arr.Count);
+ writeln('TPCUReader.ReadDeclarations ',GetObjName(Decls),' ',Arr.Count);
{$ENDIF}
for i:=0 to Arr.Count-1 do
begin
@@ -7551,6 +7551,7 @@ begin
RaiseMsg(20190720224130,Parent,IntToStr(i));
GenType:=TPasGenericTemplateType(CreateElement(TPasGenericTemplateType,GenTypeName,Parent));
GenericTemplateTypes.Add(GenType);
+ ReadPasElement(TemplObj,GenType,aContext);
ReadElementArray(TemplObj,Parent,'Constraints',GenType.Constraints,
{$IFDEF CheckPasTreeRefCount}'TPasGenericTemplateType.Constraints'{$ELSE}true{$ENDIF},
aContext);
diff --git a/packages/pastojs/tests/tcfiler.pas b/packages/pastojs/tests/tcfiler.pas
index 459506ebc9..44e172eb75 100644
--- a/packages/pastojs/tests/tcfiler.pas
+++ b/packages/pastojs/tests/tcfiler.pas
@@ -1171,10 +1171,20 @@ begin
//writeln('TCustomTestPrecompile.CheckRestoredElement Checking Parent... Orig=',GetObjName(Orig),' Rest=',GetObjName(Rest));
CheckRestoredReference(Path+'.Parent',Orig.Parent,Rest.Parent);
+ C:=Orig.ClassType;
//writeln('TCustomTestPrecompile.CheckRestoredElement Checking CustomData... Orig=',GetObjName(Orig),' Rest=',GetObjName(Rest));
- CheckRestoredCustomData(Path+'.CustomData',Rest,Orig.CustomData,Rest.CustomData,Flags);
+ if C=TPasGenericTemplateType then
+ begin
+ // TPasGenericParamsScope is only needed during parsing
+ if Orig.CustomData=nil then
+ else if not (Orig.CustomData is TPasGenericParamsScope) then
+ Fail(Path+'Orig.CustomData='+GetObjName(Orig.CustomData))
+ else if Rest.CustomData<>nil then
+ CheckRestoredCustomData(Path+'.CustomData',Rest,Orig.CustomData,Rest.CustomData,Flags);
+ end
+ else
+ CheckRestoredCustomData(Path+'.CustomData',Rest,Orig.CustomData,Rest.CustomData,Flags);
- C:=Orig.ClassType;
if C=TUnaryExpr then
CheckRestoredUnaryExpr(Path,TUnaryExpr(Orig),TUnaryExpr(Rest),Flags)
else if C=TBinaryExpr then
@@ -2671,8 +2681,6 @@ end;
procedure TTestPrecompile.TestPC_GenericClass;
begin
- exit;
-
StartUnit(false);
Add([
'interface',
@@ -2681,10 +2689,10 @@ begin
' end;',
' generic TBird<T> = class',
' a: T;',
- ' generic function Run<T>(a: T): T;',
+ ' function Run: T;',
' end;',
'implementation',
- 'function TBird.Run<T>(a: T): T;',
+ 'function TBird.Run: T;',
'var b: T;',
'begin',
' b:=a; Result:=b;',