Fix Firebird 'make dist' and build
[mono.git] / mcs / gmcs / ecore.cs
index b0b4442c33816f1c996ed8ba1a9c9ae02cc93199..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,
+
        }
 
        //
@@ -123,10 +128,10 @@ namespace Mono.CSharp {
                /// </summary>
                public void Error (int error, string s)
                {
-                       if (!Location.IsNull (loc))
-                               Report.Error (error, loc, s);
-                       else
+                       if (loc.IsNull)
                                Report.Error (error, s);
+                       else
+                               Report.Error (error, loc, s);
                }
 
                /// <summary>
@@ -233,7 +238,12 @@ namespace Mono.CSharp {
                // This is used if the expression should be resolved as a type or namespace name.
                // the default implementation fails.   
                //
-               public virtual FullNamedExpression ResolveAsTypeStep (EmitContext ec)
+               public FullNamedExpression ResolveAsTypeStep (EmitContext ec)
+               {
+                       return ResolveAsTypeStep (ec, false);
+               }
+
+               public virtual FullNamedExpression ResolveAsTypeStep (EmitContext ec,  bool silent)
                {
                        return null;
                }
@@ -243,22 +253,23 @@ namespace Mono.CSharp {
                // value will be returned if the expression is not a type
                // reference
                //
-               public virtual TypeExpr ResolveAsTypeTerminal (EmitContext ec)
+               public TypeExpr ResolveAsTypeTerminal (EmitContext ec)
+               {
+                       return ResolveAsTypeTerminal (ec, false);
+               }
+
+               public virtual TypeExpr ResolveAsTypeTerminal (EmitContext ec, bool silent)
                {
                        int errors = Report.Errors;
 
-                       FullNamedExpression fne = ResolveAsTypeStep (ec);
+                       FullNamedExpression fne = ResolveAsTypeStep (ec, silent);
 
-                       if (fne == null) {
-                               if (errors == Report.Errors)
-                                       NamespaceEntry.Error_NamespaceNotFound (Location, ToString ());
+                       if (fne == null)
                                return null;
-                       }
 
                        if (fne.eclass != ExprClass.Type) {
-                               if (errors == Report.Errors)
-                                       Report.Error (118, Location, "`{0}' denotes a `{1}', where a type was expected",
-                                                     fne.FullName, fne.ExprClassName ());
+                               if (!silent && (errors == Report.Errors))
+                                       fne.Error_UnexpectedKind (null, "type", loc);
                                return null;
                        }
 
@@ -281,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) {
@@ -316,11 +338,14 @@ namespace Mono.CSharp {
                public Expression Resolve (EmitContext ec, ResolveFlags flags)
                {
                        if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type) 
-                               return ResolveAsTypeStep (ec);
+                               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;
@@ -331,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;
@@ -364,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>
@@ -489,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)
@@ -700,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;
                        }
 
@@ -721,7 +772,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       MemberList ml = TypeManager.FindMembers (qualifier_type, MemberTypes.Constructor,
+                       MemberList ml = TypeManager.FindMembers (queried_type, MemberTypes.Constructor,
                                                                 BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, null, null);
                        if (name == ".ctor" && ml.Count == 0)
                        {
@@ -802,7 +853,7 @@ namespace Mono.CSharp {
                        return operator_true;
                }
                
-               public string ExprClassName ()
+               string ExprClassName ()
                {
                        switch (eclass){
                        case ExprClass.Invalid:
@@ -832,10 +883,19 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Reports that we were expecting `expr' to be of class `expected'
                /// </summary>
-               public void Error_UnexpectedKind (string expected, Location loc)
+               public void Error_UnexpectedKind (EmitContext ec, string expected, Location loc)
                {
-                       Report.Error (118, loc,
-                               "Expression denotes a `{0}', where a `{1}' was expected", ExprClassName (), expected);
+                       Error_UnexpectedKind (ec, expected, ExprClassName (), loc);
+               }
+
+               public void Error_UnexpectedKind (EmitContext ec, string expected, string was, Location loc)
+               {
+                       string name = GetSignatureForError ();
+                       if (ec != null)
+                               name = ec.DeclSpace.GetSignatureForError () + '.' + name;
+
+                       Report.Error (118, loc, "`{0}' is a `{1}' but a `{2}' was expected",
+                             name, was, expected);
                }
 
                public void Error_UnexpectedKind (ResolveFlags flags, Location loc)
@@ -871,290 +931,10 @@ namespace Mono.CSharp {
                                "Expression denotes a `{0}', where a `{1}' was expected", ExprClassName (), sb);
                }
                
-               static public void Error_ConstantValueCannotBeConverted (Location l, string val, Type t)
-               {
-                       Report.Error (31, l, "Constant value `" + val + "' cannot be converted to " +
-                                     TypeManager.CSharpName (t));
-               }
-
                public static void UnsafeError (Location loc)
                {
                        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;
-                       }
-                       
-                       string s = "";
-
-                       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;
-                               }
-
-                               s = v.ToString ();
-                       } 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;
-                               s = v.ToString ();
-                       } 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;
-                               }
-                               s = v.ToString ();
-                       } 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;
-                               }
-                               s = v.ToString ();
-                       } 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;
-                               s = v.ToString ();
-                       } 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;
-                               }
-                               s = v.ToString ();
-                       } 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;
-
-                               s = v.ToString ();
-                       } 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;
-
-                               s = v.ToString ();
-                       } 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;
-
-                               s = v.ToString ();
-                       }
-                       Error_ConstantValueCannotBeConverted (loc, s, target_type);
-                       return null;
-               }
 
                //
                // Load the object from the pointer.  
@@ -1526,6 +1306,11 @@ namespace Mono.CSharp {
                        child.Emit (ec);
                }
 
+               public override Constant Increment ()
+               {
+                       throw new NotSupportedException ();
+               }
+
                public override bool IsDefaultValue {
                        get {
                                throw new NotImplementedException ();
@@ -1571,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 ();
@@ -1669,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;
@@ -1684,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>
@@ -1694,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)
                {
@@ -2194,30 +1951,56 @@ namespace Mono.CSharp {
                        return null;
                }
 
-               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
+               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
                {
-                       FullNamedExpression dt = ec.DeclSpace.LookupGeneric (Name, loc);
-                       if (dt != null)
-                               return dt.ResolveAsTypeStep (ec);
+                       FullNamedExpression fne = ec.DeclSpace.LookupGeneric (Name, loc);
+                       if (fne != null)
+                               return fne.ResolveAsTypeStep (ec, silent);
 
                        int errors = Report.Errors;
-                       dt = ec.DeclSpace.LookupType (Name, loc, /*ignore_cs0104=*/ false);
-                       if (Report.Errors != errors)
-                               return null;
+                       fne = ec.DeclSpace.LookupType (Name, loc, /*ignore_cs0104=*/ false);
 
-                       if ((dt == null) || (dt.Type == null))
-                               return dt;
+                       if (fne != null) {
+                               if (fne.Type == null)
+                                       return fne;
 
-                       FullNamedExpression nested = ResolveNested (ec, dt.Type);
-                       if (nested != null)
-                               return nested.ResolveAsTypeStep (ec);
+                               FullNamedExpression nested = ResolveNested (ec, fne.Type);
+                               if (nested != null)
+                                       return nested.ResolveAsTypeStep (ec);
+
+                               if (Arguments != null) {
+                                       ConstructedType ct = new ConstructedType (fne, Arguments, loc);
+                                       return ct.ResolveAsTypeStep (ec);
+                               }
 
-                       if (Arguments != null) {
-                               ConstructedType ct = new ConstructedType (dt, Arguments, loc);
-                               return ct.ResolveAsTypeStep (ec);
+                               return fne;
                        }
 
-                       return dt;
+                       if (silent || errors != Report.Errors)
+                               return null;
+
+                       MemberCore mc = ec.DeclSpace.GetDefinition (Name);
+                       if (mc != null) {
+                               Error_UnexpectedKind (ec, "type", GetMemberType (mc), loc);
+                       } else {
+                               NamespaceEntry.Error_NamespaceNotFound (loc, Name);
+                       }
+
+                       return null;
+               }
+
+               // TODO: I am still not convinced about this. If someone else will need it
+               // implement this as virtual property in MemberCore hierarchy
+               string GetMemberType (MemberCore mc)
+               {
+                       if (mc is PropertyBase)
+                               return "property";
+                       if (mc is Indexer)
+                               return "indexer";
+                       if (mc is FieldBase)
+                               return "field";
+
+                       return "type";
                }
 
                Expression SimpleNameResolve (EmitContext ec, Expression right_side, bool intermediate)
@@ -2264,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);
@@ -2314,7 +2098,7 @@ namespace Mono.CSharp {
                                        almost_matched_type = ec.ContainerType;
                                        almost_matched = (ArrayList) almostMatchedMembers.Clone ();
                                }
-                               e = ResolveAsTypeStep (ec);
+                               e = ResolveAsTypeStep (ec, false);
                        }
 
                        if (e == null) {
@@ -2421,7 +2205,7 @@ namespace Mono.CSharp {
        ///   section 10.8.1 (Fully Qualified Names).
        /// </summary>
        public abstract class FullNamedExpression : Expression {
-               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
+               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
                {
                        return this;
                }
@@ -2435,7 +2219,7 @@ namespace Mono.CSharp {
        ///   Fully resolved expression that evaluates to a type
        /// </summary>
        public abstract class TypeExpr : FullNamedExpression {
-               override public FullNamedExpression ResolveAsTypeStep (EmitContext ec)
+               override public FullNamedExpression ResolveAsTypeStep (EmitContext ec, bool silent)
                {
                        TypeExpr t = DoResolveAsTypeStep (ec);
                        if (t == null)
@@ -2542,15 +2326,11 @@ namespace Mono.CSharp {
                }
 
                public override string Name {
-                       get {
-                               return Type.ToString ();
-                       }
+                       get { return Type.ToString (); }
                }
 
                public override string FullName {
-                       get {
-                               return Type.FullName != null ? Type.FullName : Type.Name;
-                       }
+                       get { return Type.FullName; }
                }
        }
 
@@ -2567,36 +2347,73 @@ namespace Mono.CSharp {
                        this.name = name;
                }
 
+               static readonly char [] dot_array = { '.' };
                protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
-                       if (type == null) {
-                               FullNamedExpression t = ec.DeclSpace.LookupType (name, Location.Null, /*ignore_cs0104=*/ false);
-                               if (t == null) {
-                                       NamespaceEntry.Error_NamespaceNotFound (loc, name);
-                                       return null;
+                       if (type != null)
+                               return this;
+
+                       // If name is of the form `N.I', first lookup `N', then search a member `I' in it.
+                       string rest = null;
+                       string lookup_name = name;
+                       int pos = name.IndexOf ('.');
+                       if (pos >= 0) {
+                               rest = name.Substring (pos + 1);
+                               lookup_name = name.Substring (0, pos);
+                       }
+
+                       FullNamedExpression resolved = Namespace.Root.Lookup (ec.DeclSpace, lookup_name, Location.Null);
+
+                       if (resolved != null && rest != null) {
+                               // Now handle the rest of the the name.
+                               string [] elements = rest.Split (dot_array);
+                               string element;
+                               int count = elements.Length;
+                               int i = 0;
+                               while (i < count && resolved != null && resolved is Namespace) {
+                                       Namespace ns = resolved as Namespace;
+                                       element = elements [i++];
+                                       lookup_name += "." + element;
+                                       resolved = ns.Lookup (ec.DeclSpace, element, Location.Null);
                                }
-                               if (!(t is TypeExpr)) {
-                                       Report.Error (118, Location, "`{0}' denotes a `{1}', where a type was expected",
-                                                     t.FullName, t.ExprClassName ());
 
-                                       return null;
+                               if (resolved != null && resolved is TypeExpr) {
+                                       Type t = ((TypeExpr) resolved).Type;
+                                       while (t != null) {
+                                               if (!ec.DeclSpace.CheckAccessLevel (t)) {
+                                                       resolved = null;
+                                                       lookup_name = t.FullName;
+                                                       break;
+                                               }
+                                               if (i == count) {
+                                                       type = t;
+                                                       return this;
+                                               }
+                                               t = TypeManager.GetNestedType (t, elements [i++]);
+                                       }
                                }
-                               type = ((TypeExpr) t).ResolveType (ec);
                        }
 
+                       if (resolved == null) {
+                               NamespaceEntry.Error_NamespaceNotFound (loc, lookup_name);
+                               return null;
+                       }
+
+                       if (!(resolved is TypeExpr)) {
+                               resolved.Error_UnexpectedKind (ec, "type", loc);
+                               return null;
+                       }
+
+                       type = ((TypeExpr) resolved).ResolveType (ec);
                        return this;
                }
 
                public override string Name {
-                       get {
-                               return name;
-                       }
+                       get { return name; }
                }
 
                public override string FullName {
-                       get {
-                               return name;
-                       }
+                       get { return name; }
                }
        }
 
@@ -2604,10 +2421,41 @@ namespace Mono.CSharp {
        ///   Represents an "unbound generic type", ie. typeof (Foo<>).
        ///   See 14.5.11.
        /// </summary>
-       public class UnboundTypeExpression : TypeLookupExpression {
-               public UnboundTypeExpression (string name)
-                       : base (name)
-               { }
+       public class UnboundTypeExpression : TypeExpr
+       {
+               MemberName name;
+
+               public UnboundTypeExpression (MemberName name, Location l)
+               {
+                       this.name = name;
+                       loc = l;
+               }
+
+               protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
+               {
+                       Expression expr;
+                       if (name.Left != null) {
+                               Expression lexpr = name.Left.GetTypeExpression ();
+                               expr = new MemberAccess (lexpr, name.Basename, loc);
+                       } else {
+                               expr = new SimpleName (name.Basename, loc);
+                       }
+
+                       FullNamedExpression fne = expr.ResolveAsTypeStep (ec);
+                       if (fne == null)
+                               return null;
+
+                       type = fne.Type;
+                       return new TypeExpression (type, loc);
+               }
+
+               public override string Name {
+                       get { return name.FullName; }
+               }
+
+               public override string FullName {
+                       get { return name.FullName; }
+               }
        }
 
        public class TypeAliasExpression : TypeExpr {
@@ -3009,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) {
@@ -3096,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 
@@ -3140,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;
@@ -3232,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);
@@ -3693,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)
                {
@@ -3701,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;
                                }
                        }
@@ -3779,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;
                        }