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)
54 // If we are doing a property assignment, then
55 // set the `value' field on the property, and Resolve
58 if (target is PropertyExpr){
59 PropertyExpr property_assign = (PropertyExpr) target;
61 property_assign.Value = source;
63 return property_assign.Resolve (ec);
66 if (source is New && target.Type.IsSubclassOf (TypeManager.value_type)){
69 n.ValueTypeVariable = target;
74 Type target_type = target.Type;
76 Type source_type = source.Type;
78 if (target_type != source_type){
79 source = ConvertImplicitRequired (ec, source, target_type, l);
84 if (!(target is LValue)){
85 Report.Error (131, l, "Left hand of an assignment must be a variable, a property or an indexer");
89 eclass = ExprClass.Value;
93 void Emit (EmitContext ec, bool is_statement)
95 ILGenerator ig = ec.ig;
97 if (target.ExprClass == ExprClass.Variable){
100 // If it is an instance field, load the this pointer
102 if (target is FieldExpr){
103 FieldExpr fe = (FieldExpr) target;
105 if (!fe.FieldInfo.IsStatic)
106 ig.Emit (OpCodes.Ldarg_0);
112 ig.Emit (OpCodes.Dup);
114 ((LValue) target).Store (ec);
115 } else if (target.ExprClass == ExprClass.PropertyAccess){
117 throw new Exception ("Can not assign to properties yet");
118 } else if (target.ExprClass == ExprClass.IndexerAccess){
120 throw new Exception ("Can not assign to indexers yet");
124 public override void Emit (EmitContext ec)
129 public override void EmitStatement (EmitContext ec)