diff options
author | Jb Evain <jbevain@gmail.com> | 2010-05-19 17:37:40 +0400 |
---|---|---|
committer | Jb Evain <jbevain@gmail.com> | 2010-05-19 17:37:40 +0400 |
commit | 7fafeb5b281b8566b2e0afb0596b28b538cebfa3 (patch) | |
tree | 0274d5df7d7ae5752403dc4b0bb1aa55b419b281 /mcs/class/System.Core | |
parent | 8ef67d1a7b8a03e4f56fb0ee6f59ba7d2bed4159 (diff) |
2010-05-19 Jb Evain <jbevain@novell.com>
backport of r157550.
* ConstantExpression.cs: fix emission of nullable constants.
svn path=/branches/mono-2-6/mcs/; revision=157552
Diffstat (limited to 'mcs/class/System.Core')
-rw-r--r-- | mcs/class/System.Core/System.Linq.Expressions/ChangeLog | 6 | ||||
-rw-r--r-- | mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs | 40 |
2 files changed, 33 insertions, 13 deletions
diff --git a/mcs/class/System.Core/System.Linq.Expressions/ChangeLog b/mcs/class/System.Core/System.Linq.Expressions/ChangeLog index 82c62437e7f..e68a6e1585a 100644 --- a/mcs/class/System.Core/System.Linq.Expressions/ChangeLog +++ b/mcs/class/System.Core/System.Linq.Expressions/ChangeLog @@ -1,3 +1,9 @@ +2010-05-19 Jb Evain <jbevain@novell.com> + + backport of r157550. + + * ConstantExpression.cs: fix emission of nullable constants. + 2010-01-08 Jb Evain <jbevain@novell.com> * Expression.cs (Call): properly deal with zero length array diff --git a/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs b/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs index 0bf985cbb47..1a8c4d7b7aa 100644 --- a/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs +++ b/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs @@ -52,9 +52,33 @@ namespace System.Linq.Expressions { internal override void Emit (EmitContext ec) { - ILGenerator ig = ec.ig; + if (Type.IsNullable ()) { + EmitNullableConstant (ec, Type, value); + return; + } + + EmitConstant (ec, Type, value); + } + + void EmitNullableConstant (EmitContext ec, Type type, object value) + { + if (value == null) { + var ig = ec.ig; + var local = ig.DeclareLocal (type); + ig.Emit (OpCodes.Ldloca, local); + ig.Emit (OpCodes.Initobj, type); + ig.Emit (OpCodes.Ldloc, local); + } else { + EmitConstant (ec, type.GetFirstGenericArgument (), value); + ec.EmitNullableNew (type); + } + } + + void EmitConstant (EmitContext ec, Type type, object value) + { + var ig = ec.ig; - switch (Type.GetTypeCode (Type)){ + switch (Type.GetTypeCode (type)){ case TypeCode.Byte: ig.Emit (OpCodes.Ldc_I4, (int) ((byte)value)); return; @@ -163,17 +187,7 @@ namespace System.Linq.Expressions { void EmitIfNotNull (EmitContext ec, Action<EmitContext> emit) { if (value == null) { - var ig = ec.ig; - - if (Type.IsValueType) { // happens for nullable types - var local = ig.DeclareLocal (Type); - ig.Emit (OpCodes.Ldloca, local); - ig.Emit (OpCodes.Initobj, Type); - ig.Emit (OpCodes.Ldloc, local); - } else { - ec.ig.Emit (OpCodes.Ldnull); - } - + ec.ig.Emit (OpCodes.Ldnull); return; } |