[msbuild] Getting build error "Error initializing task XmlPeek: Not registered task...
[mono.git] / mcs / class / Microsoft.CSharp / Microsoft.CSharp.RuntimeBinder / CSharpSetIndexBinder.cs
index 37bc449701af804ac65bba570e6b49a5f8301223..ad2f51a1dbf85f2c62ffa6d9149fbf00a133694d 100644 (file)
@@ -34,45 +34,20 @@ using Compiler = Mono.CSharp;
 
 namespace Microsoft.CSharp.RuntimeBinder
 {
-       public class CSharpSetIndexBinder : SetIndexBinder
+       class CSharpSetIndexBinder : SetIndexBinder
        {
+               readonly CSharpBinderFlags flags;
                IList<CSharpArgumentInfo> argumentInfo;
                Type callingContext;
-               
-               public CSharpSetIndexBinder (Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
+
+               public CSharpSetIndexBinder (CSharpBinderFlags flags, Type callingContext, IEnumerable<CSharpArgumentInfo> argumentInfo)
                        : base (CSharpArgumentInfo.CreateCallInfo (argumentInfo, 2))
                {
+                       this.flags = flags;
                        this.callingContext = callingContext;
                        this.argumentInfo = argumentInfo.ToReadOnly ();
                }
                
-               public IList<CSharpArgumentInfo> ArgumentInfo {
-                       get {
-                               return argumentInfo;
-                       }
-               }
-
-               public Type CallingContext {
-                       get {
-                               return callingContext;
-                       }
-               }
-               
-               public override bool Equals (object obj)
-               {
-                       var other = obj as CSharpSetIndexBinder;
-                       return other != null && other.callingContext == callingContext && 
-                               other.argumentInfo.SequenceEqual (argumentInfo);
-               }
-
-               public override int GetHashCode ()
-               {
-                       return Extensions.HashCode (
-                               callingContext.GetHashCode (),
-                               argumentInfo.GetHashCode (),
-                               GetType ().GetHashCode ());
-               }
-               
                public override DynamicMetaObject FallbackSetIndex (DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
                {
                        if (argumentInfo.Count != indexes.Length + 2) {
@@ -82,19 +57,30 @@ namespace Microsoft.CSharp.RuntimeBinder
                                return errorSuggestion;
                        }
 
-                       var expr = CSharpBinder.CreateCompilerExpression (argumentInfo [0], target);
-                       var args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (2), indexes);
-                       expr = new Compiler.ElementAccess (expr, args);
+                       var ctx = DynamicContext.Create ();
+                       var expr = ctx.CreateCompilerExpression (argumentInfo [0], target);
+                       var args = ctx.CreateCompilerArguments (argumentInfo.Skip (1), indexes);
+                       expr = new Compiler.ElementAccess (expr, args, Compiler.Location.Null);
+
+                       var source = ctx.CreateCompilerExpression (argumentInfo [indexes.Length + 1], value);
+
+                       // Same conversion as in SetMemberBinder
+                       if ((flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0) {
+                               expr = new Compiler.RuntimeExplicitAssign (expr, source);
+                       } else {
+                               expr = new Compiler.SimpleAssign (expr, source);
+                       }
+                       expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
 
-                       var source = CSharpBinder.CreateCompilerExpression (argumentInfo[1], value);
-                       expr = new Compiler.SimpleAssign (expr, source);
-                       expr = new Compiler.Cast (new Compiler.TypeExpression (typeof (object), Compiler.Location.Null), expr); // TODO: ReturnType replace
+                       if ((flags & CSharpBinderFlags.CheckedContext) != 0)
+                               expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null);
 
-                       var restrictions = CSharpBinder.CreateRestrictionsOnTarget (target).Merge (
-                               CSharpBinder.CreateRestrictionsOnTarget (value)).Merge (
-                               CSharpBinder.CreateRestrictionsOnTarget (indexes));
+                       var binder = new CSharpBinder (this, expr, errorSuggestion);
+                       binder.AddRestrictions (target);
+                       binder.AddRestrictions (value);
+                       binder.AddRestrictions (indexes);
 
-                       return CSharpBinder.Bind (target, expr, callingContext, restrictions, errorSuggestion);
+                       return binder.Bind (ctx, callingContext);
                }
        }
 }