From d50f721e965a053cca916aabae11d9823401e871 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 30 Dec 2007 16:39:41 +0000 Subject: [PATCH] * Added support for detecting no-longer used nodes in descr files git-svn-id: trunk@9585 - --- utils/fpdoc/dglobals.pp | 14 ++++++++++ utils/fpdoc/makeskel.pp | 58 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/utils/fpdoc/dglobals.pp b/utils/fpdoc/dglobals.pp index 71a3ea47d6..3f37cbc802 100644 --- a/utils/fpdoc/dglobals.pp +++ b/utils/fpdoc/dglobals.pp @@ -208,9 +208,11 @@ type FFirstExample: TDOMElement; FLink: String; FTopicNode : Boolean; + FRefCount : Integer; public constructor Create(const AName: String; ANode: TDOMElement); destructor Destroy; override; + Function IncRefcount : Integer; function FindChild(const APathName: String): TDocNode; function CreateChildren(const APathName: String): TDocNode; // Properties for tree structure @@ -228,7 +230,9 @@ type property FirstExample: TDOMElement read FFirstExample; property Link: String read FLink; Property TopicNode : Boolean Read FTopicNode; + Property RefCount : Integer Read FRefCount; end; + // The main FPDoc engine @@ -425,6 +429,13 @@ begin inherited Destroy; end; +Function TDocNode.IncRefcount : Integer; + +begin + Inc(FRefCount); + Result:=FRefCount; +end; + function TDocNode.FindChild(const APathName: String): TDocNode; var DotPos: Integer; @@ -537,6 +548,8 @@ begin '#' + APackageName, nil, '', 0)); FPackages.Add(FPackage); CurPackageDocNode := RootDocNode.FindChild('#' + APackageName); + If Assigned(CurPackageDocNode) then + CurPackageDocNode.IncRefCount; end; procedure TFPDocEngine.ReadContentFile(const AFilename, ALinkPrefix: String); @@ -1055,6 +1068,7 @@ begin if (Node.NodeType = ELEMENT_NODE) and (Node.NodeName = 'package') then begin PackageDocNode := ReadNode(RootDocNode, TDOMElement(Node)); + PackageDocNode.IncRefCount; // Scan all 'module' elements within this package element Subnode := Node.FirstChild; while Assigned(Subnode) do diff --git a/utils/fpdoc/makeskel.pp b/utils/fpdoc/makeskel.pp index 91345417a9..18b8f22bb9 100644 --- a/utils/fpdoc/makeskel.pp +++ b/utils/fpdoc/makeskel.pp @@ -29,6 +29,8 @@ resourcestring SCmdLineInvalidOption = 'Ignoring unknown option "%s"'; SNoPackageNameProvided = 'Please specify a package name with --package='; SOutputMustNotBeDescr = 'Output file must be different from description filenames.'; + SCreatingNewNode = 'Creating documentation for new node : %s'; + SNodeNotReferenced = 'Documentation node "%s" no longer used'; SDone = 'Done.'; type @@ -36,12 +38,14 @@ type TSkelEngine = class(TFPDocEngine) FModules : TStringList; + Procedure DoWriteUnReferencedNodes(N : TDocNode; NodePath : String); public Destructor Destroy; override; function FindModule(const AName: String): TPasModule; override; function CreateElement(AClass: TPTreeElement; const AName: String; AParent: TPasElement; AVisibility :TPasMemberVisibility; const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement; override; + procedure WriteUnReferencedNodes; end; const @@ -52,7 +56,7 @@ const FPCDate: String = {$I %FPCDATE%}; var - EmittedList,InputFiles, DescrFiles: TStringList; + EmittedList, InputFiles, DescrFiles: TStringList; DocLang: String; Engine: TSkelEngine; UpdateMode, @@ -111,7 +115,7 @@ function TSkelEngine.CreateElement(AClass: TPTreeElement; const AName: String; AParent: TPasElement; AVisibility : TPasMemberVisibility; const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement; - Function WriteThisNode(APasElement : TPasElement) : Boolean; + Function WriteThisNode(APasElement : TPasElement; DocNode : TDocNode) : Boolean; Var ParentVisible:Boolean; @@ -145,9 +149,9 @@ function TSkelEngine.CreateElement(AClass: TPTreeElement; const AName: String; (Not Assigned(EmittedList) or (EmittedList.IndexOf(APasElement.FullName)=-1)); If Result and updateMode then begin - Result:=FindDocNode(APasElement)=Nil; + Result:=DocNode=Nil; If Result then - Writeln(stderr,'Creating documentation for new node ',APasElement.PathName); + Writeln(stderr,Format(ScreatingNewNode,[APasElement.PathName])); end; end; @@ -169,8 +173,19 @@ function TSkelEngine.CreateElement(AClass: TPTreeElement; const AName: String; end; +Var + DN : TDocNode; + begin Result := AClass.Create(AName, AParent); + If UpdateMode then + begin + DN:=FindDocNode(Result); + If Assigned(DN) then + DN.IncRefCount; + end + else + DN:=Nil; Result.Visibility:=AVisibility; if AClass.InheritsFrom(TPasModule) then CurModule := TPasModule(Result); @@ -191,7 +206,7 @@ begin WriteLn(f, ''); end; end - else if WriteThisNode(Result) then + else if WriteThisNode(Result,DN) then begin EmittedList.Add(Result.FullName); // So we don't emit again. WriteLn(f); @@ -226,6 +241,28 @@ begin end; end; +Procedure TSkelEngine.DoWriteUnReferencedNodes(N : TDocNode; NodePath : String); + +begin + If (N<>Nil) then + begin + If (NodePath<>'') then + NodePath:=NodePath+'.'; + DoWriteUnReferencedNodes(N.FirstChild,NodePath+N.Name); + While (N<>Nil) do + begin + if (N.RefCount=0) and (N.Node<>Nil) and (Not N.TopicNode) then + Writeln(stderr,Format(SNodeNotReferenced,[NodePath+N.Name])); + N:=N.NextSibling; + end; + end; +end; + +procedure TSkelEngine.WriteUnReferencedNodes; + +begin + DoWriteUnReferencedNodes(RootDocNode,''); +end; procedure InitOptions; begin @@ -239,6 +276,7 @@ procedure FreeOptions; begin DescrFiles.Free; InputFiles.Free; + EmittedList.Free; end; Procedure Usage; @@ -374,6 +412,7 @@ end; var i,j: Integer; Module: TPasModule; + N : TDocNode; begin InitOptions; @@ -418,6 +457,12 @@ begin For J:=0 to DescrFiles.Count-1 do Engine.AddDocFile(DescrFiles[J]); Module := ParseSource(Engine, InputFiles[i], OSTarget, CPUTarget); + If UpdateMode then + begin + N:=Engine.FindDocNode(Module); + If Assigned(N) then + N.IncRefCount; + end; WriteLn(f, ''); WriteLn(f, ' '); WriteLn(f, ''); @@ -435,7 +480,8 @@ begin Halt(1); end; end; - + If UpdateMode then + Engine.WriteUnReferencedNodes; finally Engine.Free; end;