2004-08-14 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / expression.cs
index 4fd0e6887a8400cae16d1a361117be23ba0a8446..03a28b723c9b460318386a6275224b0ab4788cb1 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;
@@ -81,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
@@ -568,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;
@@ -634,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)
                {
@@ -650,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 {
+                       if (!prepared)
                                expr.Emit (ec);
+
+                       LoadFromPtr (ec.ig, Type);
+               }
+
+               public void Emit (EmitContext ec, bool leave_copy)
+               {
+                       Emit (ec);
+                       if (leave_copy) {
                                ec.ig.Emit (OpCodes.Dup);
+                               temporary = new LocalTemporary (ec, expr.Type);
                                temporary.Store (ec);
-                               have_temporary = true;
-                               }
-                       } else
-                               expr.Emit (ec);
-                       
-                       LoadFromPtr (ig, Type);
+                       }
                }
 
-               public void EmitAssign (EmitContext ec, Expression source)
+               public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
                {
-                       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);
+                       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)
@@ -707,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 + ")";
@@ -748,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)
                {
@@ -846,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;
 
@@ -966,114 +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);
+                       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)
+               {
                        //
-                       // NOTE: We should probably handle three cases:
-                       //
-                       //     * method invocation required.
-                       //     * direct stack manipulation possible
-                       //     * the object requires an "instance" field
+                       // 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 (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);
+                       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;
                        }
                        
-                       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);
-               }
-
-               public override void Emit (EmitContext ec)
-               {
                        EmitCode (ec, true);
-                       
                }
                
                public override void EmitStatement (EmitContext ec)
                {
                        EmitCode (ec, false);
                }
-
        }
 
        /// <summary>
@@ -1109,6 +1036,8 @@ namespace Mono.CSharp {
                        if (probe_type == null)
                                return null;
 
+                       CheckObsoleteAttribute (probe_type);
+
                        expr = expr.Resolve (ec);
                        if (expr == null)
                                return null;
@@ -1845,6 +1774,8 @@ namespace Mono.CSharp {
                        if (type == null)
                                return null;
 
+                       CheckObsoleteAttribute (type);
+
                        eclass = ExprClass.Value;
 
                        if (expr is Constant){
@@ -1854,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;
                }
@@ -2089,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);
@@ -2121,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)){
                                //
@@ -2288,8 +2227,6 @@ namespace Mono.CSharp {
                        Type l = left.Type;
                        Type r = right.Type;
 
-                       bool overload_failed = false;
-
                        //
                        // Special cases: string or type parameter comapred to null
                        //
@@ -2322,6 +2259,13 @@ namespace Mono.CSharp {
                                        Type = TypeManager.bool_type;
                                        return this;
                                }
+                               
+                               // IntPtr equality
+                               if (l == TypeManager.intptr_type && r == TypeManager.intptr_type) {
+                                       Type = TypeManager.bool_type;
+                                       
+                                       return this;
+                               }
                        }
 
                        //
@@ -2357,8 +2301,6 @@ namespace Mono.CSharp {
                                                MethodInfo mi = (MethodInfo) method;
                                                
                                                return new BinaryMethod (mi.ReturnType, method, args);
-                                       } else {
-                                               overload_failed = true;
                                        }
                                }
                        }
@@ -2683,14 +2625,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
                        //
@@ -2711,13 +2645,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 ();
@@ -2969,7 +2906,7 @@ namespace Mono.CSharp {
                                ig.MarkLabel (end);
                                return;
                        }
-                       
+
                        left.Emit (ec);
                        right.Emit (ec);
 
@@ -3135,7 +3072,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);
@@ -3270,7 +3207,7 @@ namespace Mono.CSharp {
                                break;
                        }
                        
-                       Invocation.EmitArguments (ec, concat_method, operands);
+                       Invocation.EmitArguments (ec, concat_method, operands, false, null);
                        ec.ig.Emit (OpCodes.Call, concat_method);
                }
        }
@@ -3299,7 +3236,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);
@@ -3347,6 +3284,7 @@ namespace Mono.CSharp {
                }
 
                Expression op_true, op_false, op;
+               LocalTemporary left_temp;
 
                public override Expression DoResolve (EmitContext ec)
                {
@@ -3359,8 +3297,10 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       left_temp = new LocalTemporary (ec, type);
+
                        ArrayList arguments = new ArrayList ();
-                       arguments.Add (new Argument (left, Argument.AType.Expression));
+                       arguments.Add (new Argument (left_temp, Argument.AType.Expression));
                        arguments.Add (new Argument (right, Argument.AType.Expression));
                        method = Invocation.OverloadResolve (
                                ec, (MethodGroupExpr) operator_group, arguments, false, loc)
@@ -3372,8 +3312,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;
@@ -3390,8 +3330,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);
@@ -3661,7 +3604,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; 
@@ -3702,6 +3645,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       CheckObsoleteAttribute (e.Type);
+
                        if (local_info.LocalBuilder == null)
                                return ec.RemapLocalLValue (local_info, right_side);
                        
@@ -3720,12 +3665,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)
@@ -3752,7 +3704,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)
                {
@@ -3887,6 +3840,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;
                        
@@ -3897,33 +3855,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
@@ -3960,7 +3941,8 @@ namespace Mono.CSharp {
                public enum AType : byte {
                        Expression,
                        Ref,
-                       Out
+                       Out,
+                       ArgList
                };
 
                public readonly AType ArgType;
@@ -3972,6 +3954,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)
@@ -3997,6 +3985,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);
@@ -4006,7 +3997,7 @@ namespace Mono.CSharp {
                {
                        ConstructedType ctype = Expr as ConstructedType;
                        if (ctype != null)
-                               Expr = ctype.GetMemberAccess (ec);
+                               Expr = ctype.GetSimpleName (ec);
 
                        // FIXME: csc doesn't report any error if you try to use `ref' or
                        //        `out' in a delegate creation expression.
@@ -4176,9 +4167,12 @@ namespace Mono.CSharp {
                /// </summary>
                static int BetterConversion (EmitContext ec, Argument a, Type p, Type q, Location loc)
                {
-                       Type argument_type = a.Type;
+                       Type argument_type = TypeManager.TypeToCoreType (a.Type);
                        Expression argument_expr = a.Expr;
 
+                       // p = TypeManager.TypeToCoreType (p);
+                       // q = TypeManager.TypeToCoreType (q);
+
                        if (argument_type == null)
                                throw new Exception ("Expression of type " + a.Expr +
                                                      " does not resolve its type");
@@ -4223,85 +4217,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);
                                
@@ -4348,7 +4263,7 @@ 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, MethodGroupExpr me, ArrayList args,
                                           MethodBase candidate, bool candidate_params,
                                            MethodBase best, bool best_params,
                                           Location loc)
@@ -4388,7 +4303,8 @@ namespace Mono.CSharp {
                        if (cand_count == 0 && argument_count == 0)
                                return best == null || best_params ? 1 : 0;
 
-                       if (candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.PARAMS)
+                       if ((candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.PARAMS) &&
+                           (candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.ARGLIST))
                                if (cand_count != argument_count)
                                        return 0;
 
@@ -4402,7 +4318,8 @@ namespace Mono.CSharp {
                                for (int j = 0; j < argument_count; ++j) {
 
                                        Argument a = (Argument) args [j];
-                                       Type t = candidate_pd.ParameterType (j);
+                                       Type t = TypeManager.TypeToCoreType (
+                                               candidate_pd.ParameterType (j));
 
                                        if (candidate_pd.ParameterModifier (j) == Parameter.Modifier.PARAMS)
                                                if (candidate_params)
@@ -4423,14 +4340,16 @@ namespace Mono.CSharp {
                        best_pd = GetParameterData (best);
 
                        int rating1 = 0, rating2 = 0;
-                       
+
                        for (int j = 0; j < argument_count; ++j) {
                                int x, y;
                                
                                Argument a = (Argument) args [j];
 
-                               Type ct = candidate_pd.ParameterType (j);
-                               Type bt = best_pd.ParameterType (j);
+                               Type ct = TypeManager.TypeToCoreType (
+                                       candidate_pd.ParameterType (j));
+                               Type bt = TypeManager.TypeToCoreType (
+                                       best_pd.ParameterType (j));
 
                                if (candidate_pd.ParameterModifier (j) == Parameter.Modifier.PARAMS)
                                        if (candidate_params)
@@ -4545,20 +4464,22 @@ namespace Mono.CSharp {
                }
 
                static bool IsParamsMethodApplicable (EmitContext ec, MethodGroupExpr me,
-                                                     ArrayList arguments, ref MethodBase candidate)
+                                                     ArrayList arguments, bool do_varargs,
+                                                     ref MethodBase candidate)
                {
                        if (!me.HasTypeArguments &&
                            !InferParamsTypeArguments (ec, arguments, ref candidate))
                                return false;
 
-                       return IsParamsMethodApplicable (ec, arguments, candidate);
+                       return IsParamsMethodApplicable (ec, arguments, candidate, do_varargs);
                }
 
                /// <summary>
                ///   Determines if the candidate method, if a params method, is applicable
                ///   in its expanded form to the given set of arguments
                /// </summary>
-               static bool IsParamsMethodApplicable (EmitContext ec, ArrayList arguments, MethodBase candidate)
+               static bool IsParamsMethodApplicable (EmitContext ec, ArrayList arguments,
+                                                     MethodBase candidate, bool do_varargs)
                {
                        int arg_count;
                        
@@ -4574,10 +4495,18 @@ namespace Mono.CSharp {
                        if (pd_count == 0)
                                return false;
                        
-                       if (pd.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS)
+                       int count = pd_count - 1;
+                       if (do_varargs) {
+                               if (pd.ParameterModifier (count) != Parameter.Modifier.ARGLIST)
+                                       return false;
+                               if (pd_count != arg_count)
+                                       return false;
+                       } else {
+                               if (pd.ParameterModifier (count) != Parameter.Modifier.PARAMS)
                                return false;
+                       }
                        
-                       if (pd_count - 1 > arg_count)
+                       if (count > arg_count)
                                return false;
                        
                        if (pd_count == 1 && arg_count == 0)
@@ -4588,7 +4517,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];
 
@@ -4619,6 +4548,14 @@ namespace Mono.CSharp {
                                
                        }
 
+                       if (do_varargs) {
+                               Argument a = (Argument) arguments [count];
+                               if (!(a.Expr is Arglist))
+                                       return false;
+
+                               return true;
+                       }
+
                        Type element_type = TypeManager.GetElementType (pd.ParameterType (pd_count - 1));
 
                        for (int i = pd_count - 1; i < arg_count; i++) {
@@ -4769,9 +4706,18 @@ namespace Mono.CSharp {
                                        applicable_type = candidate.DeclaringType;
                                        found_applicable = true;
                                        candidate_to_form [candidate] = false;
-                               } else if (IsParamsMethodApplicable (ec, me, Arguments, ref methods [i])) {
+                               } else if (IsParamsMethodApplicable (
+                                                  ec, me, Arguments,false, ref methods [i])) {
                                        // Candidate is applicable in expanded form
-                                       MethodBase candidate = methods [i];
+                                       MethodBase candidate = methods [i];
+                                       candidates.Add (candidate);
+                                       applicable_type = candidate.DeclaringType;
+                                       found_applicable = true; 
+                                       candidate_to_form [candidate] = true;
+                               } else if (IsParamsMethodApplicable (
+                                                  ec, me, Arguments,true, ref methods [i])) {
+                                       // Candidate is applicable in expanded form
+                                       MethodBase candidate = methods [i];
                                        candidates.Add (candidate);
                                        applicable_type = candidate.DeclaringType;
                                        found_applicable = true; 
@@ -4797,7 +4743,7 @@ namespace Mono.CSharp {
                                 if (method != null)
                                         method_params = (bool) candidate_to_form [method];
                                 
-                                int x = BetterFunction (ec, Arguments,
+                                int x = BetterFunction (ec, me, Arguments,
                                                         candidate, cand_params,
                                                        method, method_params,
                                                         loc);
@@ -4891,7 +4837,7 @@ namespace Mono.CSharp {
 //                                         continue;
                                 
                                 bool cand_params = (bool) candidate_to_form [candidate];
-                               int x = BetterFunction (ec, Arguments,
+                               int x = BetterFunction (ec, me, Arguments,
                                                         method, best_params,
                                                         candidate, cand_params,
                                                        loc);
@@ -4974,6 +4920,8 @@ namespace Mono.CSharp {
 
                                        if (chose_params_expanded)
                                                parameter_type = TypeManager.GetElementType (parameter_type);
+                               } else if (pm == Parameter.Modifier.ARGLIST){
+                                       continue;
                                } else {
                                        //
                                        // Check modifiers
@@ -5036,7 +4984,7 @@ namespace Mono.CSharp {
 
                static bool InferType (Type pt, Type at, ref Type[] infered)
                {
-                       if (pt.IsGenericParameter) {
+                       if (pt.IsGenericParameter && (pt.DeclaringMethod != null)) {
                                int pos = pt.GenericParameterPosition;
 
                                if (infered [pos] == null) {
@@ -5183,6 +5131,9 @@ namespace Mono.CSharp {
                public static bool InferTypeArguments (Type[] param_types, Type[] arg_types,
                                                       ref Type[] infered_types)
                {
+                       if (infered_types == null)
+                               return false;
+
                        for (int i = 0; i < arg_types.Length; i++) {
                                if (arg_types [i] == null)
                                        continue;
@@ -5276,7 +5227,7 @@ namespace Mono.CSharp {
                                is_base = true;
 
                        if (expr is ConstructedType)
-                               expr = ((ConstructedType) expr).GetMemberAccess (ec);
+                               expr = ((ConstructedType) expr).GetSimpleName (ec);
 
                        expr = expr.Resolve (ec, ResolveFlags.VariableOrValue | ResolveFlags.MethodGroup);
                        if (expr == null)
@@ -5317,8 +5268,20 @@ namespace Mono.CSharp {
                        MethodInfo mi = method as MethodInfo;
                        if (mi != null) {
                                type = TypeManager.TypeToCoreType (mi.ReturnType);
-                               if (!mi.IsStatic && !mg.IsExplicitImpl && (mg.InstanceExpression == null))
+                               if (!mi.IsStatic && !mg.IsExplicitImpl && (mg.InstanceExpression == null)) {
                                        SimpleName.Error_ObjectRefRequired (ec, loc, mi.Name);
+                                       return null;
+                               }
+
+                               Expression iexpr = mg.InstanceExpression;
+                               if (mi.IsStatic && (iexpr != null) && !(iexpr is This)) {
+                                       if (mg.IdenticalTypeName)
+                                               mg.InstanceExpression = null;
+                                       else {
+                                               MemberAccess.error176 (loc, mi.Name);
+                                               return null;
+                                       }
+                               }
                        }
 
                        if (type.IsPointer){
@@ -5388,14 +5351,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
@@ -5432,6 +5405,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 &&
@@ -5443,6 +5428,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
@@ -5461,10 +5480,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;
 
@@ -5488,84 +5522,119 @@ namespace Mono.CSharp {
                        }
 
                        //
-                       // This checks the `ConditionalAttribute' on the method, and the
-                       // ObsoleteAttribute
+                       // This checks ObsoleteAttribute on the method and on the declaring type
                        //
-                       TypeManager.MethodFlags flags = TypeManager.GetMethodFlags (method, loc);
-                       if ((flags & TypeManager.MethodFlags.IsObsoleteError) != 0)
-                               return;
-                       if ((flags & TypeManager.MethodFlags.ShouldIgnore) != 0)
+                       ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (method);
+                       if (oa != null)
+                               AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (method), loc);
+
+                       oa = AttributeTester.GetObsoleteAttribute (method.DeclaringType);
+                       if (oa != null) {
+                               AttributeTester.Report_ObsoleteMessage (oa, method.DeclaringType.FullName, loc);
+                       }
+
+
+                       oa = AttributeTester.GetObsoleteAttribute (method.DeclaringType);
+                       if (oa != null) {
+                               AttributeTester.Report_ObsoleteMessage (oa, method.DeclaringType.FullName, loc);
+                       }
+
+                       if (IsMethodExcluded (method, ec))
                                return;
                        
                        if (!is_static){
-                               if (TypeManager.IsValueType (decl_type))
+                               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){
-                                       this_call = true;
-                                       ig.Emit (OpCodes.Ldarg_0);
-                               } else {
-                                       Type itype = instance_expr.Type;
+                               if (!omit_args) {
+                                       Type t = null;
+                                       if (this_call) {
+                                               ig.Emit (OpCodes.Ldarg_0);
+                                               t = decl_type;
+                                       } else {
+                                               Type iexpr_type = instance_expr.Type;
 
-                                       //
-                                       // Push the instance expression
-                                       //
-                                       if (TypeManager.IsValueType (itype)){
                                                //
-                                               // Special case: calls to a function declared in a 
-                                               // reference-type with a value-type argument need
-                                               // to have their value boxed.  
-                                               if (decl_type.IsValueType || itype.IsGenericParameter){
-                                                       //
-                                                       // If the expression implements IMemoryLocation, then
-                                                       // we can optimize and use AddressOf on the
-                                                       // return.
+                                               // Push the instance expression
+                                               //
+                                               if (TypeManager.IsValueType (iexpr_type)) {
                                                        //
-                                                       // If not we have to use some temporary storage for
-                                                       // it.
-                                                       if (instance_expr is IMemoryLocation){
-                                                               ((IMemoryLocation)instance_expr).
-                                                                       AddressOf (ec, AddressOp.LoadStore);
-                                                       }
-                                                       else {
+                                                       // Special case: calls to a function declared in a 
+                                                       // reference-type with a value-type argument need
+                                                       // to have their value boxed.
+                                                       if (decl_type.IsValueType ||
+                                                           iexpr_type.IsGenericParameter) {
+                                                               //
+                                                               // If the expression implements IMemoryLocation, then
+                                                               // we can optimize and use AddressOf on the
+                                                               // return.
+                                                               //
+                                                               // If not we have to use some temporary storage for
+                                                               // it.
+                                                               if (instance_expr is IMemoryLocation) {
+                                                                       ((IMemoryLocation)instance_expr).
+                                                                               AddressOf (ec, AddressOp.LoadStore);
+                                                               } else {
+                                                                       LocalTemporary temp = new LocalTemporary (ec, iexpr_type);
+                                                                       instance_expr.Emit (ec);
+                                                                       temp.Store (ec);
+                                                                       temp.AddressOf (ec, AddressOp.Load);
+                                                               }
+
+                                                               // avoid the overhead of doing this all the time.
+                                                               if (dup_args)
+                                                                       t = TypeManager.GetReferenceType (iexpr_type);
+                                                       } else {
                                                                instance_expr.Emit (ec);
-                                                               LocalBuilder temp = ig.DeclareLocal (itype);
-                                                               ig.Emit (OpCodes.Stloc, temp);
-                                                               ig.Emit (OpCodes.Ldloca, temp);
+                                                               ig.Emit (OpCodes.Box, instance_expr.Type);
+                                                               t = TypeManager.object_type;
                                                        }
-                                                       if (itype.IsGenericParameter)
-                                                               ig.Emit (OpCodes.Constrained, itype);
-                                                       else
-                                                               struct_call = true;
                                                } else {
                                                        instance_expr.Emit (ec);
-                                                       ig.Emit (OpCodes.Box, itype);
-                                               } 
-                                       } 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 ((instance_expr != null) && (instance_expr.Type.IsGenericParameter))
+                               ig.Emit (OpCodes.Constrained, instance_expr.Type);
+
+                       OpCode call_op;
+                       if (is_static || struct_call || is_base || (this_call && !method.IsVirtual))
+                               call_op = OpCodes.Call;
+                       else
+                               call_op = OpCodes.Callvirt;
+
+                       if ((method.CallingConvention & CallingConventions.VarArgs) != 0) {
+                               Type[] varargs_types = GetVarargsTypes (ec, method, Arguments);
+                               ig.EmitCall (call_op, (MethodInfo) method, varargs_types);
+                               return;
+                       }
+
                        //
                        // If you have:
                        // this.DoFoo ();
                        // and DoFoo is not virtual, you can omit the callvirt,
                        // because you don't need the null checking behavior.
                        //
-                       if (is_static || struct_call || is_base || (this_call && !method.IsVirtual)){
-                               if (method is MethodInfo) {
-                                       ig.Emit (OpCodes.Call, (MethodInfo) method);
-                               } else
-                                       ig.Emit (OpCodes.Call, (ConstructorInfo) method);
-                       } else {
-                               if (method is MethodInfo)
-                                       ig.Emit (OpCodes.Callvirt, (MethodInfo) method);
-                               else
-                                       ig.Emit (OpCodes.Callvirt, (ConstructorInfo) method);
-                       }
+                       if (method is MethodInfo)
+                               ig.Emit (call_op, (MethodInfo) method);
+                       else
+                               ig.Emit (call_op, (ConstructorInfo) method);
                }
                
                public override void Emit (EmitContext ec)
@@ -5795,6 +5864,8 @@ namespace Mono.CSharp {
                        if (type == null)
                                return null;
                        
+                       CheckObsoleteAttribute (type);
+
                        bool IsDelegate = TypeManager.IsDelegateType (type);
                        
                        if (IsDelegate){
@@ -5831,7 +5902,7 @@ namespace Mono.CSharp {
                                return null;
                        }
                        
-                       bool is_struct = type.IsValueType;
+                       bool is_struct = type.IsValueType && !type.IsGenericInstance;
                        eclass = ExprClass.Value;
 
                        //
@@ -5840,9 +5911,10 @@ namespace Mono.CSharp {
                        //
                        if (is_struct && Arguments == null)
                                return this;
-                       
+
                        Expression ml;
-                       ml = MemberLookupFinal (ec, null, type, ".ctor",
+                       ml = MemberLookupFinal (ec, type, type, ".ctor",
+                                               // For member-lookup, treat 'new Foo (bar)' as call to 'foo.ctor (bar)', where 'foo' is of type 'Foo'.
                                                MemberTypes.Constructor,
                                                AllBindingFlags | BindingFlags.DeclaredOnly, loc);
 
@@ -5919,7 +5991,8 @@ namespace Mono.CSharp {
                //
                bool DoEmit (EmitContext ec, bool need_value_on_stack)
                {
-                       bool is_value_type = type.IsValueType;
+                       bool is_value_type = TypeManager.IsValueType (type) &&
+                               !type.IsGenericInstance;
                        ILGenerator ig = ec.ig;
 
                        if (is_value_type){
@@ -5936,7 +6009,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)
@@ -5992,7 +6065,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);
@@ -6013,7 +6086,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;
 
@@ -6577,7 +6650,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
@@ -6589,8 +6662,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);
@@ -6602,7 +6674,7 @@ namespace Mono.CSharp {
                //
                // This always expect the top value on the stack to be the array
                //
-               void EmitDynamicInitializers (EmitContext ec, bool is_expression)
+               void EmitDynamicInitializers (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
                        int dims = bounds.Count;
@@ -6649,8 +6721,7 @@ namespace Mono.CSharp {
                                            num_automatic_initializers <= max_automatic_initializers) {
                                                Type etype = e.Type;
                                                
-                                               if (is_expression || i != top - 1)
-                                                       ig.Emit (OpCodes.Dup);
+                                               ig.Emit (OpCodes.Dup);
 
                                                for (int idx = 0; idx < dims; idx++) 
                                                        IntConstant.EmitInt (ig, current_pos [idx]);
@@ -6678,12 +6749,20 @@ namespace Mono.CSharp {
 
                                                e.Emit (ec);
 
-                                                if (dims == 1)
-                                                        ArrayAccess.EmitStoreOpcode (ig, array_element_type);
-                                                else 
+                                               if (dims == 1) {
+                                                       bool is_stobj, has_type_arg;
+                                                       OpCode op = ArrayAccess.GetStoreOpcode (
+                                                               etype, out is_stobj,
+                                                               out has_type_arg);
+                                                       if (is_stobj)
+                                                               ig.Emit (OpCodes.Stobj, etype);
+                                                       else if (has_type_arg)
+                                                               ig.Emit (op, etype);
+                                                       else
+                                                               ig.Emit (op);
+                                               } else 
                                                         ig.Emit (OpCodes.Call, set);
-                                                
-                                        }
+                                       }
                                }
                                
                                //
@@ -6713,7 +6792,7 @@ namespace Mono.CSharp {
                        }
                }
                
-               void DoEmit (EmitContext ec, bool is_statement)
+               public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
                        
@@ -6737,23 +6816,13 @@ namespace Mono.CSharp {
                                // initialized. num_automatic_initializers will always be zero.  See
                                // CheckIndices.
                                        if (num_automatic_initializers > max_automatic_initializers)
-                                               EmitStaticInitializers (ec, dynamic_initializers || !is_statement);
+                                               EmitStaticInitializers (ec);
                                
                                if (dynamic_initializers)
-                                       EmitDynamicInitializers (ec, !is_statement);
+                                       EmitDynamicInitializers (ec);
                        }
                }
                
-               public override void Emit (EmitContext ec)
-               {
-                       DoEmit (ec, false);
-               }
-
-               public override void EmitStatement (EmitContext ec)
-               {
-                       DoEmit (ec, true);
-               }
-
                public object EncodeAsAttribute ()
                {
                        if (!is_one_dimensional){
@@ -6881,28 +6950,36 @@ namespace Mono.CSharp {
                        return this;
                }
 
-               public override void Emit (EmitContext ec)
+               public void Emit (EmitContext ec, bool leave_copy)
                {
-                       ILGenerator ig = ec.ig;
-
-                       ec.EmitThis ();
-                       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){
                                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)
                {
@@ -6919,6 +6996,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
        //
@@ -6968,6 +7124,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       CheckObsoleteAttribute (typearg);
+
                        type = TypeManager.type_type;
                        eclass = ExprClass.Type;
                        return this;
@@ -7034,6 +7192,11 @@ namespace Mono.CSharp {
                        }
 
                        type_queried = QueriedType.Type;
+                       if (type_queried == null)
+                               return null;
+
+                       CheckObsoleteAttribute (type_queried);
+
                        if (!TypeManager.IsUnmanagedType (type_queried)){
                                Report.Error (208, loc, "Cannot take the size of an unmanaged type (" + TypeManager.CSharpName (type_queried) + ")");
                                return null;
@@ -7083,7 +7246,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 " +
@@ -7091,21 +7254,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)
+                       SimpleName sn = left_original as SimpleName;
+                       if (sn == null || left == null || left.Type.Name != sn.Name)
                                return false;
 
-                       if (!(left_original is SimpleName))
-                               return false;
-
-                       SimpleName sn = (SimpleName) left_original;
-
-                       TypeExpr t = RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc);
-                       if (t != null)
-                               return true;
-
-                       return false;
+                       return RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc) != null;
                }
                
                public static Expression ResolveMemberAccess (EmitContext ec, Expression member_lookup,
@@ -7130,17 +7285,17 @@ namespace Mono.CSharp {
 
                        if (member_lookup is FieldExpr){
                                FieldExpr fe = (FieldExpr) member_lookup;
-                               FieldInfo fi = fe.FieldInfo;
+                               FieldInfo fi = fe.FieldInfo.Mono_GetGenericFieldDefinition ();
                                Type decl_type = fi.DeclaringType;
 
                                if (fi is FieldBuilder) {
                                        Const c = TypeManager.LookupConstant ((FieldBuilder) fi);
                                        
                                        if (c != null) {
-                                               object o = c.LookupConstantValue ();
-                                               if (o == null)
+                                               object o;
+                                               if (!c.LookupConstantValue (out o))
                                                        return null;
-                                               
+
                                                object real_value = ((Constant) c.Expr).GetValue ();
 
                                                return Constantify (real_value, fi.FieldType);
@@ -7159,7 +7314,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;
                                                }                                       
@@ -7213,6 +7368,7 @@ namespace Mono.CSharp {
                                                // accessors and private field etc so there's no need
                                                // to transform ourselves.
                                                //
+                                               ee.InstanceExpression = left;
                                                return ee;
                                        }
 
@@ -7226,21 +7382,23 @@ namespace Mono.CSharp {
                                        if (!left_is_explicit)
                                                left = null;
                                        
+                                       ee.InstanceExpression = left;
+
                                        return ResolveMemberAccess (ec, ml, left, loc, left_original);
                                }
                        }
 
                        if (member_lookup is IMemberExpr) {
                                IMemberExpr me = (IMemberExpr) member_lookup;
+                               MethodGroupExpr mg = me as MethodGroupExpr;
 
                                if (left_is_type){
-                                       MethodGroupExpr mg = me as MethodGroupExpr;
                                        if ((mg != null) && left_is_explicit && left.Type.IsInterface)
                                                mg.IsExplicitImpl = left_is_explicit;
 
                                        if (!me.IsStatic){
                                                if ((ec.IsFieldInitializer || ec.IsStatic) &&
-                                                   IdenticalNameAndTypeName (ec, left_original, loc))
+                                                   IdenticalNameAndTypeName (ec, left_original, member_lookup, loc))
                                                        return member_lookup;
 
                                                SimpleName.Error_ObjectRefRequired (ec, loc, me.Name);
@@ -7249,7 +7407,7 @@ namespace Mono.CSharp {
 
                                } else {
                                        if (!me.IsInstance){
-                                               if (IdenticalNameAndTypeName (ec, left_original, loc))
+                                               if (IdenticalNameAndTypeName (ec, left_original, left, loc))
                                                        return member_lookup;
 
                                                if (left_is_explicit) {
@@ -7279,6 +7437,9 @@ namespace Mono.CSharp {
                                                }
                                        }
 
+                                       if ((mg != null) && IdenticalNameAndTypeName (ec, left_original, left, loc))
+                                               mg.IdenticalTypeName = true;
+
                                        me.InstanceExpression = left;
                                }
 
@@ -7287,7 +7448,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;
                }
                
@@ -7305,7 +7466,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;
 
@@ -7331,8 +7492,7 @@ namespace Mono.CSharp {
                                expr_type = ((TypeExpr) expr).ResolveType (ec);
 
                                if (!ec.DeclSpace.CheckAccessLevel (expr_type)){
-                                       Error (122, "`" + expr_type + "' " +
-                                              "is inaccessible because of its protection level");
+                                       Report.Error_T (122, loc, expr_type);
                                        return null;
                                }
 
@@ -7343,9 +7503,23 @@ namespace Mono.CSharp {
                                                object value = en.LookupEnumValue (ec, Identifier, loc);
                                                
                                                if (value != null){
+                                                       ObsoleteAttribute oa = en.GetObsoleteAttribute (ec, Identifier);
+                                                       if (oa != null) {
+                                                               AttributeTester.Report_ObsoleteMessage (oa, en.GetSignatureForError (), Location);
+                                                       }
+
                                                        Constant c = Constantify (value, en.UnderlyingType);
                                                        return new EnumConstant (c, expr_type);
                                                }
+                                       } else {
+                                               CheckObsoleteAttribute (expr_type);
+
+                                               FieldInfo fi = expr_type.GetField (Identifier);
+                                               if (fi != null) {
+                                                       ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (fi);
+                                                       if (oa != null)
+                                                               AttributeTester.Report_ObsoleteMessage (oa, TypeManager.GetFullNameSignature (fi), Location);
+                                               }
                                        }
                                }
                        } else
@@ -7363,7 +7537,7 @@ namespace Mono.CSharp {
                        member_lookup = MemberLookup (
                                ec, expr_type, expr_type, Identifier, loc);
                        if ((member_lookup == null) && (args != null)) {
-                               string lookup_id = Identifier + "!" + args.Count;
+                               string lookup_id = MemberName.MakeName (Identifier, args);
                                member_lookup = MemberLookup (
                                        ec, expr_type, expr_type, lookup_id, loc);
                        }
@@ -7410,54 +7584,7 @@ namespace Mono.CSharp {
                                if (mg == null)
                                        throw new InternalErrorException ();
 
-                               if (args.Resolve (ec) == false)
-                                       return null;
-
-                               Type[] atypes = args.Arguments;
-
-                               int first_count = 0;
-                               MethodInfo first = null;
-
-                               ArrayList list = new ArrayList ();
-                               foreach (MethodBase mb in mg.Methods) {
-                                       MethodInfo mi = mb as MethodInfo;
-                                       if ((mi == null) || !mi.HasGenericParameters)
-                                               continue;
-
-                                       Type[] gen_params = mi.GetGenericArguments ();
-
-                                       if (first == null) {
-                                               first = mi;
-                                               first_count = gen_params.Length;
-                                       }
-
-                                       if (gen_params.Length != atypes.Length)
-                                               continue;
-
-                                       list.Add (mi.BindGenericParameters (atypes));
-                               }
-
-                               if (list.Count > 0) {
-                                       MethodGroupExpr new_mg = new MethodGroupExpr (
-                                               list, mg.Location);
-                                       new_mg.InstanceExpression = mg.InstanceExpression;
-                                       new_mg.HasTypeArguments = true;
-                                       return new_mg;
-                               }
-
-                               string name = expr_type + "." + Identifier;
-
-                               if (first != null)
-                                       Report.Error (
-                                               305, loc, "Using the generic method `{0}' " +
-                                               "requires {1} type arguments", name,
-                                               first_count);
-                               else
-                                       Report.Error (
-                                               308, loc, "The non-generic method `{0}' " +
-                                               "cannot be used with type arguments", name);
-
-                               return null;
+                               return mg.ResolveGeneric (ec, args);
                        }
 
                        // The following DoResolve/DoResolveLValue will do the definite assignment
@@ -7493,11 +7620,19 @@ namespace Mono.CSharp {
                                else
                                        fname = full_expr.Identifier;
 
+                               fname = MemberName.MakeName (fname, args);
+
                                if (full_expr.Expr is SimpleName) {
                                        string full_name = String.Concat (((SimpleName) full_expr.Expr).Name, ".", fname);
                                        Type fully_qualified = ec.DeclSpace.FindType (loc, full_name);
-                                       if (fully_qualified != null)
-                                               return new TypeExpression (fully_qualified, loc);
+                                       if (fully_qualified != null) {
+                                               if (args != null)
+                                                       return new ConstructedType (
+                                                               fully_qualified, args, loc);
+                                               else
+                                                       return new TypeExpression (
+                                                               fully_qualified, loc);
+                                       }
                                }
 
                                full_expr = full_expr.Expr as MemberAccess;
@@ -7517,6 +7652,8 @@ namespace Mono.CSharp {
                        }
 
                        Type expr_type = ((TypeExpr) new_expr).ResolveType (ec);
+                       if (expr_type == null)
+                               return null;
 
                        if (expr_type.IsPointer){
                                Error (23, "The `.' operator can not be applied to pointer operands (" +
@@ -7526,10 +7663,7 @@ namespace Mono.CSharp {
 
                        Expression member_lookup;
                        string lookup_id;
-                       if (args != null)
-                               lookup_id = Identifier + "!" + args.Count;
-                       else
-                               lookup_id = Identifier;
+                       lookup_id = MemberName.MakeName (Identifier, args);
                        member_lookup = MemberLookupFinal (
                                ec, expr_type, expr_type, lookup_id, loc);
                        if (member_lookup == null)
@@ -7571,10 +7705,7 @@ namespace Mono.CSharp {
 
                public override string ToString ()
                {
-                       if (args != null)
-                               return expr + "." + Identifier + "!" + args.Count;
-                       else
-                               return expr + "." + Identifier;
+                       return expr + "." + MemberName.MakeName (Identifier, args);
                }
        }
 
@@ -7792,7 +7923,8 @@ namespace Mono.CSharp {
                //
                ElementAccess ea;
 
-               LocalTemporary [] cached_locations;
+               LocalTemporary temp;
+               bool prepared;
                
                public ArrayAccess (ElementAccess ea_data, Location l)
                {
@@ -7893,20 +8025,6 @@ namespace Mono.CSharp {
                                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, has_type_arg;
-                       OpCode op = GetStoreOpcode (t, out is_stobj, out has_type_arg);
-                       if (has_type_arg)
-                               ig.Emit (op, t);
-                       else
-                               ig.Emit (op);
-               }
-
                /// <summary>
                ///    Returns the right opcode to store an object of Type `t'
                ///    from an array of T.  
@@ -7916,7 +8034,7 @@ namespace Mono.CSharp {
                        //Console.WriteLine (new System.Diagnostics.StackTrace ());
                        has_type_arg = false; 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)
@@ -8003,101 +8121,114 @@ 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 {
+                       if (rank == 1) {
+                               bool is_stobj, has_type_arg;
+                               OpCode op = GetStoreOpcode (t, out is_stobj, out has_type_arg);
+
+                               //
+                               // 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 if (has_type_arg)
+                                       ig.Emit (op, 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;
@@ -8113,6 +8244,9 @@ namespace Mono.CSharp {
                                
                                ig.Emit (OpCodes.Call, set);
                        }
+                       
+                       if (temp != null)
+                               temp.Emit (ec);
                }
 
                public void AddressOf (EmitContext ec, AddressOp mode)
@@ -8176,7 +8310,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;
@@ -8208,10 +8342,9 @@ namespace Mono.CSharp {
                        if (!lookup_type.IsInterface)
                                return ix;
 
-                       TypeExpr [] ifaces = TypeManager.GetInterfaces (lookup_type);
+                       Type [] ifaces = TypeManager.GetInterfaces (lookup_type);
                        if (ifaces != null) {
-                               foreach (TypeExpr iface in ifaces) {
-                                       Type itype = iface.Type;
+                               foreach (Type itype in ifaces) {
                                        MemberInfo [] mi = GetIndexersForTypeOrInterface (caller_type, itype);
                                        if (mi != null){
                                                if (ix == null)
@@ -8405,19 +8538,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);
                }
        }
 
@@ -8475,6 +8642,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,
@@ -8641,6 +8813,12 @@ namespace Mono.CSharp {
                        if (ltype == null)
                                return null;
 
+                       if ((ltype == TypeManager.void_type) && (dim != "*")) {
+                               Report.Error (1547, Location,
+                                             "Keyword 'void' cannot be used in this context");
+                               return null;
+                       }
+
                        int pos = 0;
                        while ((pos < dim.Length) && (dim [pos] == '[')) {
                                pos++;
@@ -8813,6 +8991,14 @@ namespace Mono.CSharp {
                                        return null;
                        }
 
+                       Constant c = count as Constant;
+                       // TODO: because we don't have property IsNegative
+                       if (c != null && c.ConvertToUInt () == null) {
+                                // "Cannot use a negative size with stackalloc"
+                               Report.Error_T (247, loc);
+                               return null;
+                       }
+
                        if (ec.CurrentBranching.InCatch () ||
                            ec.CurrentBranching.InFinally (true)) {
                                Error (255,