dw_xml.pp 3.2 KB

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