dw_xml.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. {
  2. $Id$
  3. FPDoc - Free Pascal Documentation Tool
  4. Copyright (C) 2000 - 2003 by
  5. Areca Systems GmbH / Sebastian Guenther, [email protected]
  6. * 'XML struct' output generator
  7. See the file COPYING, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. }
  13. {$mode objfpc}
  14. {$H+}
  15. unit dw_XML;
  16. interface
  17. uses DOM, PasTree, dwriter;
  18. Type
  19. { TXMLWriter }
  20. TXMLWriter = Class(TFPDocWriter)
  21. function ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
  22. Procedure WriteDoc; override;
  23. end;
  24. implementation
  25. function TXMLWriter.ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
  26. var
  27. ModuleElement: TDOMElement;
  28. procedure ProcessProcedure(Proc: TPasProcedure; Element: TDOMElement);
  29. var
  30. ProcEl: TDOMElement;
  31. begin
  32. ProcEl := Result.CreateElement(Proc.TypeName);
  33. Element.AppendChild(ProcEl);
  34. ProcEl['name'] := Proc.Name;
  35. end;
  36. procedure ProcessVariable(AVar: TPasVariable; Element: TDOMElement);
  37. var
  38. VarEl: TDOMElement;
  39. begin
  40. VarEl := Result.CreateElement('var');
  41. Element.AppendChild(VarEl);
  42. VarEl['name'] := AVar.Name;
  43. end;
  44. procedure ProcessSection(ASection: TPasSection; const Name: DOMString);
  45. var
  46. Element, UsesElement, UnitElement: TDOMElement;
  47. i: Integer;
  48. Decl: TPasElement;
  49. begin
  50. Element := Result.CreateElement(Name);
  51. ModuleElement.AppendChild(Element);
  52. if ASection.UsesList.Count > 0 then
  53. begin
  54. UsesElement := Result.CreateElement('uses');
  55. Element.AppendChild(UsesElement);
  56. for i := 0 to ASection.UsesList.Count - 1 do
  57. begin
  58. UnitElement := Result.CreateElement('unit-ref');
  59. UnitElement['name'] := TPasType(ASection.UsesList[i]).Name;
  60. UsesElement.AppendChild(UnitElement);
  61. end;
  62. end;
  63. for i := 0 to ASection.Declarations.Count - 1 do
  64. begin
  65. Decl := TPasElement(ASection.Declarations[i]);
  66. if Decl.InheritsFrom(TPasProcedure) then
  67. ProcessProcedure(TPasProcedure(Decl), Element)
  68. else if Decl.ClassType = TPasVariable then
  69. ProcessVariable(TPasVariable(Decl), Element);
  70. end;
  71. end;
  72. begin
  73. Result := TXMLDocument.Create;
  74. Result.AppendChild(Result.CreateComment(' Generated using FPDoc - (c) 2000-2003 Sebastian Guenther, [email protected] '));
  75. Result.AppendChild(Result.CreateElement('fp-refdoc'));
  76. ModuleElement := Result.CreateElement('unit');
  77. ModuleElement['name'] := AModule.Name;
  78. Result.DocumentElement.AppendChild(ModuleElement);
  79. ProcessSection(AModule.InterfaceSection, 'interface');
  80. end;
  81. { TXMLWriter }
  82. procedure TXMLWriter.WriteDoc;
  83. begin
  84. end;
  85. initialization
  86. // Do not localize.
  87. RegisterWriter(TXMLWriter,'xml','fpdoc XML output.');
  88. finalization
  89. UnRegisterWriter('xml');
  90. end.
  91. {
  92. $Log$
  93. Revision 1.3 2005-01-12 21:11:41 michael
  94. + New structure for writers. Implemented TXT writer
  95. Revision 1.2 2005/01/09 15:59:50 michael
  96. + Split out latex writer to linear and latex writer
  97. Revision 1.1 2003/03/17 23:03:20 michael
  98. + Initial import in CVS
  99. Revision 1.5 2003/03/13 22:02:13 sg
  100. * New version with many bugfixes and our own parser (now independent of the
  101. compiler source)
  102. Revision 1.4 2002/05/24 00:13:22 sg
  103. * much improved new version, including many linking and output fixes
  104. Revision 1.3 2002/03/12 10:58:36 sg
  105. * reworked linking engine and internal structure
  106. Revision 1.2 2001/07/27 10:21:42 sg
  107. * Just a new, improved version ;)
  108. (detailed changelogs will be provided again with the next commits)
  109. Revision 1.1 2000/10/04 09:17:37 sg
  110. * First public version
  111. }