dwlinear.pp 40 KB

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