From 18ef6ab1eccee2883cb88fd6f36887d394b3c89f Mon Sep 17 00:00:00 2001 From: Andrej Mitrovic Date: Tue, 15 Jan 2013 00:20:00 +0100 Subject: [PATCH] Fixes Issue 648 - Document template mixin instantiations. --- src/doc.c | 24 +++++ test/compilable/ddoc648.d | 90 +++++++++++++++++ test/compilable/extra-files/ddoc648.html | 123 +++++++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 test/compilable/ddoc648.d create mode 100644 test/compilable/extra-files/ddoc648.html diff --git a/src/doc.c b/src/doc.c index 0e70d259c9d5..225571e991f8 100644 --- a/src/doc.c +++ b/src/doc.c @@ -626,6 +626,26 @@ void emitDitto(Dsymbol *s, Scope *sc) emitUnittestComment(sc, p, sc->lastoffset2); } +/** Recursively expand template mixin member docs into the scope. */ +static void expandTemplateMixinComments(TemplateMixin *tm, Scope *sc) +{ + if (!tm->semanticRun) tm->semantic(sc); + TemplateDeclaration *td = (tm && tm->tempdecl) ? + tm->tempdecl->isTemplateDeclaration() : NULL; + if (td && td->members) + { + for (size_t i = 0; i < td->members->dim; i++) + { + Dsymbol *sm = (*td->members)[i]; + TemplateMixin *tmc = sm->isTemplateMixin(); + if (tmc && tmc->comment) + expandTemplateMixinComments(tmc, sc); + else + emitComment(sm, sc); + } + } +} + void emitMemberComments(ScopeDsymbol *sds, Scope *sc) { //printf("ScopeDsymbol::emitMemberComments() %s\n", toChars()); @@ -653,6 +673,10 @@ void emitMemberComments(ScopeDsymbol *sds, Scope *sc) { Dsymbol *s = (*sds->members)[i]; //printf("\ts = '%s'\n", s->toChars()); + + // only expand if parent is a non-template (semantic won't work) + if (s->comment && s->isTemplateMixin() && s->parent && !s->parent->isTemplateDeclaration()) + expandTemplateMixinComments((TemplateMixin *)s, sc); emitComment(s, sc); } sc->pop(); diff --git a/test/compilable/ddoc648.d b/test/compilable/ddoc648.d new file mode 100644 index 000000000000..49c90973a85d --- /dev/null +++ b/test/compilable/ddoc648.d @@ -0,0 +1,90 @@ +// PERMUTE_ARGS: +// REQUIRED_ARGS: -D -Dd${RESULTS_DIR}/compilable -o- +// POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh 648 + +module ddoc648; + +/// Mixin declaration +mixin template Mixin1() +{ + /// struct S + struct S { } +} + +/// class A +class A +{ + /// field x + int x; + + /// no docs for mixin statement (only for expanded members) + mixin Mixin1!(); +} + +/// class AB +class AB +{ + /// field x + int x; + + // no docs for mixin or its contents, must be a ddoc comment + mixin Mixin1!(); +} + +/// Mixin declaration2 +mixin template Mixin2() +{ + /// struct S2 + struct S2 { } +} + +/// Mixin declaration3 +mixin template Mixin3() +{ + /// another field + int f; + + /// no docs for mixin statement (only for expanded members) + mixin Mixin2!(); +} + +/// class B1 +class B1 +{ + /// no docs for mixin statement (only for expanded members) + mixin Mixin3!(); +} + + +/// Mixin declaration3 +mixin template Mixin4() +{ + /// another field + int f; + + // no docs at all for non-ddoc comment + mixin Mixin2!(); +} + +/// class B2 +class B2 +{ + /// no docs for mixin statement (only for expanded members) + mixin Mixin4!(); +} + +/// no docs for mixin statement (only for expanded members) +mixin Mixin3!(); + +/// +struct TS(T) +{ + mixin template MT() + { + } + + mixin MT; /// avoid calling semantic + + /// + int field; +} diff --git a/test/compilable/extra-files/ddoc648.html b/test/compilable/extra-files/ddoc648.html new file mode 100644 index 000000000000..93242ad59983 --- /dev/null +++ b/test/compilable/extra-files/ddoc648.html @@ -0,0 +1,123 @@ + + + ddoc648 + +

ddoc648

+

+
template Mixin1()
+
Mixin declaration

+ +
struct S; +
+
struct S

+ +
+
+
+
class A; +
+
class A

+ +
int x; +
+
field x

+ +
+
struct S; +
+
struct S

+ +
+
+
+
class AB; +
+
class AB

+ +
int x; +
+
field x

+ +
+
+
+
template Mixin2()
+
Mixin declaration2

+ +
struct S2; +
+
struct S2

+ +
+
+
+
template Mixin3()
+
Mixin declaration3

+ +
int f; +
+
another field

+ +
+
+
+
class B1; +
+
class B1

+ +
int f; +
+
another field

+ +
+
struct S2; +
+
struct S2

+ +
+
+
+
template Mixin4()
+
Mixin declaration3

+ +
int f; +
+
another field

+ +
+
+
+
class B2; +
+
class B2

+ +
int f; +
+
another field

+ +
+
+
+
int f; +
+
another field

+ +
+
struct S2; +
+
struct S2

+ +
+
struct TS(T); +
+


+
int field; +
+


+
+
+
+
+ +
Page generated by Ddoc. +