2
0

dwlinear.pp 40 KB

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