This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / gmcs / expression.cs
index 49e0467d7d3ca6d8912e089eb3c19967f5cee2ae..889d3eba69703e357e38bd15c0fb18a984ce0a12 100755 (executable)
@@ -568,6 +568,16 @@ namespace Mono.CSharp {
                        return ResolveOperator (ec);
                }
 
+               public override Expression DoResolveLValue (EmitContext ec, Expression right)
+               {
+                       if (Oper == Operator.Indirection)
+                               return base.DoResolveLValue (ec, right);
+
+                       Error (131, "The left-hand side of an assignment must be a " +
+                              "variable, property or indexer");
+                       return null;
+               }
+
                public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
@@ -1109,6 +1119,8 @@ namespace Mono.CSharp {
                        if (probe_type == null)
                                return null;
 
+                       CheckObsoleteAttribute (probe_type);
+
                        expr = expr.Resolve (ec);
                        if (expr == null)
                                return null;
@@ -1845,6 +1857,8 @@ namespace Mono.CSharp {
                        if (type == null)
                                return null;
 
+                       CheckObsoleteAttribute (type);
+
                        eclass = ExprClass.Value;
 
                        if (expr is Constant){
@@ -1854,6 +1868,10 @@ namespace Mono.CSharp {
                                        return e;
                        }
 
+                       if (type.IsPointer && !ec.InUnsafe) {
+                               UnsafeError (loc);
+                               return null;
+                       }
                        expr = Convert.ExplicitConversion (ec, expr, type, loc);
                        return expr;
                }
@@ -2089,7 +2107,7 @@ namespace Mono.CSharp {
                                                } else if (right is LongConstant){
                                                        long ll = ((LongConstant) right).Value;
 
-                                                       if (ll > 0)
+                                                       if (ll >= 0)
                                                                right = new ULongConstant ((ulong) ll);
                                                } else {
                                                        e = Convert.ImplicitNumericConversion (ec, right, l, loc);
@@ -2322,6 +2340,13 @@ namespace Mono.CSharp {
                                        Type = TypeManager.bool_type;
                                        return this;
                                }
+                               
+                               // IntPtr equality
+                               if (l == TypeManager.intptr_type && r == TypeManager.intptr_type) {
+                                       Type = TypeManager.bool_type;
+                                       
+                                       return this;
+                               }
                        }
 
                        //
@@ -2384,8 +2409,18 @@ namespace Mono.CSharp {
                                        
                                        // try to fold it in on the left
                                        if (left is StringConcat) {
-                                               ((StringConcat) left).Append (ec, right);
-                                               return left.Resolve (ec);
+
+                                               //
+                                               // We have to test here for not-null, since we can be doubly-resolved
+                                               // take care of not appending twice
+                                               //
+                                               if (type == null){
+                                                       type = TypeManager.string_type;
+                                                       ((StringConcat) left).Append (ec, right);
+                                                       return left.Resolve (ec);
+                                               } else {
+                                                       return left;
+                                               }
                                        }
 
                                        // Otherwise, start a new concat expression
@@ -2701,13 +2736,16 @@ namespace Mono.CSharp {
                            oper == Operator.BitwiseOr ||
                            oper == Operator.ExclusiveOr){
                                if (l == r){
-                                       if (!((l == TypeManager.int32_type) ||
-                                             (l == TypeManager.uint32_type) ||
-                                             (l == TypeManager.short_type) ||
-                                             (l == TypeManager.ushort_type) ||
-                                             (l == TypeManager.int64_type) ||
-                                             (l == TypeManager.uint64_type))){
+                                       if (((l == TypeManager.int32_type) ||
+                                            (l == TypeManager.uint32_type) ||
+                                            (l == TypeManager.short_type) ||
+                                            (l == TypeManager.ushort_type) ||
+                                            (l == TypeManager.int64_type) ||
+                                            (l == TypeManager.uint64_type))){
                                                type = l;
+                                       } else {
+                                               Error_OperatorCannotBeApplied ();
+                                               return null;
                                        }
                                } else {
                                        Error_OperatorCannotBeApplied ();
@@ -2959,7 +2997,7 @@ namespace Mono.CSharp {
                                ig.MarkLabel (end);
                                return;
                        }
-                       
+
                        left.Emit (ec);
                        right.Emit (ec);
 
@@ -3337,6 +3375,7 @@ namespace Mono.CSharp {
                }
 
                Expression op_true, op_false, op;
+               LocalTemporary left_temp;
 
                public override Expression DoResolve (EmitContext ec)
                {
@@ -3349,8 +3388,10 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       left_temp = new LocalTemporary (ec, type);
+
                        ArrayList arguments = new ArrayList ();
-                       arguments.Add (new Argument (left, Argument.AType.Expression));
+                       arguments.Add (new Argument (left_temp, Argument.AType.Expression));
                        arguments.Add (new Argument (right, Argument.AType.Expression));
                        method = Invocation.OverloadResolve (
                                ec, (MethodGroupExpr) operator_group, arguments, false, loc)
@@ -3362,8 +3403,8 @@ namespace Mono.CSharp {
 
                        op = new StaticCallExpr (method, arguments, loc);
 
-                       op_true = GetOperatorTrue (ec, left, loc);
-                       op_false = GetOperatorFalse (ec, left, loc);
+                       op_true = GetOperatorTrue (ec, left_temp, loc);
+                       op_false = GetOperatorFalse (ec, left_temp, loc);
                        if ((op_true == null) || (op_false == null)) {
                                Error218 ();
                                return null;
@@ -3380,8 +3421,11 @@ namespace Mono.CSharp {
 
                        ig.Emit (OpCodes.Nop);
 
-                       (is_and ? op_false : op_true).EmitBranchable (ec, false_target, false);
                        left.Emit (ec);
+                       left_temp.Store (ec);
+
+                       (is_and ? op_false : op_true).EmitBranchable (ec, false_target, false);
+                       left_temp.Emit (ec);
                        ig.Emit (OpCodes.Br, end_target);
                        ig.MarkLabel (false_target);
                        op.Emit (ec);
@@ -3692,6 +3736,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       CheckObsoleteAttribute (e.Type);
+
                        if (local_info.LocalBuilder == null)
                                return ec.RemapLocalLValue (local_info, right_side);
                        
@@ -3950,7 +3996,8 @@ namespace Mono.CSharp {
                public enum AType : byte {
                        Expression,
                        Ref,
-                       Out
+                       Out,
+                       ArgList
                };
 
                public readonly AType ArgType;
@@ -3987,6 +4034,9 @@ namespace Mono.CSharp {
 
                public static string FullDesc (Argument a)
                {
+                       if (a.ArgType == AType.ArgList)
+                               return "__arglist";
+
                        return (a.ArgType == AType.Ref ? "ref " :
                                (a.ArgType == AType.Out ? "out " : "")) +
                                TypeManager.CSharpName (a.Expr.Type);
@@ -3996,7 +4046,7 @@ namespace Mono.CSharp {
                {
                        ConstructedType ctype = Expr as ConstructedType;
                        if (ctype != null)
-                               Expr = ctype.GetMemberAccess (ec);
+                               Expr = ctype.GetSimpleName (ec);
 
                        // FIXME: csc doesn't report any error if you try to use `ref' or
                        //        `out' in a delegate creation expression.
@@ -4025,6 +4075,24 @@ namespace Mono.CSharp {
 
                        if (ArgType == AType.Expression)
                                return true;
+                       else {
+                               //
+                               // Catch errors where fields of a MarshalByRefObject are passed as ref or out
+                               // This is only allowed for `this'
+                               //
+                               FieldExpr fe = Expr as FieldExpr;
+                               if (fe != null && !fe.IsStatic){
+                                       Expression instance = fe.InstanceExpression;
+
+                                       if (instance.GetType () != typeof (This)){
+                                               if (fe.InstanceExpression.Type.IsSubclassOf (TypeManager.mbr_type)){
+                                                       Report.Error (197, loc,
+                                                                     "Can not pass a type that derives from MarshalByRefObject with out or ref");
+                                                       return false;
+                                               }
+                                       }
+                               }
+                       }
 
                        if (Expr.eclass != ExprClass.Variable){
                                //
@@ -4360,7 +4428,8 @@ namespace Mono.CSharp {
                        if (cand_count == 0 && argument_count == 0)
                                return best == null || best_params ? 1 : 0;
 
-                       if (candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.PARAMS)
+                       if ((candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.PARAMS) &&
+                           (candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.ARGLIST))
                                if (cand_count != argument_count)
                                        return 0;
 
@@ -4517,20 +4586,22 @@ namespace Mono.CSharp {
                }
 
                static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
-                                                     ArrayList arguments, ref MethodBase candidate)
+                                                     ArrayList arguments, bool do_varargs,
+                                                     ref MethodBase candidate)
                {
                        if (!me.HasTypeArguments &&
                            !InferParamsTypeArguments (ec, arguments, ref candidate))
                                return false;
 
-                       return IsParamsMethodApplicable (ec, arguments, candidate);
+                       return IsParamsMethodApplicable (ec, arguments, candidate, do_varargs);
                }
 
                /// <summary>
                ///   Determines if the candidate method, if a params method, is applicable
                ///   in its expanded form to the given set of arguments
                /// </summary>
-               static bool IsParamsMethodApplicable (EmitContext ec, ArrayList arguments, MethodBase candidate)
+               static bool IsParamsMethodApplicable (EmitContext ec, ArrayList arguments,
+                                                     MethodBase candidate, bool do_varargs)
                {
                        int arg_count;
                        
@@ -4546,10 +4617,18 @@ namespace Mono.CSharp {
                        if (pd_count == 0)
                                return false;
                        
-                       if (pd.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS)
+                       int count = pd_count - 1;
+                       if (do_varargs) {
+                               if (pd.ParameterModifier (count) != Parameter.Modifier.ARGLIST)
+                                       return false;
+                               if (pd_count != arg_count)
+                                       return false;
+                       } else {
+                               if (pd.ParameterModifier (count) != Parameter.Modifier.PARAMS)
                                return false;
+                       }
                        
-                       if (pd_count - 1 > arg_count)
+                       if (count > arg_count)
                                return false;
                        
                        if (pd_count == 1 && arg_count == 0)
@@ -4560,7 +4639,7 @@ namespace Mono.CSharp {
                        // remains is when the number of parameters is
                        // less than or equal to the argument count.
                        //
-                       for (int i = 0; i < pd_count - 1; ++i) {
+                       for (int i = 0; i < count; ++i) {
 
                                Argument a = (Argument) arguments [i];
 
@@ -4591,6 +4670,14 @@ namespace Mono.CSharp {
                                
                        }
 
+                       if (do_varargs) {
+                               Argument a = (Argument) arguments [count];
+                               if (!(a.Expr is Arglist))
+                                       return false;
+
+                               return true;
+                       }
+
                        Type element_type = TypeManager.GetElementType (pd.ParameterType (pd_count - 1));
 
                        for (int i = pd_count - 1; i < arg_count; i++) {
@@ -4741,9 +4828,18 @@ namespace Mono.CSharp {
                                        applicable_type = candidate.DeclaringType;
                                        found_applicable = true;
                                        candidate_to_form [candidate] = false;
-                               } else if (IsParamsMethodApplicable (ec, me, Arguments, ref methods [i])) {
+                               } else if (IsParamsMethodApplicable (
+                                                  ec, me, Arguments,false, ref methods [i])) {
                                        // Candidate is applicable in expanded form
-                                       MethodBase candidate = methods [i];
+                                       MethodBase candidate = methods [i];
+                                       candidates.Add (candidate);
+                                       applicable_type = candidate.DeclaringType;
+                                       found_applicable = true; 
+                                       candidate_to_form [candidate] = true;
+                               } else if (IsParamsMethodApplicable (
+                                                  ec, me, Arguments,true, ref methods [i])) {
+                                       // Candidate is applicable in expanded form
+                                       MethodBase candidate = methods [i];
                                        candidates.Add (candidate);
                                        applicable_type = candidate.DeclaringType;
                                        found_applicable = true; 
@@ -4946,6 +5042,8 @@ namespace Mono.CSharp {
 
                                        if (chose_params_expanded)
                                                parameter_type = TypeManager.GetElementType (parameter_type);
+                               } else if (pm == Parameter.Modifier.ARGLIST){
+                                       continue;
                                } else {
                                        //
                                        // Check modifiers
@@ -5248,7 +5346,7 @@ namespace Mono.CSharp {
                                is_base = true;
 
                        if (expr is ConstructedType)
-                               expr = ((ConstructedType) expr).GetMemberAccess (ec);
+                               expr = ((ConstructedType) expr).GetSimpleName (ec);
 
                        expr = expr.Resolve (ec, ResolveFlags.VariableOrValue | ResolveFlags.MethodGroup);
                        if (expr == null)
@@ -5289,8 +5387,20 @@ namespace Mono.CSharp {
                        MethodInfo mi = method as MethodInfo;
                        if (mi != null) {
                                type = TypeManager.TypeToCoreType (mi.ReturnType);
-                               if (!mi.IsStatic && !mg.IsExplicitImpl && (mg.InstanceExpression == null))
+                               if (!mi.IsStatic && !mg.IsExplicitImpl && (mg.InstanceExpression == null)) {
                                        SimpleName.Error_ObjectRefRequired (ec, loc, mi.Name);
+                                       return null;
+                               }
+
+                               Expression iexpr = mg.InstanceExpression;
+                               if (mi.IsStatic && (iexpr != null) && !(iexpr is This)) {
+                                       if (mg.IdenticalTypeName)
+                                               mg.InstanceExpression = null;
+                                       else {
+                                               MemberAccess.error176 (loc, mi.Name);
+                                               return null;
+                                       }
+                               }
                        }
 
                        if (type.IsPointer){
@@ -5415,6 +5525,40 @@ namespace Mono.CSharp {
                        }
                }
 
+               static Type[] GetVarargsTypes (EmitContext ec, MethodBase mb,
+                                              ArrayList arguments)
+               {
+                       ParameterData pd = GetParameterData (mb);
+
+                       if (arguments == null)
+                               return new Type [0];
+
+                       Argument a = (Argument) arguments [pd.Count - 1];
+                       Arglist list = (Arglist) a.Expr;
+
+                       return list.ArgumentTypes;
+               }
+
+               /// <summary>
+               /// This checks the ConditionalAttribute on the method 
+               /// </summary>
+               static bool IsMethodExcluded (MethodBase method, EmitContext ec)
+               {
+                       if (method.IsConstructor)
+                               return false;
+
+                       IMethodData md = TypeManager.GetMethod (method);
+                       if (md != null)
+                               return md.IsExcluded (ec);
+
+                       // For some methods (generated by delegate class) GetMethod returns null
+                       // because they are not included in builder_to_method table
+                       if (method.DeclaringType is TypeBuilder)
+                               return false;
+
+                       return AttributeTester.IsConditionalMethodExcluded (method);
+               }
+
                /// <remarks>
                ///   is_base tells whether we want to force the use of the `call'
                ///   opcode instead of using callvirt.  Call is required to call
@@ -5460,13 +5604,24 @@ namespace Mono.CSharp {
                        }
 
                        //
-                       // This checks the `ConditionalAttribute' on the method, and the
-                       // ObsoleteAttribute
+                       // This checks ObsoleteAttribute on the method and on the declaring type
                        //
-                       TypeManager.MethodFlags flags = TypeManager.GetMethodFlags (method, loc);
-                       if ((flags & TypeManager.MethodFlags.IsObsoleteError) != 0)
-                               return;
-                       if ((flags & TypeManager.MethodFlags.ShouldIgnore) != 0)
+                       ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (method);
+                       if (oa != null)
+                               AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (method), loc);
+
+                       oa = AttributeTester.GetObsoleteAttribute (method.DeclaringType);
+                       if (oa != null) {
+                               AttributeTester.Report_ObsoleteMessage (oa, method.DeclaringType.FullName, loc);
+                       }
+
+
+                       oa = AttributeTester.GetObsoleteAttribute (method.DeclaringType);
+                       if (oa != null) {
+                               AttributeTester.Report_ObsoleteMessage (oa, method.DeclaringType.FullName, loc);
+                       }
+
+                       if (IsMethodExcluded (method, ec))
                                return;
                        
                        if (!is_static){
@@ -5521,23 +5676,29 @@ namespace Mono.CSharp {
                        }
 
                        EmitArguments (ec, method, Arguments);
+
+                       OpCode call_op;
+                       if (is_static || struct_call || is_base || (this_call && !method.IsVirtual))
+                               call_op = OpCodes.Call;
+                       else
+                               call_op = OpCodes.Callvirt;
+
+                       if ((method.CallingConvention & CallingConventions.VarArgs) != 0) {
+                               Type[] varargs_types = GetVarargsTypes (ec, method, Arguments);
+                               ig.EmitCall (call_op, (MethodInfo) method, varargs_types);
+                               return;
+                       }
+
                        //
                        // If you have:
                        // this.DoFoo ();
                        // and DoFoo is not virtual, you can omit the callvirt,
                        // because you don't need the null checking behavior.
                        //
-                       if (is_static || struct_call || is_base || (this_call && !method.IsVirtual)){
-                               if (method is MethodInfo) {
-                                       ig.Emit (OpCodes.Call, (MethodInfo) method);
-                               } else
-                                       ig.Emit (OpCodes.Call, (ConstructorInfo) method);
-                       } else {
                                if (method is MethodInfo)
-                                       ig.Emit (OpCodes.Callvirt, (MethodInfo) method);
+                               ig.Emit (call_op, (MethodInfo) method);
                                else
-                                       ig.Emit (OpCodes.Callvirt, (ConstructorInfo) method);
-                       }
+                               ig.Emit (call_op, (ConstructorInfo) method);
                }
                
                public override void Emit (EmitContext ec)
@@ -5767,6 +5928,8 @@ namespace Mono.CSharp {
                        if (type == null)
                                return null;
                        
+                       CheckObsoleteAttribute (type);
+
                        bool IsDelegate = TypeManager.IsDelegateType (type);
                        
                        if (IsDelegate){
@@ -5814,7 +5977,8 @@ namespace Mono.CSharp {
                                return this;
                        
                        Expression ml;
-                       ml = MemberLookupFinal (ec, null, type, ".ctor",
+                       ml = MemberLookupFinal (ec, type, type, ".ctor",
+                                               // For member-lookup, treat 'new Foo (bar)' as call to 'foo.ctor (bar)', where 'foo' is of type 'Foo'.
                                                MemberTypes.Constructor,
                                                AllBindingFlags | BindingFlags.DeclaredOnly, loc);
 
@@ -5985,7 +6149,7 @@ namespace Mono.CSharp {
        ///   initialization data and the other which does not need dimensions
        ///   specified but where initialization data is mandatory.
        /// </remarks>
-       public class ArrayCreation : ExpressionStatement {
+       public class ArrayCreation : Expression {
                Expression requested_base_type;
                ArrayList initializers;
 
@@ -6549,7 +6713,7 @@ namespace Mono.CSharp {
                //
                // Emits the initializers for the array
                //
-               void EmitStaticInitializers (EmitContext ec, bool is_expression)
+               void EmitStaticInitializers (EmitContext ec)
                {
                        //
                        // First, the static data
@@ -6561,8 +6725,7 @@ namespace Mono.CSharp {
 
                        fb = RootContext.MakeStaticData (data);
 
-                       if (is_expression)
-                               ig.Emit (OpCodes.Dup);
+                       ig.Emit (OpCodes.Dup);
                        ig.Emit (OpCodes.Ldtoken, fb);
                        ig.Emit (OpCodes.Call,
                                 TypeManager.void_initializearray_array_fieldhandle);
@@ -6574,7 +6737,7 @@ namespace Mono.CSharp {
                //
                // This always expect the top value on the stack to be the array
                //
-               void EmitDynamicInitializers (EmitContext ec, bool is_expression)
+               void EmitDynamicInitializers (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
                        int dims = bounds.Count;
@@ -6621,8 +6784,7 @@ namespace Mono.CSharp {
                                            num_automatic_initializers <= max_automatic_initializers) {
                                                Type etype = e.Type;
                                                
-                                               if (is_expression || i != top - 1)
-                                                       ig.Emit (OpCodes.Dup);
+                                               ig.Emit (OpCodes.Dup);
 
                                                for (int idx = 0; idx < dims; idx++) 
                                                        IntConstant.EmitInt (ig, current_pos [idx]);
@@ -6685,7 +6847,7 @@ namespace Mono.CSharp {
                        }
                }
                
-               void DoEmit (EmitContext ec, bool is_statement)
+               public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
                        
@@ -6709,23 +6871,13 @@ namespace Mono.CSharp {
                                // initialized. num_automatic_initializers will always be zero.  See
                                // CheckIndices.
                                        if (num_automatic_initializers > max_automatic_initializers)
-                                               EmitStaticInitializers (ec, dynamic_initializers || !is_statement);
+                                               EmitStaticInitializers (ec);
                                
                                if (dynamic_initializers)
-                                       EmitDynamicInitializers (ec, !is_statement);
+                                       EmitDynamicInitializers (ec);
                        }
                }
                
-               public override void Emit (EmitContext ec)
-               {
-                       DoEmit (ec, false);
-               }
-
-               public override void EmitStatement (EmitContext ec)
-               {
-                       DoEmit (ec, true);
-               }
-
                public object EncodeAsAttribute ()
                {
                        if (!is_one_dimensional){
@@ -6856,8 +7008,8 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
-                       
-                       ig.Emit (OpCodes.Ldarg_0);
+
+                       ec.EmitThis ();
                        if (ec.TypeContainer is Struct)
                                ig.Emit (OpCodes.Ldobj, type);
                }
@@ -6867,7 +7019,7 @@ namespace Mono.CSharp {
                        ILGenerator ig = ec.ig;
                        
                        if (ec.TypeContainer is Struct){
-                               ig.Emit (OpCodes.Ldarg_0);
+                               ec.EmitThis ();
                                source.Emit (ec);
                                ig.Emit (OpCodes.Stobj, type);
                        } else {
@@ -6878,7 +7030,7 @@ namespace Mono.CSharp {
 
                public void AddressOf (EmitContext ec, AddressOp mode)
                {
-                       ec.ig.Emit (OpCodes.Ldarg_0);
+                       ec.EmitThis ();
 
                        // FIMXE
                        // FIGURE OUT WHY LDARG_S does not work
@@ -6891,6 +7043,85 @@ namespace Mono.CSharp {
                }
        }
 
+       /// <summary>
+       ///   Represents the `__arglist' construct
+       /// </summary>
+       public class ArglistAccess : Expression
+       {
+               public ArglistAccess (Location loc)
+               {
+                       this.loc = loc;
+               }
+
+               public bool ResolveBase (EmitContext ec)
+               {
+                       eclass = ExprClass.Variable;
+                       type = TypeManager.runtime_argument_handle_type;
+                       return true;
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       if (!ResolveBase (ec))
+                               return null;
+
+                       if (ec.IsFieldInitializer || !ec.CurrentBlock.HasVarargs) {
+                               Error (190, "The __arglist construct is valid only within " +
+                                      "a variable argument method.");
+                               return null;
+                       }
+
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       ec.ig.Emit (OpCodes.Arglist);
+               }
+       }
+
+       /// <summary>
+       ///   Represents the `__arglist (....)' construct
+       /// </summary>
+       public class Arglist : Expression
+       {
+               public readonly Argument[] Arguments;
+
+               public Arglist (Argument[] args, Location l)
+               {
+                       Arguments = args;
+                       loc = l;
+               }
+
+               public Type[] ArgumentTypes {
+                       get {
+                               Type[] retval = new Type [Arguments.Length];
+                               for (int i = 0; i < Arguments.Length; i++)
+                                       retval [i] = Arguments [i].Type;
+                               return retval;
+                       }
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       eclass = ExprClass.Variable;
+                       type = TypeManager.runtime_argument_handle_type;
+
+                       foreach (Argument arg in Arguments) {
+                               if (!arg.Resolve (ec, loc))
+                                       return null;
+                       }
+
+                       return this;
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       foreach (Argument arg in Arguments)
+                               arg.Emit (ec);
+               }
+       }
+
        //
        // This produces the value that renders an instance, used by the iterators code
        //
@@ -6940,6 +7171,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       CheckObsoleteAttribute (typearg);
+
                        type = TypeManager.type_type;
                        eclass = ExprClass.Type;
                        return this;
@@ -7006,6 +7239,11 @@ namespace Mono.CSharp {
                        }
 
                        type_queried = QueriedType.Type;
+                       if (type_queried == null)
+                               return null;
+
+                       CheckObsoleteAttribute (type_queried);
+
                        if (!TypeManager.IsUnmanagedType (type_queried)){
                                Report.Error (208, loc, "Cannot take the size of an unmanaged type (" + TypeManager.CSharpName (type_queried) + ")");
                                return null;
@@ -7055,7 +7293,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               static void error176 (Location loc, string name)
+               public static void error176 (Location loc, string name)
                {
                        Report.Error (176, loc, "Static member `" +
                                      name + "' cannot be accessed " +
@@ -7063,21 +7301,13 @@ namespace Mono.CSharp {
                                      "type name instead");
                }
 
-               static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Location loc)
+               public static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Expression left, Location loc)
                {
-                       if (left_original == null)
-                               return false;
-
-                       if (!(left_original is SimpleName))
+                       SimpleName sn = left_original as SimpleName;
+                       if (sn == null || left == null || left.Type.Name != sn.Name)
                                return false;
 
-                       SimpleName sn = (SimpleName) left_original;
-
-                       TypeExpr t = RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc);
-                       if (t != null)
-                               return true;
-
-                       return false;
+                       return RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc) != null;
                }
                
                public static Expression ResolveMemberAccess (EmitContext ec, Expression member_lookup,
@@ -7102,17 +7332,17 @@ namespace Mono.CSharp {
 
                        if (member_lookup is FieldExpr){
                                FieldExpr fe = (FieldExpr) member_lookup;
-                               FieldInfo fi = fe.FieldInfo;
+                               FieldInfo fi = fe.FieldInfo.Mono_GetGenericFieldDefinition ();
                                Type decl_type = fi.DeclaringType;
 
                                if (fi is FieldBuilder) {
                                        Const c = TypeManager.LookupConstant ((FieldBuilder) fi);
                                        
                                        if (c != null) {
-                                               object o = c.LookupConstantValue ();
-                                               if (o == null)
+                                               object o;
+                                               if (!c.LookupConstantValue (out o))
                                                        return null;
-                                               
+
                                                object real_value = ((Constant) c.Expr).GetValue ();
 
                                                return Constantify (real_value, fi.FieldType);
@@ -7131,7 +7361,7 @@ namespace Mono.CSharp {
                                        
                                        if (decl_type.IsSubclassOf (TypeManager.enum_type)) {
                                                if (left_is_explicit && !left_is_type &&
-                                                   !IdenticalNameAndTypeName (ec, left_original, loc)) {
+                                                   !IdenticalNameAndTypeName (ec, left_original, member_lookup, loc)) {
                                                        error176 (loc, fe.FieldInfo.Name);
                                                        return null;
                                                }                                       
@@ -7185,6 +7415,7 @@ namespace Mono.CSharp {
                                                // accessors and private field etc so there's no need
                                                // to transform ourselves.
                                                //
+                                               ee.InstanceExpression = left;
                                                return ee;
                                        }
 
@@ -7198,21 +7429,23 @@ namespace Mono.CSharp {
                                        if (!left_is_explicit)
                                                left = null;
                                        
+                                       ee.InstanceExpression = left;
+
                                        return ResolveMemberAccess (ec, ml, left, loc, left_original);
                                }
                        }
 
                        if (member_lookup is IMemberExpr) {
                                IMemberExpr me = (IMemberExpr) member_lookup;
+                               MethodGroupExpr mg = me as MethodGroupExpr;
 
                                if (left_is_type){
-                                       MethodGroupExpr mg = me as MethodGroupExpr;
                                        if ((mg != null) && left_is_explicit && left.Type.IsInterface)
                                                mg.IsExplicitImpl = left_is_explicit;
 
                                        if (!me.IsStatic){
                                                if ((ec.IsFieldInitializer || ec.IsStatic) &&
-                                                   IdenticalNameAndTypeName (ec, left_original, loc))
+                                                   IdenticalNameAndTypeName (ec, left_original, member_lookup, loc))
                                                        return member_lookup;
 
                                                SimpleName.Error_ObjectRefRequired (ec, loc, me.Name);
@@ -7221,7 +7454,7 @@ namespace Mono.CSharp {
 
                                } else {
                                        if (!me.IsInstance){
-                                               if (IdenticalNameAndTypeName (ec, left_original, loc))
+                                               if (IdenticalNameAndTypeName (ec, left_original, left, loc))
                                                        return member_lookup;
 
                                                if (left_is_explicit) {
@@ -7251,6 +7484,9 @@ namespace Mono.CSharp {
                                                }
                                        }
 
+                                       if ((mg != null) && IdenticalNameAndTypeName (ec, left_original, left, loc))
+                                               mg.IdenticalTypeName = true;
+
                                        me.InstanceExpression = left;
                                }
 
@@ -7259,7 +7495,7 @@ namespace Mono.CSharp {
 
                        Console.WriteLine ("Left is: " + left);
                        Report.Error (-100, loc, "Support for [" + member_lookup + "] is not present yet");
-                       Environment.Exit (0);
+                       Environment.Exit (1);
                        return null;
                }
                
@@ -7277,7 +7513,7 @@ namespace Mono.CSharp {
                        //
 
                        Expression original = expr;
-                       expr = expr.Resolve (ec, flags | ResolveFlags.DisableFlowAnalysis);
+                       expr = expr.Resolve (ec, flags | ResolveFlags.Intermediate | ResolveFlags.DisableFlowAnalysis);
                        if (expr == null)
                                return null;
 
@@ -7303,8 +7539,7 @@ namespace Mono.CSharp {
                                expr_type = ((TypeExpr) expr).ResolveType (ec);
 
                                if (!ec.DeclSpace.CheckAccessLevel (expr_type)){
-                                       Error (122, "`" + expr_type + "' " +
-                                              "is inaccessible because of its protection level");
+                                       Report.Error_T (122, loc, expr_type);
                                        return null;
                                }
 
@@ -7315,9 +7550,23 @@ namespace Mono.CSharp {
                                                object value = en.LookupEnumValue (ec, Identifier, loc);
                                                
                                                if (value != null){
+                                                       ObsoleteAttribute oa = en.GetObsoleteAttribute (ec, Identifier);
+                                                       if (oa != null) {
+                                                               AttributeTester.Report_ObsoleteMessage (oa, en.GetSignatureForError (), Location);
+                                                       }
+
                                                        Constant c = Constantify (value, en.UnderlyingType);
                                                        return new EnumConstant (c, expr_type);
                                                }
+                                       } else {
+                                               CheckObsoleteAttribute (expr_type);
+
+                                               FieldInfo fi = expr_type.GetField (Identifier);
+                                               if (fi != null) {
+                                                       ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (fi);
+                                                       if (oa != null)
+                                                               AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (fi), Location);
+                                               }
                                        }
                                }
                        } else
@@ -7382,54 +7631,7 @@ namespace Mono.CSharp {
                                if (mg == null)
                                        throw new InternalErrorException ();
 
-                               if (args.Resolve (ec) == false)
-                                       return null;
-
-                               Type[] atypes = args.Arguments;
-
-                               int first_count = 0;
-                               MethodInfo first = null;
-
-                               ArrayList list = new ArrayList ();
-                               foreach (MethodBase mb in mg.Methods) {
-                                       MethodInfo mi = mb as MethodInfo;
-                                       if ((mi == null) || !mi.HasGenericParameters)
-                                               continue;
-
-                                       Type[] gen_params = mi.GetGenericArguments ();
-
-                                       if (first == null) {
-                                               first = mi;
-                                               first_count = gen_params.Length;
-                                       }
-
-                                       if (gen_params.Length != atypes.Length)
-                                               continue;
-
-                                       list.Add (mi.BindGenericParameters (atypes));
-                               }
-
-                               if (list.Count > 0) {
-                                       MethodGroupExpr new_mg = new MethodGroupExpr (
-                                               list, mg.Location);
-                                       new_mg.InstanceExpression = mg.InstanceExpression;
-                                       new_mg.HasTypeArguments = true;
-                                       return new_mg;
-                               }
-
-                               string name = expr_type + "." + Identifier;
-
-                               if (first != null)
-                                       Report.Error (
-                                               305, loc, "Using the generic method `{0}' " +
-                                               "requires {1} type arguments", name,
-                                               first_count);
-                               else
-                                       Report.Error (
-                                               308, loc, "The non-generic method `{0}' " +
-                                               "cannot be used with type arguments", name);
-
-                               return null;
+                               return mg.ResolveGeneric (ec, args);
                        }
 
                        // The following DoResolve/DoResolveLValue will do the definite assignment
@@ -7854,7 +8056,9 @@ namespace Mono.CSharp {
                                ig.Emit (OpCodes.Ldelem_R8);
                        else if (type == TypeManager.intptr_type)
                                ig.Emit (OpCodes.Ldelem_I);
-                       else if (type.IsValueType){
+                       else if (TypeManager.IsEnumType (type)){
+                               EmitLoadOpcode (ig, TypeManager.EnumToUnderlying (type));
+                       } else if (type.IsValueType){
                                ig.Emit (OpCodes.Ldelema, type);
                                ig.Emit (OpCodes.Ldobj, type);
                        } else if (type.IsGenericParameter)
@@ -8146,7 +8350,7 @@ namespace Mono.CSharp {
                        MemberInfo [] mi = TypeManager.MemberLookup (
                                caller_type, caller_type, lookup_type, MemberTypes.Property,
                                BindingFlags.Public | BindingFlags.Instance |
-                               BindingFlags.DeclaredOnly, p_name);
+                               BindingFlags.DeclaredOnly, p_name, null);
 
                        if (mi == null || mi.Length == 0)
                                return null;
@@ -8445,6 +8649,11 @@ namespace Mono.CSharp {
                                Error (1511, "Keyword base is not allowed in static method");
                                return null;
                        }
+
+                       if (ec.IsFieldInitializer){
+                               Error (1512, "Keyword base is not available in the current context");
+                               return null;
+                       }
                        
                        member_lookup = MemberLookup (ec, ec.ContainerType, null, base_type,
                                                      member, AllMemberTypes, AllBindingFlags,
@@ -8611,6 +8820,12 @@ namespace Mono.CSharp {
                        if (ltype == null)
                                return null;
 
+                       if ((ltype == TypeManager.void_type) && (dim != "*")) {
+                               Report.Error (1547, Location,
+                                             "Keyword 'void' cannot be used in this context");
+                               return null;
+                       }
+
                        int pos = 0;
                        while ((pos < dim.Length) && (dim [pos] == '[')) {
                                pos++;