Mercurial > projects > ddmd
diff dmd/TemplateTupleParameter.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 2e2a5c3f943a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/TemplateTupleParameter.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,149 @@ +module dmd.TemplateTupleParameter; + +import dmd.TemplateParameter; +import dmd.Loc; +import dmd.Identifier; +import dmd.TypeIdentifier; +import dmd.AliasDeclaration; +import dmd.Scope; +import dmd.ArrayTypes; +import dmd.MATCH; +import dmd.Declaration; +import dmd.OutBuffer; +import dmd.HdrGenState; +import dmd.Util; +import dmd.Tuple; +import dmd.Dsymbol; +import dmd.TemplateInstance; +import dmd.Type; +import dmd.Expression; +import dmd.TupleDeclaration; + +class TemplateTupleParameter : TemplateParameter +{ + /* Syntax: + * ident ... + */ + + this(Loc loc, Identifier ident) + { + super(loc, ident); + this.ident = ident; + } + + TemplateTupleParameter isTemplateTupleParameter() + { + return this; + } + + TemplateParameter syntaxCopy() + { + TemplateTupleParameter tp = new TemplateTupleParameter(loc, ident); + return tp; + } + + void declareParameter(Scope sc) + { + TypeIdentifier ti = new TypeIdentifier(loc, ident); + sparam = new AliasDeclaration(loc, ident, ti); + if (!sc.insert(sparam)) + error(loc, "parameter '%s' multiply defined", ident.toChars()); + } + + void semantic(Scope) + { + } + + void print(Object oarg, Object oded) + { + writef(" %s... [", ident.toChars()); + Tuple v = isTuple(oded); + assert(v); + + //printf("|%d| ", v.objects.dim); + for (int i = 0; i < v.objects.dim; i++) + { + if (i) + writef(", "); + + Object o = cast(Object)v.objects.data[i]; + + Dsymbol sa = isDsymbol(o); + if (sa) + writef("alias: %s", sa.toChars()); + + Type ta = isType(o); + if (ta) + writef("type: %s", ta.toChars()); + + Expression ea = isExpression(o); + if (ea) + writef("exp: %s", ea.toChars()); + + assert(!isTuple(o)); // no nested Tuple arguments + } + + writef("]\n"); + } + + void toCBuffer(OutBuffer buf, HdrGenState* hgs) + { + buf.writestring(ident.toChars()); + buf.writestring("..."); + } + + Object specialization() + { + return null; + } + + Object defaultArg(Loc loc, Scope sc) + { + return null; + } + + bool overloadMatch(TemplateParameter tp) + { + TemplateTupleParameter tvp = tp.isTemplateTupleParameter(); + if (tvp) { + return true; // match + } + + Lnomatch: + return false; + } + + MATCH matchArg(Scope sc, Objects tiargs, int i, TemplateParameters parameters, Objects dedtypes, Declaration* psparam, int flags) + { + //printf("TemplateTupleParameter.matchArg()\n"); + + /* The rest of the actual arguments (tiargs[]) form the match + * for the variadic parameter. + */ + assert(i + 1 == dedtypes.dim); // must be the last one + Tuple ovar; + if (i + 1 == tiargs.dim && isTuple(cast(Object)tiargs.data[i])) + ovar = isTuple(cast(Object)tiargs.data[i]); + else + { + ovar = new Tuple(); + //printf("ovar = %p\n", ovar); + if (i < tiargs.dim) + { + //printf("i = %d, tiargs.dim = %d\n", i, tiargs.dim); + ovar.objects.setDim(tiargs.dim - i); + for (size_t j = 0; j < ovar.objects.dim; j++) + ovar.objects.data[j] = tiargs.data[i + j]; + } + } + *psparam = new TupleDeclaration(loc, ident, ovar.objects); + dedtypes.data[i] = cast(void*)ovar; + + return MATCH.MATCHexact; + } + + void* dummyArg() + { + return null; + } +} \ No newline at end of file