dwlinear.pp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. {$mode objfpc}
  2. {$H+}
  3. unit dwlinear;
  4. interface
  5. uses
  6. Classes, SysUtils, DGlobals, dWriter, pastree, dom;
  7. Type
  8. { TLinearWriter }
  9. TLinearWriter = Class(TFPDocWriter)
  10. FStream : TStream;
  11. PackageName: String;
  12. Module: TPasModule;
  13. FLastURL : DomString;
  14. private
  15. FDupLinkedDoc: Boolean;
  16. Protected
  17. ModuleName: String;
  18. // Writing support.
  19. procedure Write(const s: String); virtual;
  20. procedure WriteLn(const s: String); virtual;
  21. procedure WriteF(const s: String; const Args: array of const); virtual;
  22. procedure WriteLnF(const s: String; const Args: array of const); virtual;
  23. Function PushWriteContext(S : TStream) : TStream;
  24. Procedure PopWriteContext(S : TSTream);
  25. procedure WriteLabel(El: TPasElement);
  26. procedure WriteIndex(El: TPasElement);
  27. procedure WriteTypeDecl(El: TPasElement); virtual;
  28. procedure WriteVariableDecl(El: TPasElement); virtual;
  29. procedure WriteConstDecl(El: TPasElement); virtual;
  30. // Auxiliary routines
  31. procedure DescrBeginURL(const AURL: DOMString); override; // Provides a default implementation
  32. procedure DescrEndURL; override;
  33. procedure SortElementList(List : TFPList);
  34. procedure StartListing(Frames: Boolean);
  35. Function ShowMember(M : TPasElement) : boolean;
  36. procedure StartChapter(ChapterName : String; ChapterLabel : String); virtual;
  37. procedure StartSection(SectionName : String; SectionLabel : String); virtual;
  38. procedure StartSubSection(SubSectionName : String; SubSectionLabel : String); virtual;
  39. procedure StartSubSubSection(SubSubSectionName : String; SubSubSectionLabel : String); virtual;
  40. Function GetDescrString(AContext: TPasElement; DescrNode: TDOMElement) : String;
  41. function ConstValue(ConstDecl: TPasConst): String; virtual;
  42. procedure ProcessSection(ASection: TPasSection); virtual;
  43. // Procedures which MAY be overridden in descendents
  44. procedure WriteBeginDocument; virtual;
  45. procedure WriteEndDocument; virtual;
  46. Function EscapeText(S : String) : String; virtual;
  47. Function StripText(S : String) : String; virtual;
  48. Procedure StartProcedure; Virtual;
  49. Procedure EndProcedure; Virtual;
  50. Procedure StartProperty; Virtual;
  51. Procedure EndProperty; Virtual;
  52. Procedure StartSynopsis; Virtual;
  53. Procedure StartDeclaration; Virtual;
  54. Procedure StartVisibility; Virtual;
  55. Procedure StartDescription; Virtual;
  56. Procedure StartAccess; Virtual;
  57. Procedure StartErrors; Virtual;
  58. Procedure StartVersion; Virtual;
  59. Procedure StartSeealso; Virtual;
  60. Procedure EndSeealso; Virtual;
  61. // Procedures which MUST be overridden in descendents;
  62. procedure WriteCommentLine; virtual; abstract;
  63. procedure WriteComment(Comment : String); virtual; abstract;
  64. function GetLabel(AElement: TPasElement): String; virtual; abstract;
  65. procedure WriteLabel(Const S : String); virtual; abstract;
  66. procedure WriteIndex(Const S : String); virtual; abstract;
  67. procedure WriteType(const s: string); virtual;
  68. procedure WriteVariable(const s: string); virtual;
  69. procedure WriteConstant(const s: string); virtual;
  70. procedure StartChapter(ChapterName : String); virtual; abstract;
  71. procedure StartSection(SectionName : String); virtual; abstract;
  72. procedure StartSubSection(SubSectionName : String); virtual; abstract;
  73. procedure StartSubSubSection(SubSubSectionName : String); virtual; abstract;
  74. procedure StartListing(Frames: Boolean; const name: String); virtual; abstract;
  75. procedure EndListing; virtual; abstract;
  76. Procedure WriteExampleFile(FN : String); virtual; abstract;
  77. procedure StartOverview(Const What : String; WithAccess : Boolean); virtual; Abstract;
  78. procedure EndOverview; virtual; Abstract;
  79. procedure WriteOverviewMember(const ALabel,AName,Access,ADescr : String); virtual; Abstract;
  80. procedure WriteOverviewMember(const ALabel,AName,ADescr : String); virtual; Abstract;
  81. procedure StartUnitOverview(AModuleName,AModuleLabel : String);virtual; Abstract;
  82. procedure WriteUnitEntry(UnitRef : TPasType);virtual; Abstract;
  83. procedure EndUnitOverview; virtual; Abstract;
  84. Property LastURL : DomString Read FLastURL Write FLastURL;
  85. // Overriden from fpdocwriter;
  86. procedure DescrWriteText(const AText: DOMString); override;
  87. Public
  88. Constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
  89. function InterpretOption(const Cmd, Arg: String): Boolean; override;
  90. class procedure Usage(List: TStrings); override;
  91. procedure WriteDoc; override;
  92. // Linear Documentation writing methods.
  93. Procedure ProcessPackage;
  94. Procedure ProcessTopics(DocNode : TDocNode; Alevel : Integer);
  95. procedure WriteResourceStrings(ASection: TPasSection);
  96. procedure WriteUnitOverview(ASection: TPasSection);
  97. procedure WriteVarsConstsTypes(ASection: TPasSection);
  98. procedure WriteConsts(ASection: TPasSection);
  99. procedure WriteTypes(ASection: TPasSection); virtual;
  100. procedure WriteEnumElements(TypeDecl : TPasEnumType);
  101. procedure WriteVars(ASection: TPasSection);
  102. procedure WriteFunctionsAndProcedures(ASection: TPasSection);
  103. procedure WriteProcedure(ProcDecl: TPasProcedureBase);
  104. procedure WriteClasses(ASection: TPasSection);
  105. Procedure WriteExtendedRecords(Asection : TPasSection);
  106. procedure WriteClassDecl(ClassDecl: TPasClassType);
  107. procedure WriteMethodOverview(AParent: TPasType; Members : TFPList);
  108. procedure WritePropertyOverview(AParent: TPasType; Members : TFPList);
  109. procedure WriteClassInterfacesOverview(ClassDecl: TPasClassType);
  110. procedure WriteClassInheritanceOverview(ClassDecl: TPasClassType); virtual;
  111. procedure WriteProperty(PropDecl: TPasProperty);
  112. procedure WriteExample(ADocNode: TDocNode);
  113. procedure WriteSeeAlso(ADocNode: TDocNode);
  114. Procedure WriteTopicNode(Node : TDocNode; Level : Integer);
  115. end;
  116. implementation
  117. const
  118. cDupLinkedDocParam = '--duplinkeddoc';
  119. { TLinearWriter }
  120. { ---------------------------------------------------------------------
  121. Writing support
  122. ---------------------------------------------------------------------}
  123. function TLinearWriter.PushWriteContext(S: TStream): TStream;
  124. begin
  125. Result:=FStream;
  126. FStream:=S;
  127. end;
  128. procedure TLinearWriter.PopWriteContext(S: TSTream);
  129. begin
  130. FStream:=S;
  131. end;
  132. procedure TLinearWriter.Write(const s: String);
  133. Var
  134. L : Integer;
  135. begin
  136. L:=Length(S);
  137. If (L>0) then
  138. FStream.Write(PChar(S)^,L);
  139. end;
  140. procedure TLinearWriter.WriteF(const s: String; const Args: array of const);
  141. begin
  142. Write(Format(S,Args));
  143. end;
  144. procedure TLinearWriter.WriteLn(const s: String);
  145. begin
  146. Write(S);
  147. Write(LineEnding);
  148. end;
  149. procedure TLinearWriter.WriteLnF(const s: String; const Args: array of const);
  150. begin
  151. Write(Format(S,Args));
  152. Write(LineEnding);
  153. end;
  154. procedure TLinearWriter.DescrWriteText(const AText: DOMString);
  155. begin
  156. Write(EscapeText(AText));
  157. end;
  158. function TLinearWriter.GetDescrString(AContext: TPasElement;
  159. DescrNode: TDOMElement): String;
  160. Var
  161. S : TStringStream;
  162. F : TStream;
  163. begin
  164. Result:='';
  165. if Assigned(DescrNode) then
  166. begin
  167. S:=TStringStream.Create('');
  168. Try
  169. F:=PushWriteContext(S);
  170. Try
  171. ConvertDescr(AContext, DescrNode, False);
  172. Result:=S.DataString;
  173. FInally
  174. PopWriteContext(F);
  175. end;
  176. finally
  177. S.FRee;
  178. end;
  179. end;
  180. end;
  181. { ---------------------------------------------------------------------
  182. Auxiliary routines
  183. ---------------------------------------------------------------------}
  184. procedure TLinearWriter.WriteLabel(El: TPasElement);
  185. begin
  186. WriteLabel(GetLabel(El));
  187. end;
  188. procedure TLinearWriter.WriteIndex(El: TPasElement);
  189. begin
  190. WriteIndex(EL.Name);
  191. end;
  192. procedure TLinearWriter.WriteTypeDecl(El: TPasElement);
  193. begin
  194. WriteType(El.Name);
  195. end;
  196. procedure TLinearWriter.WriteVariableDecl(El: TPasElement);
  197. begin
  198. WriteVariable(El.Name);
  199. end;
  200. procedure TLinearWriter.WriteConstDecl(El: TPasElement);
  201. begin
  202. WriteConstant(El.Name);
  203. end;
  204. procedure TLinearWriter.DescrBeginURL(const AURL: DOMString);
  205. begin
  206. FLastURL:=AURL;
  207. end;
  208. procedure TLinearWriter.DescrEndURL;
  209. begin
  210. If (FLastURL<>'') then
  211. Writeln(Format(SSeeURL,[EscapeText(FLastURL)]));
  212. FLastURL:='';
  213. end;
  214. procedure TLinearWriter.StartListing(Frames: Boolean);
  215. begin
  216. StartListing(Frames,'');
  217. end;
  218. procedure TLinearWriter.StartChapter(ChapterName: String; ChapterLabel: String);
  219. begin
  220. StartChapter(ChapterName);
  221. WriteLabel(ChapterLabel);
  222. end;
  223. procedure TLinearWriter.StartSection(SectionName: String; SectionLabel: String);
  224. begin
  225. StartSection(SectionName);
  226. WriteLabel(SectionLabel);
  227. end;
  228. procedure TLinearWriter.StartSubSection(SubSectionName: String; SubSectionLabel: String);
  229. begin
  230. StartSubSection(SubSectionName);
  231. WriteLabel(SubSectionLabel);
  232. end;
  233. procedure TLinearWriter.StartSubSubSection(SubSubSectionName: String;
  234. SubSubSectionLabel: String);
  235. begin
  236. StartSubSubSection(SubSubSectionName);
  237. WriteLabel(SubSubSectionLabel);
  238. end;
  239. { ---------------------------------------------------------------------
  240. Default implementations, may be overridden in descendents
  241. ---------------------------------------------------------------------}
  242. function TLinearWriter.EscapeText(S: String): String;
  243. begin
  244. Result:=S;
  245. end;
  246. function TLinearWriter.StripText(S: String): String;
  247. begin
  248. Result:=S;
  249. end;
  250. procedure TLinearWriter.StartProcedure;
  251. begin
  252. Writeln(SDocProcedure+':');
  253. end;
  254. procedure TLinearWriter.StartSynopsis;
  255. begin
  256. Writeln('');
  257. Writeln(SDocSynopsis+':');
  258. end;
  259. procedure TLinearWriter.StartDeclaration;
  260. begin
  261. Writeln('');
  262. Writeln(SDocDeclaration+':');
  263. end;
  264. procedure TLinearWriter.StartVisibility;
  265. begin
  266. Writeln('');
  267. Writeln(SDocVisibility+':');
  268. end;
  269. procedure TLinearWriter.StartDescription;
  270. begin
  271. Writeln('');
  272. Writeln(SDocDescription+':');
  273. end;
  274. procedure TLinearWriter.StartAccess;
  275. begin
  276. Writeln('');
  277. Writeln(SDocAccess+':');
  278. end;
  279. procedure TLinearWriter.StartErrors;
  280. begin
  281. Writeln('');
  282. Writeln(SDocErrors+':');
  283. end;
  284. procedure TLinearWriter.StartVersion;
  285. begin
  286. Writeln('');
  287. Writeln(SDocVersion+':');
  288. end;
  289. procedure TLinearWriter.StartSeealso;
  290. begin
  291. Writeln('');
  292. Writeln(SDocSeeAlso+':');
  293. end;
  294. procedure TLinearWriter.StartProperty;
  295. begin
  296. Writeln('');
  297. Writeln(SDocProperty+':');
  298. end;
  299. procedure TLinearWriter.EndProcedure;
  300. begin
  301. Writeln('');
  302. end;
  303. procedure TLinearWriter.EndProperty;
  304. begin
  305. Writeln('');
  306. end;
  307. procedure TLinearWriter.EndSeealso;
  308. begin
  309. Writeln('');
  310. end;
  311. procedure TLinearWriter.WriteType(const s: string);
  312. begin
  313. // do nothing
  314. end;
  315. procedure TLinearWriter.WriteVariable(const s: string);
  316. begin
  317. // do nothing
  318. end;
  319. procedure TLinearWriter.WriteConstant(const s: string);
  320. begin
  321. // do nothing
  322. end;
  323. procedure TLinearWriter.WriteClassDecl(ClassDecl: TPasClassType);
  324. var
  325. DocNode: TDocNode;
  326. Member: TPasElement;
  327. i: Integer;
  328. begin
  329. DocNode := Engine.FindDocNode(ClassDecl);
  330. if Assigned(DocNode) and DocNode.IsSkipped then
  331. Exit;
  332. StartSection(ClassDecl.Name);
  333. WriteLabel(ClassDecl);
  334. WriteIndex(ClassDecl);
  335. if Assigned(DocNode) and ((not IsDescrNodeEmpty(DocNode.Descr)) or
  336. (not IsDescrNodeEmpty(DocNode.ShortDescr))) then
  337. begin
  338. StartSubSection(SDocDescription);
  339. WriteDescr(ClassDecl,DocNode);
  340. If Assigned(DocNode.Version) then
  341. begin
  342. StartSubSection(SDocVersion);
  343. WriteDescr(ClassDecl,DocNode.Version);
  344. end;
  345. if Assigned(DocNode.SeeAlso) then
  346. begin
  347. WriteSeeAlso(DocNode);
  348. end;
  349. ConvertNotes(ClassDecl,DocNode.Notes);
  350. end;
  351. // graemeg: this must move above SeeAlso, Version and Notes written above.
  352. // Write Class Hierarchy (Inheritance) Overview;
  353. WriteClassInheritanceOverView(ClassDecl);
  354. // Write Interfaces Overview;
  355. WriteClassInterfacesOverView(ClassDecl);
  356. // Write method overview
  357. WriteMethodOverView(ClassDecl,ClassDecl.Members);
  358. // Write Property Overview;
  359. WritePropertyOverView(ClassDecl,ClassDecl.Members);
  360. // Write method & property descriptions
  361. // Determine visibilities
  362. for i := 0 to ClassDecl.Members.Count - 1 do
  363. begin
  364. Member := TPasElement(ClassDecl.Members[i]);
  365. if Member.InheritsFrom(TPasProcedureBase) and Engine.ShowElement(Member) then
  366. WriteProcedure(TPasProcedureBase(Member));
  367. end;
  368. // properties.
  369. for i := 0 to ClassDecl.Members.Count - 1 do
  370. begin
  371. Member := TPasElement(ClassDecl.Members[i]);
  372. if Member.InheritsFrom(TPasProperty) and Engine.ShowElement(Member) then
  373. WriteProperty(TPasProperty(Member));
  374. end;
  375. end;
  376. procedure TLinearWriter.WritePropertyOverview(AParent: TPasType; Members : TFPList);
  377. var
  378. Member: TPasElement;
  379. i: Integer;
  380. L,N,S,A: String;
  381. DocNode: TDocNode;
  382. List : TStringList;
  383. lNode: TDocNode;
  384. begin
  385. // Write property overview
  386. List:=TStringList.Create;
  387. Try
  388. List.Sorted:=True;
  389. for i := 0 to Members.Count - 1 do
  390. begin
  391. Member := TPasElement(Members[i]);
  392. With Member do
  393. if InheritsFrom(TPasProperty) and SHowMember(Member) then
  394. List.AddObject(Member.Name,Member)
  395. end;
  396. If (List.Count>0) then
  397. begin
  398. StartSubSection(SDocPropertyOverview);
  399. WriteLabel(GetLabel(AParent) + ':Properties');
  400. StartOverView(SDocProperties,True);
  401. For I:=0 to List.Count-1 do
  402. begin
  403. Member:=TPasElement(List.objects[i]);
  404. L:=StripText(GetLabel(Member));
  405. N:=EscapeText(Member.Name);
  406. DocNode := Engine.FindDocNode(Member);
  407. if Assigned(DocNode) and DocNode.IsSkipped then
  408. Continue;
  409. if Assigned(DocNode) then
  410. begin
  411. if FDupLinkedDoc and (DocNode.Link <> '') then
  412. begin
  413. lNode := Engine.FindLinkedNode(DocNode);
  414. if not Assigned(lNode) then
  415. lNode := DocNode;
  416. end
  417. else
  418. lNode := DocNode;
  419. S := GetDescrString(Member, lNode.ShortDescr);
  420. end
  421. else
  422. S := '';
  423. A:='';
  424. if Length(TPasProperty(Member).ReadAccessorName) > 0 then
  425. a := a + 'r';
  426. if Length(TPasProperty(Member).WriteAccessorName) > 0 then
  427. a := a + 'w';
  428. if Length(TPasProperty(Member).StoredAccessorName) > 0 then
  429. a := a + 's';
  430. WriteOverviewMember(L,N,A,S);
  431. S := '';
  432. end;
  433. EndOverview;
  434. end;
  435. Finally
  436. List.Free;
  437. end;
  438. end;
  439. procedure TLinearWriter.WriteClassInterfacesOverview(ClassDecl: TPasClassType);
  440. var
  441. lInterface: TPasElement;
  442. i: Integer;
  443. L,N,S,A: String;
  444. DocNode: TDocNode;
  445. List : TStringList;
  446. lNode: TDocNode;
  447. begin
  448. // Write Interfaces overview
  449. List:=TStringList.Create;
  450. try
  451. List.Sorted:=True;
  452. for i := 0 to ClassDecl.Interfaces.Count-1 do
  453. begin
  454. lInterface := TPasElement(ClassDecl.Interfaces[i]);
  455. List.AddObject(lInterface.Name,lInterface);
  456. end;
  457. if (List.Count>0) then
  458. begin
  459. StartSubSection(SDocInterfacesOverview);
  460. WriteLabel(GetLabel(ClassDecl) + ':Interfaces');
  461. StartOverView(SDocInterface,False);
  462. for i := 0 to List.Count-1 do
  463. begin
  464. lInterface := TPasElement(List.Objects[i]);
  465. L := StripText(GetLabel(lInterface));
  466. N := EscapeText(lInterface.Name);
  467. DocNode := Engine.FindDocNode(lInterface);
  468. if Assigned(DocNode) and DocNode.IsSkipped then
  469. Continue;
  470. if Assigned(DocNode) then
  471. begin
  472. if FDupLinkedDoc and (DocNode.Link <> '') then
  473. begin
  474. lNode := Engine.FindLinkedNode(DocNode);
  475. if not Assigned(lNode) then
  476. lNode := DocNode;
  477. end
  478. else
  479. lNode := DocNode;
  480. S := GetDescrString(lInterface, lNode.ShortDescr);
  481. end
  482. else
  483. S := '';
  484. WriteOverviewMember(L,N,S);
  485. S := '';
  486. end;
  487. EndOverview;
  488. end;
  489. finally
  490. List.Free;
  491. end;
  492. end;
  493. procedure TLinearWriter.WriteClassInheritanceOverview(ClassDecl: TPasClassType);
  494. begin
  495. { Do nothing by default. This will be implemented by descendant writers. See
  496. the IPF Writer for an example. }
  497. end;
  498. function TLinearWriter.ConstValue(ConstDecl: TPasConst): String;
  499. begin
  500. if Assigned(ConstDecl) then
  501. Result := ConstDecl.ClassName
  502. else
  503. Result := '<nil>';
  504. end;
  505. procedure TLinearWriter.WriteDoc;
  506. var
  507. i : Integer;
  508. L : TstringList;
  509. begin
  510. PackageName := LowerCase(Copy(Package.Name, 2, 255));
  511. If (Engine.OutPut='') then
  512. Engine.Output:=PackageName+FileNameExtension
  513. else if (ExtractFileExt(Engine.output)='') and (FileNameExtension<>'') then
  514. Engine.Output:=ChangeFileExt(Engine.output,FileNameExtension);
  515. FStream:=TFileStream.Create(Engine.Output,fmCreate);
  516. try
  517. WriteBeginDocument;
  518. ProcessPackage;
  519. L:=TStringList.Create;
  520. Try
  521. L.Sorted:=True;
  522. // Sort modules.
  523. For I:=0 to Package.Modules.Count-1 do
  524. L.AddObject(TPasModule(Package.Modules[i]).Name,TPasModule(Package.Modules[i]));
  525. // Now create table.
  526. for i:=0 to L.Count - 1 do
  527. begin
  528. Module := TPasModule(L.Objects[i]);
  529. ModuleName := LowerCase(Module.Name);
  530. WriteCommentLine;
  531. StartChapter(Format(SDocUnitTitle, [Module.Name]));
  532. WriteLabel(Module);
  533. // extra Topics now get processed in ProcessSection()
  534. ProcessSection(Module.InterfaceSection);
  535. end;
  536. Finally
  537. L.Free;
  538. end;
  539. WriteEndDocument;
  540. finally
  541. FSTream.Free;
  542. end;
  543. end;
  544. procedure TLinearWriter.ProcessSection(ASection: TPasSection);
  545. var
  546. DocNode: TDocNode;
  547. begin
  548. With ASection do
  549. begin
  550. SortElementList(UsesList);
  551. SortElementList(Declarations);
  552. SortElementList(ResStrings);
  553. SortElementList(Types);
  554. SortElementList(Consts);
  555. SortElementList(Classes);
  556. SortElementList(Functions);
  557. SortElementList(Variables);
  558. end;
  559. WriteUnitOverView(ASection);
  560. // Now process unit (extra) Topics
  561. DocNode:=Engine.FindDocNode(Module);
  562. If Assigned(DocNode) then
  563. ProcessTopics(DocNode,1);
  564. WriteVarsConstsTypes(ASection);
  565. WriteFunctionsAndProcedures(ASection);
  566. WriteExtendedRecords(ASection);
  567. WriteClasses(ASection);
  568. end;
  569. procedure TLinearWriter.WriteVarsConstsTypes(ASection: TPasSection);
  570. begin
  571. With Asection do
  572. if (Consts.Count>0) or (Types.Count>0) or
  573. (Variables.Count>0) or (ResStrings.Count>0) then
  574. begin
  575. StartSection(SDocConstsTypesVars, ModuleName+'ConstsTypesVars');
  576. WriteResourceStrings(ASection);
  577. WriteConsts(ASection);
  578. WriteTypes(ASection);
  579. WriteVars(ASection);
  580. end;
  581. end;
  582. procedure TLinearWriter.WriteResourceStrings(ASection: TPasSection);
  583. var
  584. ResStrDecl: TPasResString;
  585. i: Integer;
  586. DocNode : TDocNode;
  587. begin
  588. if ASection.ResStrings.Count > 0 then
  589. begin
  590. StartSubSection(SDocResStrings,ModuleName+'ResStrings');
  591. for i := 0 to ASection.ResStrings.Count - 1 do
  592. begin
  593. ResStrDecl := TPasResString(ASection.ResStrings[i]);
  594. StartListing(false, '');
  595. DescrWriteText(ResStrDecl.GetDeclaration(True)); // instead of WriteLn() so we can do further processing like manual line wrapping in descendants
  596. EndListing;
  597. WriteLabel(ResStrDecl);
  598. WriteIndex(ResStrDecl);
  599. DocNode:=WriteDescr(ResStrDecl);
  600. If Assigned(DocNode) and Assigned(DocNode.Version) then
  601. begin
  602. Writeln(Format('%s : ',[SDocVersion]));
  603. WriteDescr(ResStrDecl, DocNode.Version);
  604. end;
  605. end;
  606. end;
  607. end;
  608. procedure TLinearWriter.WriteUnitOverview(ASection: TPasSection);
  609. var
  610. i: Integer;
  611. UnitRef: TPasType;
  612. DocNode: TDocNode;
  613. begin
  614. if ASection.UsesList.Count > 0 then
  615. begin
  616. StartSection(SDocUsedUnits);
  617. StartUnitOverview(Module.Name,ModuleName);
  618. for i := 0 to ASection.UsesList.Count - 1 do
  619. begin
  620. UnitRef := TPasType(ASection.UsesList[i]);
  621. WriteUnitEntry(UnitRef);
  622. end;
  623. EndUnitOverview;
  624. end;
  625. DocNode := Engine.FindDocNode(ASection.Parent);
  626. if Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr) then
  627. begin
  628. StartSection(SDocOverview);
  629. WriteDescr(ASection.Parent, DocNode.Descr);
  630. ConvertNotes(ASection.Parent,DocNode.Notes);
  631. end;
  632. end;
  633. procedure TLinearWriter.ProcessPackage;
  634. var
  635. DocNode: TDocNode;
  636. begin
  637. DocNode:=Engine.FindDocNode(Package);
  638. if not Assigned(DocNode) then
  639. exit;
  640. if Assigned(DocNode) and not IsDescrNodeEmpty(DocNode.Descr) then
  641. begin
  642. StartSection(SDocOverview);
  643. WriteDescr(Package, DocNode.Descr);
  644. end;
  645. WriteSeeAlso(DocNode);
  646. ConvertNotes(Nil,DocNode.Notes);
  647. ProcessTopics(DocNode,1);
  648. end;
  649. procedure TLinearWriter.ProcessTopics(DocNode: TDocNode; Alevel: Integer);
  650. Var
  651. Node : TDocNode;
  652. begin
  653. If Not Assigned(DocNode) then
  654. Exit;
  655. Node:=DocNode.FirstChild;
  656. While Assigned(Node) do
  657. begin
  658. If Node.TopicNode then
  659. WriteTopicNode(Node,ALevel);
  660. Node:=Node.NextSibling;
  661. end;
  662. end;
  663. procedure TLinearWriter.WriteTopicNode(Node: TDocNode; Level: Integer);
  664. Var
  665. Element : TTopicElement;
  666. SubNode : TDocNode;
  667. S : String;
  668. begin
  669. Element:=FindTopicElement(Node);
  670. If Not Assigned(Element) then
  671. Exit;
  672. S:=GetDescrString(Element,Node.ShortDescr);
  673. Case Level of
  674. 1 : StartSection(S);
  675. 2 : StartSubSection(S);
  676. 3 : StartSubSubSection(S);
  677. end;
  678. WriteLabel(Element);
  679. If Assigned(Node.Descr) then
  680. WriteDescr(Element,Node.Descr);
  681. WriteSeeAlso(Node);
  682. ConvertNotes(Element,Node.Notes);
  683. If Level<3 then
  684. begin
  685. SubNode:=Node.FirstChild;
  686. While Assigned(SubNode) do
  687. begin
  688. If SubNode.TopicNode then
  689. WriteTopicNode(SubNode,Level+1);
  690. SubNode:=SubNode.NextSibling;
  691. end;
  692. end;
  693. WriteExample(Node);
  694. end;
  695. procedure TLinearWriter.WriteConsts(ASection: TPasSection);
  696. var
  697. i: Integer;
  698. ConstDecl: TPasConst;
  699. begin
  700. if ASection.Consts.Count > 0 then
  701. begin
  702. StartSubSection(SDocConstants,EscapeText(ModuleName));
  703. for i := 0 to ASection.Consts.Count - 1 do
  704. begin
  705. DescrBeginParaGraph;
  706. ConstDecl := TPasConst(ASection.Consts[i]);
  707. WriteConstDecl(ConstDecl);
  708. StartListing(False,'');
  709. WriteLn(EscapeText(ConstDecl.GetDeclaration(True)));
  710. EndListing;
  711. WriteLabel(ConstDecl);
  712. WriteIndex(ConstDecl);
  713. WriteDescr(ConstDecl);
  714. DescrEndParaGraph;
  715. end;
  716. end;
  717. end;
  718. procedure TLinearWriter.WriteEnumElements(TypeDecl : TPasEnumType);
  719. Var
  720. EV : TPasEnumValue;
  721. I : Integer;
  722. DocNode : TDocNode;
  723. begin
  724. With TypeDecl do
  725. begin
  726. SortElementList(Values);
  727. DescrBeginTable(2,True);
  728. DescrBeginTableCaption;
  729. Writeln(EscapeText(Format(SDocValuesForEnum,[TypeDecl.Name])));
  730. DescrEndTableCaption;
  731. DescrBeginTableHeadRow;
  732. DescrBeginTableCell;
  733. Writeln(EscapeText(SDocValue));
  734. DescrEndTableCell;
  735. DescrBeginTableCell;
  736. Writeln(EscapeText(SDocExplanation));
  737. DescrEndTableCell;
  738. DescrEndTableHeadRow;
  739. For I:=0 to Values.Count-1 do
  740. begin
  741. EV:=TPasEnumValue(Values[i]);
  742. DescrBeginTableRow;
  743. DescrBeginTableCell;
  744. Writeln(EscapeText(EV.Name));
  745. DescrEndTableCell;
  746. DescrBeginTableCell;
  747. DocNode := Engine.FindDocNode(EV);
  748. if Assigned(DocNode) and (not IsDescrNodeEmpty(DocNode.ShortDescr)) then
  749. WriteDescr(EV,DocNode.ShortDescr);
  750. DescrEndTableCell;
  751. DescrEndTableRow;
  752. end;
  753. DescrEndTable;
  754. end;
  755. end;
  756. procedure TLinearWriter.WriteTypes(ASection: TPasSection);
  757. var
  758. i,j: Integer;
  759. TypeDecl: TPasType;
  760. Recdecl: TPasRecordType;
  761. Member : TPasElement;
  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. Setlength(S,0);
  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: String;
  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.InterpretOption(const Cmd, Arg: String): Boolean;
  1331. begin
  1332. Result := True;
  1333. if Cmd = cDupLinkedDocParam then
  1334. begin
  1335. FDupLinkedDoc := True;
  1336. end
  1337. else
  1338. Result := False;
  1339. end;
  1340. class procedure TLinearWriter.Usage(List: TStrings);
  1341. begin
  1342. List.Add(cDupLinkedDocParam);
  1343. List.Add(SLinearUsageDupLinkedDocsP1);
  1344. List.Add('');
  1345. List.Add(SLinearUsageDupLinkedDocsP2);
  1346. end;
  1347. end.