-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefdriver.pas
2827 lines (2502 loc) · 84.7 KB
/
defdriver.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* This file is a part of the srcdoc program for creating
documentation of Delphi/Pascal programs from comments in source
files.
Copyright (C) 2005 by Lukasz Czajka
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA *)
unit defdriver;
interface
uses
CommonClasses, SysUtils, Classes, adtfunct, adtcont, adtarray, adtmap;
type
TDeclaration = class;
TBlockDeclaration = class;
TRootDeclaration = class;
TDefaultDriver = class (TDriver)
private
Profile : String;
FileQueue : TStringDequeAdt;
currentFile : String;
recentLine : Cardinal;
{ the title of the main contents file }
ContentsTitle : String;
{ maps the names of the duplicated symbols in the current block
to the first unused function number that may be appended to
the symbol name to make it unique; the items stored are
strings which may be interpreted as integers }
duplicatedSymbols : TStringStringMap;
duplicatedSymbolsStack : TStackAdt;
{ a string comparer appropriate for the current language (either
case-sensitive or case-insensitive) }
StringComparer : IStringBinaryComparer;
{ the _copy_ of the recent comment; owned by the driver }
recentComment : TComment;
{ the number of declarations left to which recentComment should
be applied if no other comment found }
includeDecl : Cardinal;
{ the number of declarations to ignore }
ignoreDecl : Cardinal;
{ the root of the whole tree of declarations; does not represent
any declaration itself }
rootDeclaration : TRootDeclaration;
{ the current block declaration inside which declarations are
currently being declared, i.e. the current block }
currDecl : TBlockDeclaration;
{ a stack of saved currDecls (TBlockDeclarations); they are
saved each time a new block is entered, and restored when the
block is finished }
declStack : TStackAdt;
{ a map from unit names to TUnitDeclarations; <Units> does not
own the declarations; they are owned by <rootDeclaration>;
automatically sorted (a sorted set) }
Units : TMap;
{ a list of TParsedFiles for files parsed that are not modules
(units); <OtherFiles> _owns_ its items }
OtherFiles : TListAdt;
{ a list of all classes; does not own its items }
AllClasses : TArrayAdt;
{ a list of all interfaces; does not own its items }
AllInterfaces : TArrayAdt;
{ a hash table of all declarations; maps declaration names to
the declaration objects; may store duplicated items; used to
speed up searching for declarations by their names }
AllDeclarations : TMap;
{ a map of interface names to the declarations of classes
implementing them; does not own its items; items may be
repeated }
InterfacesImplementedBy : TMap;
{ a map of class names to the declarations of classes that are
immediate descendants of the given class name }
DerivedClasses : TMap;
{ sets containing file extensions belonging to particular groups }
RawTextExtensions : TStringSet;
RawCommentExtensions : TStringSet;
errorCount : Cardinal;
procedure GiveError(msg : String);
function GetTitle(title : String) : String;
{ registeres a section for <name>; handles duplicate section
names; returns the section }
function GetSection(const name : String; big : Boolean) : TSection;
{ checks if the comment matches the right profile }
function CheckProfile(comment : TComment) : Boolean;
{ starts a new declaration block, like in a class or an
interface; obj is the declaration of the new block }
procedure StartBlock(obj : TBlockDeclaration);
{ ends the current declaration block }
procedure EndBlock;
{ returns an appropriate comment object taking into account
<comment>, includeDecl and recentComment; name is the name of
the symbol }
function GetCommentObject(name, comment : String) : TComment;
function CheckedOpenInputFile(const path : String) : TFileStream;
{ reads in a whole ASCII file and returns its contents in a
string }
function ReadWholeFile(filename : String) : String;
{ creates or returns an already existing section for the given
file; for raw text/comment files only ; the returned section
should _not_ be destroyed by the caller }
function GetRawFileSection(filename : String) : TSection;
{ reads the entire contents of a file and processes it like a
comment }
procedure ProcessRawCommentFile;
procedure ProcessRawTextFile;
procedure WriteTree(section : TSection; classTree : Boolean);
procedure GenerateClassTree;
procedure GenerateInterfaceTree;
procedure GenerateSymbolIndex;
procedure GenerateContents;
public
{ @param aContentsTitle - the title of the documentation }
{ @param aprofile - the name of the profile to use }
constructor Create(aoptions : TOptions; adocwriter : TDocWriter;
asourceDirs : TStrings;
aContentsTitle, aprofile : String);
destructor Destroy; override;
procedure Run(afilequeue : TStringDequeAdt); override;
procedure RegisterFile(filename : String); override;
function RegisterUnit(name : String;
unitComment : String) : Boolean; override;
function OpenUnit(name : String) : Boolean; override;
procedure ProvideUnitInfo(ainterfaceUses : TStrings); override;
procedure ProvideUnitImplementationInfo(aimplUses : TStrings;
aunitImplComment : String); override;
procedure RegisterDeclarations(adecl : TTextObject; asymbols : TStrings;
args : TStrings; avisibility : String;
avisibilityType : TVisibilityType;
asymboltype : String; alinenum : Integer;
acomment : String); override;
procedure StartClass(decl : TTextObject; name : String;
ancestors : TStrings; interfaces : TStrings;
visibility : String; visibilitytype : TVisibilityType;
symbolType : String; linenum : Integer;
comment : String); override;
procedure FinishClass; override;
procedure StartInterface(decl : TTextObject; aname : String;
ancestors : TStrings; id : String;
visibility : String;
visibilitytype : TVisibilityType;
symboltype : String;
lineNum : Integer; comment : String); override;
procedure FinishInterface; override;
procedure SetIgnoreDeclarations(num : Cardinal); override;
function FindSection(name : String) : TSection; override;
procedure Error(msg, filename : String; linenum : Cardinal); override;
procedure Error(msg, filename : String); override;
procedure Error(msg : String); override;
procedure CommentError(msg : String); override;
procedure Warn(msg, filename : String; line : Integer); override;
procedure Warn(msg : String); override;
procedure CommentWarn(msg : String); override;
procedure WriteMessage(msg : String); override;
end;
{ -------------- several helper classes ---------------- }
{ an abstract class representing a very general notion of a
declaration; units, linked text and comment files are all treated
as such declarations; this class is sometimes instantiated for
declarations that were written out and it is not necessary to
store their data any more, except for some basic things present
here }
{ note: the parent-child relationship represents the fact that the
child is declared inside parent (i.e. as the member of a class,
interface, unit, etc.) }
{ note: declarations are uniquely identified by their sections, not
by the Names field }
TBasicDeclaration = class
protected
{ names of all the things declared }
Names : TStrings;
{ the declaration inside which self was declared; nil if it is a
root declaration (the root declaration must be of type
TRootDeclaration). }
ParentDecl : TBlockDeclaration;
{ the section containing the declaration }
Section : TSection;
{ this should be set in the constructor of TBlockDeclaration to
true; purely for efficiency reasons }
IsBlockDeclaration : Boolean;
{ returns the name of the declaration together with the scope
qualifier }
function QualifiedName : String;
public
constructor Create(anames : TStrings; asection : TSection;
aparent : TBlockDeclaration);
destructor Destroy; override;
end;
{ represents a more specific notion of a declaration; }
TDeclaration = class (TBasicDeclaration)
private
{ this is false if the comment was fetched from some related
method }
ShouldDisposeComment : Boolean;
protected
SymbolType : String;
{ the text of the declaration }
DeclText : TTextObject;
{ global, local, public, ... }
Visibility : String;
VisibilityType : TVisibilityType;
{ read, write, ... used with properties only }
Accessibility : String;
FileName : String;
LineNum : Integer;
Comment : TComment;
Title : String;
{ writes out <decls> as links separating them with commas; also
writes unrecognized as a plain text; <decls> and
<unrecognized> must be non-nil }
procedure WriteLinks(decls : TArrayAdt; unrecognized : TStrings);
{ writes a navigation panel; these are just several links for
navigation purposes; decl is the declaration after which the
panel is written; decl should be nil if it is a panel after
the unit-level description }
procedure WriteNavigationPanel;
{ opens all requisite sections }
procedure OpenSections;
{ writes the beginning of the declaration }
procedure WriteHead; virtual;
procedure WriteMiddle; virtual;
{ writes the closing part of the declaration (members + the
navigation panel) }
procedure WriteTail; virtual;
public
{ <acomment> may be nil to indicate no comment }
constructor Create(adecl : TTextObject; asymbols : TStrings;
avisibility : String; avisibilityType : TVisibilityType;
asymboltype : String; alinenum : Cardinal;
acomment : TComment; asection : TSection;
aparentDecl : TBlockDeclaration);
constructor CreateSimple(anames : TStrings; asection : TSection;
aparentDecl : TBlockDeclaration);
destructor Destroy; override;
procedure WriteOut; virtual;
end;
{ a declaration containing other declarations; this class is
abstract; it should never be instantiated }
TBlockDeclaration = class (TDeclaration)
private
{ an array of @<TDeclarations> }
Declarations : TArray;
{ a map of declaration names to the declaration objects;
<DeclsMap> does not own its items; it only caches objects from
@<Declarations> }
DeclsMap : TMap;
{ an array of TBasicDeclarations }
Ancestors : TArrayAdt;
{ ancestors for which no TBasicDeclaration object was found }
UnrecognizedAncestors : TStrings;
protected
{ writes links to declarations which are associated in the table
with the name of self; writes a declaration only if it is
either an immediate descendant of self or if self is an
interface and the declaration implements it }
procedure WriteFromHashTable(table : TMap;
heading : String);
{ <map> is a map of strings to TListAdt's. the procedure adds
<decl> to each list mapped to by one of the strings in <strs>;
if some strings in <strs> does not have an associated item in
<map>, then creates a list for this item and inserts it into
the map }
procedure FillMap(map : TMap; strs : TStrings;
decl : TDeclaration);
{ for each string in <strs> tires to find a declaration with
this name by calling SearchDeclaration; if found adds this
declaration to decls, otherwise adds the string to
unrecognized; if decls or unrecognized is nil then creates
them; destroys strs }
procedure StringsToDeclarations(var decls : TArrayAdt;
var unrecognized : TStrings;
var strs : TStrings);
{ sorts <decls> according to the symbolType field as
the primary key and to the Name fileld as the secondary key }
procedure SortDeclarations;
{ writes out the declarations <decl>; first writes a table with
the synopsis'es of all the declarations; then writes a
navigation panel and then the declarations themselves; the
argument should be a vector of TDeclaration objects; decls
must be non-nil; parent is the delaration to which decls
belong; if there is no such declaration (i.e. decls are
unit-level declarations), then parent should be nil }
procedure WriteDeclarations;
{ returns true if self contains some declarations, i.e. some
declarations were declared in the block of self }
function HasDeclarations : Boolean;
{ returns the most recently added declaration or nil if self
contains no declarations }
function LastDeclaration : TDeclaration;
{ adds a declaration to the block declaration }
procedure AddDeclaration(decl : TDeclaration);
{ finds a declaration with the name <name> in the declarations
in the current block _only_ }
function FindDeclaration(name : String) : TDeclaration;
{ searches a declaration in _all_ declarations starting from
self; performs a breadth-first search on the whole tree of all
declarations, treating it as a graph and starting from self;
(in fact, AllDeclarations table is used to speed up the
search, but the effect is roughly the same) }
function SearchDeclaration(aname : String) : TBasicDeclaration;
{ searches for the nearest methods above and including self in
the class hierarchy and with the name <name>; adds found
declarations to <decls> }
procedure SearchRelated(name : String; decls : TArrayAdt);
{ fetches a related comment by calling SearchRelated }
function FetchRelatedComment(aname : String) : TComment;
{ returns true if <decl> is present among the ancestors of self }
function IsDerivedFrom(decl : TBasicDeclaration) : Boolean;
{ should push all declarations considered to be ancestors of
self at the front of <deque> }
procedure PushAncestorsAtFront(deque : TDequeAdt); virtual;
procedure WriteHead; override;
procedure WriteMiddle; override;
procedure WriteTail; override;
public
constructor Create(adecl : TTextObject; aname : String;
aancestors : TStrings;
avisibility : String; avisibilitytype : TVisibilityType;
asymboltype : String; alinenum : Cardinal;
acomment : TComment; asection : TSection;
aparentDecl : TBlockDeclaration);
destructor Destroy; override;
procedure WriteOut; override;
end;
TClassDeclaration = class (TBlockDeclaration)
protected
{ an array of TBasicDeclarations }
Interfaces : TArrayAdt;
UnrecognizedInterfaces : TStrings;
{ retruns true if self implements <int> }
function ImplementsInterface(int : TBasicDeclaration) : Boolean;
procedure PushAncestorsAtFront(deque : TDequeAdt); override;
procedure WriteHead; override;
public
constructor Create(adecl : TTextObject; aname : String;
aancestors, ainterfaces : TStrings;
avisibility : String; avisibilitytype : TVisibilityType;
asymboltype : String; alinenum : Cardinal;
acomment : TComment; asection : TSection;
aparentDecl : TBlockDeclaration);
destructor Destroy; override;
end;
TInterfaceDeclaration = class (TBlockDeclaration)
protected
Id : String;
procedure WriteHead; override;
procedure WriteMiddle; override;
public
constructor Create(adecl : TTextObject; aname : String;
aancestors : TStrings; aid : String;
avisibility : String; avisibilityType : TVisibilityType;
asymboltype : String; alinenum : Cardinal;
acomment : TComment; asection : TSection;
aparentDecl : TBlockDeclaration);
end;
TUnitDeclaration = class (TBlockDeclaration)
protected
{ arrays of TBasicDeclarations }
InterfaceUses, ImplUses : TArrayAdt;
UnrecognizedInterfaceUses, UnrecognizedImplUses : TStrings;
Implcomment : TComment;
FFileName : String;
public
constructor Create(aunitName : String; aunitComment : TComment);
destructor Destroy; override;
{ this method should be called before writing the unit; it
provides necessary information }
procedure ProvideInfo(ainterfaceUses : TStrings);
procedure ProvideImplementationInfo(aimplUses : TStrings;
aImplComment : TComment);
procedure WriteOut; override;
property FileName : String read FFileName;
end;
{ does not represent anything particular; just serves as the root
of the whole tree of declarations }
TRootDeclaration = class (TBlockDeclaration)
public
constructor Create;
end;
implementation
uses
adtiters, adthash, adthashfunct, adtalgs, adtlist, adtqueue,
adtavltree, adtstralgs, defcommentparser, delphiparser, languages;
const
MaxErrors = 15;
var
DDriver : TDefaultDriver; { the same as Driver }
DeclarationComparer : IBinaryComparer;
{ present only for efficiency reasons }
ignoreCase : Boolean;
type
StringArrayType = array of String;
TParsedFile = class
public
FileName : String;
Title : String;
FileSect : TSection;
end;
TDeclarationComparer = class (TFunctor, IBinaryComparer)
public
function Compare(obj1, obj2 : TObject) : Integer;
end;
TDeclarationNameComparer = class (TFunctor, IUnaryPredicate)
private
Name : String;
public
constructor Create(aname : String);
function Test(obj : TObject) : Boolean;
end;
{ used only to avoid checking for special cases }
TRootSection = class (TSection)
end;
{ --------------------- helper routines -------------------------- }
function DeclarationNameComparer(name : String) : IUnaryPredicate;
begin
Result := TDeclarationNameComparer.Create(name);
end;
function BreakPathIntoSections(path : String) : StringArrayType;
var
i, j : Integer;
tab : TKmpTable;
begin
i := 0; j := 0;
tab := KmpComputeTable(docwSectionSeparator);
SetLength(Result, CountSubstrings(path, docwSectionSeparator, tab) + 1);
Result[0] := path;
while i <> -1 do
begin
i := KmpFindSubstr(Result[j], docwSectionSeparator, 1, tab);
if i <> -1 then
begin
{ copy the part of the string after the separator }
Result[j + 1] := system.Copy(Result[j], i + Length(docwSectionSeparator),
Length(Result[j]));
Result[j] := system.Copy(Result[j], 1, i - 1);
Inc(j);
end;
end;
end;
{ returns true if the strings are equal, false otherwise }
function CmpStr(const str1, str2 : String) : Boolean;
begin
if ignoreCase then
Result := AnsiCompareText(str1, str2) = 0
else
Result := str1 = str2;
end;
{ ---------------------- TDeclarationComparer ----------------------- }
function TDeclarationComparer.Compare(obj1, obj2 : TObject) : Integer;
var
vis1, vis2 : TVisibilityType;
begin
Assert(obj1 is TDeclaration);
Assert(obj2 is TDeclaration);
{ compare the visibility; publicly visible come first }
vis1 := TDeclaration(obj1).VisibilityType;
vis2 := TDeclaration(obj2).VisibilityType;
Result := Ord(vis1) - Ord(vis2);
if Result = 0 then
begin
Result := AnsiCompareStr(TDeclaration(obj1).Visibility,
TDeclaration(obj2).Visibility);
if Result = 0 then
begin
Result := AnsiCompareStr(TDeclaration(obj1).SymbolType,
TDeclaration(obj2).SymbolType);
end;
end;
end;
{ ------------------- TDeclarationNameComparer ---------------------- }
constructor TDeclarationNameComparer.Create(aname : String);
begin
{$ifdef DEBUG }
inherited Create;
{$endif }
Name := aname;
end;
function TDeclarationNameComparer.Test(obj : TObject) : Boolean;
begin
Assert(obj is TBasicDeclaration);
{ note: declarations are uniquely identified by their section
names }
Result := CmpStr(TBasicDeclaration(obj).Section.Name, Name);
end;
{ --------------------- TBasicDeclaration ---------------------------- }
constructor TBasicDeclaration.Create(anames : TStrings; asection : TSection;
aparent : TBlockDeclaration);
begin
Names := anames;
Section := asection;
ParentDecl := aparent;
IsBlockDeclaration := false;
end;
destructor TBasicDeclaration.Destroy;
begin
Names.Free;
Section.Free;
inherited;
end;
function TBasicDeclaration.QualifiedName : String;
var
i : Integer;
begin
Assert (Names <> nil);
Assert (Names.Count > 0);
if Names.Count > 1 then
begin
Result := '';
for i := 0 to Names.Count - 2 do
Result := Result + Names[i] + ', ';
Result := Result + Names[Names.Count - 1];
end else if (ParentDecl <> nil) and
((ParentDecl is TClassDeclaration) or
(ParentDecl is TInterfaceDeclaration)) then
begin
Result := ParentDecl.Names[0] +
DDriver.LanguageParser.ScopeResolutionToken + Names[0];
end else
Result := Names[0];
end;
{ ------------------------ TDeclaration ------------------------------ }
constructor TDeclaration.Create(adecl : TTextObject; asymbols : TStrings;
avisibility : String;
avisibilityType : TVisibilityType;
asymboltype : String; alinenum : Cardinal;
acomment : TComment; asection : TSection;
aparentDecl : TBlockDeclaration);
begin
Assert(asymbols <> nil);
Assert(asymbols.Count <> 0);
inherited Create(asymbols, asection, aparentDecl);
Symboltype := asymboltype;
Decltext := adecl;
Visibility := avisibility;
VisibilityType := avisibilityType;
FileName := TDefaultDriver(Driver).currentFile;
LineNum := alinenum;
Comment := acomment;
if (Comment <> nil) and (Comment.Title <> '') then
Title := Comment.Title
else
Title := GetLangString(Reference_for_str) + ' ' + asymbols[0];
ShouldDisposeComment := true;
if (Comment = nil) and (ParentDecl <> nil) and
not (ParentDecl is TRootDeclaration) and
(optFetchCommentsFromAncestors in Driver.Options) then
begin
comment := ParentDecl.FetchRelatedComment(Names[0]);
if comment <> nil then
ShouldDisposeComment := false;
end;
end; { end constructor Create }
constructor TDeclaration.CreateSimple(anames : TStrings; asection : TSection;
aparentDecl : TBlockDeclaration);
begin
Create(nil, anames, GetLangString(global_str), vtPublic,
GetLangString(file_str), 0,
nil, asection, aparentDecl);
end;
destructor TDeclaration.Destroy;
begin
Decltext.Free;
if ShouldDisposeComment then
Comment.Free;
inherited;
end;
procedure TDeclaration.WriteLinks(decls : TArrayAdt; unrecognized : TStrings);
var
i : Integer;
decl : TBasicDeclaration;
begin
Assert(decls <> nil);
Assert(unrecognized <> nil);
Assert(Section <> nil);
for i := decls.LowIndex to decls.HighIndex do
begin
decl := TBasicDeclaration(decls[i]);
Section.WriteLink(decl.Names[0], decl.Section);
if i <> decls.HighIndex then
Section.WriteText(', ');
end;
if (unrecognized.Count <> 0) and (decls.Size <> 0) then
Section.WriteText(', ');
for i := 0 to unrecognized.Count - 1 do
begin
Section.WriteText(unrecognized[i]);
if i <> unrecognized.Count - 1 then
Section.WriteText(', ');
end;
end;
procedure TDeclaration.OpenSections;
var
i : Integer;
sect : TSection;
begin
Assert(ParentDecl <> nil);
Assert(Names <> nil);
for i := 1 to Names.Count - 1 do
begin
if ParentDecl.SearchDeclaration(Names[i]) = nil then
begin
sect := Driver.DocWriter.RegisterSection(Names[i], ParentDecl.Section,
false);
sect.Open(Title);
sect.Close;
sect.Destroy;
end;
end;
Section.Open(Title);
end;
procedure TDeclaration.WriteNavigationPanel;
var
widths : TArrayOfInteger;
cols : Integer;
begin
with Section do
begin
if self <> nil then
begin
NewParagraph;
cols := 3;
SetLength(widths, cols);
widths[0] := 33;
widths[1] := 33;
widths[2] := 33;
StartTable(widths, cols);
WriteLink(Names[0], Section);
if not (ParentDecl is TRootDeclaration) then
begin
NextCell;
WriteLink(ParentDecl.Names[0], ParentDecl.Section);
if not (ParentDecl.ParentDecl is TRootDeclaration) then
begin
NextCell;
WriteLink(ParentDecl.ParentDecl.Names[0],
ParentDecl.ParentDecl.Section);
end;
end;
FinishTable;
end;
end;
end;
procedure TDeclaration.WriteHead;
begin
with Section do
begin
WriteHeading(QualifiedName(), bigHeadingSize);
WriteHeading(GetLangString(Declaration_str), subHeadingSize);
SuppressLineBreaking;
DeclText.WriteOut(Section);
ResumeLineBreaking;
if visibility <> '' then
begin
WriteHeading(GetLangString(Visibility_str), subHeadingSize);
WriteText(visibility);
end;
if accessibility <> '' then
begin
WriteHeading(GetLangString(Access_str), subHeadingSize);
WriteText(accessibility);
end;
end; { end with }
end;
procedure TDeclaration.WriteMiddle;
var
decls : TArray;
i : Integer;
dd : TBasicDeclaration;
begin
Assert(ParentDecl <> nil);
with Section do
begin
if not (ParentDecl is TRootDeclaration) then
begin
decls := TArray.Create;
decls.OwnsItems := false;
try
ParentDecl.SearchRelated(Names[0], decls);
if not decls.Empty then
begin
WriteHeading(GetLangString(Related_methods_str), subHeadingSize);
for i := decls.LowIndex to decls.HighIndex do
begin
dd := TBasicDeclaration(decls[i]);
WriteLink(dd.QualifiedName, dd.Section);
if i <> decls.HighIndex then
WriteText(', ');
end;
end;
finally
decls.Free;
end;
end;
if filename <> '' then
begin
WriteHeading(GetLangString(Source_str), subHeadingSize);
WriteText(filename);
if lineNum <> 0 then
WriteText(' ' + GetLangString(on_line_str) + ' ' + IntToStr(lineNum));
end;
end; { end with Section }
if comment <> nil then
comment.WriteOut(Section);
end;
procedure TDeclaration.WriteTail;
begin
WriteNavigationPanel;
end;
procedure TDeclaration.WriteOut;
begin
OpenSections;
WriteHead;
WriteMiddle;
WriteTail;
Section.Close;
end;
{ ---------------------- TBlockDeclaration --------------------------------- }
constructor TBlockDeclaration.Create(adecl : TTextObject; aname : String;
aancestors : TStrings;
avisibility : String;
avisibilityType : TVisibilityType;
asymboltype : String; alinenum : Cardinal;
acomment : TComment; asection : TSection;
aparentDecl : TBlockDeclaration);
var
asymbols : TStrings;
begin
asymbols := TStringList.Create;
asymbols.Add(aname);
inherited Create(adecl, asymbols, avisibility, avisibilityType,
asymboltype, alinenum, acomment, asection, aparentDecl);
Declarations := TArray.Create;
{ Driver.LanguageParser is nil when creating the root declaration }
{ DeclsMap does not own its items }
DeclsMap := TMap.Create(THashTable.Create);
if (Driver.LanguageParser <> nil) and Driver.LanguageParser.IgnoreCase then
DeclsMap.KeyComparer := NoCaseStringComparer;
DeclsMap.OwnsItems := false;
IsBlockDeclaration := true;
FillMap(DDriver.DerivedClasses, aancestors, self);
StringsToDeclarations(Ancestors, UnrecognizedAncestors, aancestors);
end;
destructor TBlockDeclaration.Destroy;
begin
Declarations.Free;
DeclsMap.Free;
Ancestors.Free;
UnrecognizedAncestors.Free;
inherited;
end;
procedure TBlockDeclaration.FillMap(map : TMap; strs : TStrings;
decl : TDeclaration);
var
i : Integer;
begin
for i := 0 to strs.Count - 1 do
begin
map.Insert(strs[i], decl);
end;
end;
procedure TBlockDeclaration.StringsToDeclarations(var decls : TArrayAdt;
var unrecognized : TStrings;
var strs : TStrings);
var
decl : TBasicDeclaration;
i : Integer;
begin
Assert(strs <> nil);
if decls = nil then
begin
decls := TArray.Create;
decls.OwnsItems := false;
end;
if unrecognized = nil then
unrecognized := TStringList.Create;
for i := 0 to strs.Count - 1 do
begin
decl := SearchDeclaration(strs[i]);
if decl <> nil then
begin
decls.PushBack(decl);
end else
unrecognized.Add(strs[i]);
end;
strs.Free;
strs := nil;
end;
procedure TBlockDeclaration.SortDeclarations;
begin
StableSort(Declarations.Start, Declarations.Finish, DeclarationComparer);
end;
procedure TBlockDeclaration.WriteDeclarations;
var
i, j : Integer;
widths : TArrayOfInteger;
decl : TDeclaration;
begin
with Section do
begin
SortDeclarations;
SetLength(widths, 4);
widths[0] := 30; { name }
widths[1] := 15; { type }
widths[2] := 15; { visibility }
widths[3] := 40; { synopsis }
StartTable(widths, 4);
WriteHeading(GetLangString(Name_str), smallHeadingSize);
NextCell;
WriteHeading(GetLangString(Type_str), smallHeadingSize);
NextCell;
WriteHeading(GetLangString(Visibility_str), smallHeadingSize);
NextCell;
WriteHeading(GetLangString(Synopsis_str), smallHeadingSize);
NextRow;
for i := Declarations.LowIndex to Declarations.HighIndex do
begin
Assert(TObject(Declarations[i]) is TDeclaration);
decl := TDeclaration(Declarations[i]);
for j := 0 to decl.Names.Count - 1 do
begin
WriteLink(decl.Names[j], decl.Section);
NextCell;
WriteText(decl.SymbolType);
NextCell;
WriteText(decl.Visibility);
NextCell;
if (decl.Comment <> nil) and (decl.Comment.Synopsis <> nil) then
decl.Comment.Synopsis.WriteOut(Section);
NextRow;
end;
end;
FinishTable;
WriteNavigationPanel;
Newline;
{ now write the descriptions of the declarations themselves }
for i := Declarations.LowIndex to Declarations.HighIndex do
begin
Assert(TObject(Declarations[i]) is TDeclaration);
TDeclaration(Declarations[i]).WriteOut;
end;
end; { end with DocWriter }
end;
function TBlockDeclaration.HasDeclarations : Boolean;
begin
Result := Declarations.Empty;
end;
function TBlockDeclaration.LastDeclaration : TDeclaration;
begin
if not Declarations.Empty then
Result := TDeclaration(Declarations.Back)
else
Result := nil;
end;
procedure TBlockDeclaration.AddDeclaration(decl : TDeclaration);
var
i : Integer;
begin
Assert(decl <> nil);
Assert(decl.ParentDecl = self);
Assert(DeclsMap.Find(decl.Section.Name) = nil);
Declarations.PushBack(decl);
DeclsMap[decl.Section.Name] := decl;
DDriver.AllDeclarations.Insert(decl.Section.Name, decl);
for i := 1 to decl.Names.Count - 1 do
DDriver.AllDeclarations.Insert(decl.Names[i], decl);
end;
function TBlockDeclaration.FindDeclaration(name : String) : TDeclaration;
begin
Result := TDeclaration(DeclsMap.Find(name));
{ note: SearchDeclaration uses DeclsMap directly instead of calling
this function for efficiency reasons }
end;
function TBlockDeclaration.SearchDeclaration(aname : String) :
TBasicDeclaration;
type
TPathArray = array of TBasicDeclaration;