* Added support for detecting no-longer used nodes in descr files

git-svn-id: trunk@9585 -
This commit is contained in:
michael 2007-12-30 16:39:41 +00:00
parent 1eec834e5a
commit d50f721e96
2 changed files with 66 additions and 6 deletions

View File

@ -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

View File

@ -29,6 +29,8 @@ resourcestring
SCmdLineInvalidOption = 'Ignoring unknown option "%s"';
SNoPackageNameProvided = 'Please specify a package name with --package=<name>';
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, '</descr>');
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, '</module> <!-- ', Module.Name, ' -->');
WriteLn(f, '');
@ -435,7 +480,8 @@ begin
Halt(1);
end;
end;
If UpdateMode then
Engine.WriteUnReferencedNodes;
finally
Engine.Free;
end;