Skip to content

Commit

Permalink
Add getEponymousParentTemplate function
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrel committed Oct 15, 2014
1 parent cb188f6 commit b66c0a4
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions src/doc.c
Expand Up @@ -130,6 +130,14 @@ bool isCVariadicParameter(Dsymbol *s, const utf8_t *p, size_t len)
return tf && tf->varargs == 1 && cmp("...", p, len) == 0;
}

static TemplateDeclaration *getEponymousParentTemplate(Dsymbol *s)
{
if (!s->parent)
return NULL;
TemplateDeclaration *td = s->parent->isTemplateDeclaration();
return (td && td->onemember == s) ? td : NULL;
}

static const char ddoc_default[] = "\
DDOC = <html><head>\n\
<META http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n\
Expand Down Expand Up @@ -523,22 +531,21 @@ static bool emitAnchorName(OutBuffer *buf, Dsymbol *s, Scope *sc)
if (!s || s->isPackage() || s->isModule())
return false;

TemplateDeclaration *td;
bool dot = false;

// Add parent names first
bool dot = false;
if (s->parent)
dot = emitAnchorName(buf, s->parent, sc);
else if (sc)
dot = emitAnchorName(buf, sc->scopesym, skipNonQualScopes(sc->enclosing));

// Eponymous template members can share the parent anchor name
if (s->parent && (td = s->parent->isTemplateDeclaration()) != NULL &&
td->onemember == s)
if (getEponymousParentTemplate(s))
return dot;
if (dot)
buf->writeByte('.');

// Use "this" not "__ctor"
TemplateDeclaration *td;
if (s->isCtorDeclaration() || ((td = s->isTemplateDeclaration()) != NULL &&
td->onemember && td->onemember->isCtorDeclaration()))
{
Expand Down Expand Up @@ -649,13 +656,7 @@ void emitDitto(Dsymbol *s, Scope *sc)
/* If 'this' is a function template, then highlightCode() was
* already run by FuncDeclaration::toDocbuffer().
*/
TemplateDeclaration *td;
if (s->parent &&
(td = s->parent->isTemplateDeclaration()) != NULL &&
td->onemember == s)
{
}
else
if (!getEponymousParentTemplate(s))
highlightCode(sc, s, &b, o);
b.writeByte(')');
buf->spread(sc->lastoffset, b.offset);
Expand Down Expand Up @@ -1220,18 +1221,14 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
//printf("FuncDeclaration::toDocbuffer() %s\n", fd->toChars());
if (fd->ident)
{
TemplateDeclaration *td;
TemplateDeclaration *td = getEponymousParentTemplate(fd);

if (fd->parent &&
(td = fd->parent->isTemplateDeclaration()) != NULL &&
td->onemember == fd)
if (td)
{
/* It's a function template
*/
size_t o = buf->offset;

declarationToDocBuffer(fd, td);

highlightCode(sc, fd, buf, o);
}
else
Expand Down Expand Up @@ -1261,11 +1258,9 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
#if 0
emitProtection(buf, sd->protection);
#endif
TemplateDeclaration *td;
TemplateDeclaration *td = getEponymousParentTemplate(sd);

if (sd->parent &&
(td = sd->parent->isTemplateDeclaration()) != NULL &&
td->onemember == sd)
if (td)
{
size_t o = buf->offset;
toDocBuffer(td, buf, sc);
Expand All @@ -1287,11 +1282,9 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
#if 0
emitProtection(buf, cd->protection);
#endif
TemplateDeclaration *td;
TemplateDeclaration *td = getEponymousParentTemplate(cd);

if (cd->parent &&
(td = cd->parent->isTemplateDeclaration()) != NULL &&
td->onemember == cd)
if (td)
{
size_t o = buf->offset;
toDocBuffer(td, buf, sc);
Expand Down

0 comments on commit b66c0a4

Please sign in to comment.