changeset 156:0c8cc2a10f99

+ ArrayInitializer.toAssocArrayLiteral() + FuncDeclaration.isUnique() + TypeEnum.alignsize() + TypeEnum.toChars() + TypeEnum.getProperty() + VarExp.equals() + expression.Util.fpunique() * fixed missing default in TypeBasic
author trass3r
date Wed, 15 Sep 2010 18:24:39 +0200
parents a43c65469219
children b7b61140701d
files dmd/ArrayInitializer.d dmd/FuncDeclaration.d dmd/TypeBasic.d dmd/TypeEnum.d dmd/VarExp.d dmd/expression/Util.d
diffstat 6 files changed, 124 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/ArrayInitializer.d	Wed Sep 15 17:31:22 2010 +0200
+++ b/dmd/ArrayInitializer.d	Wed Sep 15 18:24:39 2010 +0200
@@ -15,6 +15,7 @@
 import dmd.IntegerExp;
 import dmd.Expression;
 import dmd.ArrayLiteralExp;
+import dmd.AssocArrayLiteralExp;
 import dmd.Scope;
 import dmd.ErrorExp;
 import dmd.OutBuffer;
@@ -270,13 +271,46 @@
 	Lno:
 	    return null;
 	}
-	
-    Expression toAssocArrayLiteral()
+
+	/********************************
+	 * If possible, convert array initializer to associative array initializer.
+	 */
+	Expression toAssocArrayLiteral()
 	{
-		assert(false);
+		Expression e;
+
+		// writef("ArrayInitializer::toAssocArrayInitializer()\n");
+		// static int i; if (++i == 2) halt();
+		Expressions keys = new Expressions();
+		keys.setDim(value.dim);
+		Expressions values = new Expressions();
+		values.setDim(value.dim);
+
+		foreach (size_t i, Initializer iz; value)
+		{
+			e = index[i];
+			if (!e)
+				goto Lno;
+			keys[i] = e;
+
+			if (!iz)
+				goto Lno;
+			e = iz.toExpression();
+			if (!e)
+				goto Lno;
+			values[i] = e;
+		}
+		e = new AssocArrayLiteralExp(loc, keys, values);
+		return e;
+
+	Lno:
+		delete keys;
+		delete values;
+		error(loc, "not an associative array initializer");
+		return new ErrorExp();
 	}
 	
-    override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
 		assert(false);
 	}
--- a/dmd/FuncDeclaration.d	Wed Sep 15 17:31:22 2010 +0200
+++ b/dmd/FuncDeclaration.d	Wed Sep 15 18:24:39 2010 +0200
@@ -2932,9 +2932,12 @@
 		assert(false);
 	}
 	
-    FuncDeclaration isUnique()
-	{
-		assert(false);
+	FuncDeclaration isUnique()
+	{	
+		FuncDeclaration result = null;
+
+		overloadApply(this, &fpunique, &result);
+		return result;
 	}
 	
 	/*******************************
--- a/dmd/TypeBasic.d	Wed Sep 15 17:31:22 2010 +0200
+++ b/dmd/TypeBasic.d	Wed Sep 15 18:24:39 2010 +0200
@@ -292,6 +292,7 @@
 				case Tfloat80:
 						// For backwards compatibility - eventually, deprecate
 						goto Lmin_normal;
+				default:
 			}
 		}
 		else if (ident == Id.min_normal)
--- a/dmd/TypeEnum.d	Wed Sep 15 17:31:22 2010 +0200
+++ b/dmd/TypeEnum.d	Wed Sep 15 18:24:39 2010 +0200
@@ -16,6 +16,7 @@
 import dmd.MATCH;
 import dmd.OutBuffer;
 import dmd.CppMangleState;
+import dmd.StringExp;
 import dmd.TypeInfoDeclaration;
 import dmd.TypeInfoEnumDeclaration;
 import dmd.ArrayTypes;
@@ -57,14 +58,23 @@
 		return sym.memtype.size(loc);
 	}
 	
-    override uint alignsize()
+	override uint alignsize()
 	{
-		assert(false);
+		if (!sym.memtype)
+		{
+			debug writef("1: ");
+
+			error(Loc(0), "enum %s is forward referenced", sym.toChars());
+			return 4;
+		}
+		return sym.memtype.alignsize();
 	}
-	
-    override string toChars()
+
+	override string toChars()
 	{
-		assert(false);
+		if (mod)
+			return super.toChars();
+		return sym.toChars();
 	}
 	
     override Type semantic(Loc loc, Scope sc)
@@ -123,9 +133,46 @@
 		return em;
 	}
 	
-    override Expression getProperty(Loc loc, Identifier ident)
+	override Expression getProperty(Loc loc, Identifier ident)
 	{
-		assert(false);
+		Expression e;
+
+		if (ident is Id.max)
+		{
+			if (!sym.maxval)
+				goto Lfwd;
+			e = sym.maxval;
+		}
+		else if (ident is Id.min)
+		{
+			if (!sym.minval)
+				goto Lfwd;
+			e = sym.minval;
+		}
+		else if (ident is Id.init_)
+		{
+			e = defaultInitLiteral(loc);
+		}
+		else if (ident is Id.stringof_)
+		{
+			string s = toChars();
+			e = new StringExp(loc, s, 'c');
+			Scope sc;
+			e = e.semantic(sc);
+		}
+		else if (ident is Id.mangleof_)
+		{
+			e = Type.getProperty(loc, ident);
+		}
+		else
+		{
+			e = toBasetype().getProperty(loc, ident);
+		}
+		return e;
+
+	Lfwd:
+		error(loc, "forward reference of %s.%s", toChars(), ident.toChars());
+		return new ErrorExp();
 	}
 	
     override bool isintegral()
--- a/dmd/VarExp.d	Wed Sep 15 17:31:22 2010 +0200
+++ b/dmd/VarExp.d	Wed Sep 15 18:24:39 2010 +0200
@@ -39,7 +39,14 @@
 
 	override bool equals(Object o)
 	{
-		assert(false);
+	   VarExp ne;
+
+		if ( this == o ||
+			((cast(Expression)o).op == TOKvar &&
+			((ne = cast(VarExp)o), type.toHeadMutable().equals(ne.type.toHeadMutable())) &&
+			 var == ne.var))
+			return true;
+		return false;
 	}
 
 	override Expression semantic(Scope sc)
--- a/dmd/expression/Util.d	Wed Sep 15 17:31:22 2010 +0200
+++ b/dmd/expression/Util.d	Wed Sep 15 18:24:39 2010 +0200
@@ -136,7 +136,6 @@
  *	0	continue
  *	1	done
  */
-
 int overloadApply(FuncDeclaration fstart, int delegate(void*, FuncDeclaration) dg, void* param)
 {
     FuncDeclaration f;
@@ -185,6 +184,23 @@
 }
 
 /********************************************
+ * If there are no overloads of function f, return that function,
+ * otherwise return NULL.
+ */
+static int fpunique(void *param, FuncDeclaration f)
+{   FuncDeclaration *pf = cast(FuncDeclaration *)param;
+
+    if (*pf)
+    {   *pf is null;
+        return 1;               // ambiguous, done
+    }
+    else
+    {   *pf = f;
+        return 0;
+    }
+}
+
+/********************************************
  * Decide which function matches the arguments best.
  */