Merge pull request #960 from ermshiperete/ShowHelp
[mono.git] / mcs / mcs / argument.cs
index 22e28eaf7290267fa3754ecd6666cbd1e2f15cad..a5edeb53cf68b8e77b94dcf7a5363131038c423a 100644 (file)
@@ -34,6 +34,11 @@ namespace Mono.CSharp
                        Default = 3,            // argument created from default parameter value
                        DynamicTypeName = 4,    // System.Type argument for dynamic binding
                        ExtensionType = 5,      // Instance expression inserted as the first argument
+
+                       // Conditional instance expression inserted as the first argument
+                       ExtensionTypeConditionalAccess = 5 | ConditionalAccessFlag,
+
+                       ConditionalAccessFlag = 1 << 7
                }
 
                public readonly AType ArgType;
@@ -47,9 +52,6 @@ namespace Mono.CSharp
 
                public Argument (Expression expr)
                {
-                       if (expr == null)
-                               throw new ArgumentNullException ();
-
                        this.Expr = expr;
                }
 
@@ -63,6 +65,12 @@ namespace Mono.CSharp
                        get { return ArgType == AType.Default; }
                }
 
+               public bool IsExtensionType {
+                       get {
+                               return (ArgType & AType.ExtensionType) == AType.ExtensionType;
+                       }
+               }
+
                public Parameter.Modifier Modifier {
                        get {
                                switch (ArgType) {
@@ -108,7 +116,13 @@ namespace Mono.CSharp
                public virtual void Emit (EmitContext ec)
                {
                        if (!IsByRef) {
-                               Expr.Emit (ec);
+                               if (ArgType == AType.ExtensionTypeConditionalAccess) {
+                                       var ie = new InstanceEmitter (Expr, false);
+                                       ie.Emit (ec, true);
+                               } else {
+                                       Expr.Emit (ec);
+                               }
+
                                return;
                        }
 
@@ -130,12 +144,35 @@ namespace Mono.CSharp
                        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 ()
                {
                        if (Expr.eclass == ExprClass.MethodGroup)
                                return Expr.ExprClassName;
 
-                       return TypeManager.CSharpName (Expr.Type);
+                       return Expr.Type.GetSignatureForError ();
                }
 
                public bool ResolveMethodGroup (ResolveContext ec)
@@ -155,18 +192,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;
                }
        }
 
@@ -258,6 +293,16 @@ namespace Mono.CSharp
                                ordered.Add (arg);
                        }
 
+                       public override void FlowAnalysis (FlowAnalysisContext fc, List<MovableArgument> movable = null)
+                       {
+                               foreach (var arg in ordered) {
+                                       if (arg.ArgType != Argument.AType.Out)
+                                               arg.FlowAnalysis (fc);
+                               }
+
+                               base.FlowAnalysis (fc, ordered);
+                       }
+
                        public override Arguments Emit (EmitContext ec, bool dup_args, bool prepareAwait)
                        {
                                foreach (var a in ordered) {
@@ -350,7 +395,7 @@ 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,
@@ -479,6 +524,36 @@ namespace Mono.CSharp
                        return null;
                }
 
+               public virtual void FlowAnalysis (FlowAnalysisContext fc, List<MovableArgument> movable = null)
+               {
+                       bool has_out = false;
+                       foreach (var arg in args) {
+                               if (arg.ArgType == Argument.AType.Out) {
+                                       has_out = true;
+                                       continue;
+                               }
+
+                               if (movable == null) {
+                                       arg.FlowAnalysis (fc);
+                                       continue;
+                               }
+
+                               var ma = arg as MovableArgument;
+                               if (ma != null && !movable.Contains (ma))
+                                       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 ();