diff dmd/TypeNext.d @ 135:af1bebfd96a4 dmd2037

dmd 2.038
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 13 Sep 2010 22:19:42 +0100
parents e28b18c23469
children 14feb7ae01a6
line wrap: on
line diff
--- a/dmd/TypeNext.d	Sat Sep 11 13:03:39 2010 +0100
+++ b/dmd/TypeNext.d	Mon Sep 13 22:19:42 2010 +0100
@@ -53,6 +53,35 @@
 		return next.reliesOnTident();
 	}
 	
+    override int hasWild()
+    {
+        return mod == MOD.MODwild || next.hasWild();
+    }
+
+    /***************************************
+     * Return MOD bits matching argument type (targ) to wild parameter type (this).
+     */
+
+    override uint wildMatch(Type targ)
+    {
+        uint mod;
+
+        Type tb = targ.nextOf();
+        if (!tb)
+	        return 0;
+        tb = tb.toBasetype();
+        if (tb.isMutable())
+	        mod = MOD.MODmutable;
+        else if (tb.isConst() || tb.isWild())
+	        return MOD.MODconst;
+        else if (tb.isImmutable())
+	        mod = MOD.MODimmutable;
+        else
+	        assert(0);
+        mod |= next.wildMatch(tb);
+        return mod;
+    }
+    
     override Type nextOf()
 	{
 		return next;
@@ -70,7 +99,7 @@
 		TypeNext t = cast(TypeNext)super.makeConst();
 		if (ty != TY.Tfunction && ty != TY.Tdelegate &&
 			(next.deco || next.ty == TY.Tfunction) &&
-			!next.isInvariant() && !next.isConst())
+			!next.isImmutable() && !next.isConst())
 		{
 			if (next.isShared())
 				t.next = next.sharedConstOf();
@@ -90,11 +119,11 @@
 		//printf("TypeNext::makeInvariant() %s\n", toChars());
 		if (ito)
 		{	
-			assert(ito.isInvariant());
+			assert(ito.isImmutable());
 			return ito;
 		}
 		TypeNext t = cast(TypeNext)Type.makeInvariant();
-		if (ty != TY.Tfunction && ty != TY.Tdelegate && (next.deco || next.ty == TY.Tfunction) && !next.isInvariant())
+		if (ty != TY.Tfunction && ty != TY.Tdelegate && (next.deco || next.ty == TY.Tfunction) && !next.isImmutable())
 		{	
 			t.next = next.invariantOf();
 		}
@@ -116,9 +145,9 @@
 		TypeNext t = cast(TypeNext)Type.makeShared();
 		if (ty != Tfunction && ty != Tdelegate &&
 			(next.deco || next.ty == Tfunction) &&
-			!next.isInvariant() && !next.isShared())
+			!next.isImmutable() && !next.isShared())
 		{
-			if (next.isConst())
+			if (next.isConst() || next.isWild())
 				t.next = next.sharedConstOf();
 			else
 				t.next = next.sharedOf();
@@ -142,7 +171,7 @@
 		TypeNext t = cast(TypeNext) Type.makeSharedConst();
 		if (ty != Tfunction && ty != Tdelegate &&
 		    (next.deco || next.ty == Tfunction) &&
-			!next.isInvariant() && !next.isSharedConst())
+			!next.isImmutable() && !next.isSharedConst())
 		{
 			t.next = next.sharedConstOf();
 		}
@@ -154,6 +183,73 @@
 		return t;
 	}
 	
+    override Type makeWild()
+    {
+        //printf("TypeNext::makeWild() %s\n", toChars());
+        if (wto)
+        {
+            assert(wto.mod == MODwild);
+	        return wto;
+        }    
+        auto t = cast(TypeNext)Type.makeWild();
+        if (ty != TY.Tfunction && ty != TY.Tdelegate &&
+	    (next.deco || next.ty == TY.Tfunction) &&
+            !next.isImmutable() && !next.isConst() && !next.isWild())
+        {
+	        if (next.isShared())
+	            t.next = next.sharedWildOf();
+	        else
+	            t.next = next.wildOf();
+        }
+        if (ty == TY.Taarray)
+        {
+    	    (cast(TypeAArray)t).impl = null;		// lazily recompute it
+        }
+        //printf("TypeNext::makeWild() returns %p, %s\n", t, t->toChars());
+        return t;
+    }
+
+    Type makeSharedWild()
+    {
+        //printf("TypeNext::makeSharedWild() %s\n", toChars());
+        if (swto)
+        {
+            assert(swto.isSharedWild());
+	        return swto;
+        }    
+        auto t = cast(TypeNext)Type.makeSharedWild();
+        if (ty != TY.Tfunction && ty != TY.Tdelegate &&
+	    (next.deco || next.ty == TY.Tfunction) &&
+            !next.isImmutable() && !next.isSharedConst())
+        {
+	        t.next = next.sharedWildOf();
+        }
+        if (ty == Taarray)
+        {
+	        (cast(TypeAArray)t).impl = null;		// lazily recompute it
+        }
+        //printf("TypeNext::makeSharedWild() returns %p, %s\n", t, t->toChars());
+        return t;
+    }
+
+    Type makeMutable()
+    {
+        //printf("TypeNext::makeMutable() %p, %s\n", this, toChars());
+        auto t = cast(TypeNext)Type.makeMutable();
+        if (ty != TY.Tfunction && ty != TY.Tdelegate &&
+	    (next.deco || next.ty == TY.Tfunction) &&
+            next.isWild())
+        {
+	        t.next = next.mutableOf();
+        }
+        if (ty == Taarray)
+        {
+	        (cast(TypeAArray)t).impl = null;		// lazily recompute it
+        }
+        //printf("TypeNext::makeMutable() returns %p, %s\n", t, t->toChars());
+        return t;
+    }
+    
 	override MATCH constConv(Type to)
 	{
 		MATCH m = Type.constConv(to);