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 DoResolve (EmitContext ec)
47 target = target.Resolve (ec);
48 source = source.Resolve (ec);
50 if (target == null || source == null)
53 Type target_type = target.Type;
54 Type source_type = source.Type;
57 eclass = ExprClass.Value;
60 // If we are doing a property assignment, then
61 // set the `value' field on the property, and Resolve
64 if (target is PropertyExpr){
65 PropertyExpr property_assign = (PropertyExpr) target;
67 if (!property_assign.VerifyAssignable ())
73 if (source is New && target_type.IsSubclassOf (TypeManager.value_type)){
76 n.ValueTypeVariable = target;
81 if (target_type != source_type){
82 source = ConvertImplicitRequired (ec, source, target_type, l);
87 if (!(target is LValue)){
88 Report.Error (131, l, "Left hand of an assignment must be a variable, a property or an indexer");
95 void Emit (EmitContext ec, bool is_statement)
97 ILGenerator ig = ec.ig;
98 ExprClass eclass = target.ExprClass;
100 if (eclass == ExprClass.Variable){
103 // If it is an instance field, load the this pointer
105 if (target is FieldExpr){
106 FieldExpr fe = (FieldExpr) target;
108 if (!fe.FieldInfo.IsStatic)
109 ig.Emit (OpCodes.Ldarg_0);
115 ig.Emit (OpCodes.Dup);
117 ((LValue) target).Store (ec);
118 } else if (eclass == ExprClass.PropertyAccess){
119 PropertyExpr pe = (PropertyExpr) target;
125 LocalTemporary tempo;
127 tempo = new LocalTemporary (ec, source.Type);
136 } else if (eclass == ExprClass.IndexerAccess){
138 throw new Exception ("Can not assign to indexers yet");
142 public override void Emit (EmitContext ec)
147 public override void EmitStatement (EmitContext ec)