2 // assign.cs: Assignment representation for the IL tree.
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2001 Ximian, Inc.
10 using System.Reflection;
11 using System.Reflection.Emit;
14 public class Assign : ExpressionStatement {
15 Expression target, source;
18 public Assign (Expression target, Expression source, Location l)
25 public Expression Target {
35 public Expression Source {
45 public override Expression Resolve (TypeContainer tc)
47 target = target.Resolve (tc);
48 source = source.Resolve (tc);
50 if (target == null || source == null)
53 Type target_type = target.Type;
55 Type source_type = source.Type;
57 if (target_type != source_type){
58 source = ConvertImplicitRequired (tc, source, target_type, l);
63 if (!(target is LValue)){
64 tc.RootContext.Report.Error (131, "Left hand of an assignment must be a variable, a property or an indexer");
70 void Emit (EmitContext ec, bool is_statement)
72 ILGenerator ig = ec.ig;
74 if (target.ExprClass == ExprClass.Variable){
77 // If it is an instance field, load the this pointer
79 if (target is FieldExpr){
80 FieldExpr fe = (FieldExpr) target;
82 if (!fe.FieldInfo.IsStatic)
83 ig.Emit (OpCodes.Ldarg_0);
89 ig.Emit (OpCodes.Dup);
91 ((LValue) target).Store (ec);
92 } else if (target.ExprClass == ExprClass.PropertyAccess){
94 throw new Exception ("Can not assign to properties yet");
95 } else if (target.ExprClass == ExprClass.IndexerAccess){
97 throw new Exception ("Can not assign to indexers yet");
101 public override void Emit (EmitContext ec)
106 public override void EmitStatement (EmitContext ec)