Merge pull request #201 from QuickJack/master
[mono.git] / mcs / mcs / constant.cs
index fe0cacc7454ebf150221f87487a6f749ca48747e..86250a222af1e33e389e8ae965ccd93b1eee5707 100644 (file)
@@ -7,6 +7,7 @@
 //
 // Copyright 2001-2003 Ximian, Inc.
 // Copyright 2003-2008 Novell, Inc.
+// Copyright 2011 Xamarin Inc
 //
 
 using System;
@@ -78,6 +79,11 @@ namespace Mono.CSharp {
                        return c;
                }
 
+               public override bool ContainsEmitWithAwait ()
+               {
+                       return false;
+               }
+
                public virtual Constant ConvertImplicitly (TypeSpec type)
                {
                        if (this.type == type)
@@ -150,7 +156,7 @@ namespace Mono.CSharp {
                                if (t.IsNullableType)
                                        return Nullable.LiftedNull.Create (t, loc);
 
-                               if (TypeManager.IsReferenceType (t))
+                               if (TypeSpec.IsReferenceType (t))
                                        return new NullConstant (t, loc);
                        }
 
@@ -162,7 +168,7 @@ namespace Mono.CSharp {
                {
                        Arguments args = new Arguments (2);
                        args.Add (new Argument (this));
-                       args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
+                       args.Add (new Argument (new TypeOf (type, loc)));
 
                        return CreateExpressionFactoryCall (ec, "Constant", args);
                }
@@ -269,7 +275,7 @@ namespace Mono.CSharp {
                                return this;
 
                        Constant c;
-                       if (TypeManager.IsEnumType (target_type)) {
+                       if (target_type.IsEnum) {
                                c = TryReduce (ec, EnumSpec.GetUnderlyingType (target_type));
                                if (c == null)
                                        return null;
@@ -309,7 +315,13 @@ namespace Mono.CSharp {
                
                public virtual bool IsOneInteger {
                        get { return false; }
-               }               
+               }
+
+               public override bool IsSideEffectFree {
+                       get {
+                               return true;
+                       }
+               }
 
                //
                // Returns true iff 1) the stack type of this is one of Object, 
@@ -421,9 +433,9 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        if (Value)
-                               ec.Emit (OpCodes.Ldc_I4_1);
+                               ec.EmitInt (1);
                        else
-                               ec.Emit (OpCodes.Ldc_I4_0);
+                               ec.EmitInt (0);
                }
 
                public override bool IsDefaultValue {
@@ -1939,7 +1951,7 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        if (Value == null) {
-                               ec.Emit (OpCodes.Ldnull);
+                               ec.EmitNull ();
                                return;
                        }
 
@@ -2044,7 +2056,7 @@ namespace Mono.CSharp {
 
                public override void Emit (EmitContext ec)
                {
-                       ec.Emit (OpCodes.Ldnull);
+                       ec.EmitNull ();
 
                        // Only to make verifier happy
                        if (type.IsGenericParameter)
@@ -2073,7 +2085,7 @@ namespace Mono.CSharp {
                        if (!IsLiteral && !Convert.ImplicitStandardConversionExists (this, targetType))
                                return null;
 
-                       if (TypeManager.IsReferenceType (targetType))
+                       if (TypeSpec.IsReferenceType (targetType))
                                return new NullConstant (targetType, loc);
 
                        if (targetType.IsNullableType)
@@ -2146,7 +2158,7 @@ namespace Mono.CSharp {
                        //
                        // Emits null pointer
                        //
-                       ec.Emit (OpCodes.Ldc_I4_0);
+                       ec.EmitInt (0);
                        ec.Emit (OpCodes.Conv_U);
                }
        }
@@ -2156,7 +2168,8 @@ namespace Mono.CSharp {
        ///   used by BitwiseAnd to ensure that the second expression is invoked
        ///   regardless of the value of the left side.  
        /// </summary>
-       public class SideEffectConstant : Constant {
+       public class SideEffectConstant : Constant
+       {
                public readonly Constant value;
                Expression side_effect;
                
@@ -2172,6 +2185,12 @@ namespace Mono.CSharp {
                        this.side_effect = side_effect;
                }
 
+               public override bool IsSideEffectFree {
+                       get {
+                               return false;
+                       }
+               }
+
                public override object GetValue ()
                {
                        return value.GetValue ();