Browse Source

2008-03-12 Jb Evain <[email protected]>

	* NewArrayExpression.cs (Emit): naive implementation of emit support
	for array initialization.


svn path=/trunk/mcs/; revision=98007
Jb Evain 18 years ago
parent
commit
d36da9d01a

+ 5 - 0
mcs/class/System.Core/System.Linq.Expressions/ChangeLog

@@ -1,3 +1,8 @@
+2008-03-12  Jb Evain  <[email protected]>
+
+	* NewArrayExpression.cs (Emit): naive implementation of emit support
+	for array initialization.
+
 2008-03-11  Jb Evain  <[email protected]>
 
 	* BinaryExpression.cs: very naive implementation of emitting

+ 33 - 1
mcs/class/System.Core/System.Linq.Expressions/NewArrayExpression.cs

@@ -28,6 +28,8 @@
 
 using System;
 using System.Collections.ObjectModel;
+using System.Reflection;
+using System.Reflection.Emit;
 
 namespace System.Linq.Expressions {
 
@@ -45,9 +47,39 @@ namespace System.Linq.Expressions {
 			this.expressions = expressions;
 		}
 
-		internal override void Emit (EmitContext ec)
+		void EmitNewArrayInit (EmitContext ec)
+		{
+			var type = this.Type.GetElementType ();
+			var size = expressions.Count;
+
+			ec.ig.Emit (OpCodes.Ldc_I4, size);
+			ec.ig.Emit (OpCodes.Newarr, type);
+
+			for (int i = 0; i < size; i++) {
+				ec.ig.Emit (OpCodes.Dup);
+				ec.ig.Emit (OpCodes.Ldc_I4, i);
+				expressions [i].Emit (ec);
+				ec.ig.Emit (OpCodes.Stelem, type);
+			}
+		}
+
+		void EmitNewArrayBounds (EmitContext ec)
 		{
 			throw new NotImplementedException ();
 		}
+
+		internal override void Emit (EmitContext ec)
+		{
+			switch (this.NodeType) {
+			case ExpressionType.NewArrayInit:
+				EmitNewArrayInit (ec);
+				return;
+			case ExpressionType.NewArrayBounds:
+				EmitNewArrayBounds (ec);
+				return;
+			default:
+				throw new NotSupportedException ();
+			}
+		}
 	}
 }