[mcs] Remove used method
[mono.git] / mcs / mcs / argument.cs
index b3c0e71bd6b4358bbda4eede2ca6accf2da1b6fb..13d0526cc2cd9c5a47e422bbdc2b9c763c2de9b4 100644 (file)
@@ -6,7 +6,8 @@
 //   Marek Safar (marek.safar@gmail.com)
 //
 // Dual licensed under the terms of the MIT X11 or GNU GPL
-// Copyright 2003-2008 Novell, Inc.
+// Copyright 2003-2011 Novell, Inc.
+// Copyright 2011 Xamarin Inc
 //
 
 using System;
@@ -46,9 +47,6 @@ namespace Mono.CSharp
 
                public Argument (Expression expr)
                {
-                       if (expr == null)
-                               throw new ArgumentNullException ();
-
                        this.Expr = expr;
                }
 
@@ -119,10 +117,37 @@ namespace Mono.CSharp
                        ml.AddressOf (ec, mode);
                }
 
-               public Argument EmitToField (EmitContext ec)
+               public Argument EmitToField (EmitContext ec, bool cloneResult)
                {
                        var res = Expr.EmitToField (ec);
-                       return res == Expr ? this : new Argument (res, ArgType);
+                       if (cloneResult && res != Expr)
+                               return new Argument (res, ArgType);
+
+                       Expr = res;
+                       return this;
+               }
+
+               public void FlowAnalysis (FlowAnalysisContext fc)
+               {
+                       if (ArgType == AType.Out) {
+                               var vr = Expr as VariableReference;
+                               if (vr != null) {
+                                       if (vr.VariableInfo != null)
+                                               fc.SetVariableAssigned (vr.VariableInfo);
+
+                                       return;
+                               }
+
+                               var fe = Expr as FieldExpr;
+                               if (fe != null) {
+                                       fe.SetFieldAssigned (fc);
+                                       return;
+                               }
+
+                               return;
+                       }
+
+                       Expr.FlowAnalysis (fc);
                }
 
                public string GetSignatureForError ()
@@ -130,7 +155,7 @@ namespace Mono.CSharp
                        if (Expr.eclass == ExprClass.MethodGroup)
                                return Expr.ExprClassName;
 
-                       return TypeManager.CSharpName (Expr.Type);
+                       return Expr.Type.GetSignatureForError ();
                }
 
                public bool ResolveMethodGroup (ResolveContext ec)
@@ -150,18 +175,16 @@ namespace Mono.CSharp
 
                public void Resolve (ResolveContext ec)
                {
-//                     using (ec.With (ResolveContext.Options.DoFlowAnalysis, true)) {
-                               // Verify that the argument is readable
-                               if (ArgType != AType.Out)
-                                       Expr = Expr.Resolve (ec);
+                       // Verify that the argument is readable
+                       if (ArgType != AType.Out)
+                               Expr = Expr.Resolve (ec);
 
-                               // Verify that the argument is writeable
-                               if (Expr != null && IsByRef)
-                                       Expr = Expr.ResolveLValue (ec, EmptyExpression.OutAccess);
+                       // Verify that the argument is writeable
+                       if (Expr != null && IsByRef)
+                               Expr = Expr.ResolveLValue (ec, EmptyExpression.OutAccess);
 
-                               if (Expr == null)
-                                       Expr = ErrorExpression.Instance;
-//                     }
+                       if (Expr == null)
+                               Expr = ErrorExpression.Instance;
                }
        }
 
@@ -253,18 +276,16 @@ namespace Mono.CSharp
                                ordered.Add (arg);
                        }
 
-                       public override Arguments Emit (EmitContext ec, bool dup_args)
+                       public override Arguments Emit (EmitContext ec, bool dup_args, bool prepareAwait)
                        {
-                               bool await_inside = ContainsEmitWithAwait ();
-
                                foreach (var a in ordered) {
-                                       if (await_inside)
-                                               a.EmitToField (ec);
+                                       if (prepareAwait)
+                                               a.EmitToField (ec, false);
                                        else
                                                a.EmitToVariable (ec);
                                }
 
-                               return base.Emit (ec, dup_args);
+                               return base.Emit (ec, dup_args, prepareAwait);
                        }
                }
 
@@ -317,20 +338,20 @@ namespace Mono.CSharp
 
                                if (a.Expr is Constant) {
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc));
                                } else if (a.ArgType == Argument.AType.Ref) {
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc));
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
                                } else if (a.ArgType == Argument.AType.Out) {
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc));
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
                                } else if (a.ArgType == Argument.AType.DynamicTypeName) {
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc));
                                }
 
                                var arg_type = a.Expr.Type;
@@ -347,18 +368,18 @@ namespace Mono.CSharp
                                        } else if (arg_type.Kind == MemberKind.Void || arg_type == InternalType.Arglist || arg_type.IsPointer) {
                                                rc.Report.Error (1978, a.Expr.Location,
                                                        "An expression of type `{0}' cannot be used as an argument of dynamic operation",
-                                                       TypeManager.CSharpName (arg_type));
+                                                       arg_type.GetSignatureForError ());
                                        }
 
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
                                }
 
                                string named_value;
                                NamedArgument na = a as NamedArgument;
                                if (na != null) {
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc), loc);
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc));
 
                                        named_value = na.Name;
                                } else {
@@ -422,28 +443,26 @@ namespace Mono.CSharp
                // 
                public void Emit (EmitContext ec)
                {
-                       Emit (ec, false);
+                       Emit (ec, false, false);
                }
 
                //
                // if `dup_args' is true or any of arguments contains await.
                // A copy of all arguments will be returned to the caller
                //
-               public virtual Arguments Emit (EmitContext ec, bool dup_args)
+               public virtual Arguments Emit (EmitContext ec, bool dup_args, bool prepareAwait)
                {
                        List<Argument> dups;
 
-                       bool await_inside = ContainsEmitWithAwait ();
-
-                       if ((dup_args && Count != 0) || await_inside)
+                       if ((dup_args && Count != 0) || prepareAwait)
                                dups = new List<Argument> (Count);
                        else
                                dups = null;
 
                        LocalTemporary lt;
                        foreach (Argument a in args) {
-                               if (await_inside) {
-                                       dups.Add (a.EmitToField (ec));
+                               if (prepareAwait) {
+                                       dups.Add (a.EmitToField (ec, true));
                                        continue;
                                }
                                
@@ -478,6 +497,29 @@ namespace Mono.CSharp
                        return null;
                }
 
+               public void FlowAnalysis (FlowAnalysisContext fc)
+               {
+                       bool has_out = false;
+                       foreach (var arg in args) {
+                               if (arg.ArgType == Argument.AType.Out) {
+                                       has_out = true;
+                                       continue;
+                               }
+
+                               arg.FlowAnalysis (fc);
+                       }
+
+                       if (!has_out)
+                               return;
+
+                       foreach (var arg in args) {
+                               if (arg.ArgType != Argument.AType.Out)
+                                       continue;
+
+                               arg.FlowAnalysis (fc);
+                       }
+               }
+
                public List<Argument>.Enumerator GetEnumerator ()
                {
                        return args.GetEnumerator ();
@@ -552,6 +594,12 @@ namespace Mono.CSharp
                                        if (la == a)
                                                break;
 
+                                       //
+                                       // When the argument is filled later by default expression
+                                       //
+                                       if (la == null)
+                                               continue;
+
                                        var ma = la as MovableArgument;
                                        if (ma == null) {
                                                ma = new MovableArgument (la);