dwlinear.pp 40 KB

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