From dfdbfcd7f80e2e22a2b040ce530db32edb6fd58d Mon Sep 17 00:00:00 2001 From: k-hara Date: Thu, 13 Feb 2014 23:09:50 +0900 Subject: [PATCH 1/2] Tweak white spaces surrounding ddoc comments --- src/lexer.c | 59 ++++++++++++++++--- test/compilable/extra-files/ddoc1.html | 4 +- test/compilable/extra-files/ddoc10.html | 17 +++--- test/compilable/extra-files/ddoc2.html | 2 +- test/compilable/extra-files/ddoc3.html | 3 +- test/compilable/extra-files/ddoc8.html | 2 +- test/compilable/extra-files/ddoc9155.html | 3 - test/compilable/extra-files/ddoc9727.html | 6 +- test/compilable/extra-files/ddocunittest.html | 2 +- 9 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/lexer.c b/src/lexer.c index 0e3d5455b70f..258cb4614a63 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -2495,6 +2495,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 != '/') @@ -2510,7 +2534,6 @@ void Lexer::getDocComment(Token *t, unsigned lineComment) * Canonicalize it into buf[]. */ OutBuffer buf; - int linestart = 0; for (; q < qend; q++) { @@ -2568,6 +2591,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'); @@ -2599,19 +2630,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; } } diff --git a/test/compilable/extra-files/ddoc1.html b/test/compilable/extra-files/ddoc1.html index e97d49383e23..aee2528428b1 100644 --- a/test/compilable/extra-files/ddoc1.html +++ b/test/compilable/extra-files/ddoc1.html @@ -72,7 +72,7 @@

abc

class Bar;
-
The Class Bar

+
The Class Bar

int x;
@@ -93,7 +93,7 @@

abc

enum Easy: int;
-
The Enum Easy

+
The Enum Easy

red
the Red

diff --git a/test/compilable/extra-files/ddoc10.html b/test/compilable/extra-files/ddoc10.html index eee709baee5f..0813048b8cf8 100644 --- a/test/compilable/extra-files/ddoc10.html +++ b/test/compilable/extra-files/ddoc10.html @@ -14,14 +14,14 @@

ddoc10

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.

+ type) is not documented at all. This comment is also repeated twice.

int func2(T, U)(T x, U y);
int func2(T)(T x);
This comment is also repeated twice, and the second function signature is - not very well documented.

+ not very well documented.

int func3(T, U)(T x, U y); @@ -60,29 +60,30 @@

ddoc10

struct bar6;
-
blah

+
blah

struct Foo7(T);
-
template bodies

+
template bodies

void bar();
Attempt two: Inside. +

Attempt one: Doc outside static if.

void abc();
-
the abc function should be static

+
the abc function should be static

abstract class Foo8;
-
show abstract

+
show abstract

void bug4878(string a = ")"); @@ -105,12 +106,12 @@

ddoc10

float f10(float a, float b);
-
Produces something in (a;b]

+
Produces something in (a;b]

float h10(float a, float b);
-
Produces something in [a;b)

+
Produces something in [a;b)

void bug6090(string f = "$(B b)", char g = ')')(string h = "$(", string i = "$)"); diff --git a/test/compilable/extra-files/ddoc2.html b/test/compilable/extra-files/ddoc2.html index 8a336806a3c9..4498a0ce6714 100644 --- a/test/compilable/extra-files/ddoc2.html +++ b/test/compilable/extra-files/ddoc2.html @@ -40,7 +40,7 @@

std.test

int stars;
-
stars

+
stars

diff --git a/test/compilable/extra-files/ddoc3.html b/test/compilable/extra-files/ddoc3.html index 9a1e6b9f0790..ee65a60c6b9d 100644 --- a/test/compilable/extra-files/ddoc3.html +++ b/test/compilable/extra-files/ddoc3.html @@ -24,7 +24,6 @@

std.test

'arg1' : arg1.
'arg2' : arg2.
'arg3' : arg3.
-

Things to see also world. @@ -60,7 +59,7 @@

std.test

int stars;
-
stars

+
stars

diff --git a/test/compilable/extra-files/ddoc8.html b/test/compilable/extra-files/ddoc8.html index bc4afb5afca9..6b9462866c1f 100644 --- a/test/compilable/extra-files/ddoc8.html +++ b/test/compilable/extra-files/ddoc8.html @@ -6,7 +6,7 @@

ddoc8



class Foo(T): Bar;
-
foo

+
foo

diff --git a/test/compilable/extra-files/ddoc9155.html b/test/compilable/extra-files/ddoc9155.html index 01c5e5d0ba64..1ed6a5d925f8 100644 --- a/test/compilable/extra-files/ddoc9155.html +++ b/test/compilable/extra-files/ddoc9155.html @@ -31,14 +31,12 @@

ddoc9155

// The ElementType of data is not aggregation type foreach (encoded; Base64.encoder(data)) -

wstring ws;
 transcode("hello world",ws);
     // transcode from UTF-8 to UTF-16
 
-

Example:
@@ -56,7 +54,6 @@

ddoc9155

+ comment +/ -

#!/usr/bin/env rdmd
diff --git a/test/compilable/extra-files/ddoc9727.html b/test/compilable/extra-files/ddoc9727.html
index 741f0ff04c75..cb8245075f27 100644
--- a/test/compilable/extra-files/ddoc9727.html
+++ b/test/compilable/extra-files/ddoc9727.html
@@ -6,18 +6,18 @@ 

ddoc9727



void foo(int x);
-
The function foo.

+
The function foo.

Examples:
 foo(1);
 


Examples:
-foo can be used like this: +foo can be used like this:
 foo(2);
 


Examples:
-foo can also be used like this: +foo can also be used like this:
 foo(3);
 
diff --git a/test/compilable/extra-files/ddocunittest.html b/test/compilable/extra-files/ddocunittest.html index 45a365b051e2..39ace3eb0299 100644 --- a/test/compilable/extra-files/ddocunittest.html +++ b/test/compilable/extra-files/ddocunittest.html @@ -91,7 +91,7 @@

ddocunittest

void foobar();
-
foobar - no examples

+
foobar - no examples

void foo(int x); From e55695e692bdcad39ea4af4851f0f33a3dead50d Mon Sep 17 00:00:00 2001 From: k-hara Date: Thu, 13 Feb 2014 23:12:27 +0900 Subject: [PATCH 2/2] fix Issue 7555 - ddoc whitespace issues due to version tags --- src/doc.c | 23 +++++----- src/macro.c | 10 +++- test/compilable/ddoc7555.d | 53 +++++++++++++++++++++ test/compilable/extra-files/ddoc1.html | 2 +- test/compilable/extra-files/ddoc3.html | 4 +- test/compilable/extra-files/ddoc7555.html | 56 +++++++++++++++++++++++ 6 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 test/compilable/ddoc7555.d create mode 100644 test/compilable/extra-files/ddoc7555.html diff --git a/src/doc.c b/src/doc.c index f7f2d6a262bd..8dca6f51e6a2 100644 --- a/src/doc.c +++ b/src/doc.c @@ -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); @@ -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); @@ -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]; @@ -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 @@ -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 diff --git a/src/macro.c b/src/macro.c index 2203c20897d5..b594a269a736 100644 --- a/src/macro.c +++ b/src/macro.c @@ -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 @@ -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); diff --git a/test/compilable/ddoc7555.d b/test/compilable/ddoc7555.d new file mode 100644 index 000000000000..efbb54785e13 --- /dev/null +++ b/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(); diff --git a/test/compilable/extra-files/ddoc1.html b/test/compilable/extra-files/ddoc1.html index aee2528428b1..c6bc0da165a1 100644 --- a/test/compilable/extra-files/ddoc1.html +++ b/test/compilable/extra-files/ddoc1.html @@ -15,7 +15,7 @@

abc

windy city

-paragraph 2 about of F + paragraph 2 about of F
#include <stdio.h>
 void main()
 {
diff --git a/test/compilable/extra-files/ddoc3.html b/test/compilable/extra-files/ddoc3.html
index ee65a60c6b9d..9e33bc8c9e1b 100644
--- a/test/compilable/extra-files/ddoc3.html
+++ b/test/compilable/extra-files/ddoc3.html
@@ -29,12 +29,12 @@ 

std.test

Things to see also world.

- +
1 2 3
1 2 3
4 5 6


-
     pragma( name );
+ 
      pragma( name );
       pragma( name , option [ option ] );
       (
   


diff --git a/test/compilable/extra-files/ddoc7555.html b/test/compilable/extra-files/ddoc7555.html new file mode 100644 index 000000000000..4fc09e58b40a --- /dev/null +++ b/test/compilable/extra-files/ddoc7555.html @@ -0,0 +1,56 @@ + + + ddoc7555 + +

ddoc7555

+

+
void dummy(); +
+
Dummy doc. +

+ DelimitedString + TokenString +

+ + DelimitedString + TokenString +

+ +HexString +HexString +

+ +HexString +HexString +

+ +HexString +HexString +

+ +HexString +HexString +

+ +HexString +HexString +

+ +HexString +HexString +

+ +HexString +HexString +

+ +HexString +HexString + +

+ +
+
+ +
Page generated by Ddoc. +