Skip to content

Commit

Permalink
Issue 14633: Fixed false DDoc warnings (check parent template decl)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionello committed May 31, 2016
1 parent 3563530 commit 122bcfa
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 8 deletions.
85 changes: 77 additions & 8 deletions src/doc.d
Expand Up @@ -221,6 +221,12 @@ public:
{
size_t o = buf.offset;
Parameter fparam = isFunctionParameter(a, namestart, namelen);
if (!fparam)
{
// Comments on a template might refer to function parameters within.
// Search the parameters of nested eponymous functions (with the same name.)
fparam = isEponymousFunctionParameter(a, namestart, namelen);
}
bool isCVariadic = isCVariadicParameter(a, namestart, namelen);
if (isCVariadic)
{
Expand Down Expand Up @@ -1002,8 +1008,8 @@ extern (C++) void emitComment(Dsymbol s, OutBuffer* buf, Scope* sc)

override void visit(Declaration d)
{
//printf("Declaration::emitComment(%p '%s'), comment = '%s'\n", d, d->toChars(), d->comment);
//printf("type = %p\n", d->type);
//printf("Declaration::emitComment(%p '%s'), comment = '%s'\n", d, d.toChars(), d.comment);
//printf("type = %p\n", d.type);
const(char)* com = d.comment;
if (TemplateDeclaration td = getEponymousParent(d))
{
Expand Down Expand Up @@ -2058,23 +2064,83 @@ extern (C++) TypeFunction isTypeFunction(Dsymbol s)
return null;
}

/****************************************************
*/
private Parameter isFunctionParameter(Dsymbol s, const(char)* p, size_t len)
{
TypeFunction tf = isTypeFunction(s);
if (tf && tf.parameters)
{
for (size_t k = 0; k < tf.parameters.dim; k++)
{
Parameter fparam = (*tf.parameters)[k];
if (fparam.ident && cmp(fparam.ident.toChars(), p, len) == 0)
{
return fparam;
}
}
}
return null;
}

/****************************************************
*/
extern (C++) Parameter isFunctionParameter(Dsymbols* a, const(char)* p, size_t len)
{
for (size_t i = 0; i < a.dim; i++)
{
TypeFunction tf = isTypeFunction((*a)[i]);
if (tf && tf.parameters)
Parameter fparam = isFunctionParameter((*a)[i], p, len);
if (fparam)
{
return fparam;
}
}
return null;
}

/****************************************************
*/
private Parameter isEponymousFunctionParameter(Dsymbols *a, const(char) *p, size_t len)
{
for (size_t i = 0; i < a.dim; i++)
{
TemplateDeclaration td = (*a)[i].isTemplateDeclaration();
if (td && td.onemember)
{
/* Case 1: we refer to a template declaration inside the template
/// ...ddoc...
template case1(T) {
void case1(R)() {}
}
*/
td = td.onemember.isTemplateDeclaration();
}
if (!td)
{
/* Case 2: we're an alias to a template declaration
/// ...ddoc...
alias case2 = case1!int;
*/
AliasDeclaration ad = (*a)[i].isAliasDeclaration();
if (ad && ad.aliassym)
{
td = ad.aliassym.isTemplateDeclaration();
}
}
while (td)
{
for (size_t k = 0; k < tf.parameters.dim; k++)
Dsymbol sym = getEponymousMember(td);
if (sym)
{
Parameter fparam = (*tf.parameters)[k];
if (fparam.ident && cmp(fparam.ident.toChars(), p, len) == 0)
Parameter fparam = isFunctionParameter(sym, p, len);
if (fparam)
{
return fparam;
}
}
td = td.overnext;
}
}
return null;
Expand All @@ -2086,7 +2152,10 @@ extern (C++) TemplateParameter isTemplateParameter(Dsymbols* a, const(char)* p,
{
for (size_t i = 0; i < a.dim; i++)
{
TemplateDeclaration td = getEponymousParent((*a)[i]);
TemplateDeclaration td = (*a)[i].isTemplateDeclaration();
// Check for the parent, if the current symbol is not a template declaration.
if (!td)
td = getEponymousParent((*a)[i]);
if (td && td.origParameters)
{
for (size_t k = 0; k < td.origParameters.dim; k++)
Expand Down
23 changes: 23 additions & 0 deletions test/compilable/ddoc14633.d
@@ -0,0 +1,23 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -w -o-

/*
TEST_OUTPUT:
---
---
*/

/** Blah
Params:
T = some type
test = something
overnext = for testing overloaded functions
*/
template case1(T)
{
void case1(R)(R test) { }
void case1(R)(R test, string overnext) { }
}

///ditto
alias case2 = case1!int;

0 comments on commit 122bcfa

Please sign in to comment.