# HG changeset patch # User korDen # Date 1282360253 -14400 # Node ID caa9bdb08ae601bb4112e0a76f2e790f08063ff2 # Parent d4825905adc214f19743aeb83762d3936a48b15c TemplateValueParameter.matchArg implemented diff -r d4825905adc2 -r caa9bdb08ae6 dmd/TemplateValueParameter.d --- a/dmd/TemplateValueParameter.d Sat Aug 21 07:07:10 2010 +0400 +++ b/dmd/TemplateValueParameter.d Sat Aug 21 07:10:53 2010 +0400 @@ -12,12 +12,16 @@ import dmd.HdrGenState; import dmd.MATCH; import dmd.VarDeclaration; +import dmd.Initializer; +import dmd.ExpInitializer; import dmd.STC; import dmd.Util; import dmd.TY; import dmd.WANT; import dmd.TOK; +import dmd.Dsymbol : isExpression; + class TemplateValueParameter : TemplateParameter { /* Syntax: @@ -142,7 +146,94 @@ MATCH matchArg(Scope sc, Objects tiargs, int i, TemplateParameters parameters, Objects dedtypes, Declaration* psparam, int flags) { - assert(false); + //printf("TemplateValueParameter.matchArg()\n"); + + Initializer init; + Declaration sparam; + MATCH m = MATCHexact; + Expression ei; + Object oarg; + + if (i < tiargs.dim) + oarg = cast(Object)tiargs.data[i]; + else + { + // Get default argument instead + oarg = defaultArg(loc, sc); + if (!oarg) + { + assert(i < dedtypes.dim); + // It might have already been deduced + oarg = cast(Object)dedtypes.data[i]; + if (!oarg) + goto Lnomatch; + } + } + + ei = isExpression(oarg); + Type vt; + + if (!ei && oarg) + goto Lnomatch; + + if (ei && ei.op == TOKvar) + { + // Resolve const variables that we had skipped earlier + ei = ei.optimize(WANTvalue | WANTinterpret); + } + + if (specValue) + { + if (!ei || ei == edummy) + goto Lnomatch; + + Expression e = specValue; + + e = e.semantic(sc); + e = e.implicitCastTo(sc, valType); + e = e.optimize(WANTvalue | WANTinterpret); + //e.type = e.type.toHeadMutable(); + + ei = ei.syntaxCopy(); + ei = ei.semantic(sc); + ei = ei.optimize(WANTvalue | WANTinterpret); + //ei.type = ei.type.toHeadMutable(); + //printf("\tei: %s, %s\n", ei.toChars(), ei.type.toChars()); + //printf("\te : %s, %s\n", e.toChars(), e.type.toChars()); + if (!ei.equals(e)) + goto Lnomatch; + } + else if (dedtypes.data[i]) + { // Must match already deduced value + Expression e = cast(Expression)dedtypes.data[i]; + + if (!ei || !ei.equals(e)) + goto Lnomatch; + } + Lmatch: + //printf("\tvalType: %s, ty = %d\n", valType.toChars(), valType.ty); + vt = valType.semantic(Loc(0), sc); + //printf("ei: %s, ei.type: %s\n", ei.toChars(), ei.type.toChars()); + //printf("vt = %s\n", vt.toChars()); + if (ei.type) + { + m = cast(MATCH)ei.implicitConvTo(vt); + //printf("m: %d\n", m); + if (!m) + goto Lnomatch; + } + dedtypes.data[i] = cast(void*)ei; + + init = new ExpInitializer(loc, ei); + sparam = new VarDeclaration(loc, vt, ident, init); + sparam.storage_class = STCmanifest; + *psparam = sparam; + return m; + + Lnomatch: + //printf("\tno match\n"); + *psparam = null; + return MATCHnomatch; } void* dummyArg()