소스 검색

Merged revisions 9408,9434,9450-9456,9459-9463,9466,9468-9469,9472-9473,9476-9477,9480,9491-9492,9529,9536,9550,9566-9568,9571,9573,9576-9579,9583,9585,9587,9592 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r9408 | michael | 2007-12-07 11:55:17 +0100 (Fri, 07 Dec 2007) | 1 line

* Removed conditional define. CHM always included
........
r9578 | michael | 2007-12-29 23:49:18 +0100 (Sat, 29 Dec 2007) | 1 line

* Fixed 9808: used units now correctly parsed
........
r9585 | michael | 2007-12-30 17:39:41 +0100 (Sun, 30 Dec 2007) | 1 line

* Added support for detecting no-longer used nodes in descr files
........
r9592 | michael | 2007-12-30 22:17:56 +0100 (Sun, 30 Dec 2007) | 1 line

* makeskel in update mode can crash when looking for elements. Fixed this
........

git-svn-id: branches/fixes_2_2@9763 -

peter 17 년 전
부모
커밋
98f4321bf9
3개의 변경된 파일124개의 추가작업 그리고 26개의 파일을 삭제
  1. 27 7
      utils/fpdoc/dglobals.pp
  2. 3 13
      utils/fpdoc/dw_html.pp
  3. 94 6
      utils/fpdoc/makeskel.pp

+ 27 - 7
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);
@@ -836,17 +849,23 @@ end;
 function TFPDocEngine.FindElement(const AName: String): TPasElement;
 
   function FindInModule(AModule: TPasModule; const LocalName: String): TPasElement;
+  
   var
     l: TList;
     i: Integer;
+    
   begin
-    l := AModule.InterfaceSection.Declarations;
-    for i := 0 to l.Count - 1 do
-    begin
-      Result := TPasElement(l[i]);
-      if CompareText(Result.Name, LocalName) = 0 then
-        exit;
-    end;
+    If assigned(AModule.InterfaceSection) and 
+       Assigned(AModule.InterfaceSection.Declarations) then
+      begin
+      l:=AModule.InterfaceSection.Declarations;
+      for i := 0 to l.Count - 1 do
+        begin
+        Result := TPasElement(l[i]);
+        if  CompareText(Result.Name, LocalName) = 0 then
+          exit;
+        end;
+      end;  
     Result := nil;
  end;
 
@@ -1055,6 +1074,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

+ 3 - 13
utils/fpdoc/dw_html.pp

@@ -15,14 +15,11 @@
 {$mode objfpc}
 {$H+}
 
-{$DEFINE FPDOC_CHM}
-
 unit dw_HTML;
 
 interface
 
-uses Classes, DOM, DOM_HTML, dGlobals, PasTree, dWriter
-    {$IFDEF FPDOC_CHM},ChmWriter, ChmBase{$ENDIF};
+uses Classes, DOM, DOM_HTML, dGlobals, PasTree, dWriter, ChmWriter, ChmBase;
 
 const
   // Subpage indices for modules
@@ -255,17 +252,13 @@ type
     Procedure CreateAllocator; override;
   end;
 
-{$DEFINE FPDOC_CHM}
-
-{$IFDEF FPDOC_CHM}
   {$DEFINE chmInterface}
   {$I dw_htmlchm.inc}
   {$UNDEF chmInterface}
-{$ENDIF}
 
 implementation
 
-uses SysUtils, XHTML, XMLRead, XMLWrite, HTMWrite, sh_pas {$IFDEF FPDOC_CHM},chmsitemap{$ENDIF};
+uses SysUtils, XHTML, XMLRead, XMLWrite, HTMWrite, sh_pas,chmsitemap;
 
 
 Function FixHTMLpath(S : String) : STring;
@@ -3019,13 +3012,10 @@ initialization
   // Do not localize.
   RegisterWriter(THTMLWriter,'html','HTML output using fpdoc.css stylesheet.');
   RegisterWriter(THTMWriter,'htm','HTM (8.3 filenames) output using fpdoc.css stylesheet.');
-  {$IFDEF FPDOC_CHM}
   RegisterWriter(TCHMHTMLWriter,'chm','Compressed HTML file output using fpdoc.css stylesheet.');
-  {$ENDIF}
+
 finalization
   UnRegisterWriter('html');
   UnRegisterWriter('htm');
-  {$IFDEF FPDOC_CHM}
   UnRegisterWriter('chm');
-  {$ENDIF}
 end.

+ 94 - 6
utils/fpdoc/makeskel.pp

@@ -29,16 +29,23 @@ 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
   TCmdLineAction = (actionHelp, actionConvert);
 
   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
@@ -49,7 +56,7 @@ const
   FPCDate: String = {$I %FPCDATE%};
 
 var
-  EmittedList,InputFiles, DescrFiles: TStringList;
+  EmittedList, InputFiles, DescrFiles: TStringList;
   DocLang: String;
   Engine: TSkelEngine;
   UpdateMode,
@@ -64,12 +71,51 @@ var
   PackageName, OutputName: String;
   f: Text;
 
+function TSkelEngine.FindModule(const AName: String): TPasModule; 
+
+Var
+  I : Integer;
+
+begin
+  Result:=Inherited FindModule(AName);
+  If (Result=Nil) then
+    begin // Create dummy list and search in that.
+    If (FModules=Nil) then
+      begin
+      FModules:=TStringList.Create;
+      FModules.Sorted:=True;
+      end;
+    I:=FModules.IndexOf(AName);
+    IF (I=-1) then
+      begin
+      Result:=TPasModule.Create(AName,Nil);
+      FModules.AddObject(AName,Result);
+      end
+    else
+      Result:=FModules.Objects[i] as TPasModule;  
+    end;  
+end;
+
+Destructor TSkelEngine.Destroy; 
+
+Var
+  I : Integer;
+
+begin
+  If Assigned(FModules) then 
+    begin
+    For I:=0 to FModules.Count-1 do
+      FModules.Objects[i].Free;
+    FreeAndNil(FModules);    
+    end;
+end;
+
 
 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;
@@ -103,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;
 
@@ -127,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);
@@ -149,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);
@@ -184,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
@@ -197,6 +276,7 @@ procedure FreeOptions;
 begin
   DescrFiles.Free;
   InputFiles.Free;
+  EmittedList.Free;
 end;
 
 Procedure Usage;
@@ -332,6 +412,7 @@ end;
 var
   i,j: Integer;
   Module: TPasModule;
+  N : TDocNode;
 
 begin
   InitOptions;
@@ -376,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, '');
@@ -393,7 +480,8 @@ begin
              Halt(1);
            end;
        end;
-
+        If UpdateMode then
+          Engine.WriteUnReferencedNodes;
       finally
         Engine.Free;
        end;