From b541d1c50c0fa4afdd26ffce76622ab617022906 Mon Sep 17 00:00:00 2001 From: k-hara Date: Mon, 4 May 2015 17:26:21 +0900 Subject: [PATCH] fix Issue 14547 - Ddoc should prefer new Variable Template syntax --- src/doc.c | 20 +++++++++++++++ test/compilable/ddoc10.d | 33 +++++++++++++++++++++++++ test/compilable/extra-files/ddoc10.html | 19 ++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/src/doc.c b/src/doc.c index a36be76c40a9..39d68ae8d832 100644 --- a/src/doc.c +++ b/src/doc.c @@ -140,6 +140,8 @@ static Dsymbol *getEponymousMember(TemplateDeclaration *td) return ad; if (FuncDeclaration *fd = td->onemember->isFuncDeclaration()) return fd; + if (VarDeclaration *vd = td->onemember->isVarDeclaration()) + return td->constraint ? NULL : vd; return NULL; } @@ -1096,6 +1098,9 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc) buf->writestring("immutable "); if (d->isSynchronized()) buf->writestring("synchronized "); + + if (d->storage_class & STCmanifest) + buf->writestring("enum "); } } } @@ -1129,6 +1134,21 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc) else buf->writestring(d->ident->toChars()); + if (d->isVarDeclaration() && td) + { + buf->writeByte('('); + if (td->origParameters && td->origParameters->dim) + { + for (size_t i = 0; i < td->origParameters->dim; i++) + { + if (i) + buf->writestring(", "); + toCBuffer((*td->origParameters)[i], buf, &hgs); + } + } + buf->writeByte(')'); + } + // emit constraints if declaration is a templated declaration if (td && td->constraint) { diff --git a/test/compilable/ddoc10.d b/test/compilable/ddoc10.d index 0ae4a29785c6..90ab5a19ab25 100644 --- a/test/compilable/ddoc10.d +++ b/test/compilable/ddoc10.d @@ -175,3 +175,36 @@ struct T /// this(int){} } + + +// 14547 + +/// doc-comment +int x14547 = 1; + +/// ditto +enum int y14547 = 2; + +/// doc-comment +enum isInt14547(T) = is(T == int); + +/// ditto +enum bool isString14547(T) = is(T == string); + +/// ditto +static immutable typeName14547(T) = T.stringof; + +/// ditto +int storageFor14547(T) = 0; + +/// doc-comment +template foo14547(T) +{ + enum int foo14547 = T.stringof.length; +} + +/// ditto +template bar14547(T) if (is(T == int)) +{ + enum int bar14547 = T.stringof.length; +} diff --git a/test/compilable/extra-files/ddoc10.html b/test/compilable/extra-files/ddoc10.html index d8d885f4b997..ccd6ed3f8fc3 100644 --- a/test/compilable/extra-files/ddoc10.html +++ b/test/compilable/extra-files/ddoc10.html @@ -135,6 +135,25 @@

ddoc10



+ +
int x14547; +
enum int y14547; +
+
doc-comment

+ +
+
enum isInt14547(T); +
enum bool isString14547(T); +
static immutable typeName14547(T); +
int storageFor14547(T); +
+
doc-comment

+ +
+
enum int foo14547(T); +
template bar14547(T) if (is(T == int))
+
doc-comment

+