Fix Firebird 'make dist' and build
[mono.git] / mcs / gmcs / ecore.cs
index ba9d863aebe349336fd90947e414e0a74357c10f..3d4786437d3a1dc56537c96eb66eb7a1f6286b47 100644 (file)
@@ -59,7 +59,12 @@ namespace Mono.CSharp {
                DisableFlowAnalysis     = 8,
 
                // Set if this is resolving the first part of a MemberAccess.
-               Intermediate            = 16
+               Intermediate            = 16,
+
+               // Disable control flow analysis _of struct_ while resolving the expression.
+               // This is used when resolving the instance expression of a field expression.
+               DisableStructFlowAnalysis       = 32,
+
        }
 
        //
@@ -124,9 +129,9 @@ namespace Mono.CSharp {
                public void Error (int error, string s)
                {
                        if (loc.IsNull)
-                               Report.Error (error, loc, s);
-                       else
                                Report.Error (error, s);
+                       else
+                               Report.Error (error, loc, s);
                }
 
                /// <summary>
@@ -287,6 +292,17 @@ namespace Mono.CSharp {
                        Report.Error (122, loc, "`{0}' is inaccessible due to its protection level", name);
                }
 
+               public virtual void Error_ValueCannotBeConverted (Location loc, Type t)
+               {
+                       Convert.Error_CannotImplicitConversion (loc, Type, t);
+               }
+
+               protected static void Error_TypeDoesNotContainDefinition (Location loc, Type type, string name)
+               {
+                       Report.Error (117, loc, "`{0}' does not contain a definition for `{1}'",
+                               TypeManager.CSharpName (type), name);
+               }
+
                ResolveFlags ExprClassToResolveFlags ()
                {
                        switch (eclass) {
@@ -325,8 +341,11 @@ namespace Mono.CSharp {
                                return ResolveAsTypeStep (ec, false);
 
                        bool old_do_flow_analysis = ec.DoFlowAnalysis;
+                       bool old_omit_struct_analysis = ec.OmitStructFlowAnalysis;
                        if ((flags & ResolveFlags.DisableFlowAnalysis) != 0)
                                ec.DoFlowAnalysis = false;
+                       if ((flags & ResolveFlags.DisableStructFlowAnalysis) != 0)
+                               ec.OmitStructFlowAnalysis = true;
 
                        Expression e;
                        bool intermediate = (flags & ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
@@ -337,6 +356,7 @@ namespace Mono.CSharp {
                                e = DoResolve (ec);
 
                        ec.DoFlowAnalysis = old_do_flow_analysis;
+                       ec.OmitStructFlowAnalysis = old_omit_struct_analysis;
 
                        if (e == null)
                                return null;
@@ -370,6 +390,31 @@ namespace Mono.CSharp {
                        return e;
                }
 
+               public Constant ResolveAsConstant (EmitContext ec, MemberCore mc)
+               {
+                       Expression e = Resolve (ec);
+                       if (e != null) {
+                               Constant c = e as Constant;
+                               if (c != null)
+                                       return c;
+
+                               EmptyCast empty = e as EmptyCast;
+                               if (empty != null) {
+                                       c = empty.Child as Constant;
+                                       if (c != null) {
+                                               // TODO: not sure about this maybe there is easier way how to use EmptyCast
+                                               if (e.Type.IsEnum)
+                                                       c.Type = e.Type;
+
+                                               return c;
+                                       }
+                               }
+                       }
+
+                       Const.Error_ExpressionMustBeConstant (loc, mc.GetSignatureForError ());
+                       return null;
+               }
+
                /// <summary>
                ///   Resolves an expression for LValue assignment
                /// </summary>
@@ -495,6 +540,8 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Returns a fully formed expression after a MemberLookup
                /// </summary>
+               /// 
+               // TODO: This can be heavily cached
                public static Expression ExprClassFromMemberInfo (EmitContext ec, MemberInfo mi, Location loc)
                {
                        if (mi is EventInfo)
@@ -706,9 +753,7 @@ namespace Mono.CSharp {
                                        Report.Error (103, loc, "The name `{0}' does not exist in the context of `{1}'",
                                                name, class_name);
                                else
-                                       Report.Error (
-                                               117, loc, "`" + TypeManager.CSharpName (queried_type) + "' does not contain a " +
-                                               "definition for `" + name + "'");
+                                       Error_TypeDoesNotContainDefinition (loc, queried_type, name);
                                return;
                        }
 
@@ -890,268 +935,6 @@ namespace Mono.CSharp {
                {
                        Report.Error (214, loc, "Pointers and fixed size buffers may only be used in an unsafe context");
                }
-               
-               /// <summary>
-               ///   Converts the IntConstant, UIntConstant, LongConstant or
-               ///   ULongConstant into the integral target_type.   Notice
-               ///   that we do not return an `Expression' we do return
-               ///   a boxed integral type.
-               ///
-               ///   FIXME: Since I added the new constants, we need to
-               ///   also support conversions from CharConstant, ByteConstant,
-               ///   SByteConstant, UShortConstant, ShortConstant
-               ///
-               ///   This is used by the switch statement, so the domain
-               ///   of work is restricted to the literals above, and the
-               ///   targets are int32, uint32, char, byte, sbyte, ushort,
-               ///   short, uint64 and int64
-               /// </summary>
-               public static object ConvertIntLiteral (Constant c, Type target_type, Location loc)
-               {
-                       if (!Convert.ImplicitStandardConversionExists (Convert.ConstantEC, c, target_type)){
-                               Convert.Error_CannotImplicitConversion (loc, c.Type, target_type);
-                               return null;
-                       }
-                       
-                       if (c.Type == target_type)
-                               return ((Constant) c).GetValue ();
-
-                       //
-                       // Make into one of the literals we handle, we dont really care
-                       // about this value as we will just return a few limited types
-                       // 
-                       if (c is EnumConstant)
-                               c = ((EnumConstant)c).WidenToCompilerConstant ();
-
-                       if (c is IntConstant){
-                               int v = ((IntConstant) c).Value;
-                               
-                               if (target_type == TypeManager.uint32_type){
-                                       if (v >= 0)
-                                               return (uint) v;
-                               } else if (target_type == TypeManager.char_type){
-                                       if (v >= Char.MinValue && v <= Char.MaxValue)
-                                               return (char) v;
-                               } else if (target_type == TypeManager.byte_type){
-                                       if (v >= Byte.MinValue && v <= Byte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.sbyte_type){
-                                       if (v >= SByte.MinValue && v <= SByte.MaxValue)
-                                               return (sbyte) v;
-                               } else if (target_type == TypeManager.short_type){
-                                       if (v >= Int16.MinValue && v <= UInt16.MaxValue)
-                                               return (short) v;
-                               } else if (target_type == TypeManager.ushort_type){
-                                       if (v >= UInt16.MinValue && v <= UInt16.MaxValue)
-                                               return (ushort) v;
-                               } else if (target_type == TypeManager.int64_type)
-                                       return (long) v;
-                               else if (target_type == TypeManager.uint64_type){
-                                       if (v > 0)
-                                               return (ulong) v;
-                               }
-
-                       } else if (c is UIntConstant){
-                               uint v = ((UIntConstant) c).Value;
-
-                               if (target_type == TypeManager.int32_type){
-                                       if (v <= Int32.MaxValue)
-                                               return (int) v;
-                               } else if (target_type == TypeManager.char_type){
-                                       if (v >= Char.MinValue && v <= Char.MaxValue)
-                                               return (char) v;
-                               } else if (target_type == TypeManager.byte_type){
-                                       if (v <= Byte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.sbyte_type){
-                                       if (v <= SByte.MaxValue)
-                                               return (sbyte) v;
-                               } else if (target_type == TypeManager.short_type){
-                                       if (v <= UInt16.MaxValue)
-                                               return (short) v;
-                               } else if (target_type == TypeManager.ushort_type){
-                                       if (v <= UInt16.MaxValue)
-                                               return (ushort) v;
-                               } else if (target_type == TypeManager.int64_type)
-                                       return (long) v;
-                               else if (target_type == TypeManager.uint64_type)
-                                       return (ulong) v;
-                       } else if (c is LongConstant){ 
-                               long v = ((LongConstant) c).Value;
-
-                               if (target_type == TypeManager.int32_type){
-                                       if (v >= UInt32.MinValue && v <= UInt32.MaxValue)
-                                               return (int) v;
-                               } else if (target_type == TypeManager.uint32_type){
-                                       if (v >= 0 && v <= UInt32.MaxValue)
-                                               return (uint) v;
-                               } else if (target_type == TypeManager.char_type){
-                                       if (v >= Char.MinValue && v <= Char.MaxValue)
-                                               return (char) v;
-                               } else if (target_type == TypeManager.byte_type){
-                                       if (v >= Byte.MinValue && v <= Byte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.sbyte_type){
-                                       if (v >= SByte.MinValue && v <= SByte.MaxValue)
-                                               return (sbyte) v;
-                               } else if (target_type == TypeManager.short_type){
-                                       if (v >= Int16.MinValue && v <= UInt16.MaxValue)
-                                               return (short) v;
-                               } else if (target_type == TypeManager.ushort_type){
-                                       if (v >= UInt16.MinValue && v <= UInt16.MaxValue)
-                                               return (ushort) v;
-                               } else if (target_type == TypeManager.uint64_type){
-                                       if (v > 0)
-                                               return (ulong) v;
-                               }
-                       } else if (c is ULongConstant){
-                               ulong v = ((ULongConstant) c).Value;
-
-                               if (target_type == TypeManager.int32_type){
-                                       if (v <= Int32.MaxValue)
-                                               return (int) v;
-                               } else if (target_type == TypeManager.uint32_type){
-                                       if (v <= UInt32.MaxValue)
-                                               return (uint) v;
-                               } else if (target_type == TypeManager.char_type){
-                                       if (v >= Char.MinValue && v <= Char.MaxValue)
-                                               return (char) v;
-                               } else if (target_type == TypeManager.byte_type){
-                                       if (v >= Byte.MinValue && v <= Byte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.sbyte_type){
-                                       if (v <= (int) SByte.MaxValue)
-                                               return (sbyte) v;
-                               } else if (target_type == TypeManager.short_type){
-                                       if (v <= UInt16.MaxValue)
-                                               return (short) v;
-                               } else if (target_type == TypeManager.ushort_type){
-                                       if (v <= UInt16.MaxValue)
-                                               return (ushort) v;
-                               } else if (target_type == TypeManager.int64_type){
-                                       if (v <= Int64.MaxValue)
-                                               return (long) v;
-                               }
-                       } else if (c is ByteConstant){
-                               byte v = ((ByteConstant) c).Value;
-                               
-                               if (target_type == TypeManager.int32_type)
-                                       return (int) v;
-                               else if (target_type == TypeManager.uint32_type)
-                                       return (uint) v;
-                               else if (target_type == TypeManager.char_type)
-                                       return (char) v;
-                               else if (target_type == TypeManager.sbyte_type){
-                                       if (v <= SByte.MaxValue)
-                                               return (sbyte) v;
-                               } else if (target_type == TypeManager.short_type)
-                                       return (short) v;
-                               else if (target_type == TypeManager.ushort_type)
-                                       return (ushort) v;
-                               else if (target_type == TypeManager.int64_type)
-                                       return (long) v;
-                               else if (target_type == TypeManager.uint64_type)
-                                       return (ulong) v;
-                       } else if (c is SByteConstant){
-                               sbyte v = ((SByteConstant) c).Value;
-                               
-                               if (target_type == TypeManager.int32_type)
-                                       return (int) v;
-                               else if (target_type == TypeManager.uint32_type){
-                                       if (v >= 0)
-                                               return (uint) v;
-                               } else if (target_type == TypeManager.char_type){
-                                       if (v >= 0)
-                                               return (char) v;
-                               } else if (target_type == TypeManager.byte_type){
-                                       if (v >= 0)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.short_type)
-                                       return (short) v;
-                               else if (target_type == TypeManager.ushort_type){
-                                       if (v >= 0)
-                                               return (ushort) v;
-                               } else if (target_type == TypeManager.int64_type)
-                                       return (long) v;
-                               else if (target_type == TypeManager.uint64_type){
-                                       if (v >= 0)
-                                               return (ulong) v;
-                               }
-                       } else if (c is ShortConstant){
-                               short v = ((ShortConstant) c).Value;
-                               
-                               if (target_type == TypeManager.int32_type){
-                                       return (int) v;
-                               } else if (target_type == TypeManager.uint32_type){
-                                       if (v >= 0)
-                                               return (uint) v;
-                               } else if (target_type == TypeManager.char_type){
-                                       if (v >= 0)
-                                               return (char) v;
-                               } else if (target_type == TypeManager.byte_type){
-                                       if (v >= Byte.MinValue && v <= Byte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.sbyte_type){
-                                       if (v >= SByte.MinValue && v <= SByte.MaxValue)
-                                               return (sbyte) v;
-                               } else if (target_type == TypeManager.ushort_type){
-                                       if (v >= 0)
-                                               return (ushort) v;
-                               } else if (target_type == TypeManager.int64_type)
-                                       return (long) v;
-                               else if (target_type == TypeManager.uint64_type)
-                                       return (ulong) v;
-                       } else if (c is UShortConstant){
-                               ushort v = ((UShortConstant) c).Value;
-                               
-                               if (target_type == TypeManager.int32_type)
-                                       return (int) v;
-                               else if (target_type == TypeManager.uint32_type)
-                                       return (uint) v;
-                               else if (target_type == TypeManager.char_type){
-                                       if (v >= Char.MinValue && v <= Char.MaxValue)
-                                               return (char) v;
-                               } else if (target_type == TypeManager.byte_type){
-                                       if (v >= Byte.MinValue && v <= Byte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.sbyte_type){
-                                       if (v <= SByte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.short_type){
-                                       if (v <= Int16.MaxValue)
-                                               return (short) v;
-                               } else if (target_type == TypeManager.int64_type)
-                                       return (long) v;
-                               else if (target_type == TypeManager.uint64_type)
-                                       return (ulong) v;
-
-                       } else if (c is CharConstant){
-                               char v = ((CharConstant) c).Value;
-                               
-                               if (target_type == TypeManager.int32_type)
-                                       return (int) v;
-                               else if (target_type == TypeManager.uint32_type)
-                                       return (uint) v;
-                               else if (target_type == TypeManager.byte_type){
-                                       if (v >= Byte.MinValue && v <= Byte.MaxValue)
-                                               return (byte) v;
-                               } else if (target_type == TypeManager.sbyte_type){
-                                       if (v <= SByte.MaxValue)
-                                               return (sbyte) v;
-                               } else if (target_type == TypeManager.short_type){
-                                       if (v <= Int16.MaxValue)
-                                               return (short) v;
-                               } else if (target_type == TypeManager.ushort_type)
-                                       return (short) v;
-                               else if (target_type == TypeManager.int64_type)
-                                       return (long) v;
-                               else if (target_type == TypeManager.uint64_type)
-                                       return (ulong) v;
-
-                       }
-                       c.Error_ConstantValueCannotBeConverted (loc, target_type);
-                       return null;
-               }
 
                //
                // Load the object from the pointer.  
@@ -1523,6 +1306,11 @@ namespace Mono.CSharp {
                        child.Emit (ec);
                }
 
+               public override Constant Increment ()
+               {
+                       throw new NotSupportedException ();
+               }
+
                public override bool IsDefaultValue {
                        get {
                                throw new NotImplementedException ();
@@ -1568,69 +1356,21 @@ namespace Mono.CSharp {
                        return Child.GetValue ();
                }
 
-               public object GetValueAsEnumType ()
+               public override object GetTypedValue ()
                {
+                       // FIXME: runtime is not ready to work with just emited enums
+                       if (!RootContext.StdLib) {
+                               return Child.GetValue ();
+                       }
+
                        return System.Enum.ToObject (type, Child.GetValue ());
                }
-
-               //
-               // Converts from one of the valid underlying types for an enumeration
-               // (int32, uint32, int64, uint64, short, ushort, byte, sbyte) to
-               // one of the internal compiler literals: Int/UInt/Long/ULong Literals.
-               //
-               public Constant WidenToCompilerConstant ()
+               
+               public override void Error_ValueCannotBeConverted (Location loc, Type t)
                {
-                       Type t = TypeManager.EnumToUnderlying (Child.Type);
-                       object v = ((Constant) Child).GetValue ();;
-                       
-                       if (t == TypeManager.int32_type)
-                               return new IntConstant ((int) v);
-                       if (t == TypeManager.uint32_type)
-                               return new UIntConstant ((uint) v);
-                       if (t == TypeManager.int64_type)
-                               return new LongConstant ((long) v);
-                       if (t == TypeManager.uint64_type)
-                               return new ULongConstant ((ulong) v);
-                       if (t == TypeManager.short_type)
-                               return new ShortConstant ((short) v);
-                       if (t == TypeManager.ushort_type)
-                               return new UShortConstant ((ushort) v);
-                       if (t == TypeManager.byte_type)
-                               return new ByteConstant ((byte) v);
-                       if (t == TypeManager.sbyte_type)
-                               return new SByteConstant ((sbyte) v);
-
-                       throw new Exception ("Invalid enumeration underlying type: " + t);
+                       Convert.Error_CannotImplicitConversion (loc, Type, t);
                }
 
-               //
-               // Extracts the value in the enumeration on its native representation
-               //
-               public object GetPlainValue ()
-               {
-                       Type t = TypeManager.EnumToUnderlying (Child.Type);
-                       object v = ((Constant) Child).GetValue ();;
-                       
-                       if (t == TypeManager.int32_type)
-                               return (int) v;
-                       if (t == TypeManager.uint32_type)
-                               return (uint) v;
-                       if (t == TypeManager.int64_type)
-                               return (long) v;
-                       if (t == TypeManager.uint64_type)
-                               return (ulong) v;
-                       if (t == TypeManager.short_type)
-                               return (short) v;
-                       if (t == TypeManager.ushort_type)
-                               return (ushort) v;
-                       if (t == TypeManager.byte_type)
-                               return (byte) v;
-                       if (t == TypeManager.sbyte_type)
-                               return (sbyte) v;
-
-                       return null;
-               }
-               
                public override string AsString ()
                {
                        return Child.AsString ();
@@ -1666,6 +1406,11 @@ namespace Mono.CSharp {
                        return Child.ConvertToInt ();
                }
 
+               public override Constant Increment()
+               {
+                       return new EnumConstant (Child.Increment (), type);
+               }
+
                public override bool IsDefaultValue {
                        get {
                                return Child.IsDefaultValue;
@@ -1681,6 +1426,27 @@ namespace Mono.CSharp {
                                return Child.IsNegative;
                        }
                }
+
+               public override Constant ToType (Type type, Location loc)
+               {
+                       if (Type == type) {
+                               // This is workaround of mono bug. It can be removed when the latest corlib spreads enough
+                               if (TypeManager.IsEnumType (type.UnderlyingSystemType))
+                                       return this;
+
+                               if (type.UnderlyingSystemType != Child.Type)
+                                       Child = Child.ToType (type.UnderlyingSystemType, loc);
+                               return this;
+                       }
+
+                       if (!Convert.ImplicitStandardConversionExists (Convert.ConstantEC, this, type)){
+                               Error_ValueCannotBeConverted (loc, type);
+                               return null;
+                       }
+
+                       return Child.ToType (type, loc);
+               }
+
        }
 
        /// <summary>
@@ -1691,12 +1457,6 @@ namespace Mono.CSharp {
        /// </summary>
        public class BoxedCast : EmptyCast {
 
-               public BoxedCast (Expression expr)
-                       : base (expr, TypeManager.object_type) 
-               {
-                       eclass = ExprClass.Value;
-               }
-
                public BoxedCast (Expression expr, Type target_type)
                        : base (expr, target_type)
                {
@@ -2287,14 +2047,15 @@ namespace Mono.CSharp {
                        if (current_block != null){
                                LocalInfo vi = current_block.GetLocalInfo (Name);
                                if (vi != null){
-                                       Expression var;
-                                       
-                                       var = new LocalVariableReference (ec.CurrentBlock, Name, loc);
-                                       
-                                       if (right_side != null)
+                                       LocalVariableReference var = new LocalVariableReference (ec.CurrentBlock, Name, loc);
+                                       if (right_side != null) {
                                                return var.ResolveLValue (ec, right_side, loc);
-                                       else
-                                               return var.Resolve (ec);
+                                       } else {
+                                               ResolveFlags rf = ResolveFlags.VariableOrValue;
+                                               if (intermediate)
+                                                       rf |= ResolveFlags.DisableFlowAnalysis;
+                                               return var.Resolve (ec, rf);
+                                       }
                                }
 
                                ParameterReference pref = current_block.Toplevel.GetParameterReference (Name, loc);
@@ -3096,7 +2857,7 @@ namespace Mono.CSharp {
                                if (gen_params.Length != atypes.Length)
                                        continue;
 
-                               list.Add (mi.BindGenericParameters (atypes));
+                               list.Add (mi.MakeGenericMethod (atypes));
                        }
 
                        if (list.Count > 0) {
@@ -3183,39 +2944,31 @@ namespace Mono.CSharp {
                public override Expression ResolveMemberAccess (EmitContext ec, Expression left, Location loc,
                                                                SimpleName original)
                {
-                       bool left_is_type = left is TypeExpr;
-
                        FieldInfo fi = FieldInfo.Mono_GetGenericFieldDefinition ();
 
-                       Type decl_type = fi.DeclaringType;
-                       
-                       bool is_emitted = fi is FieldBuilder;
-                       Type t = fi.FieldType;
-                       
-                       if (is_emitted) {
-                               Const c = TypeManager.LookupConstant ((FieldBuilder) fi);
-                               
-                               if (c != null) {
-                                       object o;
-                                       if (!c.LookupConstantValue (out o))
-                                               return null;
-
-                                       c.SetMemberIsUsed ();
-                                       object real_value = ((Constant) c.Expr).GetValue ();
+                       if (fi.IsLiteral) {
+                               IConstant ic = TypeManager.GetConstant (fi);
+                               if (ic == null) {
+                                       ic = new ExternalConstant (fi);
+                                       TypeManager.RegisterConstant (fi, ic);
+                               }
 
-                                       Expression exp = Constantify (real_value, t);
-                                       
-                                       if (!left_is_type && 
-                                           (original == null || !original.IdenticalNameAndTypeName (ec, left, loc))) {
-                                               Report.SymbolRelatedToPreviousError (c);
-                                               error176 (loc, c.GetSignatureForError ());
-                                               return null;
-                                       }
-                                       
-                                       return exp;
+                               bool left_is_type = left is TypeExpr;
+                               if (!left_is_type && (original == null || !original.IdenticalNameAndTypeName (ec, left, loc))) {
+                                       Report.SymbolRelatedToPreviousError (FieldInfo);
+                                       error176 (loc, TypeManager.GetFullNameSignature (FieldInfo));
+                                       return null;
                                }
+
+                               if (ic.ResolveValue ())
+                                       ic.CheckObsoleteness (loc);
+
+                               return ic.Value;
                        }
 
+                       bool is_emitted = fi is FieldBuilder;
+                       Type t = fi.FieldType;
+                       
                        //
                        // Decimal constants cannot be encoded in the constant blob, and thus are marked
                        // as IsInitOnly ('readonly' in C# parlance).  We get its value from the 
@@ -3227,46 +2980,6 @@ namespace Mono.CSharp {
                                        return new DecimalConstant (((System.Runtime.CompilerServices.DecimalConstantAttribute) attrs [0]).Value);
                        }
                        
-                       if (fi.IsLiteral) {
-                               object o;
-
-                               if (is_emitted)
-                                       o = TypeManager.GetValue ((FieldBuilder) fi);
-                               else
-                                       o = fi.GetValue (fi);
-                               
-                               if (decl_type.IsSubclassOf (TypeManager.enum_type)) {
-                                       if (!left_is_type &&
-                                           (original == null || !original.IdenticalNameAndTypeName (ec, left, loc))) {
-                                               error176 (loc, TypeManager.GetFullNameSignature (FieldInfo));
-                                               return null;
-                                       }                                       
-                                       
-                                       Expression enum_member = MemberLookup (
-                                              ec, decl_type, "value__", MemberTypes.Field,
-                                              AllBindingFlags | BindingFlags.NonPublic, loc); 
-                                       
-                                       Enum en = TypeManager.LookupEnum (decl_type);
-                                       
-                                       Constant c;
-                                       if (en != null)
-                                               c = Constantify (o, en.UnderlyingType);
-                                       else 
-                                               c = Constantify (o, enum_member.Type);
-                                       
-                                       return new EnumConstant (c, decl_type);
-                               }
-
-                               Expression exp = Constantify (o, t);
-                               
-                               if (!left_is_type) {
-                                       error176 (loc, TypeManager.GetFullNameSignature (FieldInfo));
-                                       return null;
-                               }
-                               
-                               return exp;
-                       }
-                       
                        if (t.IsPointer && !ec.InUnsafe) {
                                UnsafeError (loc);
                                return null;
@@ -3319,9 +3032,7 @@ namespace Mono.CSharp {
                                ObsoleteAttribute oa;
                                FieldBase f = TypeManager.GetField (FieldInfo);
                                if (f != null) {
-                                       oa = f.GetObsoleteAttribute (f.Parent);
-                                       if (oa != null)
-                                               AttributeTester.Report_ObsoleteMessage (oa, f.GetSignatureForError (), loc);
+                                       f.CheckObsoleteness (loc);
                                        // To be sure that type is external because we do not register generated fields
                                } else if (!(FieldInfo.DeclaringType is TypeBuilder)) {                                
                                        oa = AttributeTester.GetMemberObsoleteAttribute (FieldInfo);
@@ -3780,6 +3491,26 @@ namespace Mono.CSharp {
 
                        return true;
                }
+
+               void Error_PropertyNotFound (MethodInfo mi, bool getter)
+               {
+                       // TODO: correctly we should compare arguments but it will lead to bigger changes
+                       if (mi is MethodBuilder) {
+                               Error_TypeDoesNotContainDefinition (loc, PropertyInfo.DeclaringType, Name);
+                               return;
+                       }
+
+                       StringBuilder sig = new StringBuilder (TypeManager.CSharpName (mi.DeclaringType));
+                       sig.Append ('.');
+                       ParameterData iparams = TypeManager.GetParameterData (mi);
+                       sig.Append (getter ? "get_" : "set_");
+                       sig.Append (Name);
+                       sig.Append (iparams.GetSignatureForError ());
+
+                       Report.SymbolRelatedToPreviousError (mi);
+                       Report.Error (1546, loc, "Property `{0}' is not supported by the C# language. Try to call the accessor method `{1}' directly",
+                               Name, sig.ToString ());
+               }
                
                override public Expression DoResolve (EmitContext ec)
                {
@@ -3788,10 +3519,7 @@ namespace Mono.CSharp {
 
                        if (getter != null){
                                if (TypeManager.GetArgumentTypes (getter).Length != 0){
-                                       Report.Error (
-                                               117, loc, "`{0}' does not contain a " +
-                                               "definition for `{1}'.", getter.DeclaringType,
-                                               Name);
+                                       Error_PropertyNotFound (getter, true);
                                        return null;
                                }
                        }
@@ -3866,10 +3594,7 @@ namespace Mono.CSharp {
                        }
 
                        if (TypeManager.GetArgumentTypes (setter).Length != 1){
-                               Report.Error (
-                                       117, loc, "`{0}' does not contain a " +
-                                       "definition for `{1}'.", getter.DeclaringType,
-                                       Name);
+                               Error_PropertyNotFound (setter, false);
                                return null;
                        }