From c9972ca53bd20362b615834061939094a30c94b8 Mon Sep 17 00:00:00 2001 From: k-hara Date: Mon, 4 May 2015 14:06:48 +0900 Subject: [PATCH] Partial fix Issue 11003 - Improve .di generation Use shorthand syntax for eponymous variable templates --- src/hdrgen.c | 28 +++++++++++++++++++++++++ test/compilable/extra-files/header2.d | 14 +++++++++++++ test/compilable/extra-files/header2.di | 9 ++++++++ test/compilable/extra-files/header2i.di | 9 ++++++++ 4 files changed, 60 insertions(+) diff --git a/src/hdrgen.c b/src/hdrgen.c index eef44e85a2f8..023b1f25ccbb 100644 --- a/src/hdrgen.c +++ b/src/hdrgen.c @@ -1412,6 +1412,34 @@ class PrettyPrintVisitor : public Visitor hgs->tpltMember--; return true; } + if (VarDeclaration *vd = onemember->isVarDeclaration()) + { + if (d->constraint) + return false; + + StorageClassDeclaration::stcToCBuffer(buf, vd->storage_class); + if (vd->type) + typeToBuffer(vd->type, vd->ident); + else + buf->writestring(vd->ident->toChars()); + + buf->writeByte('('); + visitTemplateParameters(hgs->ddoc ? d->origParameters : d->parameters); + buf->writeByte(')'); + + if (vd->init) + { + buf->writestring(" = "); + ExpInitializer *ie = vd->init->isExpInitializer(); + if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit)) + ((AssignExp *)ie->exp)->e2->accept(this); + else + vd->init->accept(this); + } + buf->writeByte(';'); + buf->writenl(); + return true; + } return false; } diff --git a/test/compilable/extra-files/header2.d b/test/compilable/extra-files/header2.d index 95765fae118c..b0d8019e2c4d 100644 --- a/test/compilable/extra-files/header2.d +++ b/test/compilable/extra-files/header2.d @@ -74,6 +74,20 @@ template MyClass4(T) class MyClass4 {} } +enum isInt(T) = is(T == int); +enum bool isString(T) = is(T == string); +static immutable typeName(T) = T.stringof; +int storageFor(T) = 0; + +template templateVariableFoo(T) +{ + enum int templateVariableFoo = T.stringof.length; +} +template templateVariableBar(T) if (is(T == int)) +{ + enum int templateVariableBar = T.stringof.length; +} + auto flit = 3 / 2.0; // 11217 diff --git a/test/compilable/extra-files/header2.di b/test/compilable/extra-files/header2.di index b92442d32d74..d35bf91e0032 100644 --- a/test/compilable/extra-files/header2.di +++ b/test/compilable/extra-files/header2.di @@ -62,6 +62,15 @@ template MyClass4(T) if (is(typeof(T.subtype))) { } } +enum isInt(T) = is(T == int); +enum bool isString(T) = is(T == string); +static immutable typeName(T) = T.stringof; +int storageFor(T) = 0; +enum int templateVariableFoo(T) = T.stringof.length; +template templateVariableBar(T) if (is(T == int)) +{ + enum int templateVariableBar = T.stringof.length; +} auto flit = 3 / 2.00000; void foo11217()(const int[] arr) { diff --git a/test/compilable/extra-files/header2i.di b/test/compilable/extra-files/header2i.di index cdb97342686c..dbc88fe4dc31 100644 --- a/test/compilable/extra-files/header2i.di +++ b/test/compilable/extra-files/header2i.di @@ -75,6 +75,15 @@ template MyClass4(T) if (is(typeof(T.subtype))) { } } +enum isInt(T) = is(T == int); +enum bool isString(T) = is(T == string); +static immutable typeName(T) = T.stringof; +int storageFor(T) = 0; +enum int templateVariableFoo(T) = T.stringof.length; +template templateVariableBar(T) if (is(T == int)) +{ + enum int templateVariableBar = T.stringof.length; +} auto flit = 3 / 2.00000; void foo11217()(const int[] arr) {