-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdoc2.d
5547 lines (4621 loc) · 144 KB
/
doc2.d
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
module adrdox.main;
// version=with_http_server
// version=with_postgres
__gshared string dataDirectory;
__gshared string skeletonFile = "skeleton.html";
__gshared string outputDirectory = "generated-docs";
__gshared TexMathOpt texMathOpt = TexMathOpt.LaTeX;
__gshared bool writePrivateDocs = false;
__gshared bool documentInternal = false;
__gshared bool documentTest = false;
__gshared bool documentUndocumented = false;
__gshared bool minimalDescent = false;
version(linux)
__gshared bool caseInsensitiveFilenames = false;
else
__gshared bool caseInsensitiveFilenames = true;
__gshared bool searchPostgresOnly = false; // DISGUSTING HACK THAT SHOULD NOT BE USED but im too lazy to fix the real problem. arcz + fork() = pain rn
/*
Glossary feature: little short links that lead somewhere else.
FIXME: it should be able to handle bom. consider core/thread.d the unittest example is offset.
FIXME:
* make sure there's a link to the source for everything
* search
* package index without needing to build everything at once
* version specifiers
* prettified constraints
*/
import dparse.parser;
import dparse.lexer;
import dparse.ast;
import arsd.dom;
import arsd.docgen.comment;
version(with_postgres)
import arsd.postgres;
else
private alias PostgreSql = typeof(null);
import std.algorithm :sort, canFind;
import std.string;
import std.conv : to;
string handleCaseSensitivity(string s) {
if(!caseInsensitiveFilenames)
return s;
string ugh;
foreach(ch; s) {
if(ch >= 'A' && ch <= 'Z')
ugh ~= "_";
ugh ~= ch;
}
return ugh;
}
bool checkDataDirectory(string stdpath) {
import std.file : exists;
import std.path : buildPath;
string[] stdfiles = ["script.js",
"style.css",
"search-docs.js",
"search-docs.html",
"skeleton-default.html"];
foreach (stdfile; stdfiles) {
if (!buildPath(stdpath, stdfile).exists) {
return false;
}
}
return true;
}
bool detectDataDirectory(ref string dataDir) {
import std.file : thisExePath;
import std.path : buildPath, dirName;
string exeDir = thisExePath.dirName;
string[] stdpaths = [exeDir,
exeDir.dirName,
buildPath(exeDir.dirName, "share/adrdox")];
foreach (stdpath; stdpaths) {
if (checkDataDirectory(stdpath)) {
dataDir = stdpath;
return true;
}
}
return false;
}
// returns empty string if file not found
string findStandardFile(bool dofail=true) (string stdfname) {
import std.file : exists;
import std.path : buildPath;
if (!stdfname.exists) {
if (stdfname.length && stdfname[0] != '/') {
string newname = buildPath(dataDirectory, stdfname);
if (newname.exists) return newname;
}
static if (dofail) throw new Exception("standard file '" ~stdfname ~ "' not found!");
}
return stdfname;
}
string outputFilePath(string[] names...) {
import std.path : buildPath;
names = outputDirectory ~ names;
return buildPath(names);
}
void copyStandardFileTo(bool timecheck=true) (string destname, string stdfname) {
if(arcz !is null) {
synchronized(arcz) {
import std.file;
auto info = cast(ubyte[]) std.file.read(findStandardFile(stdfname));
arcz.newFile(destname, cast(int) info.length);
arcz.rawWrite(info);
}
return;
}
import std.file;
if (exists(destname)) {
static if (timecheck) {
if (timeLastModified(destname) >= timeLastModified(findStandardFile(stdfname))) return;
} else {
return;
}
}
copy(findStandardFile(stdfname), destname);
}
__gshared static Object directoriesForPackageMonitor = new Object; // intentional CTFE
__gshared string[string] directoriesForPackage;
string getDirectoryForPackage(string packageName) {
if(packageName.indexOf("/") != -1)
return ""; // not actually a D package!
if(packageName.indexOf("#") != -1)
return ""; // not actually a D package!
synchronized(modulesByNameMonitor)
if(packageName in modulesByName) {
return ""; // don't redirect locally generated things
}
string bestMatch = "";
int bestMatchDots = -1;
import std.path;
synchronized(directoriesForPackageMonitor)
foreach(pkg, dir; directoriesForPackage) {
if(globMatch!(CaseSensitive.yes)(packageName, pkg)) {
int cnt;
foreach(ch; pkg)
if(ch == '.')
cnt++;
if(cnt > bestMatchDots) {
bestMatch = dir;
bestMatchDots = cnt;
}
}
}
return bestMatch;
}
// FIXME: make See Also automatically list dittos that are not overloads
enum skip_undocumented = true;
static bool sorter(Decl a, Decl b) {
if(a.declarationType == b.declarationType)
return (blogMode && a.declarationType == "Article") ? (b.name < a.name) : (a.name < b.name);
else if(a.declarationType == "module" || b.declarationType == "module") // always put modules up top
return
(a.declarationType == "module" ? "AAAAAA" : a.declarationType)
< (b.declarationType == "module" ? "AAAAAA" : b.declarationType);
else
return a.declarationType < b.declarationType;
}
void annotatedPrototype(T)(T decl, MyOutputRange output) {
static if(is(T == TemplateDecl)) {
auto td = cast(TemplateDecl) decl;
auto epony = td.eponymousMember;
if(epony) {
if(auto e = cast(FunctionDecl) epony) {
doFunctionDec(e, output);
return;
}
}
}
auto classDec = decl.astNode;
auto f = new MyFormatter!(typeof(output))(output, decl);
void writePrototype() {
output.putTag("<div class=\"aggregate-prototype\">");
if(decl.parent !is null && !decl.parent.isModule) {
output.putTag("<div class=\"parent-prototype\">");
decl.parent.getSimplifiedPrototype(output);
output.putTag("</div><div>");
}
writeAttributes(f, output, decl.attributes);
output.putTag("<span class=\"builtin-type\">");
output.put(decl.declarationType);
output.putTag("</span>");
output.put(" ");
output.put(decl.name);
output.put(" ");
foreach(idx, ir; decl.inheritsFrom()) {
if(idx == 0)
output.put(" : ");
else
output.put(", ");
if(ir.decl is null)
output.put(ir.plainText);
else
output.putTag(`<a class="xref parent-class" href="`~ir.decl.link~`">`~ir.decl.name~`</a> `);
}
if(classDec.templateParameters)
f.format(classDec.templateParameters);
if(classDec.constraint)
f.format(classDec.constraint);
// FIXME: invariant
if(decl.children.length) {
output.put(" {");
foreach(child; decl.children) {
if(((child.isPrivate() || child.isPackage()) && !writePrivateDocs))
continue;
// I want to show undocumented plain data members (if not private)
// since they might be used as public fields or in ctors for simple
// structs, but I'll skip everything else undocumented.
if(!child.isDocumented() && (cast(VariableDecl) child) is null)
continue;
output.putTag("<div class=\"aggregate-member\">");
if(child.isDocumented())
output.putTag("<a href=\""~child.link~"\">");
child.getAggregatePrototype(output);
if(child.isDocumented())
output.putTag("</a>");
output.putTag("</div>");
}
output.put("}");
}
if(decl.parent !is null && !decl.parent.isModule) {
output.putTag("</div>");
}
output.putTag("</div>");
}
writeOverloads!writePrototype(decl, output);
}
void doEnumDecl(T)(T decl, Element content)
{
auto enumDec = decl.astNode;
static if(is(typeof(enumDec) == const(AnonymousEnumDeclaration))) {
if(enumDec.members.length == 0) return;
auto name = enumDec.members[0].name.text;
auto type = enumDec.baseType;
auto members = enumDec.members;
} else {
auto name = enumDec.name.text;
auto type = enumDec.type;
const(EnumMember)[] members;
if(enumDec.enumBody)
members = enumDec.enumBody.enumMembers;
}
static if(is(typeof(enumDec) == const(AnonymousEnumDeclaration))) {
// undocumented anonymous enums get a pass if any of
// their members are documented because that's what dmd does...
// FIXME maybe
bool foundOne = false;
foreach(member; members) {
if(member.comment.length) {
foundOne = true;
break;
}
}
if(!foundOne && skip_undocumented)
return;
} else {
if(enumDec.comment.length == 0 && skip_undocumented)
return;
}
/*
auto f = new MyFormatter!(typeof(output))(output);
if(type) {
output.putTag("<div class=\"base-type\">");
f.format(type);
output.putTag("</div>");
}
*/
Element table;
if(members.length) {
content.addChild("h2", "Values").attrs.id = "values";
table = content.addChild("table").addClass("enum-members");
table.appendHtml("<tr><th>Value</th><th>Meaning</th></tr>");
}
foreach(member; members) {
auto memberComment = formatDocumentationComment(preprocessComment(member.comment, decl), decl);
auto tr = table.addChild("tr");
tr.addClass("enum-member");
tr.attrs.id = member.name.text;
auto td = tr.addChild("td");
if(member.isDisabled) {
td.addChild("span", "@disable").addClass("enum-disabled");
td.addChild("br");
}
if(member.type) {
td.addChild("span", toHtml(member.type)).addClass("enum-type");
}
td.addChild("a", member.name.text, "#" ~ member.name.text).addClass("enum-member-name");
if(member.assignExpression) {
td.addChild("span", toHtml(member.assignExpression)).addClass("enum-member-value");
}
auto ea = td.addChild("div", "", "enum-attributes");
foreach(attribute; member.atAttributes) {
ea.addChild("div", toHtml(attribute));
}
// type
// assignExpression
td = tr.addChild("td");
td.innerHTML = memberComment;
if(member.deprecated_) {
auto p = td.prependChild(Element.make("div", Element.make("span", member.deprecated_.stringLiterals.length ? "Deprecated: " : "Deprecated", "deprecated-label"))).addClass("enum-deprecated");
foreach(sl; member.deprecated_.stringLiterals)
p.addChild("span", sl.text[1 .. $-1]);
}
// I might write to parent list later if I can do it all semantically inside the anonymous enum
// since these names are introduced into the parent scope i think it is justified to list them there
// maybe.
}
}
void doFunctionDec(T)(T decl, MyOutputRange output)
{
auto functionDec = decl.astNode;
//if(!decl.isDocumented() && skip_undocumented)
//return;
string[] conceptsFound;
auto f = new MyFormatter!(typeof(output))(output, decl);
/+
auto comment = parseDocumentationComment(dittoSupport(functionDec, functionDec.comment), fullyQualifiedName ~ name);
if(auto ptr = name in overloadChain[$-1]) {
*ptr += 1;
name ~= "." ~ to!string(*ptr);
} else {
overloadChain[$-1][name] = 1;
overloadNodeChain[$-1] = cast() functionDec;
}
const(ASTNode)[] overloadsList;
if(auto overloads = overloadNodeChain[$-1] in additionalModuleInfo.overloadsOf) {
overloadsList = *overloads;
}
if(dittoChain[$-1])
if(auto dittos = dittoChain[$-1] in additionalModuleInfo.dittos) {
auto list = *dittos;
outer: foreach(item; list) {
if(item is functionDec)
continue;
// already listed as a formal overload which means we
// don't need to list it again under see also
foreach(ol; overloadsList)
if(ol is item)
continue outer;
string linkHtml;
linkHtml ~= `<a href="`~htmlEncode(linkMapping[item])~`">` ~ htmlEncode(nameMapping[item]) ~ `</a>`;
comment.see_alsos ~= linkHtml;
}
}
descendInto(name);
output.putTag("<h1><span class=\"entity-name\">" ~ name ~ "</span> "~typeString~"</h1>");
writeBreadcrumbs();
output.putTag("<div class=\"function-declaration\">");
comment.writeSynopsis(output);
+/
void writeFunctionPrototype() {
string outputStr;
auto originalOutput = output;
MyOutputRange output = MyOutputRange(&outputStr);
auto f = new MyFormatter!(typeof(output))(output);
output.putTag("<div class=\"function-prototype\">");
//output.putTag(`<a href="http://dpldocs.info/reading-prototypes" id="help-link">?</a>`);
if(decl.parent !is null && !decl.parent.isModule) {
output.putTag("<div class=\"parent-prototype\">");
decl.parent.getSimplifiedPrototype(output);
output.putTag("</div><div>");
}
writeAttributes(f, output, decl.attributes);
static if(
!is(typeof(functionDec) == const(Constructor)) &&
!is(typeof(functionDec) == const(Postblit)) &&
!is(typeof(functionDec) == const(Destructor))
) {
output.putTag("<div class=\"return-type\">");
if (functionDec.hasAuto && functionDec.hasRef)
output.putTag(`<a class="lang-feature" href="http://dpldocs.info/auto-ref-function-return-prototype">auto ref</a> `);
else {
if (functionDec.hasAuto)
output.putTag(`<a class="lang-feature" href="http://dpldocs.info/auto-function-return-prototype">auto</a> `);
if (functionDec.hasRef)
output.putTag(`<a class="lang-feature" href="http://dpldocs.info/ref-function-return-prototype">ref</a> `);
}
if (functionDec.returnType !is null)
f.format(functionDec.returnType);
output.putTag("</div>");
}
output.putTag("<div class=\"function-name\">");
output.put(decl.name);
output.putTag("</div>");
output.putTag("<div class=\"template-parameters\" data-count=\""~to!string((functionDec.templateParameters && functionDec.templateParameters.templateParameterList) ? functionDec.templateParameters.templateParameterList.items.length : 0)~"\">");
if (functionDec.templateParameters !is null)
f.format(functionDec.templateParameters);
output.putTag("</div>");
output.putTag("<div class=\"runtime-parameters\" data-count=\""~to!string(functionDec.parameters.parameters.length)~"\">");
f.format(functionDec.parameters);
output.putTag("</div>");
if(functionDec.constraint !is null) {
output.putTag("<div class=\"template-constraint\">");
f.format(functionDec.constraint);
output.putTag("</div>");
}
if(functionDec.functionBody !is null) {
// FIXME: list inherited contracts
output.putTag("<div class=\"function-contracts\">");
import dparse.formatter;
auto f2 = new Formatter!(typeof(output))(output);
// I'm skipping statements cuz they ugly. but the shorter expressions aren't too bad
if(functionDec.functionBody.inStatement && functionDec.functionBody.inStatement.expression) {
output.putTag("<div class=\"in-contract\">");
f2.format(functionDec.functionBody.inStatement);
output.putTag("</div>");
}
if(functionDec.functionBody.outStatement) {
output.putTag("<div class=\"out-contract\">");
f2.format(functionDec.functionBody.outStatement);
output.putTag("</div>");
}
output.putTag("</div>");
}
//output.put(" : ");
//output.put(to!string(functionDec.name.line));
if(decl.parent !is null && !decl.parent.isModule) {
output.putTag("</div>");
decl.parent.writeTemplateConstraint(output);
}
output.putTag("</div>");
originalOutput.putTag(linkUpHtml(outputStr, decl));
}
writeOverloads!writeFunctionPrototype(decl, output);
}
void writeOverloads(alias writePrototype, D : Decl)(D decl, ref MyOutputRange output) {
auto overloadsList = decl.getImmediateDocumentedOverloads();
// I'm treating dittos similarly to overloads
if(overloadsList.length == 1) {
overloadsList = decl.getDittos();
} else {
foreach(ditto; decl.getDittos()) {
if(!overloadsList.canFind(ditto))
overloadsList ~= ditto;
}
}
if(overloadsList.length > 1) {
import std.conv;
output.putTag("<ol class=\"overloads\">");
foreach(idx, item; overloadsList) {
assert(item.parent !is null);
string cn;
Decl epony;
if(auto t = cast(TemplateDecl) item)
epony = t.eponymousMember;
if(item !is decl && decl !is epony)
cn = "overload-option";
else
cn = "active-overload-option";
if(item.name != decl.name)
cn ~= " ditto-option";
output.putTag("<li class=\""~cn~"\">");
//if(item is decl)
//writeFunctionPrototype();
//} else {
{
if(item !is decl)
output.putTag(`<a href="`~item.link~`">`);
output.putTag("<span class=\"overload-signature\">");
item.getSimplifiedPrototype(output);
output.putTag("</span>");
if(item !is decl)
output.putTag(`</a>`);
}
if(item is decl || decl is epony)
writePrototype();
output.putTag("</li>");
}
output.putTag("</ol>");
} else {
writePrototype();
}
}
void writeAttributes(F, W)(F formatter, W writer, const(VersionOrAttribute)[] attrs, bool bracket = true)
{
if(bracket) writer.putTag("<div class=\"attributes\">");
IdType protection;
LinkageAttribute linkage;
string versions;
const(VersionOrAttribute)[] remainingBuiltIns;
const(VersionOrAttribute)[] remainingCustoms;
foreach(a; attrs) {
if (a.attr && isProtection(a.attr.attribute.type)) {
protection = a.attr.attribute.type;
} else if (a.attr && a.attr.linkageAttribute) {
linkage = cast() a.attr.linkageAttribute;
} else if (auto v = cast(VersionFakeAttribute) a) {
if(versions.length)
versions ~= " && ";
if(v.inverted)
versions ~= "!";
versions ~= v.cond;
} else if(a.attr && a.attr.attribute.type == tok!"auto") {
// skipping auto because it is already handled as the return value
} else if(a.isBuiltIn) {
remainingBuiltIns ~= a;
} else {
remainingCustoms ~= a;
}
}
if(versions.length) {
writer.putTag("<div class=\"versions-container\">");
writer.put("version(");
writer.put(versions);
writer.put(")");
writer.putTag("</div>");
}
switch (protection)
{
case tok!"private": writer.put("private "); break;
case tok!"package": writer.put("package "); break;
case tok!"protected": writer.put("protected "); break;
case tok!"export": writer.put("export "); break;
case tok!"public": // see below
default:
// I'm not printing public so this is commented intentionally
// public is the default state of documents so saying it outright
// is kinda just a waste of time IMO.
//writer.put("public ");
break;
}
if(linkage) {
formatter.format(linkage);
writer.put(" ");
}
void innards(const VersionOrAttribute a) {
if(auto fakeAttr = cast(const MemberFakeAttribute) a) {
formatter.format(fakeAttr.attr);
writer.put(" ");
} else if(auto dbg = cast(const FakeAttribute) a) {
writer.putTag(dbg.toHTML);
} else {
if(a.attr && a.attr.deprecated_)
writer.putTag(`<span class="deprecated-decl">deprecated</span>`);
else if(a.attr)
formatter.format(a.attr);
writer.put(" ");
}
}
foreach (a; remainingBuiltIns)
innards(a);
foreach (a; remainingCustoms) {
writer.putTag("<div class=\"uda\">");
innards(a);
writer.putTag("</div>");
}
if(bracket) writer.putTag("</div>");
}
class VersionOrAttribute {
const(Attribute) attr;
this(const(Attribute) attr) {
this.attr = attr;
}
bool isBuiltIn() const {
if(attr is null) return false;
if(attr.atAttribute is null) return true; // any keyword can be safely assumed...
return phelper(attr.atAttribute);
}
protected bool phelper(const AtAttribute at) const {
string txt = toText(at);
if(txt == "@(nogc)") return true;
if(txt == "@(disable)") return true;
if(txt == "@(live)") return true;
if(txt == "@(property)") return true;
if(txt == "@(safe)") return true;
if(txt == "@(system)") return true;
if(txt == "@(trusted)") return true;
return false;
}
const(VersionOrAttribute) invertedClone() const {
return new VersionOrAttribute(attr);
}
override string toString() const {
return attr ? toText(attr) : "null";
}
}
interface ConditionFakeAttribute {
string toHTML() const;
}
class FakeAttribute : VersionOrAttribute {
this() { super(null); }
abstract string toHTML() const;
}
class MemberFakeAttribute : FakeAttribute {
const(MemberFunctionAttribute) attr;
this(const(MemberFunctionAttribute) attr) {
this.attr = attr;
}
override string toHTML() const {
return toText(attr);
}
override bool isBuiltIn() const {
if(attr is null) return false;
if(attr.atAttribute is null) return true;
return phelper(attr.atAttribute);
}
override string toString() const {
return attr ? toText(attr) : "null";
}
}
class VersionFakeAttribute : FakeAttribute, ConditionFakeAttribute {
string cond;
bool inverted;
this(string condition, bool inverted = false) {
cond = condition;
this.inverted = inverted;
}
override const(VersionFakeAttribute) invertedClone() const {
return new VersionFakeAttribute(cond, !inverted);
}
override bool isBuiltIn() const {
return false;
}
override string toHTML() const {
auto element = Element.make("span");
element.addChild("span", "version", "lang-feature");
element.appendText("(");
if(inverted)
element.appendText("!");
element.addChild("span", cond);
element.appendText(")");
return element.toString;
}
override string toString() const {
return (inverted ? "!" : "") ~ cond;
}
}
class DebugFakeAttribute : FakeAttribute, ConditionFakeAttribute {
string cond;
bool inverted;
this(string condition, bool inverted = false) {
cond = condition;
this.inverted = inverted;
}
override const(DebugFakeAttribute) invertedClone() const {
return new DebugFakeAttribute(cond, !inverted);
}
override bool isBuiltIn() const {
return false;
}
override string toHTML() const {
auto element = Element.make("span");
if(cond.length) {
element.addChild("span", "debug", "lang-feature");
element.appendText("(");
if(inverted)
element.appendText("!");
element.addChild("span", cond);
element.appendText(")");
} else {
if(inverted)
element.addChild("span", "!debug", "lang-feature");
else
element.addChild("span", "debug", "lang-feature");
}
return element.toString;
}
override string toString() const {
return (inverted ? "!" : "") ~ cond;
}
}
class StaticIfFakeAttribute : FakeAttribute, ConditionFakeAttribute {
string cond;
bool inverted;
this(string condition, bool inverted = false) {
cond = condition;
this.inverted = inverted;
}
override const(StaticIfFakeAttribute) invertedClone() const {
return new StaticIfFakeAttribute(cond, !inverted);
}
override bool isBuiltIn() const {
return false;
}
override string toHTML() const {
auto element = Element.make("span");
element.addChild("span", "static if", "lang-feature");
element.appendText("(");
if(inverted)
element.appendText("!(");
element.addChild("span", cond);
if(inverted)
element.appendText(")");
element.appendText(")");
return element.toString;
}
override string toString() const {
return (inverted ? "!" : "") ~ cond;
}
}
void putSimplfiedReturnValue(MyOutputRange output, const FunctionDeclaration decl) {
if (decl.hasAuto && decl.hasRef)
output.putTag(`<span class="lang-feature">auto ref</span> `);
else {
if (decl.hasAuto)
output.putTag(`<span class="lang-feature">auto</span> `);
if (decl.hasRef)
output.putTag(`<span class="lang-feature">ref</span> `);
}
if (decl.returnType !is null)
output.putTag(toHtml(decl.returnType).source);
}
void putSimplfiedArgs(T)(MyOutputRange output, const T decl) {
// FIXME: do NOT show default values here
if(decl.parameters) {
output.putTag("(");
foreach(idx, p; decl.parameters.parameters) {
if(idx)
output.putTag(", ");
output.putTag(toText(p.type));
output.putTag(" ");
output.putTag(toText(p.name));
}
if(decl.parameters.hasVarargs) {
if(decl.parameters.parameters.length)
output.putTag(", ");
output.putTag("...");
}
output.putTag(")");
}
}
string specialPreprocess(string comment, Decl decl) {
switch(specialPreprocessor) {
case "dwt":
// translate Javadoc to adrdox
// @see, @exception/@throws, @param, @return
// @author, @version, @since, @deprecated
// {@link thing}
// one line desc is until the first <p>
// html tags are allowed in javadoc
// links go class#member(args)
// the (args) and class are optional
string parseIdentifier(ref string s, bool allowHash = false) {
int end = 0;
while(end < s.length && (
(s[end] >= 'A' && s[end] <= 'Z') ||
(s[end] >= 'a' && s[end] <= 'z') ||
(s[end] >= '0' && s[end] <= '9') ||
s[end] == '_' ||
s[end] == '.' ||
(allowHash && s[end] == '#')
))
{
end++;
}
auto i = s[0 .. end];
s = s[end .. $];
return i;
}
// javadoc is basically html with @ stuff, so start by parsing that (presumed) tag soup
auto document = new Document("<root>" ~ comment ~ "</root>");
string newComment;
string fixupJavaReference(string r) {
if(r.length == 0)
return r;
if(r[0] == '#')
r = r[1 .. $]; // local refs in adrdox need no special sigil
r = r.replace("#", ".");
auto idx = r.indexOf("(");
if(idx != -1)
r = r[0 .. idx];
return r;
}
void translate(Element element) {
if(element.nodeType == NodeType.Text) {
foreach(line; element.nodeValue.splitLines(KeepTerminator.yes)) {
auto s = line.strip;
if(s.length && s[0] == '@') {
s = s[1 .. $];
auto ident = parseIdentifier(s);
switch(ident) {
case "author":
case "deprecated":
case "version":
case "since":
line = ident ~ ": " ~ s ~ "\n";
break;
case "return":
case "returns":
line = "Returns: " ~ s ~ "\n";
break;
case "exception":
case "throws":
while(s.length && s[0] == ' ')
s = s[1 .. $];
auto p = parseIdentifier(s);
line = "Throws: [" ~ p ~ "]" ~ s ~ "\n";
break;
case "param":
while(s.length && s[0] == ' ')
s = s[1 .. $];
auto p = parseIdentifier(s);
line = "Params:\n" ~ p ~ " = " ~ s ~ "\n";
break;
case "see":
while(s.length && s[0] == ' ')
s = s[1 .. $];
auto p = parseIdentifier(s, true);
if(p.length)
line = "See_Also: [" ~ fixupJavaReference(p) ~ "]" ~ "\n";
else
line = "See_Also: " ~ s ~ "\n";
break;
default:
// idk, leave it alone.
}
}
newComment ~= line;
}
} else {
if(element.tagName == "code") {
newComment ~= "`";
// FIXME: what about ` inside code?
newComment ~= element.innerText; // .replace("`", "``");
newComment ~= "`";
} else if(element.tagName == "p") {