2009-11-05 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / dynamic.cs
1 //
2 // dynamic.cs: support for dynamic expressions
3 //
4 // Authors: Marek Safar (marek.safar@gmail.com)
5 //
6 // Dual licensed under the terms of the MIT X11 or GNU GPL
7 //
8 // Copyright 2009 Novell, Inc
9 //
10
11 using System;
12 using System.Collections;
13 using System.Reflection.Emit;
14
15 #if NET_4_0
16 using System.Dynamic;
17 using SLE = System.Linq.Expressions;
18 #endif
19
20 namespace Mono.CSharp
21 {
22         //
23         // A copy of Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinderFlags.cs
24         // has to be kept in sync
25         //
26         [Flags]
27         public enum CSharpBinderFlags
28         {
29                 None = 0,
30                 CheckedContext = 1,
31                 InvokeSimpleName = 1 << 1,
32                 InvokeSpecialName = 1 << 2,
33                 BinaryOperationLogical = 1 << 3,
34                 ConvertExplicit = 1 << 4,
35                 ConvertArrayIndex = 1 << 5,
36                 ResultIndexed = 1 << 6,
37                 ValueFromCompoundAssignment = 1 << 7,
38                 ResultDiscarded = 1 << 8
39         }
40
41         //
42         // Type expression with internal dynamic type symbol
43         //
44         class DynamicTypeExpr : TypeExpr
45         {
46                 public DynamicTypeExpr (Location loc)
47                 {
48                         this.loc = loc;
49
50                         type = InternalType.Dynamic;
51                         eclass = ExprClass.Type;
52                 }
53
54                 public override bool CheckAccessLevel (IMemberContext ds)
55                 {
56                         return true;
57                 }
58
59                 protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec)
60                 {
61                         return this;
62                 }
63         }
64
65         //
66         // Expression created from runtime dynamic object value
67         //
68         public class RuntimeValueExpression : Expression, IDynamicAssign, IMemoryLocation
69         {
70 #if !NET_4_0
71                 public class DynamicMetaObject { public Type RuntimeType; }
72 #endif
73
74                 readonly DynamicMetaObject obj;
75
76                 public RuntimeValueExpression (DynamicMetaObject obj)
77                 {
78                         this.obj = obj;
79                         this.type = obj.RuntimeType;
80                         this.eclass = ExprClass.Variable;
81                 }
82
83                 public void AddressOf (EmitContext ec, AddressOp mode)
84                 {
85                         throw new NotImplementedException ();
86                 }
87
88                 public override Expression CreateExpressionTree (ResolveContext ec)
89                 {
90                         throw new NotImplementedException ();
91                 }
92
93                 public override Expression DoResolve (ResolveContext ec)
94                 {
95                         return this;
96                 }
97
98                 public override Expression DoResolveLValue (ResolveContext ec, Expression right_side)
99                 {
100                         return this;
101                 }
102
103                 public override void Emit (EmitContext ec)
104                 {
105                         throw new NotImplementedException ();
106                 }
107
108                 #region IAssignMethod Members
109
110                 public void Emit (EmitContext ec, bool leave_copy)
111                 {
112                         throw new NotImplementedException ();
113                 }
114
115                 public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
116                 {
117                         throw new NotImplementedException ();
118                 }
119
120                 #endregion
121
122 #if NET_4_0
123                 public SLE.Expression MakeAssignExpression (BuilderContext ctx)
124                 {
125                         return obj.Expression;
126                 }
127
128                 public override SLE.Expression MakeExpression (BuilderContext ctx)
129                 {
130                         return SLE.Expression.Convert (obj.Expression, type);
131                 }
132 #endif
133
134                 public DynamicMetaObject MetaObject {
135                         get { return obj; }
136                 }
137         }
138
139         //
140         // Creates dynamic binder expression
141         //
142         interface IDynamicBinder
143         {
144                 Expression CreateCallSiteBinder (ResolveContext ec, Arguments args);
145         }
146
147         //
148         // Extends standard assignment interface for expressions
149         // supported by dynamic resolver
150         //
151         interface IDynamicAssign : IAssignMethod
152         {
153 #if NET_4_0
154                 SLE.Expression MakeAssignExpression (BuilderContext ctx);
155 #endif
156         }
157
158         //
159         // Base dynamic expression statement creator
160         //
161         class DynamicExpressionStatement : ExpressionStatement
162         {
163                 class StaticDataClass : CompilerGeneratedClass
164                 {
165                         public StaticDataClass ()
166                                 : base (new RootDeclSpace (new NamespaceEntry (null, null, null)),
167                                         new MemberName (CompilerGeneratedClass.MakeName (null, "c", "DynamicSites", 0)),
168                                         Modifiers.INTERNAL | Modifiers.STATIC)
169                         {
170                                 ModFlags &= ~Modifiers.SEALED;
171                         }
172                 }
173
174                 //
175                 // Binder flag dynamic constant, the value is combination of
176                 // flags known at resolve stage and flags known only at emit
177                 // stage
178                 //
179                 protected class BinderFlags : EnumConstant
180                 {
181                         DynamicExpressionStatement statement;
182                         CSharpBinderFlags flags;
183
184                         public BinderFlags (CSharpBinderFlags flags, DynamicExpressionStatement statement)
185                                 : base ()
186                         {
187                                 this.flags = flags;
188                                 this.statement = statement;
189                         }
190
191                         public override Expression DoResolve (ResolveContext ec)
192                         {
193                                 Child = new IntConstant ((int) (flags | statement.flags), statement.loc);
194
195                                 type = TypeManager.binder_flags;
196                                 eclass = Child.eclass;
197                                 return this;
198                         }
199                 }
200
201                 static StaticDataClass global_site_container;
202                 static int field_counter;
203                 static int container_counter;
204
205                 readonly Arguments arguments;
206                 protected IDynamicBinder binder;
207                 protected Expression binder_expr;
208
209                 // Used by BinderFlags
210                 protected CSharpBinderFlags flags;
211
212                 public DynamicExpressionStatement (IDynamicBinder binder, Arguments args, Location loc)
213                 {
214                         this.binder = binder;
215                         this.arguments = args;
216                         this.loc = loc;
217                 }
218
219                 public Arguments Arguments {
220                         get {
221                                 return arguments;
222                         }
223                 }
224
225                 static TypeContainer CreateSiteContainer ()
226                 {
227                         if (global_site_container == null) {
228                                 global_site_container = new StaticDataClass ();
229                                 RootContext.ToplevelTypes.AddCompilerGeneratedClass (global_site_container);
230                                 global_site_container.DefineType ();
231                                 global_site_container.Define ();
232 //                              global_site_container.EmitType ();
233
234                                 RootContext.RegisterCompilerGeneratedType (global_site_container.TypeBuilder);
235                         }
236
237                         return global_site_container;
238                 }
239
240                 static Field CreateSiteField (FullNamedExpression type)
241                 {
242                         TypeContainer site_container = CreateSiteContainer ();
243                         Field f = new Field (site_container, type, Modifiers.PUBLIC | Modifiers.STATIC,
244                                 new MemberName ("Site" +  field_counter++), null);
245                         f.Define ();
246
247                         site_container.AddField (f);
248                         return f;
249                 }
250
251                 public override Expression CreateExpressionTree (ResolveContext ec)
252                 {
253                         ec.Report.Error (1963, loc, "An expression tree cannot contain a dynamic operation");
254                         return null;
255                 }
256
257                 public override Expression DoResolve (ResolveContext ec)
258                 {
259                         if (eclass != ExprClass.Invalid)
260                                 return this;
261
262                         if (DoResolveCore (ec))
263                                 binder_expr = binder.CreateCallSiteBinder (ec, arguments);
264
265                         return this;
266                 }
267
268                 protected bool DoResolveCore (ResolveContext rc)
269                 {
270                         int errors = rc.Report.Errors;
271
272                         if (TypeManager.call_site_type == null)
273                                 TypeManager.call_site_type = TypeManager.CoreLookupType (rc.Compiler,
274                                         "System.Runtime.CompilerServices", "CallSite", Kind.Class, true);
275
276                         if (TypeManager.generic_call_site_type == null)
277                                 TypeManager.generic_call_site_type = TypeManager.CoreLookupType (rc.Compiler,
278                                         "System.Runtime.CompilerServices", "CallSite`1", Kind.Class, true);
279
280                         if (TypeManager.binder_type == null) {
281                                 var t = TypeManager.CoreLookupType (rc.Compiler,
282                                         "Microsoft.CSharp.RuntimeBinder", "Binder", Kind.Class, true);
283                                 if (t != null)
284                                         TypeManager.binder_type = new TypeExpression (t, Location.Null);
285                         }
286
287                         if (TypeManager.binder_flags == null) {
288                                 TypeManager.binder_flags = TypeManager.CoreLookupType (rc.Compiler,
289                                         "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags", Kind.Enum, true);
290                         }
291
292                         eclass = ExprClass.Value;
293
294                         if (type == null)
295                                 type = InternalType.Dynamic;
296
297                         return rc.Report.Errors == errors;
298                 }
299
300                 public override void Emit (EmitContext ec)
301                 {
302                         EmitCall (ec, binder_expr, arguments,  false);
303                 }
304
305                 public override void EmitStatement (EmitContext ec)
306                 {
307                         EmitCall (ec, binder_expr, arguments, true);
308                 }
309
310                 protected void EmitCall (EmitContext ec, Expression binder, Arguments arguments, bool isStatement)
311                 {
312                         int dyn_args_count = arguments == null ? 0 : arguments.Count;
313                         TypeExpr site_type = CreateSiteType (RootContext.ToplevelTypes.Compiler, arguments, dyn_args_count, isStatement);
314                         FieldExpr site_field_expr = new FieldExpr (CreateSiteField (site_type).FieldBuilder, loc);
315
316                         SymbolWriter.OpenCompilerGeneratedBlock (ec.ig);
317
318                         Arguments args = new Arguments (1);
319                         args.Add (new Argument (binder));
320                         StatementExpression s = new StatementExpression (new SimpleAssign (site_field_expr, new Invocation (new MemberAccess (site_type, "Create"), args)));
321                         
322                         BlockContext bc = new BlockContext (ec.MemberContext, null, TypeManager.void_type);             
323                         if (s.Resolve (bc)) {
324                                 Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc);
325                                 init.Emit (ec);
326                         }
327
328                         args = new Arguments (1 + dyn_args_count);
329                         args.Add (new Argument (site_field_expr));
330                         if (arguments != null) {
331                                 foreach (Argument a in arguments) {
332                                         if (a is NamedArgument) {
333                                                 // Name is not valid in this context
334                                                 args.Add (new Argument (a.Expr, a.ArgType));
335                                                 continue;
336                                         }
337
338                                         args.Add (a);
339                                 }
340                         }
341
342                         Expression target = new DelegateInvocation (new MemberAccess (site_field_expr, "Target", loc).Resolve (bc), args, loc).Resolve (bc);
343                         if (target != null)
344                                 target.Emit (ec);
345
346                         SymbolWriter.CloseCompilerGeneratedBlock (ec.ig);
347                 }
348
349                 public static MemberAccess GetBinderNamespace (Location loc)
350                 {
351                         return new MemberAccess (new MemberAccess (
352                                 new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "Microsoft", loc), "CSharp", loc), "RuntimeBinder", loc);
353                 }
354
355                 public static MemberAccess GetBinder (string name, Location loc)
356                 {
357                         return new MemberAccess (TypeManager.binder_type, name, loc);
358                 }
359
360                 TypeExpr CreateSiteType (CompilerContext ctx, Arguments arguments, int dyn_args_count, bool is_statement)
361                 {
362                         int default_args = is_statement ? 1 : 2;
363
364                         bool has_ref_out_argument = false;
365                         FullNamedExpression[] targs = new FullNamedExpression[dyn_args_count + default_args];
366                         targs [0] = new TypeExpression (TypeManager.call_site_type, loc);
367                         for (int i = 0; i < dyn_args_count; ++i) {
368                                 Type arg_type;
369                                 Argument a = arguments [i];
370                                 if (a.Type == TypeManager.null_type)
371                                         arg_type = TypeManager.object_type;
372                                 else
373                                         arg_type = TypeManager.TypeToReflectionType (a.Type);
374
375                                 if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
376                                         has_ref_out_argument = true;
377
378                                 targs [i + 1] = new TypeExpression (arg_type, loc);
379                         }
380
381                         TypeExpr del_type = null;
382                         if (!has_ref_out_argument) {
383                                 string d_name = is_statement ? "Action`" : "Func`";
384
385                                 Type t = TypeManager.CoreLookupType (ctx, "System", d_name + (dyn_args_count + default_args), Kind.Delegate, false);
386                                 if (t != null) {
387                                         if (!is_statement)
388                                                 targs [targs.Length - 1] = new TypeExpression (TypeManager.TypeToReflectionType (type), loc);
389
390                                         del_type = new GenericTypeExpr (t, new TypeArguments (targs), loc);
391                                 }
392                         }
393
394                         //
395                         // Create custom delegate when no appropriate predefined one is found
396                         //
397                         if (del_type == null) {
398                                 Type rt = is_statement ? TypeManager.void_type : type;
399                                 Parameter[] p = new Parameter [dyn_args_count + 1];
400                                 p[0] = new Parameter (targs [0], "p0", Parameter.Modifier.NONE, null, loc);
401
402                                 for (int i = 1; i < dyn_args_count + 1; ++i)
403                                         p[i] = new Parameter (targs[i], "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);
404
405                                 TypeContainer parent = CreateSiteContainer ();
406                                 Delegate d = new Delegate (parent.NamespaceEntry, parent, new TypeExpression (TypeManager.TypeToReflectionType (rt), loc),
407                                         Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
408                                         new MemberName ("Container" + container_counter++.ToString ("X")),
409                                         new ParametersCompiled (p), null);
410
411                                 d.DefineType ();
412                                 d.Define ();
413
414                                 parent.AddDelegate (d);
415                                 del_type = new TypeExpression (d.TypeBuilder, loc);
416                         }
417
418                         TypeExpr site_type = new GenericTypeExpr (TypeManager.generic_call_site_type, new TypeArguments (del_type), loc);
419                         return site_type;
420                 }
421
422                 public static void Reset ()
423                 {
424                         global_site_container = null;
425                         field_counter = container_counter = 0;
426                 }
427         }
428
429         //
430         // Dynamic member access compound assignment for events
431         //
432         class DynamicEventCompoundAssign : DynamicExpressionStatement, IDynamicBinder
433         {
434                 string name;
435                 Statement condition;
436
437                 public DynamicEventCompoundAssign (string name, Arguments args, ExpressionStatement assignment, ExpressionStatement invoke, Location loc)
438                         : base (null, args, loc)
439                 {
440                         this.name = name;
441                         base.binder = this;
442
443                         // Used by += or -= only
444                         type = TypeManager.bool_type;
445
446                         condition = new If (
447                                 new Binary (Binary.Operator.Equality, this, new BoolLiteral (true, loc)),
448                                 new StatementExpression (invoke), new StatementExpression (assignment),
449                                 loc);
450                 }
451
452                 public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
453                 {
454                         Arguments binder_args = new Arguments (3);
455
456                         binder_args.Add (new Argument (new BinderFlags (0, this)));
457                         binder_args.Add (new Argument (new StringLiteral (name, loc)));
458                         binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
459
460                         return new Invocation (GetBinder ("IsEvent", loc), binder_args);
461                 }
462
463                 public override void EmitStatement (EmitContext ec)
464                 {
465                         condition.Emit (ec);
466                 }
467         }
468
469         class DynamicConversion : DynamicExpressionStatement, IDynamicBinder
470         {
471                 public DynamicConversion (Type targetType, CSharpBinderFlags flags, Arguments args, Location loc)
472                         : base (null, args, loc)
473                 {
474                         type = targetType;
475                         base.flags = flags;
476                         base.binder = this;
477                 }
478
479                 public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
480                 {
481                         Arguments binder_args = new Arguments (2);
482
483                         flags |= ec.HasSet (ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0;
484
485                         binder_args.Add (new Argument (new BinderFlags (flags, this)));
486                         binder_args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
487                         return new Invocation (GetBinder ("Convert", loc), binder_args);
488                 }
489         }
490
491         class DynamicConstructorBinder : DynamicExpressionStatement, IDynamicBinder
492         {
493                 public DynamicConstructorBinder (Type type, Arguments args, Location loc)
494                         : base (null, args, loc)
495                 {
496                         this.type = type;
497                         base.binder = this;
498                 }
499
500                 public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
501                 {
502                         Arguments binder_args = new Arguments (3);
503
504                         binder_args.Add (new Argument (new BinderFlags (0, this)));
505                         binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
506                         binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc)));
507
508                         return new Invocation (GetBinder ("InvokeConstructor", loc), binder_args);
509                 }
510         }
511
512         class DynamicIndexBinder : DynamicMemberAssignable
513         {
514                 public DynamicIndexBinder (Arguments args, Location loc)
515                         : base (args, loc)
516                 {
517                 }
518
519                 protected override Expression CreateCallSiteBinder (ResolveContext ec, Arguments args, bool isSet)
520                 {
521                         Arguments binder_args = new Arguments (3);
522
523                         binder_args.Add (new Argument (new BinderFlags (0, this)));
524                         binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
525                         binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc)));
526
527                         return new Invocation (GetBinder (isSet ? "SetIndex" : "GetIndex", loc), binder_args);
528                 }
529         }
530
531         class DynamicInvocation : DynamicExpressionStatement, IDynamicBinder
532         {
533                 ATypeNameExpression member;
534
535                 public DynamicInvocation (ATypeNameExpression member, Arguments args, Location loc)
536                         : base (null, args, loc)
537                 {
538                         base.binder = this;
539                         this.member = member;
540                 }
541
542                 public DynamicInvocation (ATypeNameExpression member, Arguments args, Type type, Location loc)
543                         : this (member, args, loc)
544                 {
545                         // When a return type is known not to be dynamic
546                         this.type = type;
547                 }
548
549                 public static DynamicInvocation CreateSpecialNameInvoke (ATypeNameExpression member, Arguments args, Location loc)
550                 {
551                         return new DynamicInvocation (member, args, loc) {
552                                 flags = CSharpBinderFlags.InvokeSpecialName
553                         };
554                 }
555
556                 public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
557                 {
558                         Arguments binder_args = new Arguments (member != null ? 5 : 3);
559                         bool is_member_access = member is MemberAccess;
560
561                         CSharpBinderFlags call_flags;
562                         if (!is_member_access && member is SimpleName) {
563                                 call_flags = CSharpBinderFlags.InvokeSimpleName;
564                                 is_member_access = true;
565                         } else {
566                                 call_flags = 0;
567                         }
568
569                         binder_args.Add (new Argument (new BinderFlags (call_flags, this)));
570
571                         if (is_member_access)
572                                 binder_args.Add (new Argument (new StringLiteral (member.Name, member.Location)));
573
574                         if (member != null && member.HasTypeArguments) {
575                                 TypeArguments ta = member.TypeArguments;
576                                 if (ta.Resolve (ec)) {
577                                         ArrayList targs = new ArrayList (ta.Count);
578                                         foreach (Type t in ta.Arguments)
579                                                 targs.Add (new TypeOf (new TypeExpression (t, loc), loc));
580
581                                         binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", targs, loc)));
582                                 }
583                         } else if (is_member_access) {
584                                 binder_args.Add (new Argument (new NullLiteral (loc)));
585                         }
586
587                         binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
588
589                         Expression real_args;
590                         if (args == null) {
591                                 // Cannot be null because .NET trips over
592                                 real_args = new ArrayCreation (new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), "[]", new ArrayList (0), loc);
593                         } else {
594                                 real_args = new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc);
595                         }
596
597                         binder_args.Add (new Argument (real_args));
598
599                         return new Invocation (GetBinder (is_member_access ? "InvokeMember" : "Invoke", loc), binder_args);
600                 }
601
602                 public override void EmitStatement (EmitContext ec)
603                 {
604                         flags |= CSharpBinderFlags.ResultDiscarded;
605                         base.EmitStatement (ec);
606                 }
607         }
608
609         class DynamicMemberBinder : DynamicMemberAssignable
610         {
611                 readonly string name;
612
613                 public DynamicMemberBinder (string name, Arguments args, Location loc)
614                         : base (args, loc)
615                 {
616                         this.name = name;
617                 }
618
619                 protected override Expression CreateCallSiteBinder (ResolveContext ec, Arguments args, bool isSet)
620                 {
621                         Arguments binder_args = new Arguments (4);
622
623                         binder_args.Add (new Argument (new BinderFlags (0, this)));
624                         binder_args.Add (new Argument (new StringLiteral (name, loc)));
625                         binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc)));
626                         binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc)));
627
628                         return new Invocation (GetBinder (isSet ? "SetMember" : "GetMember", loc), binder_args);
629                 }
630         }
631
632         //
633         // Any member binder which can be source and target of assignment
634         //
635         abstract class DynamicMemberAssignable : DynamicExpressionStatement, IDynamicBinder, IAssignMethod
636         {
637                 Expression setter;
638                 Arguments setter_args;
639
640                 protected DynamicMemberAssignable (Arguments args, Location loc)
641                         : base (null, args, loc)
642                 {
643                         base.binder = this;
644                 }
645
646                 public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
647                 {
648                         //
649                         // DoResolve always uses getter
650                         //
651                         return CreateCallSiteBinder (ec, args, false);
652                 }
653
654                 protected abstract Expression CreateCallSiteBinder (ResolveContext ec, Arguments args, bool isSet);
655
656                 public override Expression DoResolveLValue (ResolveContext rc, Expression right_side)
657                 {
658                         if (right_side == EmptyExpression.OutAccess.Instance) {
659                                 right_side.DoResolveLValue (rc, this);
660                                 return null;
661                         }
662
663                         if (DoResolveCore (rc)) {
664                                 setter_args = new Arguments (Arguments.Count + 1);
665                                 setter_args.AddRange (Arguments);
666                                 setter_args.Add (new Argument (right_side));
667                                 setter = CreateCallSiteBinder (rc, setter_args, true);
668                         }
669
670                         eclass = ExprClass.Variable;
671                         return this;
672                 }
673
674                 public override void Emit (EmitContext ec)
675                 {
676                         // It's null for ResolveLValue used without assignment
677                         if (binder_expr == null)
678                                 EmitCall (ec, setter, Arguments, false);
679                         else
680                                 base.Emit (ec);
681                 }
682
683                 public override void EmitStatement (EmitContext ec)
684                 {
685                         // It's null for ResolveLValue used without assignment
686                         if (binder_expr == null)
687                                 EmitCall (ec, setter, Arguments, true);
688                         else
689                                 base.EmitStatement (ec);
690                 }
691
692                 #region IAssignMethod Members
693
694                 public void Emit (EmitContext ec, bool leave_copy)
695                 {
696                         throw new NotImplementedException ();
697                 }
698
699                 public void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load)
700                 {
701                         EmitCall (ec, setter, setter_args, !leave_copy);
702                 }
703
704                 #endregion
705         }
706
707         class DynamicUnaryConversion : DynamicExpressionStatement, IDynamicBinder
708         {
709                 string name;
710
711                 public DynamicUnaryConversion (string name, Arguments args, Location loc)
712                         : base (null, args, loc)
713                 {
714                         this.name = name;
715                         base.binder = this;
716                         if (name == "IsTrue" || name == "IsFalse")
717                                 type = TypeManager.bool_type;
718                 }
719
720                 public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
721                 {
722                         Arguments binder_args = new Arguments (3);
723
724                         MemberAccess sle = new MemberAccess (new MemberAccess (
725                                 new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc);
726
727                         var flags = ec.HasSet (ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0;
728
729                         binder_args.Add (new Argument (new BinderFlags (flags, this)));
730                         binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), name, loc)));
731                         binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc)));
732
733                         return new Invocation (GetBinder ("UnaryOperation", loc), binder_args);
734                 }
735         }
736 }