Skip to content

Commit

Permalink
Merge pull request #3254 from 9rnsr/fix7555
Browse files Browse the repository at this point in the history
Issue 7555 - ddoc whitespace issues due to version tags
  • Loading branch information
yebblies committed Feb 14, 2014
2 parents db477ee + e55695e commit e1b18fd
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 46 deletions.
23 changes: 12 additions & 11 deletions src/doc.c
Expand Up @@ -559,7 +559,7 @@ void emitUnittestComment(Scope *sc, Dsymbol *s, size_t ofs)
while (*c == ' ' || *c == '\t' || *c == '\n' || *c == '\r') ++c;

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

Expand Down Expand Up @@ -625,18 +625,18 @@ void ScopeDsymbol::emitMemberComments(Scope *sc)
OutBuffer *buf = sc->docbuf;

if (members)
{ const char *m = "$(DDOC_MEMBERS \n";

{
const char *m = "$(DDOC_MEMBERS ";
if (isModule())
m = "$(DDOC_MODULE_MEMBERS \n";
m = "$(DDOC_MODULE_MEMBERS ";
else if (isClassDeclaration())
m = "$(DDOC_CLASS_MEMBERS \n";
m = "$(DDOC_CLASS_MEMBERS ";
else if (isStructDeclaration())
m = "$(DDOC_STRUCT_MEMBERS \n";
m = "$(DDOC_STRUCT_MEMBERS ";
else if (isEnumDeclaration())
m = "$(DDOC_ENUM_MEMBERS \n";
m = "$(DDOC_ENUM_MEMBERS ";
else if (isTemplateDeclaration())
m = "$(DDOC_TEMPLATE_MEMBERS \n";
m = "$(DDOC_TEMPLATE_MEMBERS ";

size_t offset1 = buf->offset; // save starting offset
buf->writestring(m);
Expand Down Expand Up @@ -1365,7 +1365,7 @@ void DocComment::writeSections(Scope *sc, Dsymbol *s, OutBuffer *buf)
//printf("DocComment::writeSections()\n");
if (sections.dim || s->ddocUnittest)
{
buf->writestring("$(DDOC_SECTIONS \n");
buf->writestring("$(DDOC_SECTIONS ");
for (size_t i = 0; i < sections.dim; i++)
{ Section *sec = sections[i];

Expand Down Expand Up @@ -1461,7 +1461,7 @@ void ParamSection::write(DocComment *dc, Scope *sc, Dsymbol *s, OutBuffer *buf)
size_t o, paramcount = 0;
Parameter *arg;

buf->writestring("$(DDOC_PARAMS \n");
buf->writestring("$(DDOC_PARAMS ");
while (p < pend)
{
// Skip to start of macro
Expand Down Expand Up @@ -2262,7 +2262,8 @@ void highlightText(Scope *sc, Dsymbol *s, OutBuffer *buf, size_t offset)
i -= 2; // in next loop, c should be '\n'
}
else
{ static const char pre[] = "$(D_CODE \n";
{
static const char pre[] = "$(D_CODE ";

inCode = 1;
codeIndent = istart - iLineStart; // save indent count
Expand Down
59 changes: 50 additions & 9 deletions src/lexer.c
Expand Up @@ -2504,6 +2504,30 @@ void Lexer::getDocComment(Token *t, unsigned lineComment)
break;
}

/* Remove leading spaces until start of the comment
*/
int linestart = 0;
if (ct == '/')
{
while (q < qend && (*q == ' ' || *q == '\t'))
++q;
}
else if (q < qend)
{
if (*q == '\r')
{
++q;
if (q < qend && *q == '\n')
++q;
linestart = 1;
}
else if (*q == '\n')
{
++q;
linestart = 1;
}
}

/* Remove trailing row of ****'s or ++++'s
*/
if (ct != '/')
Expand All @@ -2519,7 +2543,6 @@ void Lexer::getDocComment(Token *t, unsigned lineComment)
* Canonicalize it into buf[].
*/
OutBuffer buf;
int linestart = 0;

for (; q < qend; q++)
{
Expand Down Expand Up @@ -2577,6 +2600,14 @@ void Lexer::getDocComment(Token *t, unsigned lineComment)
buf.writeByte(c);
}

/* Trim trailing whitespace (if the last line does not have newline)
*/
if (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
{
while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
buf.offset--;
}

// Always end with a newline
if (!buf.offset || buf.data[buf.offset - 1] != '\n')
buf.writeByte('\n');
Expand Down Expand Up @@ -2608,19 +2639,29 @@ const utf8_t *Lexer::combineComments(const utf8_t *c1, const utf8_t *c2)
const utf8_t *c = c2;

if (c1)
{ c = c1;
{
c = c1;
if (c2)
{ size_t len1 = strlen((char *)c1);
{
size_t len1 = strlen((char *)c1);
size_t len2 = strlen((char *)c2);

utf8_t *p = (utf8_t *)mem.malloc(len1 + 1 + len2 + 1);
memcpy(p, c1, len1);
int insertNewLine = 0;
if (len1 && c1[len1 - 1] != '\n')
{ p[len1] = '\n';
len1++;
{
++len1;
insertNewLine = 1;
}
memcpy(p + len1, c2, len2);
p[len1 + len2] = 0;

utf8_t *p = (utf8_t *)mem.malloc(len1 + 1 + len2 + 1);
memcpy(p, c1, len1 - insertNewLine);
if (insertNewLine)
p[len1 - 1] = '\n';

p[len1] = '\n';

memcpy(p + len1 + 1, c2, len2);
p[len1 + 1 + len2] = 0;
c = p;
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/macro.c
Expand Up @@ -120,7 +120,7 @@ size_t extractArgN(const utf8_t *p, size_t end, const utf8_t **pmarg, size_t *pm
Largstart:
#if 1
// Skip first space, if any, to find the start of the macro argument
if (v < end && isspace(p[v]))
if (n != 1 && v < end && isspace(p[v]))
v++;
#else
// Skip past spaces to find the start of the macro argument
Expand Down Expand Up @@ -278,7 +278,13 @@ void Macro::expand(OutBuffer *buf, size_t start, size_t *pend,

const utf8_t *marg;
size_t marglen;
extractArgN(arg, arglen, &marg, &marglen, n);
if (n == 0)
{
marg = arg;
marglen = arglen;
}
else
extractArgN(arg, arglen, &marg, &marglen, n);
if (marglen == 0)
{ // Just remove macro invocation
//printf("Replacing '$%c' with '%.*s'\n", p[u + 1], marglen, marg);
Expand Down
53 changes: 53 additions & 0 deletions test/compilable/ddoc7555.d
@@ -0,0 +1,53 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o-
// POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 7555
module ddoc7555;

/**
Dummy doc.
$(X0
DelimitedString
TokenString)
$(X1
DelimitedString
TokenString)
$(X2 x,HexString)
$(X2 x, HexString)
$(X3 x,x,HexString)
$(X3 x,x, HexString)
$(X4 x,x,x,HexString)
$(X4 x,x,x, HexString)
$(X5 x,x,x,x,HexString)
$(X5 x,x,x,x, HexString)
$(X6 x,x,x,x,x,HexString)
$(X6 x,x,x,x,x, HexString)
$(X7 x,x,x,x,x,x,HexString)
$(X7 x,x,x,x,x,x, HexString)
$(X8 x,x,x,x,x,x,x,HexString)
$(X8 x,x,x,x,x,x,x, HexString)
$(X9 x,x,x,x,x,x,x,x,HexString)
$(X9 x,x,x,x,x,x,x,x, HexString)
Macros:
X0=$0
X1=$1
X2=$2
X3=$3
X4=$4
X5=$5
X6=$6
X7=$7
X8=$8
X9=$9
*/
void dummy();
6 changes: 3 additions & 3 deletions test/compilable/extra-files/ddoc1.html
Expand Up @@ -15,7 +15,7 @@ <h1>abc</h1>
<dd>windy
city
<br><br>
paragraph 2 about of F
paragraph 2 about of F
<pre class="d_code">#include &lt;stdio.h&gt;
<font color=blue>void</font> main()
{
Expand Down Expand Up @@ -72,7 +72,7 @@ <h1>abc</h1>
</dd>
<dt><big><a name="Bar"></a>class <u>Bar</u>;
</big></dt>
<dd>The Class <u>Bar</u> <br><br>
<dd>The Class <u>Bar</u><br><br>

<dl><dt><big><a name="Bar.x"></a>int <u>x</u>;
</big></dt>
Expand All @@ -93,7 +93,7 @@ <h1>abc</h1>
</dd>
<dt><big><a name="Easy"></a>enum <u>Easy</u>: int;
</big></dt>
<dd>The Enum <u>Easy</u> <br><br>
<dd>The Enum <u>Easy</u><br><br>

<dl><dt><big><a name="Easy.red"></a><u>red</u></big></dt>
<dd>the Red<br><br>
Expand Down
17 changes: 9 additions & 8 deletions test/compilable/extra-files/ddoc10.html
Expand Up @@ -14,14 +14,14 @@ <h1>ddoc10</h1>
</big></dt>
<dd>This basic case doesn't work very well. The template signature is
documented twice, but the function signature (argument names and return
type) is not documented at all. This comment is also repeated twice. <br><br>
type) is not documented at all. This comment is also repeated twice.<br><br>

</dd>
<dt><big><a name="func2"></a>int <u>func2</u>(T, U)(T <i>x</i>, U <i>y</i>);
<br><a name="func2"></a>int <u>func2</u>(T)(T <i>x</i>);
</big></dt>
<dd>This comment is also repeated twice, and the second function signature is
not very well documented. <br><br>
not very well documented.<br><br>

</dd>
<dt><big><a name="func3"></a>int <u>func3</u>(T, U)(T <i>x</i>, U <i>y</i>);
Expand Down Expand Up @@ -60,29 +60,30 @@ <h1>ddoc10</h1>
</dd>
<dt><big><a name="bar6"></a>struct <u>bar6</u>;
</big></dt>
<dd>blah <br><br>
<dd>blah<br><br>

</dd>
<dt><big><a name="Foo7"></a>struct <u>Foo7</u>(T);
</big></dt>
<dd>template bodies <br><br>
<dd>template bodies<br><br>

<dl><dt><big><a name="bar"></a>void <u>bar</u>();
</big></dt>
<dd>Attempt two: Inside.
<br><br>
Attempt one: Doc outside static if.<br><br>

</dd>
<dt><big><a name="abc"></a>void <u>abc</u>();
</big></dt>
<dd>the <u>abc</u> function should be static <br><br>
<dd>the <u>abc</u> function should be static<br><br>

</dd>
</dl>
</dd>
<dt><big><a name="Foo8"></a>abstract class <u>Foo8</u>;
</big></dt>
<dd>show abstract <br><br>
<dd>show abstract<br><br>

</dd>
<dt><big><a name="bug4878"></a>void <u>bug4878</u>(string <i>a</i> = ")");
Expand All @@ -105,12 +106,12 @@ <h1>ddoc10</h1>
</dd>
<dt><big><a name="f10"></a>float <u>f10</u>(float <i>a</i>, float <i>b</i>);
</big></dt>
<dd>Produces something in (<i>a</i>;<i>b</i>] <br><br>
<dd>Produces something in (<i>a</i>;<i>b</i>]<br><br>

</dd>
<dt><big><a name="h10"></a>float <u>h10</u>(float <i>a</i>, float <i>b</i>);
</big></dt>
<dd>Produces something in [<i>a</i>;<i>b</i>) <br><br>
<dd>Produces something in [<i>a</i>;<i>b</i>)<br><br>

</dd>
<dt><big><a name="bug6090"></a>void <u>bug6090</u>(string f = "$(B b)", char g = ')')(string <i>h</i> = "$(", string <i>i</i> = "$)");
Expand Down
2 changes: 1 addition & 1 deletion test/compilable/extra-files/ddoc2.html
Expand Up @@ -40,7 +40,7 @@ <h1>std.test</h1>
</dd>
<dt><big><a name="StreamException.stars"></a>int <u>stars</u>;
</big></dt>
<dd><u>stars</u> <br><br>
<dd><u>stars</u><br><br>

</dd>
</dl>
Expand Down
7 changes: 3 additions & 4 deletions test/compilable/extra-files/ddoc3.html
Expand Up @@ -24,18 +24,17 @@ <h1>std.test</h1>
'arg1' : arg1. <br>
'arg2' : arg2. <br>
'arg3' : arg3. <br>

<br><br>

Things to see also world.
<br><br>

<table><tr><td>1</td> <td>2</td> <td>3</td> </tr>
<table> <tr><td>1</td> <td>2</td> <td>3</td> </tr>
<tr><td>4</td> <td>5</td> <td>6</td> </tr>
</table>
<br><br>

<pre class="d_code"> <b>pragma</b>( <i>name</i> );
<pre class="d_code"> <b>pragma</b>( <i>name</i> );
<b>pragma</b>( <i>name</i> , <i>option</i> [ <i>option</i> ] );
<u>(</u>
</pre><br><br>
Expand All @@ -60,7 +59,7 @@ <h1>std.test</h1>
</dd>
<dt><big><a name="StreamException.stars"></a>int <u>stars</u>;
</big></dt>
<dd><u>stars</u> <br><br>
<dd><u>stars</u><br><br>

</dd>
</dl>
Expand Down

0 comments on commit e1b18fd

Please sign in to comment.