dwlinear.pp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. {$mode objfpc}
  2. {$H+}
  3. unit dwlinear;
  4. interface
  5. uses
  6. Classes, SysUtils, DGlobals, dWriter, pastree, dom;
  7. Type
  8. { TLinearWriter }
  9. TLinearWriter = Class(TFPDocWriter)
  10. FStream : TStream;
  11. PackageName: String;
  12. Module: TPasModule;
  13. FLastURL : DomString;
  14. private
  15. FDupLinkedDoc: Boolean;
  16. Protected
  17. ModuleName: String;
  18. // Writing support.
  19. procedure Write(const s: String); virtual;
  20. procedure WriteLn(const s: String); virtual;
  21. procedure WriteF(const s: String; const Args: array of const); virtual;
  22. procedure WriteLnF(const s: String; const Args: array of const); virtual;
  23. Function PushWriteContext(S : TStream) : TStream;
  24. Procedure PopWriteContext(S : TSTream);
  25. procedure WriteLabel(El: TPasElement);
  26. procedure WriteIndex(El: TPasElement);
  27. procedure WriteTypeDecl(El: TPasElement); virtual;
  28. procedure WriteVariableDecl(El: TPasElement); virtual;
  29. procedure WriteConstDecl(El: TPasElement); virtual;
  30. // Auxiliary routines
  31. procedure DescrBeginURL(const AURL: DOMString); override; // Provides a default implementation
  32. procedure DescrEndURL; override;
  33. procedure SortElementList(List : TFPList);
  34. procedure StartListing(Frames: Boolean);
  35. Function ShowMember(M : TPasElement) : boolean;
  36. procedure StartChapter(ChapterName : String; ChapterLabel : String); virtual;
  37. procedure StartSection(SectionName : String; SectionLabel : String); virtual;
  38. procedure StartSubSection(SubSectionName : String; SubSectionLabel : String); virtual;
  39. procedure StartSubSubSection(SubSubSectionName : String; SubSubSectionLabel : String); virtual;
  40. Function GetDescrString(AContext: TPasElement; DescrNode: TDOMElement) : String;
  41. function ConstValue(ConstDecl: TPasConst): String; virtual;
  42. procedure ProcessSection(ASection: TPasSection); virtual;
  43. // Procedures which MAY be overridden in descendents
  44. procedure WriteBeginDocument; virtual;
  45. procedure WriteEndDocument; virtual;
  46. Function EscapeText(S : String) : String; virtual;
  47. Function StripText(S : String) : String; virtual;
  48. Procedure StartProcedure; Virtual;
  49. Procedure EndProcedure; Virtual;
  50. Procedure StartProperty; Virtual;
  51. Procedure EndProperty; Virtual;
  52. Procedure StartSynopsis; Virtual;
  53. Procedure StartDeclaration; Virtual;
  54. Procedure StartVisibility; Virtual;
  55. Procedure StartDescription; Virtual;
  56. Procedure StartAccess; Virtual;
  57. Procedure StartErrors; Virtual;
  58. Procedure StartVersion; Virtual;
  59. Procedure StartSeealso; Virtual;
  60. Procedure EndSeealso; Virtual;
  61. // Procedures which MUST be overridden in descendents;
  62. procedure WriteCommentLine; virtual; abstract;
  63. procedure WriteComment(Comment : String); virtual; abstract;
  64. function GetLabel(AElement: TPasElement): String; virtual; abstract;
  65. procedure WriteLabel(Const S : String); virtual; abstract;
  66. procedure WriteIndex(Const S : String); virtual; abstract;
  67. procedure WriteType(const s: string); virtual;
  68. procedure WriteVariable(const s: string); virtual;
  69. procedure WriteConstant(const s: string); virtual;
  70. procedure StartChapter(ChapterName : String); virtual; abstract;
  71. procedure StartSection(SectionName : String); virtual; abstract;
  72. procedure StartSubSection(SubSectionName : String); virtual; abstract;
  73. procedure StartSubSubSection(SubSubSectionName : String); virtual; abstract;
  74. procedure StartListing(Frames: Boolean; const name: String); virtual; abstract;
  75. procedure EndListing; virtual; abstract;
  76. Procedure WriteExampleFile(FN : String); virtual; abstract;
  77. procedure StartOverview(WithAccess : Boolean); virtual; Abstract;
  78. procedure EndOverview; virtual; Abstract;
  79. procedure WriteOverviewMember(const ALabel,AName,Access,ADescr : String); virtual; Abstract;
  80. procedure WriteOverviewMember(const ALabel,AName,ADescr : String); virtual; Abstract;
  81. procedure StartUnitOverview(AModuleName,AModuleLabel : String);virtual; Abstract;
  82. procedure WriteUnitEntry(UnitRef : TPasType);virtual; Abstract;
  83. procedure EndUnitOverview; virtual; Abstract;
  84. Property LastURL : DomString Read FLastURL Write FLastURL;
  85. // Overriden from fpdocwriter;
  86. procedure DescrWriteText(const AText: DOMString); override;
  87. Public
  88. Constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
  89. function InterpretOption(const Cmd, Arg: String): Boolean; override;
  90. class procedure Usage(List: TStrings); override;
  91. procedure WriteDoc; override;
  92. // Linear Documentation writing methods.
  93. Procedure ProcessPackage;
  94. Procedure ProcessTopics(DocNode : TDocNode; Alevel : Integer);
  95. procedure WriteResourceStrings(ASection: TPasSection);
  96. procedure WriteUnitOverview(ASection: TPasSection);
  97. procedure WriteVarsConstsTypes(ASection: TPasSection);
  98. procedure WriteConsts(ASection: TPasSection);
  99. procedure WriteTypes(ASection: TPasSection); virtual;
  100. procedure WriteEnumElements(TypeDecl : TPasEnumType);
  101. procedure WriteVars(ASection: TPasSection);
  102. procedure WriteFunctionsAndProcedures(ASection: TPasSection);
  103. procedure WriteProcedure(ProcDecl: TPasProcedureBase);
  104. procedure WriteClasses(ASection: TPasSection);
  105. procedure WriteClassDecl(ClassDecl: TPasClassType);
  106. procedure WriteClassMethodOverview(ClassDecl: TPasClassType);
  107. procedure WriteClassPropertyOverview(ClassDecl: TPasClassType);
  108. procedure WriteClassInterfacesOverview(ClassDecl: TPasClassType);
  109. procedure WriteClassInheritanceOverview(ClassDecl: TPasClassType); virtual;
  110. procedure WriteProperty(PropDecl: TPasProperty);
  111. procedure WriteExample(ADocNode: TDocNode);
  112. procedure WriteSeeAlso(ADocNode: TDocNode);
  113. Procedure WriteTopicNode(Node : TDocNode; Level : Integer);
  114. end;
  115. implementation
  116. const
  117. cDupLinkedDocParam = '--duplinkeddoc';
  118. { TLinearWriter }
  119. { ---------------------------------------------------------------------
  120. Writing support
  121. ---------------------------------------------------------------------}
  122. Function TLinearWriter.PushWriteContext(S : TStream) : TStream;
  123. begin
  124. Result:=FStream;
  125. FStream:=S;
  126. end;
  127. Procedure TLinearWriter.PopWriteContext(S : TSTream);
  128. begin
  129. FStream:=S;
  130. end;
  131. procedure TLinearWriter.Write(const s: String);
  132. Var
  133. L : Integer;
  134. begin
  135. L:=Length(S);
  136. If (L>0) then
  137. FStream.Write(PChar(S)^,L);
  138. end;
  139. procedure TLinearWriter.WriteF(const s: String; const Args: array of const);
  140. begin
  141. Write(Format(S,Args));
  142. end;
  143. procedure TLinearWriter.WriteLn(const s: String);
  144. begin
  145. Write(S);
  146. Write(LineEnding);
  147. end;
  148. procedure TLinearWriter.WriteLnF(const s: String; const Args: array of const);
  149. begin
  150. Write(Format(S,Args));
  151. Write(LineEnding);
  152. end;
  153. procedure TLinearWriter.DescrWriteText(const AText: DOMString);
  154. begin
  155. Write(EscapeText(AText));
  156. end;
  157. Function TLinearWriter.GetDescrString(AContext: TPasElement; DescrNode: TDOMElement) : String;
  158. Var
  159. S : TStringStream;
  160. F : TStream;
  161. begin
  162. Result:='';
  163. if Assigned(DescrNode) then
  164. begin
  165. S:=TStringStream.Create('');
  166. Try
  167. F:=PushWriteContext(S);
  168. Try
  169. ConvertDescr(AContext, DescrNode, False);
  170. Result:=S.DataString;
  171. FInally
  172. PopWriteContext(F);
  173. end;
  174. finally
  175. S.FRee;
  176. end;
  177. end;
  178. end;
  179. { ---------------------------------------------------------------------
  180. Auxiliary routines
  181. ---------------------------------------------------------------------}
  182. procedure TLinearWriter.WriteLabel(El: TPasElement);
  183. begin
  184. WriteLabel(GetLabel(El));
  185. end;
  186. procedure TLinearWriter.WriteIndex(El: TPasElement);
  187. begin
  188. WriteIndex(EL.Name);
  189. end;
  190. procedure TLinearWriter.WriteTypeDecl(El: TPasElement);
  191. begin
  192. WriteType(El.Name);
  193. end;
  194. procedure TLinearWriter.WriteVariableDecl(El: TPasElement);
  195. begin
  196. WriteVariable(El.Name);
  197. end;
  198. procedure TLinearWriter.WriteConstDecl(El: TPasElement);
  199. begin
  200. WriteConstant(El.Name);
  201. end;
  202. procedure TLinearWriter.DescrBeginURL(const AURL: DOMString);
  203. begin
  204. FLastURL:=AURL;
  205. end;
  206. procedure TLinearWriter.DescrEndURL;
  207. begin
  208. If (FLastURL<>'') then
  209. Writeln(Format(SSeeURL,[EscapeText(FLastURL)]));
  210. FLastURL:='';
  211. end;
  212. procedure TLinearWriter.StartListing(Frames: Boolean);
  213. begin
  214. StartListing(Frames,'');
  215. end;
  216. procedure TLinearWriter.StartChapter(ChapterName: String; ChapterLabel: String);
  217. begin
  218. StartChapter(ChapterName);
  219. WriteLabel(ChapterLabel);
  220. end;
  221. procedure TLinearWriter.StartSection(SectionName: String; SectionLabel: String);
  222. begin
  223. StartSection(SectionName);
  224. WriteLabel(SectionLabel);
  225. end;
  226. procedure TLinearWriter.StartSubSection(SubSectionName: String; SubSectionLabel: String);
  227. begin
  228. StartSubSection(SubSectionName);
  229. WriteLabel(SubSectionLabel);
  230. end;
  231. procedure TLinearWriter.StartSubSubSection(SubSubSectionName: String;
  232. SubSubSectionLabel: String);
  233. begin
  234. StartSubSubSection(SubSubSectionName);
  235. WriteLabel(SubSubSectionLabel);
  236. end;
  237. { ---------------------------------------------------------------------
  238. Default implementations, may be overridden in descendents
  239. ---------------------------------------------------------------------}
  240. Function TLinearWriter.EscapeText(S : String) : String;
  241. begin
  242. Result:=S;
  243. end;
  244. Function TLinearWriter.StripText(S : String) : String;
  245. begin
  246. Result:=S;
  247. end;
  248. Procedure TLinearWriter.StartProcedure;
  249. begin
  250. Writeln(SDocProcedure+':');
  251. end;
  252. Procedure TLinearWriter.StartSynopsis;
  253. begin
  254. Writeln('');
  255. Writeln(SDocSynopsis+':');
  256. end;
  257. Procedure TLinearWriter.StartDeclaration;
  258. begin
  259. Writeln('');
  260. Writeln(SDocDeclaration+':');
  261. end;
  262. Procedure TLinearWriter.StartVisibility;
  263. begin
  264. Writeln('');
  265. Writeln(SDocVisibility+':');
  266. end;
  267. Procedure TLinearWriter.StartDescription;
  268. begin
  269. Writeln('');
  270. Writeln(SDocDescription+':');
  271. end;
  272. Procedure TLinearWriter.StartAccess;
  273. begin
  274. Writeln('');
  275. Writeln(SDocAccess+':');
  276. end;
  277. Procedure TLinearWriter.StartErrors;
  278. begin
  279. Writeln('');
  280. Writeln(SDocErrors+':');
  281. end;
  282. Procedure TLinearWriter.StartVersion;
  283. begin
  284. Writeln('');
  285. Writeln(SDocVersion+':');
  286. end;
  287. Procedure TLinearWriter.StartSeealso;
  288. begin
  289. Writeln('');
  290. Writeln(SDocSeeAlso+':');
  291. end;
  292. Procedure TLinearWriter.StartProperty;
  293. begin
  294. Writeln('');
  295. Writeln(SDocProperty+':');
  296. end;
  297. Procedure TLinearWriter.EndProcedure;
  298. begin
  299. Writeln('');
  300. end;
  301. Procedure TLinearWriter.EndProperty;
  302. begin
  303. Writeln('');
  304. end;
  305. procedure TLinearWriter.EndSeealso;
  306. begin
  307. Writeln('');
  308. end;
  309. procedure TLinearWriter.WriteType(const s: string);
  310. begin
  311. // do nothing
  312. end;
  313. procedure TLinearWriter.WriteVariable(const s: string);
  314. begin
  315. // do nothing
  316. end;
  317. procedure TLinearWriter.WriteConstant(const s: string);
  318. begin
  319. // do nothing
  320. end;
  321. procedure TLinearWriter.WriteClassDecl(ClassDecl: TPasClassType);
  322. var
  323. DocNode: TDocNode;
  324. Vis: TPasMemberVisibilities;
  325. Member: TPasElement;
  326. i: Integer;
  327. begin
  328. StartSection(ClassDecl.Name);
  329. WriteLabel(ClassDecl);
  330. WriteIndex(ClassDecl);
  331. DocNode := Engine.FindDocNode(ClassDecl);
  332. if Assigned(DocNode) and ((not IsDescrNodeEmpty(DocNode.Descr)) or
  333. (not IsDescrNodeEmpty(DocNode.ShortDescr))) then
  334. begin
  335. StartSubSection(SDocDescription);
  336. WriteDescr(ClassDecl,DocNode);
  337. If Assigned(DocNode.Version) then
  338. begin
  339. StartSubSection(SDocVersion);
  340. WriteDescr(ClassDecl,DocNode.Version);
  341. end;
  342. if Assigned(DocNode.SeeAlso) then
  343. begin
  344. WriteSeeAlso(DocNode);
  345. end;
  346. ConvertNotes(ClassDecl,DocNode.Notes);
  347. end;
  348. // graemeg: this must move above SeeAlso, Version and Notes written above.
  349. // Write Class Hierarchy (Inheritance) Overview;
  350. WriteClassInheritanceOverView(ClassDecl);
  351. // Write Interfaces Overview;
  352. WriteClassInterfacesOverView(ClassDecl);
  353. // Write method overview
  354. WriteClassMethodOverView(ClassDecl);
  355. // Write Property Overview;
  356. WriteClassPropertyOverView(ClassDecl);
  357. // Write method & property descriptions
  358. // Determine visibilities
  359. Vis := AllVisibilities;
  360. if Engine.HidePrivate then
  361. Exclude(Vis,visPrivate);
  362. if Engine.HideProtected then
  363. Exclude(Vis,visProtected);
  364. for i := 0 to ClassDecl.Members.Count - 1 do
  365. begin
  366. Member := TPasElement(ClassDecl.Members[i]);
  367. if ((Member.InheritsFrom(TPasProcedureBase)) and
  368. (Member.Visibility in Vis)) then
  369. WriteProcedure(TPasProcedureBase(Member));
  370. end;
  371. // properties.
  372. for i := 0 to ClassDecl.Members.Count - 1 do
  373. begin
  374. Member := TPasElement(ClassDecl.Members[i]);
  375. if ((Member.InheritsFrom(TPasProperty)) and
  376. (Member.Visibility in Vis)) then
  377. WriteProperty(TPasProperty(Member));
  378. end;
  379. end;
  380. procedure TLinearWriter.WriteClassPropertyOverview(ClassDecl : TPasClassType);
  381. var
  382. Member: TPasElement;
  383. i: Integer;
  384. L,N,S,A: String;
  385. DocNode: TDocNode;
  386. List : TStringList;
  387. lNode: TDocNode;
  388. begin
  389. // Write property overview
  390. List:=TStringList.Create;
  391. Try
  392. List.Sorted:=True;
  393. for i := 0 to ClassDecl.Members.Count - 1 do
  394. begin
  395. Member := TPasElement(ClassDecl.Members[i]);
  396. With Member do
  397. if InheritsFrom(TPasProperty) and SHowMember(Member) then
  398. List.AddObject(Member.Name,Member)
  399. end;
  400. If (List.Count>0) then
  401. begin
  402. StartSubSection(SDocPropertyOverview);
  403. WriteLabel(GetLabel(ClassDecl) + ':Properties');
  404. StartOverView(True);
  405. For I:=0 to List.Count-1 do
  406. begin
  407. Member:=TPasElement(List.objects[i]);
  408. L:=StripText(GetLabel(Member));
  409. N:=EscapeText(Member.Name);
  410. DocNode := Engine.FindDocNode(Member);
  411. if Assigned(DocNode) then
  412. begin
  413. if FDupLinkedDoc and (DocNode.Link <> '') then
  414. begin
  415. lNode := Engine.FindLinkedNode(DocNode);
  416. if not Assigned(lNode) then
  417. lNode := DocNode;
  418. end
  419. else
  420. lNode := DocNode;
  421. S := GetDescrString(Member, lNode.ShortDescr);
  422. end
  423. else
  424. S := '';
  425. A:='';
  426. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  427. a := a + 'r';
  428. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  429. a := a + 'w';
  430. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  431. a := a + 's';
  432. WriteOverviewMember(L,N,A,S);
  433. S := '';
  434. end;
  435. EndOverview;
  436. end;
  437. Finally
  438. List.Free;
  439. end;
  440. end;
  441. procedure TLinearWriter.WriteClassInterfacesOverview(ClassDecl: TPasClassType);
  442. var
  443. lInterface: TPasElement;
  444. i: Integer;
  445. L,N,S,A: String;
  446. DocNode: TDocNode;
  447. List : TStringList;
  448. lNode: TDocNode;
  449. begin
  450. // Write Interfaces overview
  451. List:=TStringList.Create;
  452. try
  453. List.Sorted:=True;
  454. for i := 0 to ClassDecl.Interfaces.Count-1 do
  455. begin
  456. lInterface := TPasElement(ClassDecl.Interfaces[i]);
  457. List.AddObject(lInterface.Name,lInterface);
  458. end;
  459. if (List.Count>0) then
  460. begin
  461. StartSubSection(SDocInterfacesOverview);
  462. WriteLabel(GetLabel(ClassDecl) + ':Interfaces');
  463. StartOverView(False);
  464. for i := 0 to List.Count-1 do
  465. begin
  466. lInterface := TPasElement(List.Objects[i]);
  467. L := StripText(GetLabel(lInterface));
  468. N := EscapeText(lInterface.Name);
  469. DocNode := Engine.FindDocNode(lInterface);
  470. if Assigned(DocNode) then
  471. begin
  472. if FDupLinkedDoc and (DocNode.Link <> '') then
  473. begin
  474. lNode := Engine.FindLinkedNode(DocNode);
  475. if not Assigned(lNode) then
  476. lNode := DocNode;
  477. end
  478. else
  479. lNode := DocNode;
  480. S := GetDescrString(lInterface, lNode.ShortDescr);
  481. end
  482. else
  483. S := '';
  484. WriteOverviewMember(L,N,S);
  485. S := '';
  486. end;
  487. EndOverview;
  488. end;
  489. finally
  490. List.Free;
  491. end;
  492. end;
  493. procedure TLinearWriter.WriteClassInheritanceOverview(ClassDecl: TPasClassType);
  494. begin
  495. { Do nothing by default. This will be implemented by descendant writers. See
  496. the IPF Writer for an example. }
  497. end;
  498. function TLinearWriter.ConstValue(ConstDecl: TPasConst): String;
  499. begin
  500. if Assigned(ConstDecl) then
  501. Result := ConstDecl.ClassName
  502. else
  503. Result := '<nil>';
  504. end;
  505. procedure TLinearWriter.WriteDoc;
  506. var
  507. i : Integer;
  508. L : TstringList;
  509. begin
  510. PackageName := LowerCase(Copy(Package.Name, 2, 255));
  511. If (Engine.OutPut='') then
  512. Engine.Output:=PackageName+FileNameExtension
  513. else if (ExtractFileExt(Engine.output)='') and (FileNameExtension<>'') then
  514. Engine.Output:=ChangeFileExt(Engine.output,FileNameExtension);
  515. FStream:=TFileStream.Create(Engine.Output,fmCreate);
  516. try
  517. WriteBeginDocument;
  518. ProcessPackage;
  519. L:=TStringList.Create;
  520. Try
  521. L.Sorted:=True;
  522. // Sort modules.
  523. For I:=0 to Package.Modules.Count-1 do
  524. L.AddObject(TPasModule(Package.Modules[i]).Name,TPasModule(Package.Modules[i]));
  525. // Now create table.
  526. for i:=0 to L.Count - 1 do
  527. begin
  528. Module := TPasModule(L.Objects[i]);
  529. ModuleName := LowerCase(Module.Name);
  530. WriteCommentLine;
  531. StartChapter(Format(SDocUnitTitle, [Module.Name]));
  532. WriteLabel(Module);
  533. // extra Topics now get processed in ProcessSection()
  534. ProcessSection(Module.InterfaceSection);
  535. end;
  536. Finally
  537. L.Free;
  538. end;
  539. WriteEndDocument;
  540. finally
  541. FSTream.Free;
  542. end;
  543. end;
  544. procedure TLinearWriter.ProcessSection(ASection: TPasSection);
  545. var
  546. DocNode: TDocNode;
  547. begin
  548. With ASection do
  549. begin
  550. SortElementList(UsesList);
  551. SortElementList(Declarations);
  552. SortElementList(ResStrings);
  553. SortElementList(Types);
  554. SortElementList(Consts);
  555. SortElementList(Classes);
  556. SortElementList(Functions);
  557. SortElementList(Variables);
  558. end;
  559. WriteUnitOverView(ASection);
  560. // Now process unit (extra) Topics
  561. DocNode:=Engine.FindDocNode(Module);
  562. If Assigned(DocNode) then
  563. ProcessTopics(DocNode,1);
  564. WriteVarsConstsTypes(ASection);
  565. WriteFunctionsAndProcedures(ASection);
  566. WriteClasses(ASection);
  567. end;
  568. procedure TLinearWriter.WriteVarsConstsTypes(ASection: TPasSection);
  569. begin
  570. With Asection do
  571. if (Consts.Count>0) or (Types.Count>0) or
  572. (Variables.Count>0) or (ResStrings.Count>0) then
  573. begin
  574. StartSection(SDocConstsTypesVars, ModuleName+'ConstsTypesVars');
  575. WriteResourceStrings(ASection);
  576. WriteConsts(ASection);
  577. WriteTypes(ASection);
  578. WriteVars(ASection);
  579. end;
  580. end;
  581. procedure TLinearWriter.WriteResourceStrings(ASection: TPasSection);
  582. var
  583. ResStrDecl: TPasResString;
  584. i: Integer;
  585. DocNode : TDocNode;
  586. begin
  587. if ASection.ResStrings.Count > 0 then
  588. begin
  589. StartSubSection(SDocResStrings,ModuleName+'ResStrings');
  590. for i := 0 to ASection.ResStrings.Count - 1 do
  591. begin
  592. ResStrDecl := TPasResString(ASection.ResStrings[i]);
  593. StartListing(false, '');
  594. DescrWriteText(ResStrDecl.GetDeclaration(True)); // instead of WriteLn() so we can do further processing like manual line wrapping in descendants
  595. EndListing;
  596. WriteLabel(ResStrDecl);
  597. WriteIndex(ResStrDecl);
  598. DocNode:=WriteDescr(ResStrDecl);
  599. If Assigned(DocNode) and Assigned(DocNode.Version) then
  600. begin
  601. Writeln(Format('%s : ',[SDocVersion]));
  602. WriteDescr(ResStrDecl, DocNode.Version);
  603. end;
  604. end;
  605. end;
  606. end;
  607. procedure TLinearWriter.WriteUnitOverview(ASection: TPasSection);
  608. var
  609. i: Integer;
  610. UnitRef: TPasType;
  611. DocNode: TDocNode;
  612. begin
  613. if ASection.UsesList.Count > 0 then
  614. begin
  615. StartSection(SDocUsedUnits);
  616. StartUnitOverview(Module.Name,ModuleName);
  617. for i := 0 to ASection.UsesList.Count - 1 do
  618. begin
  619. UnitRef := TPasType(ASection.UsesList[i]);
  620. WriteUnitEntry(UnitRef);
  621. end;
  622. EndUnitOverview;
  623. end;
  624. DocNode := Engine.FindDocNode(ASection.Parent);
  625. if Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr) then
  626. begin
  627. StartSection(SDocOverview);
  628. WriteDescr(ASection.Parent, DocNode.Descr);
  629. ConvertNotes(ASection.Parent,DocNode.Notes);
  630. end;
  631. end;
  632. Procedure TLinearWriter.ProcessPackage;
  633. var
  634. DocNode: TDocNode;
  635. begin
  636. DocNode:=Engine.FindDocNode(Package);
  637. if Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr) then
  638. begin
  639. StartSection(SDocOverview);
  640. WriteDescr(Package, DocNode.Descr);
  641. end;
  642. WriteSeeAlso(DocNode);
  643. ConvertNotes(Nil,DocNode.Notes);
  644. ProcessTopics(DocNode,1);
  645. end;
  646. Procedure TLinearWriter.ProcessTopics(DocNode : TDocNode; Alevel : Integer);
  647. Var
  648. Node : TDocNode;
  649. begin
  650. If Not Assigned(DocNode) then
  651. Exit;
  652. Node:=DocNode.FirstChild;
  653. While Assigned(Node) do
  654. begin
  655. If Node.TopicNode then
  656. WriteTopicNode(Node,ALevel);
  657. Node:=Node.NextSibling;
  658. end;
  659. end;
  660. Procedure TLinearWriter.WriteTopicNode(Node : TDocNode; Level : Integer);
  661. Var
  662. Element : TTopicElement;
  663. SubNode : TDocNode;
  664. S : String;
  665. begin
  666. Element:=FindTopicElement(Node);
  667. If Not Assigned(Element) then
  668. Exit;
  669. S:=GetDescrString(Element,Node.ShortDescr);
  670. Case Level of
  671. 1 : StartSection(S);
  672. 2 : StartSubSection(S);
  673. 3 : StartSubSubSection(S);
  674. end;
  675. WriteLabel(Element);
  676. If Assigned(Node.Descr) then
  677. WriteDescr(Element,Node.Descr);
  678. WriteSeeAlso(Node);
  679. ConvertNotes(Element,Node.Notes);
  680. If Level<3 then
  681. begin
  682. SubNode:=Node.FirstChild;
  683. While Assigned(SubNode) do
  684. begin
  685. If SubNode.TopicNode then
  686. WriteTopicNode(SubNode,Level+1);
  687. SubNode:=SubNode.NextSibling;
  688. end;
  689. end;
  690. WriteExample(Node);
  691. end;
  692. procedure TLinearWriter.WriteConsts(ASection: TPasSection);
  693. var
  694. i: Integer;
  695. ConstDecl: TPasConst;
  696. begin
  697. if ASection.Consts.Count > 0 then
  698. begin
  699. StartSubSection(SDocConstants,EscapeText(ModuleName));
  700. for i := 0 to ASection.Consts.Count - 1 do
  701. begin
  702. DescrBeginParaGraph;
  703. ConstDecl := TPasConst(ASection.Consts[i]);
  704. WriteConstDecl(ConstDecl);
  705. StartListing(False,'');
  706. WriteLn(EscapeText(ConstDecl.GetDeclaration(True)));
  707. EndListing;
  708. WriteLabel(ConstDecl);
  709. WriteIndex(ConstDecl);
  710. WriteDescr(ConstDecl);
  711. DescrEndParaGraph;
  712. end;
  713. end;
  714. end;
  715. procedure TLinearWriter.WriteEnumElements(TypeDecl : TPasEnumType);
  716. Var
  717. EV : TPasEnumValue;
  718. I : Integer;
  719. DocNode : TDocNode;
  720. begin
  721. With TypeDecl do
  722. begin
  723. SortElementList(Values);
  724. DescrBeginTable(2,True);
  725. DescrBeginTableCaption;
  726. Writeln(EscapeText(Format(SDocValuesForEnum,[TypeDecl.Name])));
  727. DescrEndTableCaption;
  728. DescrBeginTableHeadRow;
  729. DescrBeginTableCell;
  730. Writeln(EscapeText(SDocValue));
  731. DescrEndTableCell;
  732. DescrBeginTableCell;
  733. Writeln(EscapeText(SDocExplanation));
  734. DescrEndTableCell;
  735. DescrEndTableHeadRow;
  736. For I:=0 to Values.Count-1 do
  737. begin
  738. EV:=TPasEnumValue(Values[i]);
  739. DescrBeginTableRow;
  740. DescrBeginTableCell;
  741. Writeln(EscapeText(EV.Name));
  742. DescrEndTableCell;
  743. DescrBeginTableCell;
  744. DocNode := Engine.FindDocNode(EV);
  745. if Assigned(DocNode) and (not IsDescrNodeEmpty(DocNode.ShortDescr)) then
  746. WriteDescr(EV,DocNode.ShortDescr);
  747. DescrEndTableCell;
  748. DescrEndTableRow;
  749. end;
  750. DescrEndTable;
  751. end;
  752. end;
  753. procedure TLinearWriter.WriteTypes(ASection: TPasSection);
  754. var
  755. i: Integer;
  756. TypeDecl: TPasType;
  757. DocNode : TDocNode;
  758. begin
  759. if ASection.Types.Count > 0 then
  760. begin
  761. StartSubSection(SDocTypes,ModuleName+'Types');
  762. for i := 0 to ASection.Types.Count - 1 do
  763. begin
  764. DescrBeginParagraph;
  765. TypeDecl := TPasType(ASection.Types[i]);
  766. WriteTypeDecl(TypeDecl);
  767. StartListing(False,'');
  768. DocNode := Engine.FindDocNode(TypeDecl);
  769. If Assigned(DocNode) and
  770. Assigned(DocNode.Node) and
  771. (Docnode.Node['opaque']='1') then
  772. Writeln(TypeDecl.Name+' = '+SDocOpaque)
  773. else
  774. begin
  775. Writeln(EscapeText(TypeDecl.GetDeclaration(True)));
  776. end;
  777. EndListing;
  778. WriteLabel(TypeDecl);
  779. WriteIndex(TypeDecl);
  780. If TypeDecl is TPasEnumType then
  781. WriteENumElements(TypeDecl as TPasEnumType)
  782. else If (TypeDecl is TPasSetType)
  783. and (TPasSetType(TypeDecl).EnumType is TPasEnumType)
  784. and (TPasSetType(TypeDecl).EnumType.Name='') then
  785. WriteENumElements(TPasSetType(TypeDecl).EnumType as TPasEnumType);
  786. WriteDescr(TypeDecl,DocNode);
  787. If Assigned(DocNode) and Assigned(DocNode.Version) then
  788. begin
  789. Writeln(Format('%s : ',[SDocVersion]));
  790. WriteDescr(TypeDecl, DocNode.Version);
  791. end;
  792. if Assigned(DocNode) and assigned(DocNode.Notes) then
  793. ConvertNotes(TypeDecl,DocNode.Notes);
  794. DescrEndParagraph;
  795. end;
  796. end;
  797. end;
  798. procedure TLinearWriter.WriteVars(ASection: TPasSection);
  799. var
  800. VarDecl: TPasVariable;
  801. i: Integer;
  802. DocNode : TDocNode;
  803. begin
  804. if ASection.Variables.Count > 0 then
  805. begin
  806. StartSubsection(SDocVariables,ModuleName+'Variables');
  807. for i := 0 to ASection.Variables.Count - 1 do
  808. begin
  809. DescrBeginParaGraph;
  810. VarDecl := TPasVariable(ASection.Variables[i]);
  811. WriteVariableDecl(VarDecl);
  812. StartListing(False,'');
  813. WriteLn(EscapeText(VarDecl.GetDeclaration(True)));
  814. EndListing;
  815. WriteLabel(VarDecl);
  816. WriteIndex(VarDecl);
  817. DocNode:=WriteDescr(VarDecl);
  818. If Assigned(DocNode) and Assigned(DocNode.Version) then
  819. begin
  820. Writeln(Format('%s : ',[SDocVersion]));
  821. WriteDescr(VarDecl, DocNode.Version);
  822. ConvertNotes(VarDecl,DocNode.Notes);
  823. end;
  824. DescrEndParaGraph;
  825. end;
  826. end;
  827. end;
  828. procedure TLinearWriter.WriteProcedure(ProcDecl : TPasProcedureBase);
  829. var
  830. DocNode: TDocNode;
  831. OP : TPasOverloadedProc;
  832. i : integer;
  833. begin
  834. With ProcDecl do
  835. begin
  836. if Not (Assigned(Parent) and Parent.InheritsFrom(TPasClassType)) then
  837. begin
  838. StartSubSection(Name);
  839. WriteLabel(ProcDecl);
  840. WriteIndex(ProcDecl);
  841. end
  842. else
  843. begin // Parent assigned and hence method.
  844. StartSubSection(Parent.Name+'.'+Name);
  845. WriteLabel(ProcDecl);
  846. WriteIndex(Parent.Name+'.'+Name);
  847. end;
  848. StartProcedure;
  849. DocNode := Engine.FindDocNode(ProcDecl);
  850. if Assigned(DocNode) and Assigned(DocNode.ShortDescr) then
  851. begin
  852. StartSynopsis;
  853. WriteDescr(ProcDecl, DocNode.ShortDescr);
  854. end;
  855. StartDeclaration;
  856. StartListing(False);
  857. if ClassType = TPasOverloadedProc then
  858. begin
  859. OP:=TPasOverloadedProc(ProcDecl);
  860. for i := 0 to OP.Overloads.Count - 1 do
  861. begin
  862. WriteLn(TPasProcedure(OP.Overloads[i]).GetDeclaration(True));
  863. end;
  864. end
  865. else
  866. WriteLn(GetDeclaration(True));
  867. EndListing;
  868. If Assigned(Parent) then
  869. begin
  870. StartVisibility;
  871. Writeln(VisibilityNames[Visibility])
  872. end;
  873. if Assigned(DocNode) then
  874. begin
  875. If Assigned(DocNode.Descr) then
  876. begin
  877. StartDescription;
  878. WriteDescr(ProcDecl);
  879. end;
  880. if Assigned(DocNode.ErrorsDoc) and (DocNode.ErrorsDoc.HasChildNodes) then
  881. begin
  882. StartErrors;
  883. WriteDescr(ProcDecl, DocNode.ErrorsDoc);
  884. end;
  885. if Assigned(DocNode.Version) then
  886. begin
  887. StartVersion;
  888. WriteDescr(ProcDecl, DocNode.Version);
  889. end;
  890. WriteSeeAlso(DocNode);
  891. EndProcedure;
  892. WriteExample(DocNode);
  893. ConvertNotes(ProcDecl,DocNode.Notes);
  894. end
  895. else
  896. EndProcedure;
  897. end;
  898. end;
  899. procedure TLinearWriter.WriteFunctionsAndProcedures(ASection: TPasSection);
  900. var
  901. i: Integer;
  902. begin
  903. if ASection.Functions.Count > 0 then
  904. begin
  905. StartSection(SDocProceduresAndFunctions,ModuleName+'Functions');
  906. for i := 0 to ASection.Functions.Count - 1 do
  907. WriteProcedure(TPasProcedureBase(ASection.Functions[i]));
  908. end;
  909. end;
  910. procedure TLinearWriter.WriteExample(ADocNode: TDocNode);
  911. var
  912. Example: TDOMElement;
  913. S : string;
  914. begin
  915. S:='';
  916. if Assigned(ADocNode) then
  917. begin
  918. Example := ADocNode.FirstExample;
  919. while Assigned(Example) do
  920. begin
  921. if IsExampleNode(Example) then
  922. begin
  923. if (S<>'') then // not first example, start new paragraph
  924. DescrBeginParagraph;
  925. s:=Engine.GetExampleFileName(Example);
  926. if (S<>'') then
  927. WriteExampleFile(S);
  928. if Assigned(Example.NextSibling) then
  929. DescrEndParaGraph;
  930. end;
  931. Example := TDomElement(Example.NextSibling);
  932. end;
  933. end;
  934. end;
  935. procedure TLinearWriter.WriteProperty(PropDecl : TPasProperty);
  936. var
  937. DocNode: TDocNode;
  938. S: String;
  939. lNode: TDocNode;
  940. begin
  941. With PropDecl do
  942. begin
  943. StartSubSection(Parent.Name+'.'+Name);
  944. WriteLabel(PropDecl);
  945. WriteIndex(Parent.Name+'.'+Name);
  946. StartProperty;
  947. DocNode := Engine.FindDocNode(PropDecl);
  948. if Assigned(DocNode) then
  949. begin
  950. if FDupLinkedDoc and (DocNode.Link <> '') then
  951. begin
  952. lNode := Engine.FindLinkedNode(DocNode);
  953. if not Assigned(lNode) then
  954. lNode := DocNode;
  955. end
  956. else
  957. lNode := DocNode;
  958. if Assigned(lNode.ShortDescr) then
  959. begin
  960. StartSynopsis;
  961. WriteDescr(PropDecl, lNode.ShortDescr);
  962. end;
  963. end;
  964. StartDeclaration;
  965. StartListing(False);
  966. WriteLn('Property '+GetDeclaration(True));
  967. EndListing;
  968. If Assigned(Parent) then
  969. begin
  970. StartVisibility;
  971. Writeln(VisibilityNames[Visibility])
  972. end;
  973. StartAccess;
  974. Setlength(S,0);
  975. If Length(ReadAccessorName) > 0 then
  976. S:='Read';
  977. if Length(WriteAccessorName) > 0 then
  978. begin
  979. If S<>'' then
  980. S:=S+',';
  981. S:=S+'Write';
  982. end;
  983. Writeln(S);
  984. if Assigned(DocNode) then
  985. begin
  986. if Assigned(lNode.Descr) then // lNode will be assigned if DocNode exists
  987. begin
  988. StartDescription;
  989. WriteDescr(PropDecl, lNode);
  990. end;
  991. if Assigned(lNode.ErrorsDoc) and (lNode.ErrorsDoc.HasChildNodes) then
  992. begin
  993. StartErrors;
  994. WriteDescr(PropDecl, DocNode.ErrorsDoc);
  995. end;
  996. if Assigned(lNode.Version) then
  997. begin
  998. StartVersion;
  999. WriteDescr(PropDecl, lNode.Version);
  1000. end;
  1001. WriteSeeAlso(lNode);
  1002. ConvertNotes(PropDecl,lNode.Notes);
  1003. EndProperty;
  1004. WriteExample(lNode);
  1005. end
  1006. else
  1007. EndProperty;
  1008. end;
  1009. end;
  1010. procedure TLinearWriter.WriteSeeAlso(ADocNode: TDocNode);
  1011. var
  1012. Node: TDOMNode;
  1013. s: String;
  1014. First : Boolean;
  1015. begin
  1016. if Not (Assigned(ADocNode) and Assigned(ADocNode.SeeAlso)) then
  1017. Exit;
  1018. Node := ADocNode.SeeAlso.FirstChild;
  1019. First:=True;
  1020. while Assigned(Node) do
  1021. begin
  1022. if IsLinkNode(Node) then
  1023. begin
  1024. If First then
  1025. begin
  1026. StartSeealso;
  1027. First:=False;
  1028. end
  1029. else
  1030. Writeln(',');
  1031. S:=TDomElement(Node)['id'];
  1032. DescrBeginLink(S);
  1033. if Node.FirstChild <> nil then
  1034. s := Node.FirstChild.NodeValue;
  1035. Write(EscapeText(S));
  1036. DescrEndLink();
  1037. end;
  1038. Node:=Node.NextSibling;
  1039. end;
  1040. If Not First then
  1041. EndSeeAlso
  1042. end;
  1043. Function CompareElements(P1,P2 : Pointer) : Integer;
  1044. begin
  1045. Result:=CompareText(TPasElement(P1).Name,TPasElement(P2).Name);
  1046. end;
  1047. procedure TLinearWriter.SortElementList(List : TFPList);
  1048. begin
  1049. List.Sort(@CompareElements);
  1050. end;
  1051. Function TLinearWriter.ShowMember(M : TPasElement) : boolean;
  1052. begin
  1053. Result:=not ((M.Visibility=visPrivate) and Engine.HidePrivate);
  1054. If Result then
  1055. Result:=Not ((M.Visibility=visProtected) and Engine.HideProtected)
  1056. end;
  1057. procedure TLinearWriter.WriteClasses(ASection: TPasSection);
  1058. var
  1059. i: Integer;
  1060. begin
  1061. if (ASection.Classes.Count > 0) then
  1062. for i := 0 to ASection.Classes.Count - 1 do
  1063. WriteClassDecl(TPasClassType(ASection.Classes[i]));
  1064. end;
  1065. procedure TLinearWriter.WriteClassMethodOverview(ClassDecl: TPasClassType);
  1066. var
  1067. Member : TPasElement;
  1068. i : Integer;
  1069. L,N,S : String;
  1070. DocNode : TDocNode;
  1071. List : TStringList;
  1072. begin
  1073. List:=TStringList.Create;
  1074. Try
  1075. List.Sorted:=True;
  1076. for i := 0 to ClassDecl.Members.Count - 1 do
  1077. begin
  1078. Member := TPasElement(ClassDecl.Members[i]);
  1079. With Member do
  1080. if InheritsFrom(TPasProcedureBase) and ShowMember(Member) then
  1081. List.AddObject(Member.Name,Member);
  1082. end;
  1083. If List.Count>0 then
  1084. begin
  1085. StartSubSection(SDocMethodOverview);
  1086. WriteLabel(GetLabel(ClassDecl) + ':Methods');
  1087. StartOverview(False);
  1088. For I:=0 to List.Count-1 do
  1089. begin
  1090. Member:=TPasElement(List.Objects[i]);
  1091. L:=StripText(GetLabel(Member));
  1092. N:=EscapeText(Member.Name);
  1093. DocNode := Engine.FindDocNode(Member);
  1094. If Assigned(DocNode) then
  1095. S:=GetDescrString(Member, DocNode.ShortDescr)
  1096. else
  1097. S:='';
  1098. WriteOverviewMember(L,N,S);
  1099. end;
  1100. EndOverview;
  1101. end;
  1102. Finally
  1103. List.Free;
  1104. end;
  1105. end;
  1106. constructor TLinearWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
  1107. procedure AddLabel(AElement: TPasElement);
  1108. begin
  1109. Engine.AddLink(AElement.PathName, GetLabel(AElement));
  1110. end;
  1111. procedure AddList(AElement: TPasElement; AList: TFPList);
  1112. var
  1113. i: Integer;
  1114. begin
  1115. for i := 0 to AList.Count - 1 do
  1116. AddLabel(TPasElement(AList[i]));
  1117. end;
  1118. procedure AddTopicPages(AElement: TPasElement);
  1119. var
  1120. PreviousTopic,
  1121. TopicElement : TTopicElement;
  1122. DocNode,
  1123. TopicNode : TDocNode;
  1124. begin
  1125. DocNode:=Engine.FindDocNode(AElement);
  1126. If not Assigned(DocNode) then
  1127. exit;
  1128. TopicNode:=DocNode.FirstChild;
  1129. PreviousTopic:=Nil;
  1130. While Assigned(TopicNode) do
  1131. begin
  1132. If TopicNode.TopicNode then
  1133. begin
  1134. TopicElement:=TTopicElement.Create(TopicNode.Name,AElement);
  1135. Topics.Add(TopicElement);
  1136. TopicElement.TopicNode:=TopicNode;
  1137. TopicElement.Previous:=PreviousTopic;
  1138. If Assigned(PreviousTopic) then
  1139. PreviousTopic.Next:=TopicElement;
  1140. PreviousTopic:=TopicElement;
  1141. if AElement is TTopicElement then
  1142. TTopicElement(AElement).SubTopics.Add(TopicElement);
  1143. Engine.AddLink(TopicElement.PathName, GetLabel(TopicElement));
  1144. if AElement is TTopicElement then
  1145. TTopicElement(AElement).SubTopics.Add(TopicElement)
  1146. else // Only one level of recursion.
  1147. AddTopicPages(TopicElement);
  1148. end;
  1149. TopicNode:=TopicNode.NextSibling;
  1150. end;
  1151. end;
  1152. procedure ScanModule(AModule: TPasModule);
  1153. var
  1154. i, j, k: Integer;
  1155. ClassEl: TPasClassType;
  1156. FPEl, AncestorMemberEl: TPasElement;
  1157. DocNode: TDocNode;
  1158. DidAutolink: Boolean;
  1159. begin
  1160. AddLabel(AModule);
  1161. AddTopicPages(AModule);
  1162. with AModule do
  1163. begin
  1164. AddList(AModule, InterfaceSection.ResStrings);
  1165. AddList(AModule, InterfaceSection.Consts);
  1166. AddList(AModule, InterfaceSection.Types);
  1167. if InterfaceSection.Classes.Count > 0 then
  1168. begin
  1169. for i := 0 to InterfaceSection.Classes.Count - 1 do
  1170. begin
  1171. ClassEl := TPasClassType(InterfaceSection.Classes[i]);
  1172. AddLabel(ClassEl);
  1173. for j := 0 to ClassEl.Members.Count - 1 do
  1174. begin
  1175. FPEl := TPasElement(ClassEl.Members[j]);
  1176. if ((FPEl.Visibility = visPrivate) and Engine.HidePrivate) or
  1177. ((FPEl.Visibility = visProtected) and Engine.HideProtected) then
  1178. continue;
  1179. DocNode := Engine.FindDocNode(FPEl);
  1180. if not Assigned(DocNode) then
  1181. begin
  1182. DidAutolink := False;
  1183. if Assigned(ClassEl.AncestorType) and
  1184. (ClassEl.AncestorType.ClassType = TPasClassType) then
  1185. begin
  1186. for k := 0 to TPasClassType(ClassEl.AncestorType).Members.Count - 1 do
  1187. begin
  1188. AncestorMemberEl :=
  1189. TPasElement(TPasClassType(ClassEl.AncestorType).Members[k]);
  1190. if AncestorMemberEl.Name = FPEl.Name then
  1191. begin
  1192. DocNode := Engine.FindDocNode(AncestorMemberEl);
  1193. if Assigned(DocNode) then
  1194. begin
  1195. DidAutolink := True;
  1196. Engine.AddLink(FPEl.PathName,
  1197. Engine.FindAbsoluteLink(AncestorMemberEl.PathName));
  1198. break;
  1199. end;
  1200. end;
  1201. end;
  1202. end;
  1203. if not DidAutolink then
  1204. AddLabel(FPEl);
  1205. end else
  1206. AddLabel(FPEl);
  1207. end;
  1208. end;
  1209. end;
  1210. AddList(AModule, InterfaceSection.Functions);
  1211. AddList(AModule, InterfaceSection.Variables);
  1212. end;
  1213. end;
  1214. var
  1215. i: Integer;
  1216. begin
  1217. inherited ;
  1218. FDupLinkedDoc := False; // by default we don't duplicate linked element documentation
  1219. { Allocate labels for all elements for which we are going to create
  1220. documentation. This is needed for links to work correctly. }
  1221. // Allocate label for the package itself, if a name is given (i.e. <> '#')
  1222. if Length(Package.Name) > 1 then
  1223. begin
  1224. AddLabel(Package);
  1225. AddTopicPages(Package);
  1226. end;
  1227. for i := 0 to Package.Modules.Count - 1 do
  1228. ScanModule(TPasModule(Package.Modules[i]));
  1229. end;
  1230. procedure TLinearWriter.WriteBeginDocument;
  1231. begin
  1232. WriteComment('This file has been created automatically by FPDoc.');
  1233. WriteComment('Linear output (c) 2005 Michael Van Canneyt');
  1234. end;
  1235. procedure TLinearWriter.WriteEndDocument;
  1236. begin
  1237. // do nothing
  1238. end;
  1239. function TLinearWriter.InterpretOption(const Cmd: String; const Arg: String): Boolean;
  1240. begin
  1241. Result := True;
  1242. if Cmd = cDupLinkedDocParam then
  1243. begin
  1244. FDupLinkedDoc := True;
  1245. end
  1246. else
  1247. Result := False;
  1248. end;
  1249. class procedure TLinearWriter.Usage(List: TStrings);
  1250. begin
  1251. List.Add(cDupLinkedDocParam);
  1252. List.Add(SLinearUsageDupLinkedDocsP1);
  1253. List.Add('');
  1254. List.Add(SLinearUsageDupLinkedDocsP2);
  1255. end;
  1256. end.