Skip to content

Commit

Permalink
Merge pull request dlang#1481 from 9rnsr/fix9305
Browse files Browse the repository at this point in the history
Issue 9305 - Ugly Ddoc for default template lambda expressions
  • Loading branch information
WalterBright committed Jan 14, 2013
2 parents e97e886 + 2d6db80 commit 67ffded
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/func.c
Expand Up @@ -3442,10 +3442,27 @@ const char *FuncLiteralDeclaration::kind()

void FuncLiteralDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring(kind());
buf->writeByte(' ');
type->toCBuffer(buf, NULL, hgs);
bodyToCBuffer(buf, hgs);
if (tok != TOKreserved)
{
buf->writestring(kind());
buf->writeByte(' ');
}

TypeFunction *tf = (TypeFunction *)type;
// Don't print tf->mod, tf->trust, and tf->linkage
if (tf->next)
tf->next->toCBuffer2(buf, hgs, 0);
Parameter::argsToCBuffer(buf, hgs, tf->parameters, tf->varargs);

ReturnStatement *ret = !fbody->isCompoundStatement() ?
fbody->isReturnStatement() : NULL;
if (ret && ret->exp)
{
buf->writestring(" => ");
ret->exp->toCBuffer(buf, hgs);
}
else
bodyToCBuffer(buf, hgs);
}


Expand Down
7 changes: 7 additions & 0 deletions src/mtype.c
Expand Up @@ -9384,6 +9384,13 @@ void Parameter::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Parameters *argu
{ if (arg->ident)
argbuf.writestring(arg->ident->toChars());
}
else if (arg->type->ty == Tident &&
((TypeIdentifier *)arg->type)->ident->len > 3 &&
strncmp(((TypeIdentifier *)arg->type)->ident->string, "__T", 3) == 0)
{
// print parameter name, instead of undetermined type parameter
argbuf.writestring(arg->ident->toChars());
}
else
arg->type->toCBuffer(&argbuf, arg->ident, hgs);
if (arg->defaultArg)
Expand Down
38 changes: 38 additions & 0 deletions test/compilable/ddoc9305.d
@@ -0,0 +1,38 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Ddtest_results/compilable -o-
// POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 9305

module ddoc9305;

/**
foo()
*/
void foo(alias p = (a => a))() {}

/* ret / prm / body */
/* _ / _ / expr */ template X(alias pred = x => x) {} ///
/* _ / _ / stmt */ template X(alias pred = (x){ int y; return y; }) {} /// ditto
/* _ / x / expr */ template X(alias pred = (int x) => x) {} /// ditto
/* _ / x / stmt */ template X(alias pred = (int x){ int y; return y; }) {} /// ditto
/* x / _ / expr */
/* x / _ / stmt */
/* x / x / expr */
/* x / x / stmt */

/* _ / _ / expr */ template X(alias pred = function (x) => x) {} ///
/* _ / _ / stmt */ template X(alias pred = function (x){ return x + 1; }) {} /// ditto
/* _ / x / expr */ template X(alias pred = function (int x) => x) {} /// ditto
/* _ / x / stmt */ template X(alias pred = function (int x){ return x + 1; }) {} /// ditto
/* x / _ / expr */ template X(alias pred = function int(x) => x) {} /// ditto
/* x / _ / stmt */ template X(alias pred = function int(x){ return x + 1; }) {} /// ditto
/* x / x / expr */ template X(alias pred = function int(int x) => x) {} /// ditto
/* x / x / stmt */ template X(alias pred = function int(int x){ return x + 1; }) {} /// ditto

/* _ / _ / expr */ template X(alias pred = delegate (x) => x) {} ///
/* _ / _ / stmt */ template X(alias pred = delegate (x){ return x + 1; }) {} /// ditto
/* _ / x / expr */ template X(alias pred = delegate (int x) => x) {} /// ditto
/* _ / x / stmt */ template X(alias pred = delegate (int x){ return x + 1; }) {} /// ditto
/* x / _ / expr */ template X(alias pred = delegate int(x) => x) {} /// ditto
/* x / _ / stmt */ template X(alias pred = delegate int(x){ return x + 1; }) {} /// ditto
/* x / x / expr */ template X(alias pred = delegate int(int x) => x) {} /// ditto
/* x / x / stmt */ template X(alias pred = delegate int(int x){ return x + 1; }) {} /// ditto
66 changes: 66 additions & 0 deletions test/compilable/extra-files/ddoc9305.html
@@ -0,0 +1,66 @@
<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>ddoc9305</title>
</head><body>
<h1>ddoc9305</h1>
<br><br>
<dl><dt><big><a name="foo"></a>void <u>foo</u>(alias p = (a) =&gt; a)();
</big></dt>
<dd><u>foo</u>()<br><br>

</dd>
<dt><big><a name="X"></a>template <u>X</u>(alias pred = (x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = (x)
{
int y;
return y;
}
)<br><a name="X"></a>template <u>X</u>(alias pred = (int x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = (int x)
{
int y;
return y;
}
)</big></dt>
<dd><br><br>
</dd>
<dt><big><a name="X"></a>template <u>X</u>(alias pred = function (x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = function (x)
{
return x + 1;
}
)<br><a name="X"></a>template <u>X</u>(alias pred = function (int x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = function (int x)
{
return x + 1;
}
)<br><a name="X"></a>template <u>X</u>(alias pred = function int(x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = function int(x)
{
return x + 1;
}
)<br><a name="X"></a>template <u>X</u>(alias pred = function int(int x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = function int(int x)
{
return x + 1;
}
)</big></dt>
<dd><br><br>
</dd>
<dt><big><a name="X"></a>template <u>X</u>(alias pred = delegate (x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = delegate (x)
{
return x + 1;
}
)<br><a name="X"></a>template <u>X</u>(alias pred = delegate (int x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = delegate (int x)
{
return x + 1;
}
)<br><a name="X"></a>template <u>X</u>(alias pred = delegate int(x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = delegate int(x)
{
return x + 1;
}
)<br><a name="X"></a>template <u>X</u>(alias pred = delegate int(int x) =&gt; x)<br><a name="X"></a>template <u>X</u>(alias pred = delegate int(int x)
{
return x + 1;
}
)</big></dt>
<dd><br><br>
</dd>
</dl>

<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small>
</body></html>

0 comments on commit 67ffded

Please sign in to comment.