pastojs: filer skip not fully specialized

This commit is contained in:
mattias 2020-12-03 20:57:09 +00:00
parent 8b35ab0512
commit 7e130ffc53
3 changed files with 53 additions and 13 deletions

View File

@ -18837,7 +18837,10 @@ begin
begin begin
// inside procedure: first param is function result // inside procedure: first param is function result
ProcScope:=TPasProcedureScope(Scopes[i]); ProcScope:=TPasProcedureScope(Scopes[i]);
CtxProc:=TPasProcedure(ProcScope.Element); if ProcScope.DeclarationProc<>nil then
CtxProc:=ProcScope.DeclarationProc
else
CtxProc:=TPasProcedure(ProcScope.Element);
if not (CtxProc.ProcType is TPasFunctionType) then if not (CtxProc.ProcType is TPasFunctionType) then
begin begin
if RaiseOnError then if RaiseOnError then

View File

@ -1281,7 +1281,7 @@ begin
if CanSkipGenericType(ProcType) then exit; if CanSkipGenericType(ProcType) then exit;
for i:=0 to ProcType.Args.Count-1 do for i:=0 to ProcType.Args.Count-1 do
UseSubEl(TPasArgument(ProcType.Args[i]).ArgType); UseSubEl(TPasArgument(ProcType.Args[i]).ArgType);
if El is TPasFunctionType then if (El is TPasFunctionType) and (TPasFunctionType(El).ResultEl<>nil) then
UseSubEl(TPasFunctionType(El).ResultEl.ResultType); UseSubEl(TPasFunctionType(El).ResultEl.ResultType);
end end
else if C=TPasSpecializeType then else if C=TPasSpecializeType then
@ -1543,12 +1543,15 @@ begin
UseExpr(ForLoop.StartExpr); UseExpr(ForLoop.StartExpr);
UseExpr(ForLoop.EndExpr); UseExpr(ForLoop.EndExpr);
ForScope:=ForLoop.CustomData as TPasForLoopScope; ForScope:=ForLoop.CustomData as TPasForLoopScope;
MarkImplScopeRef(ForLoop,ForScope.GetEnumerator,psraRead); if ForScope<>nil then
UseProcedure(ForScope.GetEnumerator); begin
MarkImplScopeRef(ForLoop,ForScope.MoveNext,psraRead); MarkImplScopeRef(ForLoop,ForScope.GetEnumerator,psraRead);
UseProcedure(ForScope.MoveNext); UseProcedure(ForScope.GetEnumerator);
MarkImplScopeRef(ForLoop,ForScope.Current,psraRead); MarkImplScopeRef(ForLoop,ForScope.MoveNext,psraRead);
UseVariable(ForScope.Current,rraRead,false); UseProcedure(ForScope.MoveNext);
MarkImplScopeRef(ForLoop,ForScope.Current,psraRead);
UseVariable(ForScope.Current,rraRead,false);
end;
UseImplElement(ForLoop.Body); UseImplElement(ForLoop.Body);
end end
else if C=TPasImplIfElse then else if C=TPasImplIfElse then
@ -1650,12 +1653,14 @@ procedure TPasAnalyzer.UseExpr(El: TPasExpr);
UseElement(SubEl,rraAssign,false); UseElement(SubEl,rraAssign,false);
end; end;
procedure UseBuilInFuncTypeInfo; procedure UseBuiltInFuncTypeInfo;
var var
ParentParams: TPRParentParams; ParentParams: TPRParentParams;
ParamResolved: TPasResolverResult; ParamResolved: TPasResolverResult;
SubEl: TPasElement; SubEl: TPasElement;
Params: TPasExprArray; Params: TPasExprArray;
ProcScope: TPasProcedureScope;
Proc: TPasProcedure;
begin begin
Resolver.GetParamsOfNameExpr(El,ParentParams); Resolver.GetParamsOfNameExpr(El,ParentParams);
if ParentParams.Params=nil then if ParentParams.Params=nil then
@ -1672,7 +1677,11 @@ procedure TPasAnalyzer.UseExpr(El: TPasExpr);
if (ParamResolved.IdentEl is TPasProcedure) if (ParamResolved.IdentEl is TPasProcedure)
and (TPasProcedure(ParamResolved.IdentEl).ProcType is TPasFunctionType) then and (TPasProcedure(ParamResolved.IdentEl).ProcType is TPasFunctionType) then
begin begin
SubEl:=TPasFunctionType(TPasProcedure(ParamResolved.IdentEl).ProcType).ResultEl.ResultType; Proc:=TPasProcedure(ParamResolved.IdentEl);
ProcScope:=Proc.CustomData as TPasProcedureScope;
if ProcScope.DeclarationProc<>nil then
Proc:=ProcScope.DeclarationProc;
SubEl:=TPasFunctionType(Proc.ProcType).ResultEl.ResultType;
MarkImplScopeRef(El,SubEl,psraTypeInfo); MarkImplScopeRef(El,SubEl,psraTypeInfo);
UseTypeInfo(SubEl); UseTypeInfo(SubEl);
end end
@ -1751,7 +1760,7 @@ begin
end; end;
bfTypeInfo: bfTypeInfo:
begin begin
UseBuilInFuncTypeInfo; UseBuiltInFuncTypeInfo;
exit; exit;
end; end;
bfAssert: bfAssert:

View File

@ -3455,7 +3455,7 @@ begin
ParentRef.Obj.Add('Specs',ParentRef.Specs); ParentRef.Obj.Add('Specs',ParentRef.Specs);
end; end;
ParentRef.Specs.Add(Ref.Obj); ParentRef.Specs.Add(Ref.Obj);
if Ref.Id=0 then if (Ref.Id=0) then
CreateElReferenceId(Ref); // every specialization needs an ID CreateElReferenceId(Ref); // every specialization needs an ID
end end
else else
@ -5651,11 +5651,12 @@ procedure TPCUReader.ResolveSpecializedElements(Complete: boolean);
OtherPendSpec: TPCUReaderPendingSpecialized; OtherPendSpec: TPCUReaderPendingSpecialized;
begin begin
Result:=false; Result:=false;
if PendSpec.RefEl=nil then exit;
for i:=0 to PendSpec.Params.Count-1 do for i:=0 to PendSpec.Params.Count-1 do
begin begin
Param:=TPCUReaderPendingSpecializedParam(PendSpec.Params[i]); Param:=TPCUReaderPendingSpecializedParam(PendSpec.Params[i]);
Ref:=GetElReference(Param.Id,PendSpec.GenericEl); Ref:=GetElReference(Param.Id,PendSpec.GenericEl);
if Ref.Element<>nil then continue; if (Ref=nil) or (Ref.Element<>nil) then continue;
OtherPendSpec:=FPendingSpecialize; OtherPendSpec:=FPendingSpecialize;
while OtherPendSpec<>nil do while OtherPendSpec<>nil do
begin begin
@ -5669,6 +5670,27 @@ procedure TPCUReader.ResolveSpecializedElements(Complete: boolean);
end; end;
end; end;
function FreeTemplateSpecialization(PendSpec: TPCUReaderPendingSpecialized): boolean;
// checks if PendSpec params are only TPasGenericTemplateType
// if yes, frees this PendSpec
var
i: Integer;
Param: TPCUReaderPendingSpecializedParam;
Ref: TPCUFilerElementRef;
begin
Result:=true;
for i:=0 to PendSpec.Params.Count-1 do
begin
Param:=TPCUReaderPendingSpecializedParam(PendSpec.Params[i]);
Ref:=GetElReference(Param.Id,PendSpec.GenericEl);
if Ref=nil then
exit(false);
if not (Ref.Element is TPasGenericTemplateType) then
exit(false);
end;
DeletePendingSpecialize(PendSpec);
end;
var var
PendSpec, NextPendSpec, UnresolvedSpec: TPCUReaderPendingSpecialized; PendSpec, NextPendSpec, UnresolvedSpec: TPCUReaderPendingSpecialized;
Changed: Boolean; Changed: Boolean;
@ -5681,6 +5703,7 @@ begin
while PendSpec<>nil do while PendSpec<>nil do
begin begin
NextPendSpec:=PendSpec.Next; NextPendSpec:=PendSpec.Next;
if PendSpec.RefEl=nil then if PendSpec.RefEl=nil then
begin begin
// no referrer -> use the first element, waiting for this ID // no referrer -> use the first element, waiting for this ID
@ -5698,6 +5721,11 @@ begin
Changed:=true Changed:=true
else else
UnresolvedSpec:=PendSpec; UnresolvedSpec:=PendSpec;
end
else if Complete and (PendSpec.RefEl=nil) then
begin
if FreeTemplateSpecialization(PendSpec) then
Changed:=true;
end; end;
PendSpec:=NextPendSpec; PendSpec:=NextPendSpec;
end; end;