2004-09-04 Marek Safar <marek.safar@seznam.cz>
[mono.git] / mcs / mcs / expression.cs
index d8fa7dde56053425a0f05f2d216ee0e44514337f..2d34749aec33fefbea17a5d4d2a7e96b5483550a 100755 (executable)
@@ -46,13 +46,13 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        if (args != null) 
-                               Invocation.EmitArguments (ec, mi, args);
+                               Invocation.EmitArguments (ec, mi, args, false, null);
 
                        ec.ig.Emit (OpCodes.Call, mi);
                        return;
                }
                
-               static public Expression MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
+               static public StaticCallExpr MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
                                                         Expression e, Location loc)
                {
                        ArrayList args;
@@ -66,7 +66,8 @@ namespace Mono.CSharp {
                                 return null;
 
                         args.Add (a);
-                       method = Invocation.OverloadResolve (ec, (MethodGroupExpr) mg, args, loc);
+                       method = Invocation.OverloadResolve (
+                               ec, (MethodGroupExpr) mg, args, false, loc);
 
                        if (method == null)
                                return null;
@@ -80,6 +81,10 @@ namespace Mono.CSharp {
                        if (TypeManager.TypeToCoreType (type) != TypeManager.void_type)
                                ec.ig.Emit (OpCodes.Pop);
                }
+               
+               public MethodInfo Method {
+                       get { return mi; }
+               }
        }
 
        public class ParenthesizedExpression : Expression
@@ -428,6 +433,11 @@ namespace Mono.CSharp {
                                               "of a fixed statement initializer");
                                        return null;
                                }
+                               
+                               if (ec.InFixedInitializer && ((variable != null) && variable.VerifyFixed (false))) {
+                                       Error (213, "You can not fix an already fixed expression");
+                                       return null;
+                               }
 
                                // According to the specs, a variable is considered definitely assigned if you take
                                // its address.
@@ -562,6 +572,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;
@@ -628,7 +648,7 @@ namespace Mono.CSharp {
        public class Indirection : Expression, IMemoryLocation, IAssignMethod {
                Expression expr;
                LocalTemporary temporary;
-               bool have_temporary;
+               bool prepared;
                
                public Indirection (Expression expr, Location l)
                {
@@ -644,54 +664,47 @@ namespace Mono.CSharp {
                
                public override void Emit (EmitContext ec)
                {
-                       ILGenerator ig = ec.ig;
-
-                       if (temporary != null){
-                               if (have_temporary) {
-                                       temporary.Emit (ec);
-                               } else {
-                                       expr.Emit (ec);
-                                       ec.ig.Emit (OpCodes.Dup);
-                                       temporary.Store (ec);
-                                       have_temporary = true;
-                               }
-                       } else
+                       if (!prepared)
                                expr.Emit (ec);
                        
-                       LoadFromPtr (ig, Type);
+                       LoadFromPtr (ec.ig, Type);
                }
 
-               public void EmitAssign (EmitContext ec, Expression source)
+               public void Emit (EmitContext ec, bool leave_copy)
                {
-                       if (temporary != null){
-                               if (have_temporary)
-                                       temporary.Emit (ec);
-                               else {
-                                       expr.Emit (ec);
-                                       ec.ig.Emit (OpCodes.Dup);
-                                       temporary.Store (ec);
-                                       have_temporary = true;
-                               }
-                       } else 
-                               expr.Emit (ec);
+                       Emit (ec);
+                       if (leave_copy) {
+                               ec.ig.Emit (OpCodes.Dup);
+                               temporary = new LocalTemporary (ec, expr.Type);
+                               temporary.Store (ec);
+                       }
+               }
+               
+               public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
+               {
+                       prepared = prepare_for_load;
+                       
+                       expr.Emit (ec);
 
+                       if (prepare_for_load)
+                               ec.ig.Emit (OpCodes.Dup);
+                       
                        source.Emit (ec);
+                       if (leave_copy) {
+                               ec.ig.Emit (OpCodes.Dup);
+                               temporary = new LocalTemporary (ec, expr.Type);
+                               temporary.Store (ec);
+                       }
+                       
                        StoreFromPtr (ec.ig, type);
+                       
+                       if (temporary != null)
+                               temporary.Emit (ec);
                }
                
                public void AddressOf (EmitContext ec, AddressOp Mode)
                {
-                       if (temporary != null){
-                               if (have_temporary){
-                                       temporary.Emit (ec);
-                                       return;
-                               }
-                               expr.Emit (ec);
-                               ec.ig.Emit (OpCodes.Dup);
-                               temporary.Store (ec);
-                               have_temporary = true;
-                       } else
-                               expr.Emit (ec);
+                       expr.Emit (ec);
                }
 
                public override Expression DoResolve (EmitContext ec)
@@ -701,12 +714,7 @@ namespace Mono.CSharp {
                        //
                        return this;
                }
-
-               public new void CacheTemporaries (EmitContext ec)
-               {
-                       temporary = new LocalTemporary (ec, expr.Type);
-               }
-
+               
                public override string ToString ()
                {
                        return "*(" + expr + ")";
@@ -742,13 +750,15 @@ namespace Mono.CSharp {
                }
                
                Mode mode;
+               bool is_expr = false;
+               bool recurse = false;
+               
                Expression expr;
-               LocalTemporary temp_storage;
 
                //
                // This is expensive for the simplest case.
                //
-               Expression method;
+               StaticCallExpr method;
                        
                public UnaryMutator (Mode m, Expression e, Location l)
                {
@@ -840,9 +850,7 @@ namespace Mono.CSharp {
                        } else if (expr.eclass == ExprClass.IndexerAccess){
                                IndexerAccess ia = (IndexerAccess) expr;
                                
-                               temp_storage = new LocalTemporary (ec, expr.Type);
-                               
-                               expr = ia.ResolveLValue (ec, temp_storage);
+                               expr = ia.ResolveLValue (ec, this);
                                if (expr == null)
                                        return null;
 
@@ -960,107 +968,39 @@ namespace Mono.CSharp {
                        }
                        
                }
-
-               static EmptyExpression empty_expr;
                
                void EmitCode (EmitContext ec, bool is_expr)
                {
-                       ILGenerator ig = ec.ig;
-                       IAssignMethod ia = (IAssignMethod) expr;
-                       Type expr_type = expr.Type;
-
-                       ia.CacheTemporaries (ec);
-
-                       if (temp_storage == null){
-                               //
-                               // Temporary improvement: if we are dealing with something that does
-                               // not require complicated instance setup, avoid using a temporary
-                               //
-                               // For now: only localvariables when not remapped
-                               //
-
-                               if (method == null &&
-                                   ((expr is LocalVariableReference) ||(expr is FieldExpr && ((FieldExpr) expr).FieldInfo.IsStatic))){
-                                       if (empty_expr == null)
-                                               empty_expr = new EmptyExpression ();
-                                       
-                                       switch (mode){
-                                       case Mode.PreIncrement:
-                                       case Mode.PreDecrement:
-                                               expr.Emit (ec);
-                                       
-                                               LoadOneAndEmitOp (ec, expr_type);
-                                               if (is_expr)
-                                                       ig.Emit (OpCodes.Dup);
-                                               ia.EmitAssign (ec, empty_expr);
-                                               break;
-                                               
-                                       case Mode.PostIncrement:
-                                       case Mode.PostDecrement:
-                                               expr.Emit (ec);
-                                               if (is_expr)
-                                                       ig.Emit (OpCodes.Dup);
-                                               
-                                               LoadOneAndEmitOp (ec, expr_type);
-                                               ia.EmitAssign (ec, empty_expr);
-                                               break;
-                                       }
-                                       return;
-                               }
-                               temp_storage = new LocalTemporary (ec, expr_type);
-                       }
-                       
-                       switch (mode){
-                       case Mode.PreIncrement:
-                       case Mode.PreDecrement:
-                               if (method == null){
-                                       expr.Emit (ec);
-                                       
-                                       LoadOneAndEmitOp (ec, expr_type);
-                               } else 
-                                       method.Emit (ec);
-                               
-                               temp_storage.Store (ec);
-                               ia.EmitAssign (ec, temp_storage);
-                               if (is_expr)
-                                       temp_storage.Emit (ec);
-                               break;
-                               
-                       case Mode.PostIncrement:
-                       case Mode.PostDecrement:
-                               if (is_expr)
-                                       expr.Emit (ec);
-                               
-                               if (method == null){
-                                       if (!is_expr)
-                                               expr.Emit (ec);
-                                       else
-                                               ig.Emit (OpCodes.Dup);
-                                       
-                                       LoadOneAndEmitOp (ec, expr_type);
-                               } else {
-                                       method.Emit (ec);
-                               }
-                               
-                               temp_storage.Store (ec);
-                               ia.EmitAssign (ec, temp_storage);
-                               break;
-                       }
-
-                       temp_storage.Release (ec);
+                       recurse = true;
+                       this.is_expr = is_expr;
+                       ((IAssignMethod) expr).EmitAssign (ec, this, is_expr && (mode == Mode.PreIncrement || mode == Mode.PreDecrement), true);
                }
+               
 
                public override void Emit (EmitContext ec)
                {
-                       EmitCode (ec, true);
+                       //
+                       // We use recurse to allow ourselfs to be the source
+                       // of an assignment. This little hack prevents us from
+                       // having to allocate another expression
+                       //
+                       if (recurse) {
+                               ((IAssignMethod) expr).Emit (ec, is_expr && (mode == Mode.PostIncrement  || mode == Mode.PostDecrement));
+                               if (method == null)
+                                       LoadOneAndEmitOp (ec, expr.Type);
+                               else
+                                       ec.ig.Emit (OpCodes.Call, method.Method);
+                               recurse = false;
+                               return;
+                       }
                        
+                       EmitCode (ec, true);
                }
                
                public override void EmitStatement (EmitContext ec)
                {
                        EmitCode (ec, false);
                }
-
        }
 
        /// <summary>
@@ -1096,6 +1036,8 @@ namespace Mono.CSharp {
                        if (probe_type == null)
                                return null;
 
+                       CheckObsoleteAttribute (probe_type);
+
                        expr = expr.Resolve (ec);
                        if (expr == null)
                                return null;
@@ -1219,16 +1161,11 @@ namespace Mono.CSharp {
                                warning_never_matches = true;
                        }
                        
-                       if (RootContext.WarningLevel >= 1){
-                               if (warning_always_matches)
-                                       Warning (183, "The expression is always of type `" +
-                                                TypeManager.CSharpName (probe_type) + "'");
-                               else if (warning_never_matches){
-                                       if (!(probe_type.IsInterface || expr.Type.IsInterface))
-                                               Warning (184,
-                                                        "The expression is never of type `" +
-                                                        TypeManager.CSharpName (probe_type) + "'");
-                               }
+                       if (warning_always_matches)
+                               Warning (183, "The given expression is always of the provided ('{0}') type", TypeManager.CSharpName (probe_type));
+                       else if (warning_never_matches){
+                               if (!(probe_type.IsInterface || expr.Type.IsInterface))
+                                       Warning (184, "The given expression is never of the provided ('{0}') type", TypeManager.CSharpName (probe_type));
                        }
 
                        return this;
@@ -1384,7 +1321,7 @@ namespace Mono.CSharp {
                        Expression real_expr = expr;
                        if (real_expr is EnumConstant)
                                real_expr = ((EnumConstant) real_expr).Child;
-                               
+
                        if (real_expr is ByteConstant){
                                byte v = ((ByteConstant) real_expr).Value;
        
@@ -1832,6 +1769,13 @@ namespace Mono.CSharp {
                        if (type == null)
                                return null;
 
+                       CheckObsoleteAttribute (type);
+
+                       if (type.IsAbstract && type.IsSealed) {
+                               Report.Error (716, loc, "Cannot convert to static type '{0}'", TypeManager.CSharpName (type));
+                               return null;
+                       }
+
                        eclass = ExprClass.Value;
 
                        if (expr is Constant){
@@ -1841,6 +1785,10 @@ namespace Mono.CSharp {
                                        return e;
                        }
 
+                       if (type.IsPointer && !ec.InUnsafe) {
+                               UnsafeError (loc);
+                               return null;
+                       }
                        expr = Convert.ExplicitConversion (ec, expr, type, loc);
                        return expr;
                }
@@ -2076,7 +2024,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);
@@ -2108,6 +2056,10 @@ namespace Mono.CSharp {
                                    (other == TypeManager.int32_type) ||
                                    (other == TypeManager.int64_type))
                                        Error_OperatorAmbiguous (loc, oper, l, r);
+                               else {
+                                       left = ForceConversion (ec, left, TypeManager.uint64_type);
+                                       right = ForceConversion (ec, right, TypeManager.uint64_type);
+                               }
                                type = TypeManager.uint64_type;
                        } else if (IsOfType (ec, l, r, TypeManager.int64_type, check_user_conv)){
                                //
@@ -2275,8 +2227,6 @@ namespace Mono.CSharp {
                        Type l = left.Type;
                        Type r = right.Type;
 
-                       bool overload_failed = false;
-
                        //
                        // Special cases: string comapred to null
                        //
@@ -2287,6 +2237,13 @@ namespace Mono.CSharp {
                                        
                                        return this;
                                }
+                               
+                               // IntPtr equality
+                               if (l == TypeManager.intptr_type && r == TypeManager.intptr_type) {
+                                       Type = TypeManager.bool_type;
+                                       
+                                       return this;
+                               }
                        }
 
                        //
@@ -2315,13 +2272,13 @@ namespace Mono.CSharp {
                                        args.Add (new Argument (left, Argument.AType.Expression));
                                        args.Add (new Argument (right, Argument.AType.Expression));
                                        
-                                       MethodBase method = Invocation.OverloadResolve (ec, union, args, Location.Null);
+                                       MethodBase method = Invocation.OverloadResolve (
+                                               ec, union, args, true, Location.Null);
+
                                        if (method != null) {
                                                MethodInfo mi = (MethodInfo) method;
                                                
                                                return new BinaryMethod (mi.ReturnType, method, args);
-                                       } else {
-                                               overload_failed = true;
                                        }
                                }
                        }
@@ -2334,93 +2291,35 @@ namespace Mono.CSharp {
                                // If any of the arguments is a string, cast to string
                                //
                                
-                               if (l == TypeManager.string_type){
-                                       MethodBase method;
-                                       
-                                       if (r == TypeManager.void_type) {
+                               // Simple constant folding
+                               if (left is StringConstant && right is StringConstant)
+                                       return new StringConstant (((StringConstant) left).Value + ((StringConstant) right).Value);
+                               
+                               if (l == TypeManager.string_type || r == TypeManager.string_type) {
+
+                                       if (r == TypeManager.void_type || l == TypeManager.void_type) {
                                                Error_OperatorCannotBeApplied ();
                                                return null;
                                        }
                                        
-                                       if (r == TypeManager.string_type){
-                                               if (left is Constant && right is Constant){
-                                                       StringConstant ls = (StringConstant) left;
-                                                       StringConstant rs = (StringConstant) right;
-                                                       
-                                                       return new StringConstant (
-                                                               ls.Value + rs.Value);
-                                               }
-
-                                               if (left is BinaryMethod){
-                                                       BinaryMethod b = (BinaryMethod) left;
-
-                                                       //
-                                                       // Call String.Concat (string, string, string) or
-                                                       // String.Concat (string, string, string, string)
-                                                       // if possible.
-                                                       //
-                                                       if (b.method == TypeManager.string_concat_string_string ||
-                                                            b.method == TypeManager.string_concat_string_string_string){
-                                                               int count = b.Arguments.Count;
-                                                               
-                                                               if (count == 2){
-                                                                       ArrayList bargs = new ArrayList (3);
-                                                                       bargs.AddRange (b.Arguments);
-                                                                       bargs.Add (new Argument (right, Argument.AType.Expression));
-                                                                       return new BinaryMethod (
-                                                                               TypeManager.string_type,
-                                                                               TypeManager.string_concat_string_string_string, bargs);
-                                                               } else if (count == 3){
-                                                                       ArrayList bargs = new ArrayList (4);
-                                                                       bargs.AddRange (b.Arguments);
-                                                                       bargs.Add (new Argument (right, Argument.AType.Expression));
-                                                                       return new BinaryMethod (
-                                                                               TypeManager.string_type,
-                                                                               TypeManager.string_concat_string_string_string_string, bargs);
-                                                               }
-                                                       }
-                                               }
+                                       // try to fold it in on the left
+                                       if (left is StringConcat) {
 
-                                               // string + string
-                                               method = TypeManager.string_concat_string_string;
-                                       } else {
-                                               // string + object
-                                               method = TypeManager.string_concat_object_object;
-                                               right = Convert.ImplicitConversion (
-                                                       ec, right, TypeManager.object_type, loc);
-                                               if (right == null){
-                                                       Error_OperatorCannotBeApplied (loc, OperName (oper), l, r);
-                                                       return null;
+                                               //
+                                               // 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;
                                                }
                                        }
-
-                                       //
-                                       // Cascading concats will hold up to 2 arguments, any extras will be
-                                       // reallocated above.
-                                       //
-                                       ArrayList args = new ArrayList (2);
-                                       args.Add (new Argument (left, Argument.AType.Expression));
-                                       args.Add (new Argument (right, Argument.AType.Expression));
-
-                                       return new BinaryMethod (TypeManager.string_type, method, args);
-                               } else if (r == TypeManager.string_type){
-                                       // object + string
-
-                                       if (l == TypeManager.void_type) {
-                                               Error_OperatorCannotBeApplied ();
-                                               return null;
-                                       }
                                        
-                                       left = Convert.ImplicitConversion (ec, left, TypeManager.object_type, loc);
-                                       if (left == null){
-                                               Error_OperatorCannotBeApplied (loc, OperName (oper), l, r);
-                                               return null;
-                                       }
-                                       ArrayList args = new ArrayList (2);
-                                       args.Add (new Argument (left, Argument.AType.Expression));
-                                       args.Add (new Argument (right, Argument.AType.Expression));
-
-                                       return new BinaryMethod (TypeManager.string_type, TypeManager.string_concat_object_object, args);
+                                       // Otherwise, start a new concat expression
+                                       return new StringConcat (ec, loc, left, right).Resolve (ec);
                                }
 
                                //
@@ -2503,7 +2402,8 @@ namespace Mono.CSharp {
                        //
                        if (oper == Operator.Addition || oper == Operator.Subtraction) {
                                if (l.IsSubclassOf (TypeManager.delegate_type)){
-                                       if (right.eclass == ExprClass.MethodGroup && RootContext.V2){
+                                       if ((right.eclass == ExprClass.MethodGroup) &&
+                                           (RootContext.Version != LanguageVersion.ISO_1)){
                                                Expression tmp = Convert.ImplicitConversionRequired (ec, right, l, loc);
                                                if (tmp == null)
                                                        return null;
@@ -2558,16 +2458,16 @@ namespace Mono.CSharp {
                                                if (r == l)
                                                        return new PointerArithmetic (
                                                                false, left, right, TypeManager.int64_type,
-                                                               loc);
+                                                               loc).Resolve (ec);
                                        } else {
                                                Expression t = Make32or64 (ec, right);
                                                if (t != null)
-                                                       return new PointerArithmetic (oper == Operator.Addition, left, t, l, loc);
+                                                       return new PointerArithmetic (oper == Operator.Addition, left, t, l, loc).Resolve (ec);
                                        }
                                } else if (r.IsPointer && oper == Operator.Addition){
                                        Expression t = Make32or64 (ec, left);
                                        if (t != null)
-                                               return new PointerArithmetic (true, right, t, r, loc);
+                                               return new PointerArithmetic (true, right, t, r, loc).Resolve (ec);
                                }
                        }
                        
@@ -2704,14 +2604,6 @@ namespace Mono.CSharp {
                                }
                        }
                        
-                       //
-                       // We are dealing with numbers
-                       //
-                       if (overload_failed){
-                               Error_OperatorCannotBeApplied ();
-                               return null;
-                       }
-
                        //
                        // This will leave left or right set to null if there is an error
                        //
@@ -2732,13 +2624,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 ();
@@ -2810,18 +2705,19 @@ namespace Mono.CSharp {
                        // but on top of that we want for == and != to use a special path
                        // if we are comparing against null
                        //
-                       if (oper == Operator.Equality || oper == Operator.Inequality) {
+                       if ((oper == Operator.Equality || oper == Operator.Inequality) && (left is Constant || right is Constant)) {
                                bool my_on_true = oper == Operator.Inequality ? onTrue : !onTrue;
-
-                               if (left is NullLiteral || left is IntConstant && ((IntConstant) left).Value == 0) {
-                                       right.Emit (ec);
-                                       if (my_on_true)
-                                               ig.Emit (OpCodes.Brtrue, target);
-                                       else
-                                               ig.Emit (OpCodes.Brfalse, target);
-                                       
-                                       return;
-                               } else if (right is NullLiteral || right is IntConstant && ((IntConstant) right).Value == 0){
+                               
+                               //
+                               // put the constant on the rhs, for simplicity
+                               //
+                               if (left is Constant) {
+                                       Expression swap = right;
+                                       right = left;
+                                       left = swap;
+                               }
+                               
+                               if (((Constant) right).IsZeroInteger) {
                                        left.Emit (ec);
                                        if (my_on_true)
                                                ig.Emit (OpCodes.Brtrue, target);
@@ -2829,15 +2725,7 @@ namespace Mono.CSharp {
                                                ig.Emit (OpCodes.Brfalse, target);
                                        
                                        return;
-                               } else if (left is BoolConstant){
-                                       right.Emit (ec);
-                                       if (my_on_true != ((BoolConstant) left).Value)
-                                               ig.Emit (OpCodes.Brtrue, target);
-                                       else
-                                               ig.Emit (OpCodes.Brfalse, target);
-                                       
-                                       return;
-                               } else if (right is BoolConstant){
+                               } else if (right is BoolConstant) {
                                        left.Emit (ec);
                                        if (my_on_true != ((BoolConstant) right).Value)
                                                ig.Emit (OpCodes.Brtrue, target);
@@ -2887,8 +2775,8 @@ namespace Mono.CSharp {
                        right.Emit (ec);
 
                        Type t = left.Type;
-                       bool isUnsigned = is_unsigned (t);
-
+                       bool isUnsigned = is_unsigned (t) || t == TypeManager.double_type || t == TypeManager.float_type;
+                       
                        switch (oper){
                        case Operator.Equality:
                                if (onTrue)
@@ -2931,9 +2819,6 @@ namespace Mono.CSharp {
                                break;
 
                        case Operator.LessThanOrEqual:
-                               if (t == TypeManager.double_type || t == TypeManager.float_type)
-                                       isUnsigned = true;
-
                                if (onTrue)
                                        if (isUnsigned)
                                                ig.Emit (OpCodes.Ble_Un, target);
@@ -2948,8 +2833,6 @@ namespace Mono.CSharp {
 
 
                        case Operator.GreaterThanOrEqual:
-                               if (t == TypeManager.double_type || t == TypeManager.float_type)
-                                       isUnsigned = true;
                                if (onTrue)
                                        if (isUnsigned)
                                                ig.Emit (OpCodes.Bge_Un, target);
@@ -3002,7 +2885,7 @@ namespace Mono.CSharp {
                                ig.MarkLabel (end);
                                return;
                        }
-                       
+
                        left.Emit (ec);
                        right.Emit (ec);
 
@@ -3168,7 +3051,7 @@ namespace Mono.CSharp {
                        ILGenerator ig = ec.ig;
                        
                        if (Arguments != null) 
-                               Invocation.EmitArguments (ec, method, Arguments);
+                               Invocation.EmitArguments (ec, method, Arguments, false, null);
                        
                        if (method is MethodInfo)
                                ig.Emit (OpCodes.Call, (MethodInfo) method);
@@ -3176,6 +3059,137 @@ namespace Mono.CSharp {
                                ig.Emit (OpCodes.Call, (ConstructorInfo) method);
                }
        }
+       
+       //
+       // Represents the operation a + b [+ c [+ d [+ ...]]], where a is a string
+       // b, c, d... may be strings or objects.
+       //
+       public class StringConcat : Expression {
+               ArrayList operands;
+               bool invalid = false;
+               
+               
+               public StringConcat (EmitContext ec, Location loc, Expression left, Expression right)
+               {
+                       this.loc = loc;
+                       type = TypeManager.string_type;
+                       eclass = ExprClass.Value;
+               
+                       operands = new ArrayList (2);
+                       Append (ec, left);
+                       Append (ec, right);
+               }
+               
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       if (invalid)
+                               return null;
+                       
+                       return this;
+               }
+               
+               public void Append (EmitContext ec, Expression operand)
+               {
+                       //
+                       // Constant folding
+                       //
+                       if (operand is StringConstant && operands.Count != 0) {
+                               StringConstant last_operand = operands [operands.Count - 1] as StringConstant;
+                               if (last_operand != null) {
+                                       operands [operands.Count - 1] = new StringConstant (last_operand.Value + ((StringConstant) operand).Value);
+                                       return;
+                               }
+                       }
+                       
+                       //
+                       // Conversion to object
+                       //
+                       if (operand.Type != TypeManager.string_type) {
+                               Expression no = Convert.ImplicitConversion (ec, operand, TypeManager.object_type, loc);
+                               
+                               if (no == null) {
+                                       Binary.Error_OperatorCannotBeApplied (loc, "+", TypeManager.string_type, operand.Type);
+                                       invalid = true;
+                               }
+                               operand = no;
+                       }
+                       
+                       operands.Add (operand);
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       MethodInfo concat_method = null;
+                       
+                       //
+                       // Are we also concating objects?
+                       //
+                       bool is_strings_only = true;
+                       
+                       //
+                       // Do conversion to arguments; check for strings only
+                       //
+                       for (int i = 0; i < operands.Count; i ++) {
+                               Expression e = (Expression) operands [i];
+                               is_strings_only &= e.Type == TypeManager.string_type;
+                       }
+                       
+                       for (int i = 0; i < operands.Count; i ++) {
+                               Expression e = (Expression) operands [i];
+                               
+                               if (! is_strings_only && e.Type == TypeManager.string_type) {
+                                       // need to make sure this is an object, because the EmitParams
+                                       // method might look at the type of this expression, see it is a
+                                       // string and emit a string [] when we want an object [];
+                                       
+                                       e = Convert.ImplicitConversion (ec, e, TypeManager.object_type, loc);
+                               }
+                               operands [i] = new Argument (e, Argument.AType.Expression);
+                       }
+                       
+                       //
+                       // Find the right method
+                       //
+                       switch (operands.Count) {
+                       case 1:
+                               //
+                               // This should not be possible, because simple constant folding
+                               // is taken care of in the Binary code.
+                               //
+                               throw new Exception ("how did you get here?");
+                       
+                       case 2:
+                               concat_method = is_strings_only ? 
+                                       TypeManager.string_concat_string_string :
+                                       TypeManager.string_concat_object_object ;
+                               break;
+                       case 3:
+                               concat_method = is_strings_only ? 
+                                       TypeManager.string_concat_string_string_string :
+                                       TypeManager.string_concat_object_object_object ;
+                               break;
+                       case 4:
+                               //
+                               // There is not a 4 param overlaod for object (the one that there is
+                               // is actually a varargs methods, and is only in corlib because it was
+                               // introduced there before.).
+                               //
+                               if (!is_strings_only)
+                                       goto default;
+                               
+                               concat_method = TypeManager.string_concat_string_string_string_string;
+                               break;
+                       default:
+                               concat_method = is_strings_only ? 
+                                       TypeManager.string_concat_string_dot_dot_dot :
+                                       TypeManager.string_concat_object_dot_dot_dot ;
+                               break;
+                       }
+                       
+                       Invocation.EmitArguments (ec, concat_method, operands, false, null);
+                       ec.ig.Emit (OpCodes.Call, concat_method);
+               }
+       }
 
        //
        // Object created with +/= on delegates
@@ -3201,7 +3215,7 @@ namespace Mono.CSharp {
                {
                        ILGenerator ig = ec.ig;
                        
-                       Invocation.EmitArguments (ec, method, args);
+                       Invocation.EmitArguments (ec, method, args, false, null);
                        
                        ig.Emit (OpCodes.Call, (MethodInfo) method);
                        ig.Emit (OpCodes.Castclass, type);
@@ -3249,6 +3263,7 @@ namespace Mono.CSharp {
                }
 
                Expression op_true, op_false, op;
+               LocalTemporary left_temp;
 
                public override Expression DoResolve (EmitContext ec)
                {
@@ -3261,10 +3276,14 @@ 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, loc) as MethodInfo;
+                       method = Invocation.OverloadResolve (
+                               ec, (MethodGroupExpr) operator_group, arguments, false, loc)
+                               as MethodInfo;
                        if ((method == null) || (method.ReturnType != type)) {
                                Error19 ();
                                return null;
@@ -3272,8 +3291,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;
@@ -3290,8 +3309,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);
@@ -3311,7 +3333,6 @@ namespace Mono.CSharp {
                public PointerArithmetic (bool is_addition, Expression l, Expression r, Type t, Location loc)
                {
                        type = t;
-                       eclass = ExprClass.Variable;
                        this.loc = loc;
                        left = l;
                        right = r;
@@ -3320,17 +3341,22 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       //
-                       // We are born fully resolved
-                       //
-                       return this;
+                       eclass = ExprClass.Variable;
+                       
+                       if (left.Type == TypeManager.void_ptr_type) {
+                               Error (242, "The operation in question is undefined on void pointers");
+                               return null;
+                       }
+                       
+                       return this;
                }
 
                public override void Emit (EmitContext ec)
                {
                        Type op_type = left.Type;
                        ILGenerator ig = ec.ig;
-                       int size = GetTypeSize (TypeManager.GetElementType (op_type));
+                       Type element = TypeManager.GetElementType (op_type);
+                       int size = GetTypeSize (element);
                        Type rtype = right.Type;
                        
                        if (rtype.IsPointer){
@@ -3343,7 +3369,7 @@ namespace Mono.CSharp {
 
                                if (size != 1){
                                        if (size == 0)
-                                               ig.Emit (OpCodes.Sizeof, op_type);
+                                               ig.Emit (OpCodes.Sizeof, element);
                                        else 
                                                IntLiteral.EmitInt (ig, size);
                                        ig.Emit (OpCodes.Div);
@@ -3358,7 +3384,7 @@ namespace Mono.CSharp {
                                right.Emit (ec);
                                if (size != 1){
                                        if (size == 0)
-                                               ig.Emit (OpCodes.Sizeof, op_type);
+                                               ig.Emit (OpCodes.Sizeof, element);
                                        else 
                                                IntLiteral.EmitInt (ig, size);
                                        if (rtype == TypeManager.int64_type)
@@ -3561,7 +3587,7 @@ namespace Mono.CSharp {
                        if (e != null) {
                                local_info.Used = true;
                                eclass = ExprClass.Value;
-                               return e;
+                               return e.Resolve (ec);
                        }
 
                        VariableInfo variable_info = local_info.VariableInfo; 
@@ -3602,6 +3628,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       CheckObsoleteAttribute (e.Type);
+
                        if (local_info.LocalBuilder == null)
                                return ec.RemapLocalLValue (local_info, right_side);
                        
@@ -3620,12 +3648,19 @@ namespace Mono.CSharp {
                        ig.Emit (OpCodes.Ldloc, local_info.LocalBuilder);
                }
                
-               public void EmitAssign (EmitContext ec, Expression source)
+               public void Emit (EmitContext ec, bool leave_copy)
+               {
+                       Emit (ec);
+                       if (leave_copy)
+                               ec.ig.Emit (OpCodes.Dup);
+               }
+               
+               public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
                {
-                       ILGenerator ig = ec.ig;
-
                        source.Emit (ec);
-                       ig.Emit (OpCodes.Stloc, local_info.LocalBuilder);
+                       if (leave_copy)
+                               ec.ig.Emit (OpCodes.Dup);
+                       ec.ig.Emit (OpCodes.Stloc, local_info.LocalBuilder);
                }
                
                public void AddressOf (EmitContext ec, AddressOp mode)
@@ -3652,7 +3687,8 @@ namespace Mono.CSharp {
                Block block;
                VariableInfo vi;
                public Parameter.Modifier mod;
-               public bool is_ref, is_out;
+               public bool is_ref, is_out, prepared;
+               LocalTemporary temp;
                
                public ParameterReference (Parameters pars, Block block, int idx, string name, Location loc)
                {
@@ -3787,6 +3823,11 @@ namespace Mono.CSharp {
                }
                
                public override void Emit (EmitContext ec)
+               {
+                       Emit (ec, false);
+               }
+               
+               public void Emit (EmitContext ec, bool leave_copy)
                {
                        ILGenerator ig = ec.ig;
                        
@@ -3797,33 +3838,56 @@ namespace Mono.CSharp {
 
                        EmitLdArg (ig, arg_idx);
 
-                       if (!is_ref)
-                               return;
-
-                       //
-                       // If we are a reference, we loaded on the stack a pointer
-                       // Now lets load the real value
-                       //
-                       LoadFromPtr (ig, type);
+                       if (is_ref) {
+                               if (prepared)
+                                       ec.ig.Emit (OpCodes.Dup);
+       
+                               //
+                               // If we are a reference, we loaded on the stack a pointer
+                               // Now lets load the real value
+                               //
+                               LoadFromPtr (ig, type);
+                       }
+                       
+                       if (leave_copy) {
+                               ec.ig.Emit (OpCodes.Dup);
+                               
+                               if (is_ref) {
+                                       temp = new LocalTemporary (ec, type);
+                                       temp.Store (ec);
+                               }
+                       }
                }
-
-               public void EmitAssign (EmitContext ec, Expression source)
+               
+               public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
                {
                        ILGenerator ig = ec.ig;
-                       
                        int arg_idx = idx;
-
+                       
+                       prepared = prepare_for_load;
+                       
                        if (!ec.IsStatic)
                                arg_idx++;
 
-                       if (is_ref)
+                       if (is_ref && !prepared)
                                EmitLdArg (ig, arg_idx);
                        
                        source.Emit (ec);
 
-                       if (is_ref)
+                       if (leave_copy)
+                               ec.ig.Emit (OpCodes.Dup);
+                       
+                       if (is_ref) {
+                               if (leave_copy) {
+                                       temp = new LocalTemporary (ec, type);
+                                       temp.Store (ec);
+                               }
+                               
                                StoreFromPtr (ig, type);
-                       else {
+                               
+                               if (temp != null)
+                                       temp.Emit (ec);
+                       } else {
                                if (arg_idx <= 255)
                                        ig.Emit (OpCodes.Starg_S, (byte) arg_idx);
                                else
@@ -3860,7 +3924,8 @@ namespace Mono.CSharp {
                public enum AType : byte {
                        Expression,
                        Ref,
-                       Out
+                       Out,
+                       ArgList
                };
 
                public readonly AType ArgType;
@@ -3872,6 +3937,12 @@ namespace Mono.CSharp {
                        this.ArgType = type;
                }
 
+               public Argument (Expression expr)
+               {
+                       this.Expr = expr;
+                       this.ArgType = AType.Expression;
+               }
+
                public Type Type {
                        get {
                                if (ArgType == AType.Ref || ArgType == AType.Out)
@@ -3897,6 +3968,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);
@@ -3931,6 +4005,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){
                                //
@@ -3976,8 +4068,9 @@ namespace Mono.CSharp {
                                                
                                                pr.AddressOf (ec, mode);
                                        }
-                               } else
+                               } else {
                                        ((IMemoryLocation)Expr).AddressOf (ec, mode);
+                               }
                        } else
                                Expr.Emit (ec);
                }
@@ -4039,8 +4132,7 @@ namespace Mono.CSharp {
 
                                return (ParameterData) ip;
                        } else {
-                               ParameterInfo [] pi = mb.GetParameters ();
-                               ReflectionParameters rp = new ReflectionParameters (pi);
+                               ReflectionParameters rp = new ReflectionParameters (mb);
                                method_parameter_cache [mb] = rp;
 
                                return (ParameterData) rp;
@@ -4062,9 +4154,11 @@ namespace Mono.CSharp {
                                throw new Exception ("Expression of type " + a.Expr +
                                                      " does not resolve its type");
 
+                       if (p == null || q == null)
+                               throw new InternalErrorException ("BetterConversion Got a null conversion");
+
                        //
-                       // This is a special case since csc behaves this way. I can't find
-                       // it anywhere in the spec but oh well ...
+                       // This is a special case since csc behaves this way.
                        //
                        if (argument_expr is NullLiteral &&
                             p == TypeManager.string_type &&
@@ -4075,6 +4169,24 @@ namespace Mono.CSharp {
                                  q == TypeManager.string_type)
                                return 0;
                        
+                        //
+                        // csc behaves this way so we emulate it. Basically, if the argument
+                        // is null and one of the types to compare is 'object' and the other
+                        // is a reference type, we prefer the other.
+                        //
+                        // I can't find this anywhere in the spec but we can interpret this
+                        // to mean that null can be of any type you wish in such a context
+                        //
+                       if (argument_expr is NullLiteral &&
+                           !p.IsValueType &&
+                           q == TypeManager.object_type)
+                               return 1;
+                       else if (argument_expr is NullLiteral &&
+                                !q.IsValueType &&
+                                p == TypeManager.object_type)
+                               return 0;
+
+                                
                        if (p == q)
                                return 0;
                        
@@ -4084,94 +4196,6 @@ namespace Mono.CSharp {
                        if (argument_type == q)
                                return 0;
 
-                       //
-                       // Now probe whether an implicit constant expression conversion
-                       // can be used.
-                       //
-                       // An implicit constant expression conversion permits the following
-                       // conversions:
-                       //
-                       //    * A constant-expression of type `int' can be converted to type
-                       //      sbyte, byute, short, ushort, uint, ulong provided the value of
-                       //      of the expression is withing the range of the destination type.
-                       //
-                       //    * A constant-expression of type long can be converted to type
-                       //      ulong, provided the value of the constant expression is not negative
-                       //
-                       // FIXME: Note that this assumes that constant folding has
-                       // taken place.  We dont do constant folding yet.
-                       //
-
-                       if (argument_expr is IntConstant){
-                               IntConstant ei = (IntConstant) argument_expr;
-                               int value = ei.Value;
-
-                               if (p == TypeManager.sbyte_type){
-                                       if (value >= SByte.MinValue && value <= SByte.MaxValue)
-                                               return 1;
-                               } else if (p == TypeManager.byte_type){
-                                       if (q == TypeManager.sbyte_type &&
-                                           value >= SByte.MinValue && value <= SByte.MaxValue)
-                                               return 0;
-                                       else if (Byte.MinValue >= 0 && value <= Byte.MaxValue)
-                                               return 1;
-                               } else if (p == TypeManager.short_type){
-                                       if (value >= Int16.MinValue && value <= Int16.MaxValue)
-                                               return 1;
-                               } else if (p == TypeManager.ushort_type){
-                                       if (q == TypeManager.short_type &&
-                                           value >= Int16.MinValue && value <= Int16.MaxValue)
-                                               return 0;
-                                       else if (value >= UInt16.MinValue && value <= UInt16.MaxValue)
-                                               return 1;
-                               } else if (p == TypeManager.int32_type){
-                                       if (value >= Int32.MinValue && value <= Int32.MaxValue)
-                                               return 1;
-                               } else if (p == TypeManager.uint32_type){
-                                       //
-                                       // we can optimize this case: a positive int32
-                                       // always fits on a uint32
-                                       //
-                                       if (value >= 0)
-                                               return 1;
-                               } else if (p == TypeManager.uint64_type){
-                                       //
-                                       // we can optimize this case: a positive int32
-                                       // always fits on a uint64
-                                       //
-
-                                        //
-                                        // This special case is needed because csc behaves like this.
-                                        // int -> uint is better than int -> ulong!
-                                        //
-                                        if (q == TypeManager.uint32_type)
-                                                return 0;
-                                        
-                                       if (q == TypeManager.int64_type)
-                                               return 0;
-                                       else if (value >= 0)
-                                               return 1;
-                               } else if (p == TypeManager.int64_type){
-                                       return 1;
-                               }
-                       } else if (argument_type == TypeManager.int64_type && argument_expr is LongConstant){
-                               LongConstant lc = (LongConstant) argument_expr;
-                               
-                               if (p == TypeManager.uint64_type){
-                                       if (lc.Value > 0)
-                                               return 1;
-                               }
-                       }
-
-                       if (q == null) {
-                               Expression tmp = Convert.ImplicitConversion (ec, argument_expr, p, loc);
-                               
-                               if (tmp != null)
-                                       return 1;
-                               else
-                                       return 0;
-                       }
-
                        Expression p_tmp = new EmptyExpression (p);
                        Expression q_tmp = new EmptyExpression (q);
                        
@@ -4209,20 +4233,13 @@ namespace Mono.CSharp {
                ///     0 if candidate ain't better
                ///     1 if candidate is better than the current best match
                /// </remarks>
-               static int BetterFunction (EmitContext ec, ArrayList args,
+               static int BetterFunction (EmitContext ec, ArrayList args, int argument_count,
                                           MethodBase candidate, bool candidate_params,
-                                           MethodBase best, bool best_params,
-                                          Location loc)
+                                          MethodBase best, bool best_params, Location loc)
                {
                        ParameterData candidate_pd = GetParameterData (candidate);
-                       ParameterData best_pd;
-                       int argument_count;
+                       ParameterData best_pd = GetParameterData (best);
                
-                       if (args == null)
-                               argument_count = 0;
-                       else
-                               argument_count = args.Count;
-
                        int cand_count = candidate_pd.Count;
                        
                        //
@@ -4231,7 +4248,6 @@ namespace Mono.CSharp {
                        // best method, we cant tell. This happens
                        // if we have:
                        // 
-                       //
                        //      interface IFoo {
                        //              void DoIt ();
                        //      }
@@ -4246,42 +4262,15 @@ namespace Mono.CSharp {
                        //
                        // However, we have to consider that
                        // Trim (); is better than Trim (params char[] chars);
+                        //
                        if (cand_count == 0 && argument_count == 0)
-                               return best == null || best_params ? 1 : 0;
+                               return 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;
 
-                       if (best == null) {
-                               int x = 0;
-
-                               if (argument_count == 0 && cand_count == 1 &&
-                                   candidate_pd.ParameterModifier (cand_count - 1) == Parameter.Modifier.PARAMS)
-                                       return 1;
-                               
-                               for (int j = 0; j < argument_count; ++j) {
-
-                                       Argument a = (Argument) args [j];
-                                       Type t = candidate_pd.ParameterType (j);
-
-                                       if (candidate_pd.ParameterModifier (j) == Parameter.Modifier.PARAMS)
-                                               if (candidate_params)
-                                                       t = TypeManager.GetElementType (t);
-
-                                       x = BetterConversion (ec, a, t, null, loc);
-                                       
-                                       if (x <= 0)
-                                               break;
-                               }
-
-                               if (x > 0)
-                                       return 1;
-                               else
-                                       return 0;
-                       }
-
-                       best_pd = GetParameterData (best);
 
                        int rating1 = 0, rating2 = 0;
                        
@@ -4331,6 +4320,9 @@ namespace Mono.CSharp {
                {
                        string ret_type = "";
 
+                        if (mb == null)
+                                return "";
+
                        if (mb is MethodInfo)
                                ret_type = TypeManager.CSharpName (((MethodInfo) mb).ReturnType);
                        
@@ -4402,30 +4394,52 @@ namespace Mono.CSharp {
                        return union;
                }
 
+               static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
+                                                     ArrayList arguments, int arg_count,
+                                                     ref MethodBase candidate)
+               {
+                       return IsParamsMethodApplicable (
+                               ec, me, arguments, arg_count, false, ref candidate) ||
+                               IsParamsMethodApplicable (
+                                       ec, me, arguments, arg_count, true, ref candidate);
+
+
+               }
+
+               static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
+                                                     ArrayList arguments, int arg_count,
+                                                     bool do_varargs, ref MethodBase candidate)
+               {
+                       return IsParamsMethodApplicable (
+                               ec, arguments, arg_count, 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,
+                                                     int arg_count, MethodBase candidate,
+                                                     bool do_varargs)
                {
-                       int arg_count;
-                       
-                       if (arguments == null)
-                               arg_count = 0;
-                       else
-                               arg_count = arguments.Count;
-                       
                        ParameterData pd = GetParameterData (candidate);
-                       
-                       int pd_count = pd.Count;
 
+                       int pd_count = pd.Count;
                        if (pd_count == 0)
                                return false;
+
+                       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.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS)
-                               return false;
-                       
-                       if (pd_count - 1 > arg_count)
+                       if (count > arg_count)
                                return false;
                        
                        if (pd_count == 1 && arg_count == 0)
@@ -4436,7 +4450,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];
 
@@ -4467,11 +4481,19 @@ 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++) {
                                Argument a = (Argument) arguments [i];
-                               
+
                                if (!Convert.ImplicitConversionExists (ec, a.Expr, element_type))
                                        return false;
                        }
@@ -4479,20 +4501,20 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               static bool IsApplicable (EmitContext ec, MethodGroupExpr me,
+                                         ArrayList arguments, int arg_count,
+                                         ref MethodBase candidate)
+               {
+                       return IsApplicable (ec, arguments, arg_count, candidate);
+               }
+
                /// <summary>
                ///   Determines if the candidate method is applicable (section 14.4.2.1)
                ///   to the given set of arguments
                /// </summary>
-               static bool IsApplicable (EmitContext ec, ArrayList arguments, MethodBase candidate)
+               static bool IsApplicable (EmitContext ec, ArrayList arguments, int arg_count,
+                                         MethodBase candidate)
                {
-                       int arg_count;
-
-                       if (arguments == null)
-                               arg_count = 0;
-                       else
-                               arg_count = arguments.Count;
-
-
                        ParameterData pd = GetParameterData (candidate);
 
                        if (arg_count != pd.Count)
@@ -4533,9 +4555,14 @@ namespace Mono.CSharp {
 
                        return true;
                }
-               
-               
 
+               static private bool IsAncestralType (Type first_type, Type second_type)
+               {
+                       return first_type != second_type &&
+                               (second_type.IsSubclassOf (first_type) ||
+                                TypeManager.ImplementsInterface (second_type, first_type));
+               }
+               
                /// <summary>
                ///   Find the Applicable Function Members (7.4.2.1)
                ///
@@ -4553,11 +4580,13 @@ namespace Mono.CSharp {
                ///
                /// </summary>
                public static MethodBase OverloadResolve (EmitContext ec, MethodGroupExpr me,
-                                                         ArrayList Arguments, Location loc)
+                                                         ArrayList Arguments, bool may_fail,
+                                                         Location loc)
                {
                        MethodBase method = null;
+                       bool method_params = false;
                        Type applicable_type = null;
-                       int argument_count;
+                       int arg_count = 0;
                        ArrayList candidates = new ArrayList ();
 
                         //
@@ -4565,162 +4594,204 @@ namespace Mono.CSharp {
                         // and whether it is being considered in its
                         // normal or expanded form
                         //
-                        Hashtable candidate_to_form = new PtrHashtable ();
+                        // false is normal form, true is expanded form
+                        //
+                        Hashtable candidate_to_form = null;
 
+                       if (Arguments != null)
+                               arg_count = Arguments.Count;
 
-                        //
-                        // First we construct the set of applicable methods
-                        //
-                        // We start at the top of the type hierarchy and
-                        // go down to find applicable methods
-                        //
-                        applicable_type = me.DeclaringType;
-                        
-                        if (me.Name == "Invoke" && TypeManager.IsDelegateType (applicable_type)) {
+                        if ((me.Name == "Invoke") &&
+                           TypeManager.IsDelegateType (me.DeclaringType)) {
                                 Error_InvokeOnDelegate (loc);
                                 return null;
                         }
 
-                        bool found_applicable = false;
+                       MethodBase[] methods = me.Methods;
 
-                       foreach (MethodBase candidate in me.Methods){
-                                Type decl_type = candidate.DeclaringType;
+                        //
+                        // First we construct the set of applicable methods
+                        //
+                       bool is_sorted = true;
+                       for (int i = 0; i < methods.Length; i++){
+                                Type decl_type = methods [i].DeclaringType;
 
                                 //
                                 // If we have already found an applicable method
                                 // we eliminate all base types (Section 14.5.5.1)
                                 //
-                                if (decl_type != applicable_type &&
-                                    (applicable_type.IsSubclassOf (decl_type) ||
-                                     TypeManager.ImplementsInterface (applicable_type, decl_type)) &&
-                                    found_applicable)
-                                                continue;
-
+                                if ((applicable_type != null) &&
+                                   IsAncestralType (decl_type, applicable_type))
+                                       continue;
 
+                               //
                                // Check if candidate is applicable (section 14.4.2.1)
-                               if (IsApplicable (ec, Arguments, candidate)) {
-                                        // Candidate is applicable in normal form
-                                        candidates.Add (candidate);
-                                        applicable_type = candidate.DeclaringType;
-                                        found_applicable = true;
-                                        candidate_to_form [candidate] = false;
-                                } else {
-                                        if (IsParamsMethodApplicable (ec, Arguments, candidate)) {
-                                                // Candidate is applicable in expanded form
-                                                candidates.Add (candidate);
-                                                applicable_type = candidate.DeclaringType;
-                                                found_applicable = true; 
-                                                candidate_to_form [candidate] = true;
-                                        }
-                                }
-                        }
-                        
+                               //   Is candidate applicable in normal form?
+                               //
+                               bool is_applicable = IsApplicable (
+                                       ec, me, Arguments, arg_count, ref methods [i]);
 
-                        //
-                        // Now we actually find the best method
-                        //
-                       int candidate_top = candidates.Count;
-                       for (int ix = 0; ix < candidate_top; ix++){
-                               MethodBase candidate = (MethodBase) candidates [ix];
+                               if (!is_applicable &&
+                                   (IsParamsMethodApplicable (
+                                           ec, me, Arguments, arg_count, ref methods [i]))) {
+                                       MethodBase candidate = methods [i];
+                                       if (candidate_to_form == null)
+                                               candidate_to_form = new PtrHashtable ();
+                                       candidate_to_form [candidate] = candidate;
+                                       // Candidate is applicable in expanded form
+                                       is_applicable = true;
+                               }
 
-                                bool cand_params = (bool) candidate_to_form [candidate];
-                                bool method_params = false;
+                               if (!is_applicable)
+                                       continue;
 
-                                if (method != null)
-                                        method_params = (bool) candidate_to_form [method];
-                                
-                                int x = BetterFunction (ec, Arguments,
-                                                        candidate, cand_params,
-                                                        method, method_params,
-                                                        loc);
-                                
-                                if (x == 0)
-                                        continue;
-                                
-                                method = candidate;
-                        }
+                               candidates.Add (methods [i]);
 
-                       if (Arguments == null)
-                               argument_count = 0;
-                       else
-                               argument_count = Arguments.Count;
-                       
+                               if (applicable_type == null)
+                                       applicable_type = decl_type;
+                               else if (applicable_type != decl_type) {
+                                       is_sorted = false;
+                                       if (IsAncestralType (applicable_type, decl_type))
+                                               applicable_type = decl_type;
+                               }
+                       }
 
-                       if (method == null) {
+                       int candidate_top = candidates.Count;
+
+                       if (candidate_top == 0) {
                                //
                                // Okay so we have failed to find anything so we
                                // return by providing info about the closest match
                                //
-                               for (int i = 0; i < me.Methods.Length; ++i) {
-
-                                       MethodBase c = (MethodBase) me.Methods [i];
+                               for (int i = 0; i < methods.Length; ++i) {
+                                       MethodBase c = (MethodBase) methods [i];
                                        ParameterData pd = GetParameterData (c);
 
-                                       if (pd.Count != argument_count)
+                                       if (pd.Count != arg_count)
                                                continue;
 
-                                       VerifyArgumentsCompat (ec, Arguments, argument_count, c, false,
-                                                              null, loc);
-                                        break;
+                                       VerifyArgumentsCompat (ec, Arguments, arg_count,
+                                                              c, false, null, may_fail, loc);
+                                       break;
                                }
 
-                                if (!Location.IsNull (loc)) {
+                                if (!may_fail) {
                                         string report_name = me.Name;
                                         if (report_name == ".ctor")
                                                 report_name = me.DeclaringType.ToString ();
                                         
-                                        Error_WrongNumArguments (loc, report_name, argument_count);
+                                       Error_WrongNumArguments (
+                                               loc, report_name, arg_count);
+                                       return null;
                                 }
                                 
                                return null;
                        }
 
+                       if (!is_sorted) {
+                               //
+                               // At this point, applicable_type is _one_ of the most derived types
+                               // in the set of types containing the methods in this MethodGroup.
+                               // Filter the candidates so that they only contain methods from the
+                               // most derived types.
+                               //
+
+                               int finalized = 0; // Number of finalized candidates
+
+                               do {
+                                       // Invariant: applicable_type is a most derived type
+
+                                       // We'll try to complete Section 14.5.5.1 for 'applicable_type' by 
+                                       // eliminating all it's base types.  At the same time, we'll also move
+                                       // every unrelated type to the end of the array, and pick the next
+                                       // 'applicable_type'.
+
+                                       Type next_applicable_type = null;
+                                       int j = finalized; // where to put the next finalized candidate
+                                       int k = finalized; // where to put the next undiscarded candidate
+                                       for (int i = finalized; i < candidate_top; ++i) {
+                                               Type decl_type = ((MethodBase) candidates[i]).DeclaringType;
+
+                                               if (decl_type == applicable_type) {
+                                                       candidates[k++] = candidates[j];
+                                                       candidates[j++] = candidates[i];
+                                                       continue;
+                                               }
+
+                                               if (IsAncestralType (decl_type, applicable_type))
+                                                       continue;
+
+                                               if (next_applicable_type != null &&
+                                                   IsAncestralType (decl_type, next_applicable_type))
+                                                       continue;
+
+                                               candidates[k++] = candidates[i];
+
+                                               if (next_applicable_type == null ||
+                                                   IsAncestralType (next_applicable_type, decl_type))
+                                                       next_applicable_type = decl_type;
+                                       }
+
+                                       applicable_type = next_applicable_type;
+                                       finalized = j;
+                                       candidate_top = k;
+                               } while (applicable_type != null);
+                       }
+
+                        //
+                        // Now we actually find the best method
+                        //
+
+                       method = (MethodBase) candidates[0];
+                       method_params = candidate_to_form != null && candidate_to_form.Contains (method);
+                       for (int ix = 1; ix < candidate_top; ix++){
+                               MethodBase candidate = (MethodBase) candidates [ix];
+                               bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
+                                
+                               if (BetterFunction (ec, Arguments, arg_count, 
+                                                   candidate, cand_params,
+                                                   method, method_params, loc) != 0) {
+                                       method = candidate;
+                                       method_params = cand_params;
+                               }
+                       }
+
                        //
                        // Now check that there are no ambiguities i.e the selected method
                        // should be better than all the others
                        //
-                        bool best_params = (bool) candidate_to_form [method];
-
+                       bool ambiguous = false;
                        for (int ix = 0; ix < candidate_top; ix++){
                                MethodBase candidate = (MethodBase) candidates [ix];
 
                                 if (candidate == method)
                                         continue;
-                                               
-                               //
-                               // If a normal method is applicable in
-                               // the sense that it has the same
-                               // number of arguments, then the
-                               // expanded params method is never
-                               // applicable so we debar the params
-                               // method.
-                               //
-                                if ((IsParamsMethodApplicable (ec, Arguments, candidate) &&
-                                     IsApplicable (ec, Arguments, method)))
-                                        continue;
-                                
-                                bool cand_params = (bool) candidate_to_form [candidate];
-                               int x = BetterFunction (ec, Arguments,
-                                                        method, best_params,
-                                                        candidate, cand_params,
-                                                       loc);
-
-                               if (x != 1) {
-                                       Report.Error (
-                                               121, loc,
-                                               "Ambiguous call when selecting function due to implicit casts");
-                                       return null;
-                               }
+
+                                bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
+                               if (BetterFunction (ec, Arguments, arg_count,
+                                                   method, method_params,
+                                                   candidate, cand_params,
+                                                   loc) != 1) {
+                                       Report.SymbolRelatedToPreviousError (candidate);
+                                       ambiguous = true;
+                               }
+                       }
+
+                       if (ambiguous) {
+                               Report.SymbolRelatedToPreviousError (method);
+                               Report.Error (121, loc, "Ambiguous call when selecting function due to implicit casts");                                        
+                               return null;
                        }
 
+
                        //
                        // And now check if the arguments are all
                        // compatible, perform conversions if
                        // necessary etc. and return if everything is
                        // all right
                        //
-                        if (!VerifyArgumentsCompat (ec, Arguments, argument_count, method,
-                                                    best_params, null, loc))
+                        if (!VerifyArgumentsCompat (ec, Arguments, arg_count, method,
+                                                    method_params, null, may_fail, loc))
                                return null;
 
                        return method;
@@ -4757,16 +4828,15 @@ namespace Mono.CSharp {
                }
                
                public static bool VerifyArgumentsCompat (EmitContext ec, ArrayList Arguments,
-                                                         int argument_count,
-                                                         MethodBase method, 
+                                                         int arg_count, MethodBase method, 
                                                          bool chose_params_expanded,
-                                                         Type delegate_type,
+                                                         Type delegate_type, bool may_fail,
                                                          Location loc)
                {
                        ParameterData pd = GetParameterData (method);
                        int pd_count = pd.Count;
-                       
-                       for (int j = 0; j < argument_count; j++) {
+
+                       for (int j = 0; j < arg_count; j++) {
                                Argument a = (Argument) Arguments [j];
                                Expression a_expr = a.Expr;
                                Type parameter_type = pd.ParameterType (j);
@@ -4774,7 +4844,7 @@ namespace Mono.CSharp {
                                
                                if (pm == Parameter.Modifier.PARAMS){
                                        if ((pm & ~Parameter.Modifier.PARAMS) != a.GetParameterModifier ()) {
-                                               if (!Location.IsNull (loc))
+                                               if (!may_fail)
                                                        Error_InvalidArguments (
                                                                loc, j, method, delegate_type,
                                                                Argument.FullDesc (a), pd.ParameterDesc (j));
@@ -4783,12 +4853,14 @@ namespace Mono.CSharp {
 
                                        if (chose_params_expanded)
                                                parameter_type = TypeManager.GetElementType (parameter_type);
+                               } else if (pm == Parameter.Modifier.ARGLIST){
+                                       continue;
                                } else {
                                        //
                                        // Check modifiers
                                        //
                                        if (pd.ParameterModifier (j) != a.GetParameterModifier ()){
-                                               if (!Location.IsNull (loc))
+                                               if (!may_fail)
                                                        Error_InvalidArguments (
                                                                loc, j, method, delegate_type,
                                                                Argument.FullDesc (a), pd.ParameterDesc (j));
@@ -4799,13 +4871,13 @@ namespace Mono.CSharp {
                                //
                                // Check Type
                                //
-                               if (a.Type != parameter_type){
+                               if (!a.Type.Equals (parameter_type)){
                                        Expression conv;
                                        
                                        conv = Convert.ImplicitConversion (ec, a_expr, parameter_type, loc);
 
                                        if (conv == null) {
-                                               if (!Location.IsNull (loc)) 
+                                               if (!may_fail)
                                                        Error_InvalidArguments (
                                                                loc, j, method, delegate_type,
                                                                Argument.FullDesc (a), pd.ParameterDesc (j));
@@ -4826,7 +4898,7 @@ namespace Mono.CSharp {
                                
                                if (a_mod != p_mod &&
                                    pd.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS) {
-                                       if (!Location.IsNull (loc)) {
+                                       if (!may_fail) {
                                                Report.Error (1502, loc,
                                                       "The best overloaded match for method '" + FullMethodDesc (method)+
                                                       "' has some invalid arguments");
@@ -4883,19 +4955,28 @@ namespace Mono.CSharp {
                        }
 
                        MethodGroupExpr mg = (MethodGroupExpr) expr;
-                       method = OverloadResolve (ec, mg, Arguments, loc);
+                       method = OverloadResolve (ec, mg, Arguments, false, loc);
 
-                       if (method == null){
-                               Error (-6,
-                                      "Could not find any applicable function for this argument list");
+                       if (method == null)
                                return null;
-                       }
-
+                       
                        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){
@@ -4918,7 +4999,7 @@ namespace Mono.CSharp {
                                if (TypeManager.IsSpecialMethod (method))
                                        Report.Error (571, loc, method.Name + ": can not call operator or accessor");
                        }
-                       
+
                        eclass = ExprClass.Value;
                        return this;
                }
@@ -4932,19 +5013,15 @@ namespace Mono.CSharp {
                        int count = arguments.Count - idx;
                        Argument a = (Argument) arguments [idx];
                        Type t = a.Expr.Type;
-                       string array_type = t.FullName + "[]";
-                       LocalBuilder array;
-
-                       array = ig.DeclareLocal (TypeManager.LookupType (array_type));
+                       
                        IntConstant.EmitInt (ig, count);
                        ig.Emit (OpCodes.Newarr, TypeManager.TypeToCoreType (t));
-                       ig.Emit (OpCodes.Stloc, array);
 
                        int top = arguments.Count;
                        for (int j = idx; j < top; j++){
                                a = (Argument) arguments [j];
                                
-                               ig.Emit (OpCodes.Ldloc, array);
+                               ig.Emit (OpCodes.Dup);
                                IntConstant.EmitInt (ig, j - idx);
 
                                bool is_stobj;
@@ -4959,7 +5036,6 @@ namespace Mono.CSharp {
                                else
                                        ig.Emit (op);
                        }
-                       ig.Emit (OpCodes.Ldloc, array);
                }
                
                /// <summary>
@@ -4970,14 +5046,24 @@ namespace Mono.CSharp {
                ///   emission of the arguments is known not to contain
                ///   a `params' field (for example in constructors or other routines
                ///   that keep their arguments in this structure)
+               ///   
+               ///   if `dup_args' is true, a copy of the arguments will be left
+               ///   on the stack. If `dup_args' is true, you can specify `this_arg'
+               ///   which will be duplicated before any other args. Only EmitCall
+               ///   should be using this interface.
                /// </summary>
-               public static void EmitArguments (EmitContext ec, MethodBase mb, ArrayList arguments)
+               public static void EmitArguments (EmitContext ec, MethodBase mb, ArrayList arguments, bool dup_args, LocalTemporary this_arg)
                {
                        ParameterData pd;
                        if (mb != null)
                                pd = GetParameterData (mb);
                        else
                                pd = null;
+                       
+                       LocalTemporary [] temps = null;
+                       
+                       if (dup_args)
+                               temps = new LocalTemporary [arguments.Count];
 
                        //
                        // If we are calling a params method with no arguments, special case it
@@ -5014,6 +5100,18 @@ namespace Mono.CSharp {
                                }
                                            
                                a.Emit (ec);
+                               if (dup_args) {
+                                       ec.ig.Emit (OpCodes.Dup);
+                                       (temps [i] = new LocalTemporary (ec, a.Type)).Store (ec);
+                               }
+                       }
+                       
+                       if (dup_args) {
+                               if (this_arg != null)
+                                       this_arg.Emit (ec);
+                               
+                               for (int i = 0; i < top; i ++)
+                                       temps [i].Emit (ec);
                        }
 
                        if (pd != null && pd.Count > top &&
@@ -5025,6 +5123,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
@@ -5043,9 +5175,25 @@ namespace Mono.CSharp {
                public static void EmitCall (EmitContext ec, bool is_base,
                                             bool is_static, Expression instance_expr,
                                             MethodBase method, ArrayList Arguments, Location loc)
+               {
+                       EmitCall (ec, is_base, is_static, instance_expr, method, Arguments, loc, false, false);
+               }
+               
+               // `dup_args' leaves an extra copy of the arguments on the stack
+               // `omit_args' does not leave any arguments at all.
+               // So, basically, you could make one call with `dup_args' set to true,
+               // and then another with `omit_args' set to true, and the two calls
+               // would have the same set of arguments. However, each argument would
+               // only have been evaluated once.
+               public static void EmitCall (EmitContext ec, bool is_base,
+                                            bool is_static, Expression instance_expr,
+                                            MethodBase method, ArrayList Arguments, Location loc,
+                                            bool dup_args, bool omit_args)
                {
                        ILGenerator ig = ec.ig;
                        bool struct_call = false;
+                       bool this_call = false;
+                       LocalTemporary this_arg = null;
 
                        Type decl_type = method.DeclaringType;
 
@@ -5069,35 +5217,44 @@ 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)
-                               return;
+                       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);
+                       }
+
+                       if (IsMethodExcluded (method, ec))
+                return; 
                        
                        if (!is_static){
-                               if (decl_type.IsValueType)
+                               this_call = instance_expr == null;
+                               if (decl_type.IsValueType || (!this_call && instance_expr.Type.IsValueType))
                                        struct_call = true;
+                               
                                //
                                // If this is ourselves, push "this"
                                //
-                               if (instance_expr == null){
+                               if (!omit_args) {
+                               Type t = null;
+                               if (this_call) {
                                        ig.Emit (OpCodes.Ldarg_0);
+                                       t = decl_type;
                                } else {
                                        //
                                        // Push the instance expression
                                        //
-                                       if (instance_expr.Type.IsValueType){
+                                       if (instance_expr.Type.IsValueType) {
                                                //
                                                // Special case: calls to a function declared in a 
                                                // reference-type with a value-type argument need
-                                               // to have their value boxed.  
-
-                                               struct_call = true;
-                                               if (decl_type.IsValueType){
+                                               // to have their value boxed.
+                                               if (decl_type.IsValueType) {
                                                        //
                                                        // If the expression implements IMemoryLocation, then
                                                        // we can optimize and use AddressOf on the
@@ -5105,40 +5262,63 @@ namespace Mono.CSharp {
                                                        //
                                                        // If not we have to use some temporary storage for
                                                        // it.
-                                                       if (instance_expr is IMemoryLocation){
+                                                       if (instance_expr is IMemoryLocation) {
                                                                ((IMemoryLocation)instance_expr).
                                                                        AddressOf (ec, AddressOp.LoadStore);
-                                                       }
-                                                       else {
-                                                               Type t = instance_expr.Type;
-                                                               
+                                                       } else {
+                                                               LocalTemporary temp = new LocalTemporary (ec, instance_expr.Type);
                                                                instance_expr.Emit (ec);
-                                                               LocalBuilder temp = ig.DeclareLocal (t);
-                                                               ig.Emit (OpCodes.Stloc, temp);
-                                                               ig.Emit (OpCodes.Ldloca, temp);
+                                                               temp.Store (ec);
+                                                               temp.AddressOf (ec, AddressOp.Load);
                                                        }
+                                                       
+                                                       // avoid the overhead of doing this all the time.
+                                                       if (dup_args)
+                                                               t = TypeManager.GetReferenceType (instance_expr.Type);
                                                } else {
                                                        instance_expr.Emit (ec);
                                                        ig.Emit (OpCodes.Box, instance_expr.Type);
+                                                       t = TypeManager.object_type;
                                                } 
-                                       } else
+                                       } else {
                                                instance_expr.Emit (ec);
+                                               t = instance_expr.Type;
+                                       }
+                               }
+                               
+                               if (dup_args) {
+                                       this_arg = new LocalTemporary (ec, t);
+                                       ig.Emit (OpCodes.Dup);
+                                       this_arg.Store (ec);
+                               }
                                }
                        }
 
-                       EmitArguments (ec, method, Arguments);
+                       if (!omit_args)
+                               EmitArguments (ec, method, Arguments, dup_args, this_arg);
 
-                       if (is_static || struct_call || is_base){
-                               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);
-                               else
-                                       ig.Emit (OpCodes.Callvirt, (ConstructorInfo) method);
+                       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 (method is MethodInfo)
+                               ig.Emit (call_op, (MethodInfo) method);
+                       else
+                               ig.Emit (call_op, (ConstructorInfo) method);
                }
                
                public override void Emit (EmitContext ec)
@@ -5367,6 +5547,8 @@ namespace Mono.CSharp {
                        if (type == null)
                                return null;
                        
+                       CheckObsoleteAttribute (type);
+
                        bool IsDelegate = TypeManager.IsDelegateType (type);
                        
                        if (IsDelegate){
@@ -5377,6 +5559,11 @@ namespace Mono.CSharp {
                                return RequestedType;
                        }
 
+                       if (type.IsAbstract && type.IsSealed) {
+                               Report.Error (712, loc, "Cannot create an instance of the static class '{0}'", TypeManager.CSharpName (type));
+                               return null;
+                       }
+
                        if (type.IsInterface || type.IsAbstract){
                                Error (144, "It is not possible to create instances of interfaces or abstract classes");
                                return null;
@@ -5393,7 +5580,8 @@ namespace Mono.CSharp {
                                return this;
                        
                        Expression ml;
-                       ml = MemberLookupFinal (ec, null, type, ".ctor",
+                       // For member-lookup, treat 'new Foo (bar)' as call to 'foo.ctor (bar)', where 'foo' is of type 'Foo'.
+                       ml = MemberLookupFinal (ec, type, type, ".ctor",
                                                MemberTypes.Constructor,
                                                AllBindingFlags | BindingFlags.DeclaredOnly, loc);
 
@@ -5415,7 +5603,8 @@ namespace Mono.CSharp {
                                        }
                                }
 
-                               method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml, Arguments, loc);
+                               method = Invocation.OverloadResolve (
+                                       ec, (MethodGroupExpr) ml, Arguments, false, loc);
                                
                        }
 
@@ -5474,7 +5663,7 @@ namespace Mono.CSharp {
                        }
 
                        if (method != null)
-                               Invocation.EmitArguments (ec, method, Arguments);
+                               Invocation.EmitArguments (ec, method, Arguments, false, null);
 
                        if (is_value_type){
                                if (method == null)
@@ -5521,7 +5710,7 @@ namespace Mono.CSharp {
                        IMemoryLocation ml = (IMemoryLocation) value_target;
                        ml.AddressOf (ec, AddressOp.Store);
                        if (method != null)
-                               Invocation.EmitArguments (ec, method, Arguments);
+                               Invocation.EmitArguments (ec, method, Arguments, false, null);
 
                        if (method == null)
                                ec.ig.Emit (OpCodes.Initobj, type);
@@ -5542,7 +5731,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;
 
@@ -5688,10 +5877,15 @@ namespace Mono.CSharp {
                                        
                                        if (conv == null) 
                                                return false;
-
-                                       if (conv is StringConstant)
+                                       
+                                       if (conv is StringConstant || conv is DecimalConstant || conv is NullCast) {
+                                               // These are subclasses of Constant that can appear as elements of an
+                                               // array that cannot be statically initialized (with num_automatic_initializers
+                                               // > max_automatic_initializers), so num_automatic_initializers should be left as zero.
                                                array_data.Add (conv);
-                                       else if (conv is Constant) {
+                                       } else if (conv is Constant) {
+                                               // These are the types of Constant that can appear in arrays that can be
+                                               // statically allocated.
                                                array_data.Add (conv);
                                                num_automatic_initializers++;
                                        } else
@@ -5847,10 +6041,12 @@ namespace Mono.CSharp {
 
                        if (type == null)
                                return false;
-
-                       underlying_type = type;
-                       if (underlying_type.IsArray)
-                               underlying_type = TypeManager.GetElementType (underlying_type);
+                       
+                       if (!type.IsArray) {
+                               Error (622, "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
+                               return false;
+                       }
+                       underlying_type = TypeManager.GetElementType (type);
                        dimensions = type.GetArrayRank ();
 
                        return true;
@@ -5888,6 +6084,11 @@ namespace Mono.CSharp {
                        
                        array_element_type = TypeManager.GetElementType (type);
 
+                       if (array_element_type.IsAbstract && array_element_type.IsSealed) {
+                               Report.Error (719, loc, "'{0}': array elements cannot be of static type", TypeManager.CSharpName (array_element_type));
+                               return null;
+                       }
+
                        if (arg_count == 1) {
                                is_one_dimensional = true;
                                eclass = ExprClass.Value;
@@ -5913,7 +6114,8 @@ namespace Mono.CSharp {
                                        return null;
                                }
                                
-                               new_method = Invocation.OverloadResolve (ec, (MethodGroupExpr) ml, arguments, loc);
+                               new_method = Invocation.OverloadResolve (
+                                       ec, (MethodGroupExpr) ml, arguments, false, loc);
 
                                if (new_method == null) {
                                        Error (-6, "New invocation: Can not find a constructor for " +
@@ -5924,7 +6126,7 @@ namespace Mono.CSharp {
                                eclass = ExprClass.Value;
                                return this;
                        } else {
-                               ModuleBuilder mb = CodeGen.ModuleBuilder;
+                               ModuleBuilder mb = CodeGen.Module.Builder;
                                ArrayList args = new ArrayList ();
                                
                                if (arguments != null) {
@@ -6100,7 +6302,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
@@ -6112,8 +6314,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);
@@ -6125,22 +6326,19 @@ 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;
                        int [] current_pos = new int [dims];
                        int top = array_data.Count;
-                       LocalBuilder temp = ig.DeclareLocal (type);
-
-                       ig.Emit (OpCodes.Stloc, temp);
 
                        MethodInfo set = null;
 
                        if (dims != 1){
                                Type [] args;
                                ModuleBuilder mb = null;
-                               mb = CodeGen.ModuleBuilder;
+                               mb = CodeGen.Module.Builder;
                                args = new Type [dims + 1];
 
                                int j;
@@ -6175,7 +6373,7 @@ namespace Mono.CSharp {
                                            num_automatic_initializers <= max_automatic_initializers) {
                                                Type etype = e.Type;
                                                
-                                               ig.Emit (OpCodes.Ldloc, temp);
+                                               ig.Emit (OpCodes.Dup);
 
                                                for (int idx = 0; idx < dims; idx++) 
                                                        IntConstant.EmitInt (ig, current_pos [idx]);
@@ -6203,12 +6401,17 @@ namespace Mono.CSharp {
 
                                                e.Emit (ec);
 
-                                                if (dims == 1)
-                                                        ArrayAccess.EmitStoreOpcode (ig, array_element_type);
-                                                else 
-                                                        ig.Emit (OpCodes.Call, set);
-                                                
-                                        }
+                                               if (dims == 1) {
+                                                       bool is_stobj;
+                                                       OpCode op = ArrayAccess.GetStoreOpcode (etype, out is_stobj);
+                                                       if (is_stobj)
+                                                               ig.Emit (OpCodes.Stobj, etype);
+                                                       else
+                                                               ig.Emit (op);
+                                               } else 
+                                                       ig.Emit (OpCodes.Call, set);
+
+                                       }
                                }
                                
                                //
@@ -6221,9 +6424,6 @@ namespace Mono.CSharp {
                                        current_pos [j] = 0;
                                }
                        }
-
-                       if (is_expression)
-                               ig.Emit (OpCodes.Ldloc, temp);
                }
 
                void EmitArrayArguments (EmitContext ec)
@@ -6241,7 +6441,7 @@ namespace Mono.CSharp {
                        }
                }
                
-               void DoEmit (EmitContext ec, bool is_statement)
+               public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
                        
@@ -6261,27 +6461,16 @@ namespace Mono.CSharp {
                                // 
                                bool dynamic_initializers = true;
 
-                               if (underlying_type != TypeManager.string_type &&
-                                   underlying_type != TypeManager.decimal_type &&
-                                   underlying_type != TypeManager.object_type) {
-                                       if (num_automatic_initializers > max_automatic_initializers)
-                                               EmitStaticInitializers (ec, dynamic_initializers || !is_statement);
-                               }
+                               // This will never be true for array types that cannot be statically
+                               // initialized. num_automatic_initializers will always be zero.  See
+                               // CheckIndices.
+                               if (num_automatic_initializers > max_automatic_initializers)
+                                       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 ()
                {
@@ -6303,13 +6492,23 @@ namespace Mono.CSharp {
                                if (e is NullLiteral)
                                        v = null;
                                else {
-                                       if (!Attribute.GetAttributeArgumentExpression (e, Location, out v))
+                                       if (!Attribute.GetAttributeArgumentExpression (e, Location, array_element_type, out v))
                                                return null;
                                }
                                ret [i++] = v;
                        }
                        return ret;
                }
+
+               public Expression TurnIntoConstant ()
+               {
+                       //
+                       // Should use something like the above attribute thing.
+                       // It should return a subclass of Constant that just returns
+                       // the computed value of the array
+                       //
+                       throw new Exception ("Does not support yet Turning array into a Constant");
+               }
        }
        
        /// <summary>
@@ -6396,32 +6595,40 @@ namespace Mono.CSharp {
                        return this;
                }
 
-               public override void Emit (EmitContext ec)
+               public void Emit (EmitContext ec, bool leave_copy)
                {
-                       ILGenerator ig = ec.ig;
-                       
-                       ig.Emit (OpCodes.Ldarg_0);
-                       if (ec.TypeContainer is Struct)
-                               ig.Emit (OpCodes.Ldobj, type);
+                       Emit (ec);
+                       if (leave_copy)
+                               ec.ig.Emit (OpCodes.Dup);
                }
-
-               public void EmitAssign (EmitContext ec, Expression source)
+               
+               public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
                {
                        ILGenerator ig = ec.ig;
                        
                        if (ec.TypeContainer is Struct){
-                               ig.Emit (OpCodes.Ldarg_0);
+                               ec.EmitThis ();
                                source.Emit (ec);
+                               if (leave_copy)
+                                       ec.ig.Emit (OpCodes.Dup);
                                ig.Emit (OpCodes.Stobj, type);
                        } else {
-                               source.Emit (ec);
-                               ig.Emit (OpCodes.Starg, 0);
+                               throw new Exception ("how did you get here");
                        }
                }
+               
+               public override void Emit (EmitContext ec)
+               {
+                       ILGenerator ig = ec.ig;
+
+                       ec.EmitThis ();
+                       if (ec.TypeContainer is Struct)
+                               ig.Emit (OpCodes.Ldobj, type);
+               }
 
                public void AddressOf (EmitContext ec, AddressOp mode)
                {
-                       ec.ig.Emit (OpCodes.Ldarg_0);
+                       ec.EmitThis ();
 
                        // FIMXE
                        // FIGURE OUT WHY LDARG_S does not work
@@ -6434,6 +6641,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
        //
@@ -6483,6 +6769,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       CheckObsoleteAttribute (typearg);
+
                        type = TypeManager.type_type;
                        eclass = ExprClass.Type;
                        return this;
@@ -6543,6 +6831,8 @@ namespace Mono.CSharp {
                        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;
@@ -6584,7 +6874,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 " +
@@ -6592,21 +6882,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;
-
-                       Type 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,
@@ -6638,10 +6920,10 @@ namespace Mono.CSharp {
                                        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);
@@ -6660,7 +6942,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;
                                                }                                       
@@ -6714,6 +6996,7 @@ namespace Mono.CSharp {
                                                // accessors and private field etc so there's no need
                                                // to transform ourselves.
                                                //
+                                               ee.InstanceExpression = left;
                                                return ee;
                                        }
 
@@ -6726,38 +7009,40 @@ 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);
                                                return null;
                                        }
 
                                } else {
-                                       if (!me.IsInstance){
-                                               if (IdenticalNameAndTypeName (ec, left_original, loc))
+                                       if (!me.IsInstance) {
+                                               if (IdenticalNameAndTypeName (ec, left_original, left, loc))
                                                        return member_lookup;
 
                                                if (left_is_explicit) {
                                                        error176 (loc, me.Name);
                                                        return null;
                                                }
-                                       }
+                                       }                       
 
                                        //
                                        // Since we can not check for instance objects in SimpleName,
@@ -6780,6 +7065,9 @@ namespace Mono.CSharp {
                                                }
                                        }
 
+                                       if ((mg != null) && IdenticalNameAndTypeName (ec, left_original, left, loc))
+                                               mg.IdenticalTypeName = true;
+
                                        me.InstanceExpression = left;
                                }
 
@@ -6788,7 +7076,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;
                }
                
@@ -6805,7 +7093,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;
 
@@ -6829,8 +7117,7 @@ namespace Mono.CSharp {
                        Type expr_type = expr.Type;
                        if (expr is TypeExpr){
                                if (!ec.DeclSpace.CheckAccessLevel (expr_type)){
-                                       Error (122, "`" + expr_type + "' " +
-                                              "is inaccessible because of its protection level");
+                                       Report.Error (122, loc, "'{0}' is inaccessible due to its protection level", expr_type);
                                        return null;
                                }
 
@@ -6841,9 +7128,28 @@ namespace Mono.CSharp {
                                                object value = en.LookupEnumValue (ec, Identifier, loc);
                                                
                                                if (value != null){
+                                                       MemberCore mc = en.GetDefinition (Identifier);
+                                                       ObsoleteAttribute oa = mc.GetObsoleteAttribute (en);
+                                                       if (oa != null) {
+                                                               AttributeTester.Report_ObsoleteMessage (oa, mc.GetSignatureForError (), Location);
+                                                       }
+                                                       oa = en.GetObsoleteAttribute (en);
+                                                       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);
+                                               }
                                        }
                                }
                        }
@@ -7102,7 +7408,7 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               Expression MakePointerAccess ()
+               Expression MakePointerAccess (EmitContext ec)
                {
                        Type t = Expr.Type;
 
@@ -7116,8 +7422,10 @@ namespace Mono.CSharp {
                        }
                        Expression p;
 
-                       p = new PointerArithmetic (true, Expr, ((Argument)Arguments [0]).Expr, t, loc);
-                       return new Indirection (p, loc);
+                       p = new PointerArithmetic (true, Expr, ((Argument)Arguments [0]).Expr, t, loc).Resolve (ec);
+                       if (p == null)
+                               return null;
+                       return new Indirection (p, loc).Resolve (ec);
                }
                
                public override Expression DoResolve (EmitContext ec)
@@ -7141,7 +7449,7 @@ namespace Mono.CSharp {
                        if (t.IsArray)
                                return (new ArrayAccess (this, loc)).Resolve (ec);
                        else if (t.IsPointer)
-                               return MakePointerAccess ();
+                               return MakePointerAccess (ec);
                        else
                                return (new IndexerAccess (this, loc)).Resolve (ec);
                }
@@ -7155,7 +7463,7 @@ namespace Mono.CSharp {
                        if (t.IsArray)
                                return (new ArrayAccess (this, loc)).ResolveLValue (ec, right_side);
                        else if (t.IsPointer)
-                               return MakePointerAccess ();
+                               return MakePointerAccess (ec);
                        else
                                return (new IndexerAccess (this, loc)).ResolveLValue (ec, right_side);
                }
@@ -7175,7 +7483,8 @@ namespace Mono.CSharp {
                //
                ElementAccess ea;
 
-               LocalTemporary [] cached_locations;
+               LocalTemporary temp;
+               bool prepared;
                
                public ArrayAccess (ElementAccess ea_data, Location l)
                {
@@ -7265,27 +7574,15 @@ 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 
                                ig.Emit (OpCodes.Ldelem_Ref);
                }
 
-               /// <summary>
-               ///    Emits the right opcode to store an object of Type `t'
-               ///    from an array of T.  
-               /// </summary>
-               static public void EmitStoreOpcode (ILGenerator ig, Type t)
-               {
-                       bool is_stobj;
-                       OpCode op = GetStoreOpcode (t, out is_stobj);
-                       if (is_stobj)
-                               ig.Emit (OpCodes.Stobj, t);
-                       else
-                               ig.Emit (op);
-               }
-
                /// <summary>
                ///    Returns the right opcode to store an object of Type `t'
                ///    from an array of T.  
@@ -7295,7 +7592,7 @@ namespace Mono.CSharp {
                        //Console.WriteLine (new System.Diagnostics.StackTrace ());
                        is_stobj = false;
                        t = TypeManager.TypeToCoreType (t);
-                       if (TypeManager.IsEnumType (t) && t != TypeManager.enum_type)
+                       if (TypeManager.IsEnumType (t))
                                t = TypeManager.EnumToUnderlying (t);
                        if (t == TypeManager.byte_type || t == TypeManager.sbyte_type ||
                            t == TypeManager.bool_type)
@@ -7323,7 +7620,7 @@ namespace Mono.CSharp {
 
                MethodInfo FetchGetMethod ()
                {
-                       ModuleBuilder mb = CodeGen.ModuleBuilder;
+                       ModuleBuilder mb = CodeGen.Module.Builder;
                        int arg_count = ea.Arguments.Count;
                        Type [] args = new Type [arg_count];
                        MethodInfo get;
@@ -7344,7 +7641,7 @@ namespace Mono.CSharp {
 
                MethodInfo FetchAddressMethod ()
                {
-                       ModuleBuilder mb = CodeGen.ModuleBuilder;
+                       ModuleBuilder mb = CodeGen.Module.Builder;
                        int arg_count = ea.Arguments.Count;
                        Type [] args = new Type [arg_count];
                        MethodInfo address;
@@ -7377,101 +7674,111 @@ namespace Mono.CSharp {
                {
                        ILGenerator ig = ec.ig;
                        
-                       if (cached_locations == null){
-                               ea.Expr.Emit (ec);
-                               foreach (Argument a in ea.Arguments){
-                                       Type argtype = a.Expr.Type;
-                                       
-                                       a.Expr.Emit (ec);
-                                       
-                                       if (argtype == TypeManager.int64_type)
-                                               ig.Emit (OpCodes.Conv_Ovf_I);
-                                       else if (argtype == TypeManager.uint64_type)
-                                               ig.Emit (OpCodes.Conv_Ovf_I_Un);
-                               }
-                               return;
-                       }
-
-                       if (cached_locations [0] == null){
-                               cached_locations [0] = new LocalTemporary (ec, ea.Expr.Type);
-                               ea.Expr.Emit (ec);
-                               ig.Emit (OpCodes.Dup);
-                               cached_locations [0].Store (ec);
+                       ea.Expr.Emit (ec);
+                       foreach (Argument a in ea.Arguments){
+                               Type argtype = a.Expr.Type;
                                
-                               int j = 1;
+                               a.Expr.Emit (ec);
                                
-                               foreach (Argument a in ea.Arguments){
-                                       Type argtype = a.Expr.Type;
-                                       
-                                       cached_locations [j] = new LocalTemporary (ec, TypeManager.intptr_type /* a.Expr.Type */);
-                                       a.Expr.Emit (ec);
-                                       if (argtype == TypeManager.int64_type)
-                                               ig.Emit (OpCodes.Conv_Ovf_I);
-                                       else if (argtype == TypeManager.uint64_type)
-                                               ig.Emit (OpCodes.Conv_Ovf_I_Un);
-
-                                       ig.Emit (OpCodes.Dup);
-                                       cached_locations [j].Store (ec);
-                                       j++;
-                               }
-                               return;
+                               if (argtype == TypeManager.int64_type)
+                                       ig.Emit (OpCodes.Conv_Ovf_I);
+                               else if (argtype == TypeManager.uint64_type)
+                                       ig.Emit (OpCodes.Conv_Ovf_I_Un);
                        }
-
-                       foreach (LocalTemporary lt in cached_locations)
-                               lt.Emit (ec);
                }
 
-               public new void CacheTemporaries (EmitContext ec)
-               {
-                       cached_locations = new LocalTemporary [ea.Arguments.Count + 1];
-               }
-               
-               public override void Emit (EmitContext ec)
+               public void Emit (EmitContext ec, bool leave_copy)
                {
                        int rank = ea.Expr.Type.GetArrayRank ();
                        ILGenerator ig = ec.ig;
 
-                       LoadArrayAndArguments (ec);
-                       
-                       if (rank == 1)
-                               EmitLoadOpcode (ig, type);
-                       else {
-                               MethodInfo method;
+                       if (!prepared) {
+                               LoadArrayAndArguments (ec);
                                
-                               method = FetchGetMethod ();
-                               ig.Emit (OpCodes.Call, method);
+                               if (rank == 1)
+                                       EmitLoadOpcode (ig, type);
+                               else {
+                                       MethodInfo method;
+                                       
+                                       method = FetchGetMethod ();
+                                       ig.Emit (OpCodes.Call, method);
+                               }
+                       } else
+                               LoadFromPtr (ec.ig, this.type);
+                       
+                       if (leave_copy) {
+                               ec.ig.Emit (OpCodes.Dup);
+                               temp = new LocalTemporary (ec, this.type);
+                               temp.Store (ec);
                        }
                }
+               
+               public override void Emit (EmitContext ec)
+               {
+                       Emit (ec, false);
+               }
 
-               public void EmitAssign (EmitContext ec, Expression source)
+               public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
                {
                        int rank = ea.Expr.Type.GetArrayRank ();
                        ILGenerator ig = ec.ig;
                        Type t = source.Type;
+                       prepared = prepare_for_load;
 
-                       LoadArrayAndArguments (ec);
-
-                       //
-                       // The stobj opcode used by value types will need
-                       // an address on the stack, not really an array/array
-                       // pair
-                       //
-                       if (rank == 1){
-                               if (t == TypeManager.enum_type || t == TypeManager.decimal_type ||
-                                   (t.IsSubclassOf (TypeManager.value_type) && !TypeManager.IsEnumType (t) && !TypeManager.IsBuiltinType (t)))
-                                       ig.Emit (OpCodes.Ldelema, t);
+                       if (prepare_for_load) {
+                               AddressOf (ec, AddressOp.LoadStore);
+                               ec.ig.Emit (OpCodes.Dup);
+                               source.Emit (ec);
+                               if (leave_copy) {
+                                       ec.ig.Emit (OpCodes.Dup);
+                                       temp = new LocalTemporary (ec, this.type);
+                                       temp.Store (ec);
+                               }
+                               StoreFromPtr (ec.ig, t);
+                               
+                               if (temp != null)
+                                       temp.Emit (ec);
+                               
+                               return;
                        }
                        
-                       source.Emit (ec);
+                       LoadArrayAndArguments (ec);
 
-                       if (rank == 1)
-                               EmitStoreOpcode (ig, t);
-                       else {
-                               ModuleBuilder mb = CodeGen.ModuleBuilder;
+                       if (rank == 1) {
+                               bool is_stobj;
+                               OpCode op = GetStoreOpcode (t, out is_stobj);
+                               //
+                               // The stobj opcode used by value types will need
+                               // an address on the stack, not really an array/array
+                               // pair
+                               //
+                               if (is_stobj)
+                                       ig.Emit (OpCodes.Ldelema, t);
+                               
+                               source.Emit (ec);
+                               if (leave_copy) {
+                                       ec.ig.Emit (OpCodes.Dup);
+                                       temp = new LocalTemporary (ec, this.type);
+                                       temp.Store (ec);
+                               }
+                               
+                               if (is_stobj)
+                                       ig.Emit (OpCodes.Stobj, t);
+                               else
+                                       ig.Emit (op);
+                       } else {
+                               ModuleBuilder mb = CodeGen.Module.Builder;
                                int arg_count = ea.Arguments.Count;
                                Type [] args = new Type [arg_count + 1];
                                MethodInfo set;
                                
+                               source.Emit (ec);
+                               if (leave_copy) {
+                                       ec.ig.Emit (OpCodes.Dup);
+                                       temp = new LocalTemporary (ec, this.type);
+                                       temp.Store (ec);
+                               }
+                               
                                for (int i = 0; i < arg_count; i++){
                                        //args [i++] = a.Type;
                                        args [i] = TypeManager.int32_type;
@@ -7487,6 +7794,9 @@ namespace Mono.CSharp {
                                
                                ig.Emit (OpCodes.Call, set);
                        }
+                       
+                       if (temp != null)
+                               temp.Emit (ec);
                }
 
                public void AddressOf (EmitContext ec, AddressOp mode)
@@ -7550,7 +7860,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;
@@ -7669,7 +7979,8 @@ namespace Mono.CSharp {
                        if (AllGetters.Count > 0) {
                                found_any_getters = true;
                                get = (MethodInfo) Invocation.OverloadResolve (
-                                       ec, new MethodGroupExpr (AllGetters, loc), arguments, loc);
+                                       ec, new MethodGroupExpr (AllGetters, loc),
+                                       arguments, false, loc);
                        }
 
                        if (!found_any) {
@@ -7733,7 +8044,7 @@ namespace Mono.CSharp {
                                set_arguments.Add (new Argument (right_side, Argument.AType.Expression));
                                set = (MethodInfo) Invocation.OverloadResolve (
                                        ec, new MethodGroupExpr (AllSetters, loc),
-                                       set_arguments, loc);
+                                       set_arguments, false, loc);
                        }
 
                        if (!found_any) {
@@ -7778,19 +8089,53 @@ namespace Mono.CSharp {
                        return this;
                }
                
-               public override void Emit (EmitContext ec)
+               bool prepared = false;
+               LocalTemporary temp;
+               
+               public void Emit (EmitContext ec, bool leave_copy)
                {
-                       Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, get, arguments, loc);
+                       Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, get, arguments, loc, prepared, false);
+                       if (leave_copy) {
+                               ec.ig.Emit (OpCodes.Dup);
+                               temp = new LocalTemporary (ec, Type);
+                               temp.Store (ec);
+                       }
                }
-
+               
                //
                // source is ignored, because we already have a copy of it from the
                // LValue resolution and we have already constructed a pre-cached
                // version of the arguments (ea.set_arguments);
                //
-               public void EmitAssign (EmitContext ec, Expression source)
+               public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
+               {
+                       prepared = prepare_for_load;
+                       Argument a = (Argument) set_arguments [set_arguments.Count - 1];
+                       
+                       if (prepared) {
+                               source.Emit (ec);
+                               if (leave_copy) {
+                                       ec.ig.Emit (OpCodes.Dup);
+                                       temp = new LocalTemporary (ec, Type);
+                                       temp.Store (ec);
+                               }
+                       } else if (leave_copy) {
+                               temp = new LocalTemporary (ec, Type);
+                               source.Emit (ec);
+                               temp.Store (ec);
+                               a.Expr = temp;
+                       }
+                       
+                       Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, set, set_arguments, loc, false, prepared);
+                       
+                       if (temp != null)
+                               temp.Emit (ec);
+               }
+               
+               
+               public override void Emit (EmitContext ec)
                {
-                       Invocation.EmitCall (ec, is_base_indexer, false, instance_expr, set, set_arguments, loc);
+                       Emit (ec, false);
                }
        }
 
@@ -7848,6 +8193,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, loc);
@@ -7870,6 +8220,9 @@ namespace Mono.CSharp {
 
                                pe.IsBase = true;
                        }
+                       
+                       if (e is MethodGroupExpr)
+                               ((MethodGroupExpr) e).IsBase = true;
 
                        return e;
                }
@@ -8012,6 +8365,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;
+                       }
+
                        //
                        // ltype.Fullname is already fully qualified, so we can skip
                        // a lot of probes, and go directly to TypeManager.LookupType
@@ -8150,6 +8509,13 @@ namespace Mono.CSharp {
                                        return null;
                        }
 
+                       Constant c = count as Constant;
+                       // TODO: because we don't have property IsNegative
+                       if (c != null && c.ConvertToUInt () == null) {
+                               Report.Error (247, loc, "Cannot use a negative size with stackalloc");
+                               return null;
+                       }
+
                        if (ec.CurrentBranching.InCatch () ||
                            ec.CurrentBranching.InFinally (true)) {
                                Error (255,