Mercurial > projects > ddmd
diff dmd/TemplateDeclaration.d @ 110:12c0c84d13fd
merged in 2.036 changes
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 22:29:00 +0200 |
parents | acd69f84627e a1cf34da9ebe |
children | 3482c73a991b |
line wrap: on
line diff
--- a/dmd/TemplateDeclaration.d Tue Aug 31 22:08:52 2010 +0200 +++ b/dmd/TemplateDeclaration.d Tue Aug 31 22:29:00 2010 +0200 @@ -53,35 +53,35 @@ TemplateTupleParameter isVariadic(TemplateParameters parameters) { size_t dim = parameters.dim; - TemplateTupleParameter tp = null; + TemplateTupleParameter tp = null; - if (dim) + if (dim) tp = (cast(TemplateParameter)parameters.data[dim - 1]).isTemplateTupleParameter(); - return tp; + return tp; } void ObjectToCBuffer(OutBuffer buf, HdrGenState* hgs, Object oarg) { - //printf("ObjectToCBuffer()\n"); - Type t = isType(oarg); - Expression e = isExpression(oarg); - Dsymbol s = isDsymbol(oarg); - Tuple v = isTuple(oarg); - if (t) - { + //printf("ObjectToCBuffer()\n"); + Type t = isType(oarg); + Expression e = isExpression(oarg); + Dsymbol s = isDsymbol(oarg); + Tuple v = isTuple(oarg); + if (t) + { //printf("\tt: %s ty = %d\n", t.toChars(), t.ty); t.toCBuffer(buf, null, hgs); - } - else if (e) + } + else if (e) e.toCBuffer(buf, hgs); - else if (s) - { + else if (s) + { string p = s.ident ? s.ident.toChars() : s.toChars(); buf.writestring(p); - } - else if (v) - { + } + else if (v) + { Objects args = v.objects; for (size_t i = 0; i < args.dim; i++) { @@ -90,36 +90,36 @@ Object o = cast(Object)args.data[i]; ObjectToCBuffer(buf, hgs, o); } - } - else if (!oarg) - { + } + else if (!oarg) + { buf.writestring("null"); - } - else - { + } + else + { debug writef("bad Object = %p\n", oarg); assert(0); - } + } } class TemplateDeclaration : ScopeDsymbol { - TemplateParameters parameters; // array of TemplateParameter's + TemplateParameters parameters; // array of TemplateParameter's - TemplateParameters origParameters; // originals for Ddoc - Expression constraint; - Array instances; // array of TemplateInstance's + TemplateParameters origParameters; // originals for Ddoc + Expression constraint; + Array instances; // array of TemplateInstance's - TemplateDeclaration overnext; // next overloaded TemplateDeclaration - TemplateDeclaration overroot; // first in overnext list + TemplateDeclaration overnext; // next overloaded TemplateDeclaration + TemplateDeclaration overroot; // first in overnext list - int semanticRun; // 1 semantic() run + int semanticRun; // 1 semantic() run - Dsymbol onemember; // if !=NULL then one member of this template + Dsymbol onemember; // if !=NULL then one member of this template - int literal; // this template declaration is a literal + int literal; // this template declaration is a literal - this(Loc loc, Identifier id, TemplateParameters parameters, Expression constraint, Dsymbols decldefs) + this(Loc loc, Identifier id, TemplateParameters parameters, Expression constraint, Dsymbols decldefs) { super(id); @@ -150,7 +150,7 @@ instances = new Array(); } - override Dsymbol syntaxCopy(Dsymbol) + override Dsymbol syntaxCopy(Dsymbol) { //printf("TemplateDeclaration.syntaxCopy()\n"); TemplateDeclaration td; @@ -177,7 +177,7 @@ return td; } - override void semantic(Scope sc) + override void semantic(Scope sc) { version (LOG) { printf("TemplateDeclaration.semantic(this = %p, id = '%s')\n", this, ident.toChars()); @@ -273,7 +273,7 @@ * Overload existing TemplateDeclaration 'this' with the new one 's'. * Return !=0 if successful; i.e. no conflict. */ - override bool overloadInsert(Dsymbol s) + override bool overloadInsert(Dsymbol s) { TemplateDeclaration *pf; TemplateDeclaration f; @@ -323,9 +323,49 @@ return true; } - override void toCBuffer(OutBuffer buf, HdrGenState* hgs) + override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { - assert(false); +static if (false) // Should handle template functions +{ + if (onemember && onemember.isFuncDeclaration()) + buf.writestring("foo "); +} + buf.writestring(kind()); + buf.writeByte(' '); + buf.writestring(ident.toChars()); + buf.writeByte('('); + for (int i = 0; i < parameters.dim; i++) + { + TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; + if (hgs.ddoc) + tp = cast(TemplateParameter)origParameters.data[i]; + if (i) + buf.writeByte(','); + tp.toCBuffer(buf, hgs); + } + buf.writeByte(')'); +version(DMDV2) +{ + if (constraint) + { buf.writestring(" if ("); + constraint.toCBuffer(buf, hgs); + buf.writeByte(')'); + } +} + + if (hgs.hdrgen) + { + hgs.tpltMember++; + buf.writenl(); + buf.writebyte('{'); + buf.writenl(); + foreach (Dsymbol s; members) + s.toCBuffer(buf, hgs); + + buf.writebyte('}'); + buf.writenl(); + hgs.tpltMember--; + } } override void toJsonBuffer(OutBuffer buf) @@ -359,14 +399,14 @@ buf.writestring("}\n"); } - override string kind() + override string kind() { return (onemember && onemember.isAggregateDeclaration()) ? onemember.kind() : "template"; } - override string toChars() + override string toChars() { OutBuffer buf = new OutBuffer(); HdrGenState hgs; @@ -394,12 +434,12 @@ return buf.extractString(); } - override void emitComment(Scope sc) + override void emitComment(Scope sc) { assert(false); } -// void toDocBuffer(OutBuffer *buf); +// void toDocBuffer(OutBuffer *buf); /*************************************** * Given that ti is an instance of this TemplateDeclaration, @@ -412,7 +452,7 @@ * dedtypes deduced arguments * Return match level. */ - MATCH matchWithInstance(TemplateInstance ti, Objects dedtypes, int flag) + MATCH matchWithInstance(TemplateInstance ti, Objects dedtypes, int flag) { MATCH m; int dedtypes_dim = dedtypes.dim; @@ -574,9 +614,9 @@ * match this is at least as specialized as td2 * 0 td2 is more specialized than this */ - MATCH leastAsSpecialized(TemplateDeclaration td2) + MATCH leastAsSpecialized(TemplateDeclaration td2) { - /* This works by taking the template parameters to this template + /* This works by taking the template parameters to this template * declaration and feeding them to td2 as if it were a template * instance. * If it works, then this template is at least as specialized @@ -598,9 +638,9 @@ { TemplateParameter tp = cast(TemplateParameter)parameters.data[i]; - void* p = tp.dummyArg(); + auto p = tp.dummyArg(); if (p) - ti.tiargs.data[i] = p; + ti.tiargs[i] = p; else ti.tiargs.setDim(i); } @@ -643,7 +683,7 @@ * Returns: * match level */ - MATCH deduceFunctionTemplateMatch(Loc loc, Objects targsi, Expression ethis, Expressions fargs, Objects dedargs) + MATCH deduceFunctionTemplateMatch(Loc loc, Objects targsi, Expression ethis, Expressions fargs, Objects dedargs) { size_t nfparams; size_t nfargs; @@ -711,15 +751,15 @@ /* The extra initial template arguments * now form the tuple argument. */ - Tuple t = new Tuple(); + auto t = new Tuple(); assert(parameters.dim); - dedargs.data[parameters.dim - 1] = cast(void*)t; + dedargs[parameters.dim - 1] = t; tuple_dim = nargsi - n; t.objects.setDim(tuple_dim); for (size_t i = 0; i < tuple_dim; i++) { - t.objects.data[i] = cast(void*)targsi.data[n + i]; + t.objects[i] = targsi[n + i]; } declareParameter(paramscope, tp, t); } @@ -786,9 +826,9 @@ { if (nfparams == 0 && nfargs != 0) // if no function parameters { - Tuple t = new Tuple(); + auto t = new Tuple(); //printf("t = %p\n", t); - dedargs.data[parameters.dim - 1] = cast(void*)t; + dedargs[parameters.dim - 1] = t; declareParameter(paramscope, tp, t); goto L2; } @@ -816,15 +856,15 @@ /* The types of the function arguments * now form the tuple argument. */ - Tuple t = new Tuple(); - dedargs.data[parameters.dim - 1] = cast(void*)t; + auto t = new Tuple(); + dedargs[parameters.dim - 1] = t; tuple_dim = nfargs - (nfparams - 1); t.objects.setDim(tuple_dim); for (size_t i = 0; i < tuple_dim; i++) { auto farg = fargs[fptupindex + i]; - t.objects.data[i] = cast(void*)farg.type; + t.objects[i] = farg.type; } declareParameter(paramscope, tp, t); goto L2; @@ -1039,14 +1079,14 @@ * the oded == oarg */ Declaration sparam; - dedargs.data[i] = cast(void*)oded; + dedargs[i] = oded; MATCH m2 = tp2.matchArg(paramscope, dedargs, i, parameters, dedtypes, &sparam, 0); //printf("m2 = %d\n", m2); if (!m2) goto Lnomatch; if (m2 < match) match = m2; // pick worst match - if (dedtypes.data[i] !is cast(void*)oded) + if (dedtypes[i] !is oded) error("specialization not allowed for deduced parameter %s", tp2.ident.toChars()); } } @@ -1057,7 +1097,7 @@ goto Lnomatch; } declareParameter(paramscope, tp2, oded); - dedargs.data[i] = cast(void*)oded; + dedargs[i] = oded; } } @@ -1097,7 +1137,7 @@ //printf("\tnomatch\n"); return MATCHnomatch; } - + /************************************************* * Given function arguments, figure out which template function * to expand, and return that function. @@ -1121,7 +1161,7 @@ static if (false) { printf("TemplateDeclaration.deduceFunctionTemplate() %s\n", toChars()); - printf(" targsi:\n"); + printf(" targsi:\n"); if (targsi) { for (int i = 0; i < targsi.dim; i++) @@ -1130,7 +1170,7 @@ printf("\t%s\n", arg.toChars()); } } - printf(" fargs:\n"); + printf(" fargs:\n"); for (int i = 0; i < fargs.dim; i++) { Expression arg = cast(Expression)fargs.data[i]; @@ -1249,7 +1289,7 @@ /************************************************** * Declare template parameter tp with value o, and install it in the scope sc. */ - void declareParameter(Scope sc, TemplateParameter tp, Object o) + void declareParameter(Scope sc, TemplateParameter tp, Object o) { //printf("TemplateDeclaration.declareParameter('%s', o = %p)\n", tp.ident.toChars(), o); @@ -1317,9 +1357,9 @@ s.semantic(sc); } - override TemplateDeclaration isTemplateDeclaration() { return this; } + override TemplateDeclaration isTemplateDeclaration() { return this; } - TemplateTupleParameter isVariadic() + TemplateTupleParameter isVariadic() { return .isVariadic(parameters); } @@ -1327,8 +1367,8 @@ /*********************************** * We can overload templates. */ - override bool isOverloadable() + override bool isOverloadable() { - return 1; + return true; } }