diff dmd/TypeSArray.d @ 51:b7d29f613539

StaticAssertStatement.syntaxCopy IfStatement.syntaxCopy CompoundDeclarationStatement.syntaxCopy VoidInitializer.syntaxCopy TypeAArray.syntaxCopy TypeTypeof.syntaxCopy TypeAArray.resolve TypeSArray.deduceType TypeAArray.deduceType TypeAArray.implicitConvTo TemplateDeclaration.leastAsSpecialized TemplateTypeParameter.dummyArg TypeIdentifier.deduceType TemplateTypeParameter.syntaxCopy Lexer.hexStringConstant Lexer.delimitedStringConstant GotoDefaultStatement.ctor CaseRangeStatement.ctor Type.castMod StorageClassDeclaration.syntaxCopy TemplateDeclaration.syntaxCopy
author korDen
date Sat, 21 Aug 2010 11:17:42 +0400
parents f23312cb6f2e
children 4290d870944a
line wrap: on
line diff
--- a/dmd/TypeSArray.d	Sat Aug 21 10:38:26 2010 +0400
+++ b/dmd/TypeSArray.d	Sat Aug 21 11:17:42 2010 +0400
@@ -1,8 +1,12 @@
 module dmd.TypeSArray;
 
 import dmd.TypeArray;
+import dmd.TypeAArray;
 import dmd.MOD;
 import dmd.Argument;
+import dmd.TypeIdentifier;
+import dmd.TemplateParameter;
+import dmd.TemplateValueParameter;
 import dmd.TypeStruct;
 import dmd.TypeTuple;
 import dmd.VarExp;
@@ -476,7 +480,97 @@
 	
     MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
 	{
-		assert(false);
+static if (false) {
+		printf("TypeSArray.deduceType()\n");
+		printf("\tthis   = %d, ", ty); print();
+		printf("\ttparam = %d, ", tparam.ty); tparam.print();
+}
+
+		// Extra check that array dimensions must match
+		if (tparam)
+		{
+			if (tparam.ty == Tsarray)
+			{
+				TypeSArray tp = cast(TypeSArray)tparam;
+
+				if (tp.dim.op == TOKvar && (cast(VarExp)tp.dim).var.storage_class & STCtemplateparameter)
+				{	
+					int i = templateIdentifierLookup((cast(VarExp)tp.dim).var.ident, parameters);
+				// This code matches code in TypeInstance.deduceType()
+					if (i == -1)
+						goto Lnomatch;
+					TemplateParameter tp2 = cast(TemplateParameter)parameters.data[i];
+					TemplateValueParameter tvp = tp2.isTemplateValueParameter();
+					if (!tvp)
+						goto Lnomatch;
+					Expression e = cast(Expression)dedtypes.data[i];
+					if (e)
+					{
+						if (!dim.equals(e))
+						goto Lnomatch;
+					}
+					else
+					{   
+						Type vt = tvp.valType.semantic(Loc(0), sc);
+						MATCH m = cast(MATCH)dim.implicitConvTo(vt);
+						if (!m)
+							goto Lnomatch;
+						dedtypes.data[i] = cast(void*)dim;
+					}
+				}
+				else if (dim.toInteger() != tp.dim.toInteger())
+					return MATCHnomatch;
+			}
+			else if (tparam.ty == Taarray)
+			{
+				TypeAArray tp = cast(TypeAArray)tparam;
+				if (tp.index.ty == Tident)
+				{	
+					TypeIdentifier tident = cast(TypeIdentifier)tp.index;
+
+					if (tident.idents.dim == 0)
+					{   
+						Identifier id = tident.ident;
+
+						for (size_t i = 0; i < parameters.dim; i++)
+						{
+							TemplateParameter tp2 = cast(TemplateParameter)parameters.data[i];
+
+							if (tp2.ident.equals(id))
+							{   
+								// Found the corresponding template parameter
+								TemplateValueParameter tvp = tp2.isTemplateValueParameter();
+								if (!tvp || !tvp.valType.isintegral())
+								goto Lnomatch;
+
+								if (dedtypes.data[i])
+								{
+									if (!dim.equals(cast(Object)dedtypes.data[i]))
+										goto Lnomatch;
+								}
+								else
+								{	dedtypes.data[i] = cast(void*)dim;
+								}
+								return next.deduceType(sc, tparam.nextOf(), parameters, dedtypes);
+							}
+						}
+					}
+				}
+			}
+			else if (tparam.ty == Tarray)
+			{   
+				MATCH m;
+
+				m = next.deduceType(sc, tparam.nextOf(), parameters, dedtypes);
+				if (m == MATCHexact)
+					m = MATCHconvert;
+				return m;
+			}
+		}
+		return Type.deduceType(sc, tparam, parameters, dedtypes);
+
+	  Lnomatch:
+		return MATCHnomatch;
 	}
 	
     TypeInfoDeclaration getTypeInfoDeclaration()