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 source = source.Resolve (ec);
51 target = target.ResolveLValue (ec, source);
56 Type target_type = target.Type;
57 Type source_type = source.Type;
60 eclass = ExprClass.Value;
63 // If we are doing a property assignment, then
64 // set the `value' field on the property, and Resolve
67 if (target is PropertyExpr){
68 PropertyExpr property_assign = (PropertyExpr) target;
71 // FIXME: Maybe handle this in the LValueResolve
73 if (!property_assign.VerifyAssignable ())
79 if (target is IndexerAccess){
80 IndexerAccess ia = (IndexerAccess) target;
85 if (source is New && target_type.IsSubclassOf (TypeManager.value_type)){
88 n.ValueTypeVariable = target;
93 if (target_type != source_type){
94 source = ConvertImplicitRequired (ec, source, target_type, l);
99 if (target.ExprClass != ExprClass.Variable){
100 Report.Error (131, l,
101 "Left hand of an assignment must be a variable, " +
102 "a property or an indexer");
109 void Emit (EmitContext ec, bool is_statement)
111 ILGenerator ig = ec.ig;
112 ExprClass eclass = target.ExprClass;
114 if (eclass == ExprClass.Variable){
117 // If it is an instance field, load the this pointer
119 if (target is FieldExpr){
120 FieldExpr fe = (FieldExpr) target;
122 if (!fe.FieldInfo.IsStatic)
123 ig.Emit (OpCodes.Ldarg_0);
129 ig.Emit (OpCodes.Dup);
131 ((IStackStore) target).Store (ec);
132 } else if (eclass == ExprClass.PropertyAccess){
133 PropertyExpr pe = (PropertyExpr) target;
139 LocalTemporary tempo;
141 tempo = new LocalTemporary (ec, source.Type);
150 } else if (eclass == ExprClass.IndexerAccess){
151 IndexerAccess ia = (IndexerAccess) target;
154 ia.EmitSet (ec, source);
156 LocalTemporary tempo;
158 tempo = new LocalTemporary (ec, source.Type);
162 ia.EmitSet (ec, source);
169 public override void Emit (EmitContext ec)
174 public override void EmitStatement (EmitContext ec)