Skip to content

Commit

Permalink
Use "try write sections, back out if nothing exists" method in DocCom…
Browse files Browse the repository at this point in the history
…ment::writeSection
  • Loading branch information
9rnsr committed May 12, 2015
1 parent 17023b1 commit 65a4990
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions src/doc.c
Expand Up @@ -1528,37 +1528,44 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
loc = m->md->loc;
}

if (sections.dim || s->ddocUnittest)
size_t offset1 = buf->offset;
buf->writestring("$(DDOC_SECTIONS ");
size_t offset2 = buf->offset;

for (size_t i = 0; i < sections.dim; i++)
{
buf->writestring("$(DDOC_SECTIONS ");
for (size_t i = 0; i < sections.dim; i++)
{
Section *sec = sections[i];
Section *sec = sections[i];
if (sec->nooutput)
continue;

if (sec->nooutput)
continue;
//printf("Section: '%.*s' = '%.*s'\n", sec->namelen, sec->name, sec->bodylen, sec->body);
if (sec->namelen || i)
sec->write(loc, this, sc, s, buf);
else
{
buf->writestring("$(DDOC_SUMMARY ");
size_t o = buf->offset;
buf->write(sec->body, sec->bodylen);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, s, buf, o);
buf->writestring(")\n");
}
//printf("Section: '%.*s' = '%.*s'\n", sec->namelen, sec->name, sec->bodylen, sec->body);
if (!sec->namelen && i == 0)
{
buf->writestring("$(DDOC_SUMMARY ");
size_t o = buf->offset;
buf->write(sec->body, sec->bodylen);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, s, buf, o);
buf->writestring(")\n");
}
if (s->ddocUnittest)
emitUnittestComment(sc, s, buf->offset);
sc->lastoffset2 = buf->offset;
buf->writestring(")\n");
else
sec->write(loc, this, sc, s, buf);
}
else
if (s->ddocUnittest)
emitUnittestComment(sc, s, buf->offset);

if (buf->offset == offset2)
{
/* Didn't write out any sections, so back out last write
*/
buf->offset = offset1;
buf->writestring("$(DDOC_BLANKLINE)\n");
}
else
{
sc->lastoffset2 = buf->offset;
buf->writestring(")\n");
}
}

/***************************************************
Expand Down

0 comments on commit 65a4990

Please sign in to comment.