changeset 41:f23312cb6f2e

TypeSArray.syntaxCopy & TypeSArray.resolve implemented
author korDen
date Sat, 21 Aug 2010 07:17:13 +0400
parents caa9bdb08ae6
children 24674203f62c
files dmd/TypeSArray.d
diffstat 1 files changed, 68 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/TypeSArray.d	Sat Aug 21 07:10:53 2010 +0400
+++ b/dmd/TypeSArray.d	Sat Aug 21 07:17:13 2010 +0400
@@ -24,9 +24,12 @@
 import dmd.ArrayTypes;
 import dmd.WANT;
 import dmd.TypeInfoDeclaration;
+import dmd.ScopeDsymbol;
+import dmd.ArrayScopeSymbol;
 import dmd.TY;
 import dmd.Util;
 import dmd.Id;
+import dmd.IndexExp;
 
 import dmd.type.Util;
 
@@ -58,7 +61,11 @@
 
     Type syntaxCopy()
 	{
-		assert(false);
+		Type t = next.syntaxCopy();
+		Expression e = dim.syntaxCopy();
+		t = new TypeSArray(t, e);
+		t.mod = mod;
+		return t;
 	}
 
     ulong size(Loc loc)
@@ -215,7 +222,66 @@
 
     void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
 	{
-		assert(false);
+		//printf("TypeSArray.resolve() %s\n", toChars());
+		next.resolve(loc, sc, pe, pt, ps);
+		//printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt);
+		if (*pe)
+		{	
+			// It's really an index expression
+			Expression e = new IndexExp(loc, *pe, dim);
+			*pe = e;
+		}
+		else if (*ps)
+		{	
+			Dsymbol s = *ps;
+			TupleDeclaration td = s.isTupleDeclaration();
+			if (td)
+			{
+				ScopeDsymbol sym = new ArrayScopeSymbol(sc, td);
+				sym.parent = sc.scopesym;
+				sc = sc.push(sym);
+
+				dim = dim.semantic(sc);
+				dim = dim.optimize(WANTvalue | WANTinterpret);
+				ulong d = dim.toUInteger();
+
+				sc = sc.pop();
+
+				if (d >= td.objects.dim)
+				{	
+					error(loc, "tuple index %ju exceeds %u", d, td.objects.dim);
+					goto Ldefault;
+				}
+				Object o = cast(Object)td.objects.data[cast(size_t)d];
+				if ((*ps = isDsymbol(o)) !is null)	/// !
+				{
+					return;
+				}
+				if ((*pe = isExpression(o)) !is null)	/// !
+				{
+					return;
+				}
+
+				/* Create a new TupleDeclaration which
+				 * is a slice [d..d+1] out of the old one.
+				 * Do it this way because TemplateInstance.semanticTiargs()
+				 * can handle unresolved Objects this way.
+				 */
+				Objects objects = new Objects;
+				objects.setDim(1);
+				objects.data[0] = cast(void*)o;
+
+				TupleDeclaration tds = new TupleDeclaration(loc, td.ident, objects);
+				*ps = tds;
+			}
+			else
+				goto Ldefault;
+		}
+		else
+		{
+		 Ldefault:
+		Type.resolve(loc, sc, pe, pt, ps);
+		}
 	}
 
     void toDecoBuffer(OutBuffer buf, int flag)