Fix warning.
[mono.git] / mcs / gmcs / expression.cs
index a561ca5f29dabc2acfcf823326eff7a90b4d7a67..dad971332431f25d5370495b330041392c1775b0 100644 (file)
@@ -1054,9 +1054,8 @@ namespace Mono.CSharp {
                        probe_type_expr = ProbeType.ResolveAsTypeTerminal (ec);
                        if (probe_type_expr == null)
                                return null;
-                       Type probe_type = probe_type_expr.Type;
-
-                       CheckObsoleteAttribute (probe_type);
+                       if (probe_type_expr.ResolveType (ec) == null)
+                               return null;
 
                        expr = expr.Resolve (ec);
                        if (expr == null)
@@ -1210,6 +1209,7 @@ namespace Mono.CSharp {
                }
 
                bool do_isinst = false;
+               Expression resolved_type;
                
                public override void Emit (EmitContext ec)
                {
@@ -1230,10 +1230,12 @@ namespace Mono.CSharp {
                
                public override Expression DoResolve (EmitContext ec)
                {
-                       Expression e = base.DoResolve (ec);
+                       if (resolved_type == null) {
+                               resolved_type = base.DoResolve (ec);
 
-                       if (e == null)
-                               return null;
+                               if (resolved_type == null)
+                                       return null;
+                       }
 
                        type = probe_type_expr.Type;
                        eclass = ExprClass.Value;
@@ -1270,7 +1272,7 @@ namespace Mono.CSharp {
                                }
                        }
                        
-                       e = Convert.ImplicitConversion (ec, expr, type, loc);
+                       Expression e = Convert.ImplicitConversion (ec, expr, type, loc);
                        if (e != null){
                                expr = e;
                                do_isinst = false;
@@ -1326,503 +1328,6 @@ namespace Mono.CSharp {
                                expr = value;
                        }
                }
-
-               bool CheckRange (EmitContext ec, long value, Type type, long min, long max)
-               {
-                       if (!ec.ConstantCheckState)
-                               return true;
-
-                       if ((value < min) || (value > max)) {
-                               Error (221, "Constant value `" + value + "' cannot be converted " +
-                                      "to a `" + TypeManager.CSharpName (type) + "' (use `unchecked' " +
-                                      "syntax to override)");
-                               return false;
-                       }
-
-                       return true;
-               }
-
-               bool CheckRange (EmitContext ec, ulong value, Type type, ulong max)
-               {
-                       if (!ec.ConstantCheckState)
-                               return true;
-
-                       if (value > max) {
-                               Error (221, "Constant value `" + value + "' cannot be converted " +
-                                      "to a `" + TypeManager.CSharpName (type) + "' (use `unchecked' " +
-                                      "syntax to override)");
-                               return false;
-                       }
-
-                       return true;
-               }
-
-               bool CheckUnsigned (EmitContext ec, long value, Type type)
-               {
-                       if (!ec.ConstantCheckState)
-                               return true;
-
-                       if (value < 0) {
-                               Error (221, "Constant value `" + value + "' cannot be converted " +
-                                      "to a `" + TypeManager.CSharpName (type) + "' (use `unchecked' " +
-                                      "syntax to override)");
-                               return false;
-                       }
-
-                       return true;
-               }
-
-               // TODO: move to constant
-               /// <summary>
-               ///   Attempts to do a compile-time folding of a constant cast.
-               /// </summary>
-               Expression TryReduce (EmitContext ec, Type target_type)
-               {
-                       if (expr.Type == target_type)
-                               return expr;
-
-                       if (TypeManager.IsEnumType (target_type) && TypeManager.EnumToUnderlying (target_type) == expr.Type)
-                               return new EnumConstant ((Constant)expr, target_type);
-
-                       Expression real_expr = expr;
-                       if (real_expr is EnumConstant)
-                               real_expr = ((EnumConstant) real_expr).Child;
-                               
-                       if (real_expr is ByteConstant){
-                               byte v = ((ByteConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, SByte.MinValue, SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type)
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               if (target_type == TypeManager.ushort_type)
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               if (target_type == TypeManager.int32_type)
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               if (target_type == TypeManager.uint32_type)
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type)
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type)
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is SByteConstant){
-                               sbyte v = ((SByteConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type)
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               if (target_type == TypeManager.ushort_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               } if (target_type == TypeManager.int32_type)
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               if (target_type == TypeManager.uint32_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               } if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is ShortConstant){
-                               short v = ((ShortConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckRange (ec, v, target_type, Byte.MinValue, Byte.MaxValue))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, SByte.MinValue, SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.ushort_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int32_type)
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               if (target_type == TypeManager.uint32_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MinValue, Char.MaxValue))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is UShortConstant){
-                               ushort v = ((UShortConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckRange (ec, v, target_type, Byte.MinValue, Byte.MaxValue))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, SByte.MinValue, SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type) {
-                                       if (!CheckRange (ec, v, target_type, Int16.MinValue, Int16.MaxValue))
-                                               return null;
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int32_type)
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               if (target_type == TypeManager.uint32_type)
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type)
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MinValue, Char.MaxValue))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is IntConstant){
-                               int v = ((IntConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckRange (ec, v, target_type, Byte.MinValue, Byte.MaxValue))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, SByte.MinValue, SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type) {
-                                       if (!CheckRange (ec, v, target_type, Int16.MinValue, Int16.MaxValue))
-                                               return null;
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.ushort_type) {
-                                       if (!CheckRange (ec, v, target_type, UInt16.MinValue, UInt16.MaxValue))
-                                               return null;
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.uint32_type) {
-                                       if (!CheckRange (ec, v, target_type, Int32.MinValue, Int32.MaxValue))
-                                               return null;
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MinValue, Char.MaxValue))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is UIntConstant){
-                               uint v = ((UIntConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MinValue, Char.MaxValue))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, SByte.MinValue, SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type) {
-                                       if (!CheckRange (ec, v, target_type, Int16.MinValue, Int16.MaxValue))
-                                               return null;
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.ushort_type) {
-                                       if (!CheckRange (ec, v, target_type, UInt16.MinValue, UInt16.MaxValue))
-                                               return null;
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int32_type) {
-                                       if (!CheckRange (ec, v, target_type, Int32.MinValue, Int32.MaxValue))
-                                               return null;
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type)
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MinValue, Char.MaxValue))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is LongConstant){
-                               long v = ((LongConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckRange (ec, v, target_type, Byte.MinValue, Byte.MaxValue))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, SByte.MinValue, SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type) {
-                                       if (!CheckRange (ec, v, target_type, Int16.MinValue, Int16.MaxValue))
-                                               return null;
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.ushort_type) {
-                                       if (!CheckRange (ec, v, target_type, UInt16.MinValue, UInt16.MaxValue))
-                                               return null;
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int32_type) {
-                                       if (!CheckRange (ec, v, target_type, Int32.MinValue, Int32.MaxValue))
-                                               return null;
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.uint32_type) {
-                                       if (!CheckRange (ec, v, target_type, UInt32.MinValue, UInt32.MaxValue))
-                                               return null;
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.uint64_type) {
-                                       if (!CheckUnsigned (ec, v, target_type))
-                                               return null;
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MinValue, Char.MaxValue))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is ULongConstant){
-                               ulong v = ((ULongConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckRange (ec, v, target_type, Byte.MaxValue))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, (ulong) SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type) {
-                                       if (!CheckRange (ec, v, target_type, (ulong) Int16.MaxValue))
-                                               return null;
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.ushort_type) {
-                                       if (!CheckRange (ec, v, target_type, UInt16.MaxValue))
-                                               return null;
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int32_type) {
-                                       if (!CheckRange (ec, v, target_type, Int32.MaxValue))
-                                               return null;
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.uint32_type) {
-                                       if (!CheckRange (ec, v, target_type, UInt32.MaxValue))
-                                               return null;
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int64_type) {
-                                       if (!CheckRange (ec, v, target_type, (ulong) Int64.MaxValue))
-                                               return null;
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MaxValue))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is FloatConstant){
-                               float v = ((FloatConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type)
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               if (target_type == TypeManager.sbyte_type)
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               if (target_type == TypeManager.short_type)
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               if (target_type == TypeManager.ushort_type)
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               if (target_type == TypeManager.int32_type)
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               if (target_type == TypeManager.uint32_type)
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type)
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type)
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-                       if (real_expr is DoubleConstant){
-                               double v = ((DoubleConstant) real_expr).Value;
-       
-                               if (target_type == TypeManager.byte_type){
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               } if (target_type == TypeManager.sbyte_type)
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               if (target_type == TypeManager.short_type)
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               if (target_type == TypeManager.ushort_type)
-                                       return new UShortConstant ((ushort) v, real_expr.Location);
-                               if (target_type == TypeManager.int32_type)
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               if (target_type == TypeManager.uint32_type)
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type)
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type)
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-
-                       if (real_expr is CharConstant){
-                               char v = ((CharConstant) real_expr).Value;
-                               
-                               if (target_type == TypeManager.byte_type) {
-                                       if (!CheckRange (ec, v, target_type, Byte.MinValue, Byte.MaxValue))
-                                               return null;
-                                       return new ByteConstant ((byte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.sbyte_type) {
-                                       if (!CheckRange (ec, v, target_type, SByte.MinValue, SByte.MaxValue))
-                                               return null;
-                                       return new SByteConstant ((sbyte) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.short_type) {
-                                       if (!CheckRange (ec, v, target_type, Int16.MinValue, Int16.MaxValue))
-                                               return null;
-                                       return new ShortConstant ((short) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.int32_type)
-                                       return new IntConstant ((int) v, real_expr.Location);
-                               if (target_type == TypeManager.uint32_type)
-                                       return new UIntConstant ((uint) v, real_expr.Location);
-                               if (target_type == TypeManager.int64_type)
-                                       return new LongConstant ((long) v, real_expr.Location);
-                               if (target_type == TypeManager.uint64_type)
-                                       return new ULongConstant ((ulong) v, real_expr.Location);
-                               if (target_type == TypeManager.float_type)
-                                       return new FloatConstant ((float) v, real_expr.Location);
-                               if (target_type == TypeManager.double_type)
-                                       return new DoubleConstant ((double) v, real_expr.Location);
-                               if (target_type == TypeManager.char_type) {
-                                       if (!CheckRange (ec, v, target_type, Char.MinValue, Char.MaxValue))
-                                               return null;
-                                       return new CharConstant ((char) v, real_expr.Location);
-                               }
-                               if (target_type == TypeManager.decimal_type)
-                                       return new DecimalConstant ((decimal) v, real_expr.Location);
-                       }
-
-                       return null;
-               }
                
                public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
                {
@@ -1848,9 +1353,7 @@ namespace Mono.CSharp {
                        if (target == null)
                                return null;
                        
-                       type = target.Type;
-
-                       CheckObsoleteAttribute (type);
+                       type = target.ResolveType (ec);
 
                        if (type.IsAbstract && type.IsSealed) {
                                Report.Error (716, loc, "Cannot convert to static type `{0}'", TypeManager.CSharpName (type));
@@ -1859,11 +1362,11 @@ namespace Mono.CSharp {
 
                        eclass = ExprClass.Value;
 
-                       if (expr is Constant){
-                               Expression e = TryReduce (ec, type);
-
-                               if (e != null)
-                                       return e;
+                       Constant c = expr as Constant;
+                       if (c != null) {
+                               c = c.TryReduce (ec, type, loc);
+                               if (c != null)
+                                       return c;
                        }
 
                        if (type.IsPointer && !ec.InUnsafe) {
@@ -1970,7 +1473,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Returns a stringified representation of the Operator
                /// </summary>
-               static string OperName (Operator oper)
+               public static string OperName (Operator oper)
                {
                        switch (oper){
                        case Operator.Multiply:
@@ -2108,7 +1611,7 @@ namespace Mono.CSharp {
                                                        if (ll >= 0)
                                                                right = new ULongConstant ((ulong) ll, right.Location);
                                                } else {
-                                                       e = Convert.ImplicitNumericConversion (ec, right, l, loc);
+                                                       e = Convert.ImplicitNumericConversion (ec, right, l);
                                                        if (e != null)
                                                                right = e;
                                                }
@@ -2125,7 +1628,7 @@ namespace Mono.CSharp {
                                                if (ll > 0)
                                                        left = new ULongConstant ((ulong) ll, right.Location);
                                        } else {
-                                               e = Convert.ImplicitNumericConversion (ec, left, r, loc);
+                                               e = Convert.ImplicitNumericConversion (ec, left, r);
                                                if (e != null)
                                                        left = e;
                                        }
@@ -2841,6 +2344,43 @@ namespace Mono.CSharp {
                        return this;
                }
 
+               Constant EnumLiftUp (EmitContext ec, Constant left, Constant right)
+               {
+                       switch (oper) {
+                               case Operator.BitwiseOr:
+                               case Operator.BitwiseAnd:
+                               case Operator.ExclusiveOr:
+                               case Operator.Equality:
+                               case Operator.Inequality:
+                               case Operator.LessThan:
+                               case Operator.LessThanOrEqual:
+                               case Operator.GreaterThan:
+                               case Operator.GreaterThanOrEqual:
+                                       if (left is EnumConstant)
+                                               return left;
+
+                                       if (left.IsZeroInteger)
+                                               return new EnumConstant (left, right.Type);
+
+                                       break;
+
+                               case Operator.Addition:
+                               case Operator.Subtraction:
+                                       return left;
+
+                               case Operator.Multiply:
+                               case Operator.Division:
+                               case Operator.Modulus:
+                               case Operator.LeftShift:
+                               case Operator.RightShift:
+                                       if (right is EnumConstant || left is EnumConstant)
+                                               break;
+                                       return left;
+                       }
+                       Error_OperatorCannotBeApplied (loc, Binary.OperName (oper), left.Type, right.Type);
+                       return null;
+               }
+
                public override Expression DoResolve (EmitContext ec)
                {
                        if ((oper == Operator.Subtraction) && (left is ParenthesizedExpression)) {
@@ -2874,9 +2414,18 @@ namespace Mono.CSharp {
                                return null;
 
                        eclass = ExprClass.Value;
-
                        Constant rc = right as Constant;
 
+                       if (lc != null && rc != null && (TypeManager.IsEnumType (left.Type) || TypeManager.IsEnumType (right.Type))) {
+                               left = lc = EnumLiftUp (ec, lc, rc);
+                               if (lc == null)
+                                       return null;
+
+                               right = rc = EnumLiftUp (ec, rc, lc);
+                               if (rc == null)
+                                       return null;
+                       }
+
                        if (oper == Operator.BitwiseAnd) {
                                if (rc != null && rc.IsZeroInteger) {
                                        return lc is EnumConstant ?
@@ -3994,11 +3543,7 @@ namespace Mono.CSharp {
 
                override public Expression DoResolveLValue (EmitContext ec, Expression right_side)
                {
-                       Expression ret = DoResolveBase (ec, right_side);
-                       if (ret != null)
-                               CheckObsoleteAttribute (ret.Type);
-
-                       return ret;
+                       return DoResolveBase (ec, right_side);
                }
 
                public bool VerifyFixed ()
@@ -5688,33 +5233,12 @@ namespace Mono.CSharp {
                /// </summary>
                public static void EmitArguments (EmitContext ec, MethodBase mb, ArrayList arguments, bool dup_args, LocalTemporary this_arg)
                {
-                       ParameterData pd;
-                       if (mb != null)
-                               pd = TypeManager.GetParameterData (mb);
-                       else
-                               pd = null;
-                       
+                       ParameterData pd = mb == null ? null : TypeManager.GetParameterData (mb);
+                       int top = arguments == null ? 0 : arguments.Count;
                        LocalTemporary [] temps = null;
                        
-                       if (dup_args)
-                               temps = new LocalTemporary [arguments.Count];
-
-                       //
-                       // If we are calling a params method with no arguments, special case it
-                       //
-                       if (arguments == null){
-                               if (pd != null && pd.Count > 0 &&
-                                   pd.ParameterModifier (0) == Parameter.Modifier.PARAMS){
-                                       ILGenerator ig = ec.ig;
-
-                                       IntConstant.EmitInt (ig, 0);
-                                       ig.Emit (OpCodes.Newarr, TypeManager.GetElementType (pd.ParameterType (0)));
-                               }
-
-                               return;
-                       }
-
-                       int top = arguments.Count;
+                       if (dup_args && top != 0)
+                               temps = new LocalTemporary [top];
 
                        for (int i = 0; i < top; i++){
                                Argument a = (Argument) arguments [i];
@@ -5925,9 +5449,11 @@ namespace Mono.CSharp {
                                        }
 
                                        if (dup_args) {
-                                               this_arg = new LocalTemporary (ec, t);
                                                ig.Emit (OpCodes.Dup);
-                                               this_arg.Store (ec);
+                                               if (Arguments != null && Arguments.Count != 0) {
+                                                       this_arg = new LocalTemporary (ec, t);
+                                                       this_arg.Store (ec);
+                                               }
                                        }
                                }
                        }
@@ -6224,19 +5750,15 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return null;
 
+                       type = texpr.ResolveType (ec);
+
                        if (Arguments == null) {
                                Expression c = Constantify (type);
                                if (c != null)
                                        return c;
                        }
 
-                       type = texpr.Type;
-                       if (type == null)
-                               return null;
-                       
-                       CheckObsoleteAttribute (type);
-
-                       if (TypeManager.IsDelegateType (type)) {
+                       if (TypeManager.IsDelegateType (type)) {
                                RequestedType = (new NewDelegate (type, Arguments, loc)).Resolve (ec);
                                if (RequestedType != null)
                                        if (!(RequestedType is DelegateCreation))
@@ -6714,7 +6236,7 @@ namespace Mono.CSharp {
                        if (array_type_expr == null)
                                return false;
 
-                       type = array_type_expr.Type;
+                       type = array_type_expr.ResolveType (ec);
 
                        if (!type.IsArray) {
                                Error (622, "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
@@ -7445,7 +6967,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return null;
 
-                       typearg = texpr.Type;
+                       typearg = texpr.ResolveType (ec);
 
                        if (typearg == TypeManager.void_type) {
                                Error (673, "System.Void cannot be used from C#. Use typeof (void) to get the void type object");
@@ -7456,7 +6978,6 @@ namespace Mono.CSharp {
                                UnsafeError (loc);
                                return null;
                        }
-                       CheckObsoleteAttribute (typearg);
 
                        type = TypeManager.type_type;
                        // Even though what is returned is a type object, it's treated as a value by the compiler.
@@ -7519,7 +7040,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       type_queried = texpr.Type;
+                       type_queried = texpr.ResolveType (ec);
 
                        int size_of = GetTypeSize (type_queried);
                        if (size_of > 0) {
@@ -7532,8 +7053,6 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       CheckObsoleteAttribute (type_queried);
-
                        if (!TypeManager.VerifyUnManaged (type_queried, loc)){
                                return null;
                        }
@@ -7641,15 +7160,16 @@ namespace Mono.CSharp {
        ///   Implements the member access expression
        /// </summary>
        public class MemberAccess : Expression {
-               public readonly string Identifier;  // TODO: LocatedToken
+               public readonly string Identifier;
                Expression expr;
                TypeArguments args;
                
+               // TODO: Location can be removed
                public MemberAccess (Expression expr, string id, Location l)
                {
                        this.expr = expr;
                        Identifier = id;
-                       loc = l;
+                       loc = expr.Location;
                }
 
                public MemberAccess (Expression expr, string id, TypeArguments args,
@@ -7816,7 +7336,7 @@ namespace Mono.CSharp {
                        if (tnew_expr == null)
                                return null;
 
-                       Type expr_type = tnew_expr.Type;
+                       Type expr_type = tnew_expr.ResolveType (ec);
 
                        if (expr_type.IsPointer){
                                Error (23, "The `.' operator can not be applied to pointer operands (" +
@@ -9068,7 +8588,10 @@ namespace Mono.CSharp {
                        if (lexpr == null)
                                return null;
 
-                       Type ltype = lexpr.Type;
+                       bool old = ec.TestObsoleteMethodUsage;
+                       ec.TestObsoleteMethodUsage = true;
+                       Type ltype = lexpr.ResolveType (ec);
+                       ec.TestObsoleteMethodUsage = old;
 
                        if ((ltype == TypeManager.void_type) && (dim != "*")) {
                                Report.Error (1547, Location,
@@ -9124,7 +8647,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class FixedBufferPtr: Expression {
+       public class FixedBufferPtr : Expression {
                Expression array;
 
                public FixedBufferPtr (Expression array, Type array_type, Location l)
@@ -9250,7 +8773,7 @@ namespace Mono.CSharp {
                        if (texpr == null)
                                return null;
 
-                       otype = texpr.Type;
+                       otype = texpr.ResolveType (ec);
 
                        if (!TypeManager.VerifyUnManaged (otype, loc))
                                return null;