* MenuAPI.cs: On instance of MenuTracker check if source control is
[mono.git] / mcs / mcs / assign.cs
index 25a56936ad3cbcc1dd2d145ee45b2a2d774f01ed..6a5c34d2872608c9e0fd04f861a618fff99ed553 100644 (file)
@@ -282,6 +282,12 @@ namespace Mono.CSharp {
                {
                        this.is_embedded = true;
                }
+               
+               public override Expression CreateExpressionTree (EmitContext ec)
+               {
+                       Report.Error (832, loc, "An expression tree cannot contain an assignment operator");
+                       return null;
+               }
 
                protected virtual Assign GetEmbeddedAssign (Location loc)
                {
@@ -325,6 +331,7 @@ namespace Mono.CSharp {
                                source = embedded = ((Assign) source).GetEmbeddedAssign (loc);
 
                        real_source = source = source.Resolve (ec);
+                                               
                        if (source == null) {
                                // Ensure that we don't propagate the error as spurious "uninitialized variable" errors.
                                target = target.ResolveLValue (ec, EmptyExpression.Null, Location);
@@ -359,12 +366,12 @@ namespace Mono.CSharp {
                        // local variable as source.
                        if (embedded != null)
                                source = (embedded.temp != null) ? embedded.temp : embedded.source;
-
+                       
                        target = target.ResolveLValue (ec, source, Location);
 
                        if (target == null)
                                return null;
-
+                       
                        bool same_assignment = (embedded != null) ? embedded.Target.Equals(target) : source.Equals (target);
                        if (same_assignment) {
                                Report.Warning (1717, 3, loc, "Assignment made to same variable; did you mean to assign something else?");
@@ -422,15 +429,18 @@ namespace Mono.CSharp {
 
                        }
 
-                       if (target_type == source_type){
-                               if (source is New && target_type.IsValueType &&
-                                   (target.eclass != ExprClass.IndexerAccess) && (target.eclass != ExprClass.PropertyAccess)){
-                                       New n = (New) source;
+                       if (target_type == source_type) {
+                               if (target.eclass == ExprClass.Variable) {
+                                       New n = source as New;
+                                       if (n == null)
+                                               return this;
 
-                                       if (n.SetValueTypeVariable (target))
+                                       if (n.HasInitializer) {
+                                               n.SetTargetVariable (target);
+                                       } else if (target_type.IsValueType) {
+                                               n.SetTargetVariable (target);
                                                return n;
-                                       else
-                                               return null;
+                                       }
                                }
 
                                return this;
@@ -454,7 +464,7 @@ namespace Mono.CSharp {
 
                                        source = Convert.ExplicitConversion (ec, source, target_type, loc);
                                        if (source == null){
-                                               a.original_source.Error_ValueCannotBeConverted (loc, target_type, true);
+                                               a.original_source.Error_ValueCannotBeConverted (ec, loc, target_type, true);
                                                return null;
                                        }
 
@@ -462,7 +472,7 @@ namespace Mono.CSharp {
                                        // 2. and the original right side is implicitly convertible to
                                        // the type of target
                                        //
-                                       if (Convert.ImplicitStandardConversionExists (a.original_source, target_type))
+                                       if (Convert.ImplicitConversionExists (ec, a.original_source, target_type))
                                                return this;
 
                                        //
@@ -473,7 +483,7 @@ namespace Mono.CSharp {
                                            (b.Oper == Binary.Operator.LeftShift || b.Oper == Binary.Operator.RightShift))
                                                return this;
 
-                                       a.original_source.Error_ValueCannotBeConverted (loc, target_type, false);
+                                       a.original_source.Error_ValueCannotBeConverted (ec, loc, target_type, false);
                                        return null;
                                }
                        }
@@ -582,6 +592,74 @@ namespace Mono.CSharp {
                {
                        Emit (ec, true);
                }
+
+               protected override void CloneTo (CloneContext clonectx, Expression t)
+               {
+                       Assign _target = (Assign) t;
+
+                       _target.target = target.Clone (clonectx);
+                       _target.source = source.Clone (clonectx);
+               }
+       }
+
+
+       // This class implements fields and events class initializers
+       public class FieldInitializer : Assign
+       {
+               //
+               // Keep resolved value because field initializers have their own rules
+               //
+               ExpressionStatement resolved;
+
+               public FieldInitializer (FieldBuilder field, Expression expression)
+                       : base (new FieldExpr (field, expression.Location, true), expression)
+               {
+                       if (!field.IsStatic)
+                               ((FieldExpr)target).InstanceExpression = CompilerGeneratedThis.Instance;
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       // Field initializer can be resolved (fail) many times
+                       if (Source == null)
+                               return null;
+
+                       if (resolved == null)
+                               resolved = base.DoResolve (ec) as ExpressionStatement;
+
+                       return resolved;
+               }
+
+               public override void EmitStatement (EmitContext ec)
+               {
+                       if (resolved == null)
+                               return;
+                       
+                       if (resolved != this)
+                               resolved.EmitStatement (ec);
+                       else
+                               base.EmitStatement (ec);
+               }
+               
+               public bool IsComplexInitializer {
+                       get {
+                               if (embedded != null)
+                                       return true;
+
+                               return !(source is Constant);
+                       }
+               }
+
+               public bool IsDefaultInitializer {
+                       get {
+                               Constant c = source as Constant;
+                               if (c == null)
+                                       return false;
+                               
+                               FieldExpr fe = (FieldExpr)target;
+                               return c.IsDefaultInitializer (fe.Type);
+                       }
+               }
        }
 
 
@@ -616,7 +694,10 @@ namespace Mono.CSharp {
                        if (original_source == null)
                                return null;
 
-                       target = target.Resolve (ec);
+                       using (ec.Set (EmitContext.Flags.InCompoundAssignment)) {
+                               target = target.Resolve (ec);
+                       }
+                       
                        if (target == null)
                                return null;
 
@@ -629,8 +710,15 @@ namespace Mono.CSharp {
                        // into a tree, to guarantee that we do not have side
                        // effects.
                        //
-                       source = new Binary (op, target, original_source);
+                       source = new Binary (op, target, original_source, true);
                        return base.DoResolve (ec);
                }
+
+               protected override void CloneTo (CloneContext clonectx, Expression t)
+               {
+                       CompoundAssign target = (CompoundAssign) t;
+
+                       target.original_source = original_source.Clone (clonectx);
+               }
        }
 }