Skip to content

Commit

Permalink
Simplify documented unittests handling by using DocComment::a
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed May 17, 2015
1 parent 335b964 commit 47efe28
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
94 changes: 47 additions & 47 deletions src/doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct DocComment
static void parseEscapes(Escape **pescapetable, const utf8_t *textstart, size_t textlen);

void parseSections(const utf8_t *comment);
void writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf);
void writeSections(Scope *sc, Dsymbols *a, OutBuffer *buf);
};


Expand Down Expand Up @@ -350,7 +350,9 @@ void gendocfile(Module *m)
}
else
{
dc->writeSections(sc, m, &buf);
Dsymbols a;
a.push(m);
dc->writeSections(sc, &a, &buf);
emitMemberComments(m, &buf, sc);
}

Expand Down Expand Up @@ -621,42 +623,6 @@ static size_t getCodeIndent(const char *src)
return codeIndent;
}

void emitUnittestComment(OutBuffer *buf, Scope *sc, Dsymbol *s, size_t ofs)
{
if (Dsymbol *td = getEponymousParent(s))
s = td;

for (UnitTestDeclaration *utd = s->ddocUnittest; utd; utd = utd->ddocUnittest)
{
if (utd->protection.kind == PROTprivate || !utd->comment || !utd->fbody)
continue;

// Strip whitespaces to avoid showing empty summary
const utf8_t *c = utd->comment;
while (*c == ' ' || *c == '\t' || *c == '\n' || *c == '\r') ++c;

OutBuffer codebuf;
codebuf.writestring("$(DDOC_EXAMPLES ");
size_t o = codebuf.offset;
codebuf.writestring((char *)c);

if (utd->codedoc)
{
size_t i = getCodeIndent(utd->codedoc);
while (i--) codebuf.writeByte(' ');
codebuf.writestring("----\n");
codebuf.writestring(utd->codedoc);
codebuf.writestring("----\n");
highlightText(sc, s, &codebuf, o);
}

codebuf.writestring(")");
buf->insert(ofs, codebuf.data, codebuf.offset);
ofs += codebuf.offset;
sc->lastoffset2 = ofs;
}
}

/** Recursively expand template mixin member docs into the scope. */
static void expandTemplateMixinComments(TemplateMixin *tm, OutBuffer *buf, Scope *sc)
{
Expand Down Expand Up @@ -797,9 +763,8 @@ void emitComment(Dsymbol *s, OutBuffer *buf, Scope *sc)
// Put the ddoc comment as the document 'description'
buf->writestring(ddoc_decl_dd_s);
{
Dsymbol *sx = dc->a[0];
dc->writeSections(sc, sx, buf);
if (ScopeDsymbol *sds = sx->isScopeDsymbol())
dc->writeSections(sc, &dc->a, buf);
if (ScopeDsymbol *sds = dc->a[0]->isScopeDsymbol())
emitMemberComments(sds, buf, sc);
}
buf->writestring(ddoc_decl_dd_e);
Expand Down Expand Up @@ -1450,11 +1415,13 @@ void DocComment::parseSections(const utf8_t *comment)
}
}

void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
void DocComment::writeSections(Scope *sc, Dsymbols *a, OutBuffer *buf)
{
assert(a->dim);

//printf("DocComment::writeSections()\n");
Loc loc = s->loc;
if (Module *m = s->isModule())
Loc loc = (*a)[0]->loc;
if (Module *m = (*a)[0]->isModule())
{
if (m->md)
loc = m->md->loc;
Expand All @@ -1477,13 +1444,46 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
size_t o = buf->offset;
buf->write(sec->body, sec->bodylen);
escapeStrayParenthesis(loc, buf, o);
highlightText(sc, s, buf, o);
highlightText(sc, (*a)[0], buf, o);
buf->writestring(")\n");
}
else
sec->write(loc, this, sc, s, buf);
sec->write(loc, this, sc, (*a)[0], buf);
}

for (size_t i = 0; i < a->dim; i++)
{
Dsymbol *s = (*a)[i];
if (Dsymbol *td = getEponymousParent(s))
s = td;

for (UnitTestDeclaration *utd = s->ddocUnittest; utd; utd = utd->ddocUnittest)
{
if (utd->protection.kind == PROTprivate || !utd->comment || !utd->fbody)
continue;

// Strip whitespaces to avoid showing empty summary
const utf8_t *c = utd->comment;
while (*c == ' ' || *c == '\t' || *c == '\n' || *c == '\r') ++c;

buf->writestring("$(DDOC_EXAMPLES ");

size_t o = buf->offset;
buf->writestring((char *)c);

if (utd->codedoc)
{
size_t n = getCodeIndent(utd->codedoc);
while (n--) buf->writeByte(' ');
buf->writestring("----\n");
buf->writestring(utd->codedoc);
buf->writestring("----\n");
highlightText(sc, (*a)[0], buf, o);
}

buf->writestring(")");
}
}
emitUnittestComment(buf, sc, s, buf->offset);

if (buf->offset == offset2)
{
Expand Down
1 change: 0 additions & 1 deletion src/magicport.json
Original file line number Diff line number Diff line change
Expand Up @@ -2978,7 +2978,6 @@
"function emitAnchorName",
"function emitAnchor",
"function getCodeIndent",
"function emitUnittestComment",
"function expandTemplateMixinComments",
"function emitMemberComments",
"function emitProtection",
Expand Down
4 changes: 2 additions & 2 deletions test/compilable/extra-files/ddocunittest.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ <h1>ddocunittest</h1>
</big></dt>
<dd>test for bugzilla 9757<br><br>
<b>Examples:</b><br>
<pre class="d_code">foo9757(); bar9757();
<pre class="d_code"><u>foo9757</u>(); bar9757();
</pre>
<br><br><b>Examples:</b><br>
<pre class="d_code">bar9757(); foo9757();
<pre class="d_code">bar9757(); <u>foo9757</u>();
</pre>
<br><br>
</dd>
Expand Down

0 comments on commit 47efe28

Please sign in to comment.