dw_xml.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. {
  2. FPDoc - Free Pascal Documentation Tool
  3. Copyright (C) 2000 - 2003 by
  4. Areca Systems GmbH / Sebastian Guenther, [email protected]
  5. * 'XML struct' output generator
  6. See the file COPYING, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. {$mode objfpc}
  13. {$H+}
  14. unit dw_XML;
  15. interface
  16. uses DOM, PasTree, dwriter, xmlWrite, SysUtils;
  17. Type
  18. { TXMLWriter }
  19. TXMLWriter = Class(TFPDocWriter)
  20. function ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
  21. Procedure WriteDoc; override;
  22. end;
  23. implementation
  24. function TXMLWriter.ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
  25. var
  26. ModuleElement: TDOMElement;
  27. procedure ProcessProcedure(Proc: TPasProcedure; Element: TDOMElement);
  28. var
  29. ProcEl: TDOMElement;
  30. begin
  31. ProcEl := Result.CreateElement(Proc.TypeName);
  32. Element.AppendChild(ProcEl);
  33. ProcEl['name'] := Proc.Name;
  34. end;
  35. procedure ProcessVariable(AVar: TPasVariable; Element: TDOMElement);
  36. var
  37. VarEl: TDOMElement;
  38. begin
  39. VarEl := Result.CreateElement('var');
  40. Element.AppendChild(VarEl);
  41. VarEl['name'] := AVar.Name;
  42. end;
  43. procedure ProcessSection(ASection: TPasSection; const Name: DOMString);
  44. var
  45. Element, UsesElement, UnitElement: TDOMElement;
  46. i: Integer;
  47. Decl: TPasElement;
  48. begin
  49. Element := Result.CreateElement(Name);
  50. ModuleElement.AppendChild(Element);
  51. if ASection.UsesList.Count > 0 then
  52. begin
  53. UsesElement := Result.CreateElement('uses');
  54. Element.AppendChild(UsesElement);
  55. for i := 0 to ASection.UsesList.Count - 1 do
  56. begin
  57. UnitElement := Result.CreateElement('unit-ref');
  58. UnitElement['name'] := TPasType(ASection.UsesList[i]).Name;
  59. UsesElement.AppendChild(UnitElement);
  60. end;
  61. end;
  62. for i := 0 to ASection.Declarations.Count - 1 do
  63. begin
  64. Decl := TPasElement(ASection.Declarations[i]);
  65. if Decl.InheritsFrom(TPasProcedure) then
  66. ProcessProcedure(TPasProcedure(Decl), Element)
  67. else if Decl.ClassType = TPasVariable then
  68. ProcessVariable(TPasVariable(Decl), Element);
  69. end;
  70. end;
  71. begin
  72. Result := TXMLDocument.Create;
  73. Result.AppendChild(Result.CreateComment(' Generated using FPDoc - (c) 2000-2003 Sebastian Guenther, [email protected] '));
  74. Result.AppendChild(Result.CreateElement('fp-refdoc'));
  75. ModuleElement := Result.CreateElement('unit');
  76. ModuleElement['name'] := AModule.Name;
  77. Result.DocumentElement.AppendChild(ModuleElement);
  78. ProcessSection(AModule.InterfaceSection, 'interface');
  79. end;
  80. { TXMLWriter }
  81. procedure TXMLWriter.WriteDoc;
  82. var
  83. doc: TXMLDocument;
  84. i: Integer;
  85. begin
  86. if Engine.Output <> '' then
  87. Engine.Output := IncludeTrailingBackSlash(Engine.Output);
  88. for i := 0 to Package.Modules.Count - 1 do
  89. begin
  90. doc := ModuleToXMLStruct(TPasModule(Package.Modules[i]));
  91. WriteXMLFile(doc, Engine.Output + TPasModule(Package.Modules[i]).Name + '.xml' );
  92. doc.Free;
  93. end;
  94. end;
  95. initialization
  96. // Do not localize.
  97. RegisterWriter(TXMLWriter,'xml','fpdoc XML output.');
  98. finalization
  99. UnRegisterWriter('xml');
  100. end.