Skip to content

Commit 97c394d

Browse files
authored
Merge pull request #177 from MartinNowak/fix177
ellipsis for typesafe variadic parameters not shown
2 parents 697399f + 66d1b03 commit 97c394d

File tree

21 files changed

+1251
-11
lines changed

21 files changed

+1251
-11
lines changed

source/ddox/api.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ void formatType(R)(ref R dst, CachedType type, scope string delegate(in Entity)
319319
dst.put(type._parameterDefaultValues[i].valueString.str);
320320
}
321321
}
322+
if (auto suffix = getVariadicSuffix(type))
323+
dst.highlightDCode(suffix);
322324
dst.highlightDCode(")");
323325
foreach (att; type.modifiers)
324326
dst.formattedWrite(" %s", att);
@@ -350,6 +352,19 @@ void formatType(R)(ref R dst, CachedType type, scope string delegate(in Entity)
350352
if (include_code_tags) dst.put("</code>");
351353
}
352354

355+
string getVariadicSuffix(Type type)
356+
{
357+
final switch (type.variadic) {
358+
case Type.Variadic.no:
359+
return null;
360+
case Type.Variadic.c:
361+
case Type.Variadic.d:
362+
return type.parameterTypes.length ? ", ..." : "...";
363+
case Type.Variadic.typesafe:
364+
return "...";
365+
}
366+
}
367+
353368
void renderTemplateArgs(R)(ref R output, Declaration decl, scope string delegate(in Entity) link_to)
354369
if (isOutputRange!(R, char))
355370
{

source/ddox/entities.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ struct Type {
612612
immutable(CachedType)[] parameterTypes;
613613
immutable(CachedString)[] _parameterNames;
614614
immutable(Value)[] _parameterDefaultValues;
615+
public import std.traits : Variadic;
616+
Variadic variadic;
615617

616618
static Type makePointer(CachedType base_type) { Type ret; ret.kind = TypeKind.Pointer; ret.elementType = base_type; return ret; }
617619
static Type makeArray(CachedType base_type) { Type ret; ret.kind = TypeKind.Array; ret.elementType = base_type; return ret; }

source/ddox/parsers/jsonparser.d

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,7 @@ private struct Parser
485485
size_t i = end;
486486

487487
string type_name, nested_name;
488-
if( i == 0 && tokens[0] == "..." ){
489-
type_name = "...";
490-
nested_name = null;
491-
} else if( i == 0 && tokens[0] == "(" ){
488+
if( i == 0 && tokens[0] == "(" ){
492489
type_name = "constructor";
493490
nested_name = null;
494491
} else {
@@ -610,20 +607,37 @@ private struct Parser
610607
if (tokens.front != "(") tokens.popFront();
611608
enforce(tokens.front == "(");
612609
tokens.popFront();
613-
if (!tokens.empty && tokens.front == ",") tokens.popFront(); // sometimes demangleType() returns something like "void(, ...)"
610+
// demangleType() returns something like "void(, ...)" for variadic functions or "void(, type)" for typeof(null) parameters
611+
if (!tokens.empty && tokens.front == ",") tokens.popFront();
612+
// (...) - D variadic function
613+
if (tokens.front == "...") {
614+
ftype.variadic = Type.Variadic.d;
615+
tokens.popFront();
616+
}
614617
while (true) {
615618
if (tokens.front == ")") break;
619+
620+
// (int) - parameter type
616621
enforce(!tokens.empty);
617622
ftype.parameterTypes ~= CachedType(parseTypeDecl(tokens, sc));
623+
624+
625+
// (int[]...), (Clazz...) - typesafe variadic function
626+
if (tokens.front == "...") {
627+
ftype.variadic = Type.Variadic.typesafe;
628+
tokens.popFront();
629+
}
630+
// (type, ...) - D or extern(C) variadic
631+
else if (tokens.length > 2 && tokens[0] == "," && tokens[1] == "...") {
632+
ftype.variadic = Type.Variadic.c; // c and d treated identical for doc-gen
633+
tokens.popFrontN(2);
634+
}
635+
618636
string pname;
619637
if (tokens.front != "," && tokens.front != ")") {
620638
pname = tokens.front;
621639
tokens.popFront();
622640
}
623-
if (tokens.front == "...") {
624-
pname ~= tokens.front;
625-
tokens.popFront();
626-
}
627641
ftype._parameterNames ~= CachedString(pname);
628642
if (tokens.front == "=") {
629643
tokens.popFront();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8"/>
5+
<title>API documentation</title>
6+
<link rel="stylesheet" type="text/css" href="./styles/ddox.css"/>
7+
<link rel="stylesheet" href="./prettify/prettify.css" type="text/css"/>
8+
<script type="text/javascript" src="./scripts/jquery.js">/**/</script><script type="text/javascript" src="./scripts/ddox.js">/**/</script>
9+
</head>
10+
<body onload="setupDdox();">
11+
<nav id="main-nav">
12+
<noscript>
13+
<p style="color: red">The search functionality needs JavaScript enabled</p>
14+
</noscript>
15+
<div id="symbolSearchPane" style="display: none">
16+
<form action="#" method="GET">
17+
<input id="symbolSearch" type="text" name="q" placeholder="Search for symbols" autocomplete="off" onchange="performSymbolSearch(40);" onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();"/>
18+
</form>
19+
<ul id="symbolSearchResults" class="symbolList" style="display: none"></ul><script type="application/javascript" src="./symbols.js"></script><script type="application/javascript">var symbolSearchRootDir = "./";
20+
$('#symbolSearchPane').show();</script>
21+
</div>
22+
<ul class="tree-view">
23+
<li>
24+
<div class="module ">
25+
<a href="./test.html">test</a>
26+
</div>
27+
</li>
28+
</ul>
29+
</nav>
30+
<div id="main-contents">
31+
<h1>API documentation</h1>
32+
<table>
33+
<col class="caption"/>
34+
<tr>
35+
<th>Module</th><th>Description</th>
36+
</tr>
37+
<tr>
38+
<td>
39+
<a href="./test.html">test</a>
40+
</td>
41+
<td>
42+
43+
</td>
44+
</tr>
45+
</table>
46+
<footer>
47+
<p class="faint">Generated using the DDOX documentation generator</p>
48+
</footer>
49+
</div>
50+
</body>
51+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3+
<url><loc>http://127.0.0.1/index.html</loc></url>
4+
<url><loc>http://127.0.0.1/test.html</loc></url>
5+
<url><loc>http://127.0.0.1/test/bug.html</loc></url>
6+
<url><loc>http://127.0.0.1/test/bug.html</loc></url>
7+
<url><loc>http://127.0.0.1/test/bug.html</loc></url>
8+
<url><loc>http://127.0.0.1/test/bug.html</loc></url>
9+
<url><loc>http://127.0.0.1/test/bug.html</loc></url>
10+
<url><loc>http://127.0.0.1/test/C.html</loc></url>
11+
<url><loc>http://127.0.0.1/test/FT1.html</loc></url>
12+
<url><loc>http://127.0.0.1/test/FT2.html</loc></url>
13+
<url><loc>http://127.0.0.1/test/FT3.html</loc></url>
14+
<url><loc>http://127.0.0.1/test/FT4.html</loc></url>
15+
<url><loc>http://127.0.0.1/test/FT5.html</loc></url>
16+
<url><loc>http://127.0.0.1/test/var1.html</loc></url>
17+
<url><loc>http://127.0.0.1/test/var2.html</loc></url>
18+
<url><loc>http://127.0.0.1/test/var3.html</loc></url>
19+
<url><loc>http://127.0.0.1/test/var4.html</loc></url>
20+
<url><loc>http://127.0.0.1/test/var5.html</loc></url>
21+
</urlset>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// symbol index generated by DDOX - do not edit
2+
var symbols = [
3+
{name: 'test', kind: "module", path: './test.html', attributes: []},
4+
{name: 'test.bug', kind: "functiondeclaration", path: './test/bug.html', attributes: []},
5+
{name: 'test.C', kind: "classdeclaration", path: './test/C.html', attributes: []},
6+
{name: 'test.FT1', kind: "aliasdeclaration", path: './test/FT1.html', attributes: []},
7+
{name: 'test.FT2', kind: "aliasdeclaration", path: './test/FT2.html', attributes: []},
8+
{name: 'test.FT3', kind: "aliasdeclaration", path: './test/FT3.html', attributes: []},
9+
{name: 'test.FT4', kind: "aliasdeclaration", path: './test/FT4.html', attributes: []},
10+
{name: 'test.FT5', kind: "aliasdeclaration", path: './test/FT5.html', attributes: []},
11+
{name: 'test.var1', kind: "variabledeclaration", path: './test/var1.html', attributes: []},
12+
{name: 'test.var2', kind: "variabledeclaration", path: './test/var2.html', attributes: []},
13+
{name: 'test.var3', kind: "variabledeclaration", path: './test/var3.html', attributes: []},
14+
{name: 'test.var4', kind: "variabledeclaration", path: './test/var4.html', attributes: []},
15+
{name: 'test.var5', kind: "variabledeclaration", path: './test/var5.html', attributes: ["extern(C)"]},
16+
];

0 commit comments

Comments
 (0)