summaryrefslogtreecommitdiff
path: root/avx512-0037785/packages/fcl-passrc/src/pasuseanalyzer.pas
diff options
context:
space:
mode:
Diffstat (limited to 'avx512-0037785/packages/fcl-passrc/src/pasuseanalyzer.pas')
-rw-r--r--avx512-0037785/packages/fcl-passrc/src/pasuseanalyzer.pas73
1 files changed, 49 insertions, 24 deletions
diff --git a/avx512-0037785/packages/fcl-passrc/src/pasuseanalyzer.pas b/avx512-0037785/packages/fcl-passrc/src/pasuseanalyzer.pas
index 177f94c63a..320a83a1ff 100644
--- a/avx512-0037785/packages/fcl-passrc/src/pasuseanalyzer.pas
+++ b/avx512-0037785/packages/fcl-passrc/src/pasuseanalyzer.pas
@@ -62,6 +62,10 @@ const
// non fpc hints
nPAParameterInOverrideNotUsed = 4501;
sPAParameterInOverrideNotUsed = 'Parameter "%s" not used';
+ nPAFieldNotUsed = 4502;
+ sPAFieldNotUsed = 'Field "%s" not used';
+ nPAFieldIsAssignedButNeverUsed = 4503;
+ sPAFieldIsAssignedButNeverUsed = 'Field "%s" is assigned but never used';
// fpc hints: use same IDs as fpc
nPAUnitNotUsed = 5023;
sPAUnitNotUsed = 'Unit "%s" not used in %s';
@@ -180,7 +184,7 @@ type
{$ifdef pas2js}
constructor Create(const OnItemToName, OnKeyToName: TPASItemToNameProc); reintroduce;
{$else}
- constructor Create(const OnCompareMethod: TListSortCompare;
+ constructor Create(const OnCompareProc: TListSortCompare;
const OnCompareKeyWithData: TListSortCompare);
{$endif}
destructor Destroy; override;
@@ -198,7 +202,7 @@ type
TPasAnalyzerOption = (
paoOnlyExports, // default: use all class members accessible from outside (protected, but not private)
- paoImplReferences, // collect references of top lvl proc implementations, initializationa dn finalization sections
+ paoImplReferences, // collect references of top lvl proc implementations, initializationa and finalization sections
paoSkipGenericProc // ignore generic procedure body
);
TPasAnalyzerOptions = set of TPasAnalyzerOption;
@@ -434,10 +438,10 @@ begin
FItems:=TJSObject.new;
end;
{$else}
-constructor TPasAnalyzerKeySet.Create(const OnCompareMethod: TListSortCompare;
+constructor TPasAnalyzerKeySet.Create(const OnCompareProc: TListSortCompare;
const OnCompareKeyWithData: TListSortCompare);
begin
- FTree:=TAVLTree.Create(OnCompareMethod);
+ FTree:=TAVLTree.Create(OnCompareProc);
FCompareKeyWithData:=OnCompareKeyWithData;
end;
{$endif}
@@ -1009,6 +1013,8 @@ procedure TPasAnalyzer.MarkImplScopeRef(El, RefEl: TPasElement;
if (RefEl.Name='') and not (RefEl is TInterfaceSection) then
exit; // reference to anonymous type -> not needed
+ if RefEl=ElImplScope.Element then
+ exit;
if ElImplScope is TPasProcedureScope then
TPasProcedureScope(ElImplScope).AddReference(RefEl,Access)
else if ElImplScope is TPasInitialFinalizationScope then
@@ -1279,7 +1285,7 @@ begin
if CanSkipGenericType(ProcType) then exit;
for i:=0 to ProcType.Args.Count-1 do
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);
end
else if C=TPasSpecializeType then
@@ -1311,6 +1317,9 @@ begin
UseElement(El,rraNone,true);
UseAttributes(El);
+
+ if El.Parent is TPasMembersType then
+ UseTypeInfo(El.Parent);
end;
procedure TPasAnalyzer.UseAttributes(El: TPasElement);
@@ -1541,12 +1550,15 @@ begin
UseExpr(ForLoop.StartExpr);
UseExpr(ForLoop.EndExpr);
ForScope:=ForLoop.CustomData as TPasForLoopScope;
- MarkImplScopeRef(ForLoop,ForScope.GetEnumerator,psraRead);
- UseProcedure(ForScope.GetEnumerator);
- MarkImplScopeRef(ForLoop,ForScope.MoveNext,psraRead);
- UseProcedure(ForScope.MoveNext);
- MarkImplScopeRef(ForLoop,ForScope.Current,psraRead);
- UseVariable(ForScope.Current,rraRead,false);
+ if ForScope<>nil then
+ begin
+ MarkImplScopeRef(ForLoop,ForScope.GetEnumerator,psraRead);
+ UseProcedure(ForScope.GetEnumerator);
+ MarkImplScopeRef(ForLoop,ForScope.MoveNext,psraRead);
+ UseProcedure(ForScope.MoveNext);
+ MarkImplScopeRef(ForLoop,ForScope.Current,psraRead);
+ UseVariable(ForScope.Current,rraRead,false);
+ end;
UseImplElement(ForLoop.Body);
end
else if C=TPasImplIfElse then
@@ -1648,12 +1660,14 @@ procedure TPasAnalyzer.UseExpr(El: TPasExpr);
UseElement(SubEl,rraAssign,false);
end;
- procedure UseBuilInFuncTypeInfo;
+ procedure UseBuiltInFuncTypeInfo;
var
ParentParams: TPRParentParams;
ParamResolved: TPasResolverResult;
SubEl: TPasElement;
Params: TPasExprArray;
+ ProcScope: TPasProcedureScope;
+ Proc: TPasProcedure;
begin
Resolver.GetParamsOfNameExpr(El,ParentParams);
if ParentParams.Params=nil then
@@ -1670,7 +1684,11 @@ procedure TPasAnalyzer.UseExpr(El: TPasExpr);
if (ParamResolved.IdentEl is TPasProcedure)
and (TPasProcedure(ParamResolved.IdentEl).ProcType is TPasFunctionType) then
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);
UseTypeInfo(SubEl);
end
@@ -1749,7 +1767,7 @@ begin
end;
bfTypeInfo:
begin
- UseBuilInFuncTypeInfo;
+ UseBuiltInFuncTypeInfo;
exit;
end;
bfAssert:
@@ -2386,6 +2404,8 @@ begin
RaiseNotSupported(20180328224632,aClass,GetObjName(o));
end;
end;
+
+ UseAttributes(El);
end;
procedure TPasAnalyzer.UseClassConstructor(El: TPasMembersType);
@@ -2664,6 +2684,7 @@ begin
{$IFDEF VerbosePasAnalyzer}
writeln('TPasAnalyzer.EmitSectionHints ',GetElModName(Section));
{$ENDIF}
+ if Section=nil then exit;
// initialization, program or library sections
aModule:=Section.GetModule;
UsesClause:=Section.UsesClause;
@@ -2810,8 +2831,14 @@ begin
sPAPrivateFieldIsNeverUsed,[El.FullName],El);
end
else if El.ClassType=TPasVariable then
- EmitMessage(20170311234201,mtHint,nPALocalVariableNotUsed,
- sPALocalVariableNotUsed,[El.Name],El)
+ begin
+ if El.Parent is TPasMembersType then
+ EmitMessage(20201229033108,mtHint,nPAFieldNotUsed,
+ sPAFieldNotUsed,[El.Name],El)
+ else
+ EmitMessage(20170311234201,mtHint,nPALocalVariableNotUsed,
+ sPALocalVariableNotUsed,[El.Name],El);
+ end
else
EmitMessage(20170314221334,mtHint,nPALocalXYNotUsed,
sPALocalXYNotUsed,[El.ElementTypeName,El.Name],El);
@@ -2825,6 +2852,9 @@ begin
if El.Visibility in [visPrivate,visStrictPrivate] then
EmitMessage(20170311234159,mtHint,nPAPrivateFieldIsAssignedButNeverUsed,
sPAPrivateFieldIsAssignedButNeverUsed,[El.FullName],El)
+ else if El.Parent is TPasMembersType then
+ EmitMessage(20201229033618,mtHint,nPAFieldIsAssignedButNeverUsed,
+ sPAFieldIsAssignedButNeverUsed,[El.Name],El)
else
EmitMessage(20170311233825,mtHint,nPALocalVariableIsAssignedButNeverUsed,
sPALocalVariableIsAssignedButNeverUsed,[El.Name],El);
@@ -3155,15 +3185,10 @@ begin
end;
function TPasAnalyzer.IsSpecializedGenericType(El: TPasElement): boolean;
-var
- GenScope: TPasGenericScope;
begin
- if El is TPasGenericType then
- begin
- GenScope:=El.CustomData as TPasGenericScope;
- if (GenScope<>nil) and (GenScope.SpecializedFromItem<>nil) then
- exit(true);
- end;
+ if (El is TPasGenericType) and (El.CustomData is TPasGenericScope)
+ and (TPasGenericScope(El.CustomData).SpecializedFromItem<>nil) then
+ exit(true);
Result:=false;
end;