New tests.
[mono.git] / mcs / mcs / argument.cs
index e5a75f645df6e1471692bbb6e17f9c6954576d8f..79dc4417ddc37496f15f188c55df4343b78fdc9f 100644 (file)
@@ -10,9 +10,9 @@
 //
 
 using System;
-using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
+using System.Collections.Generic;
 
 namespace Mono.CSharp
 {
@@ -47,7 +47,7 @@ namespace Mono.CSharp
                        this.Expr = expr;
                }
 
-               public Type Type {
+               public TypeSpec Type {
                        get { return Expr.Type; }
                }
 
@@ -136,16 +136,7 @@ namespace Mono.CSharp
                                mode |= AddressOp.Load;
 
                        IMemoryLocation ml = (IMemoryLocation) Expr;
-                       ParameterReference pr = ml as ParameterReference;
-
-                       //
-                       // ParameterReferences might already be references, so we want
-                       // to pass just the value
-                       //
-                       if (pr != null && pr.IsRef)
-                               pr.EmitLoad (ec);
-                       else
-                               ml.AddressOf (ec, mode);
+                       ml.AddressOf (ec, mode);
                }
 
                public Argument Clone (CloneContext clonectx)
@@ -158,18 +149,25 @@ namespace Mono.CSharp
 
        public class NamedArgument : Argument
        {
-               public readonly LocatedToken Name;
+               public readonly string Name;
+               readonly Location loc;
                LocalTemporary variable;
 
-               public NamedArgument (LocatedToken name, Expression expr)
-                       : base (expr)
+               public NamedArgument (string name, Location loc, Expression expr)
+                       : this (name, loc, expr, AType.None)
+               {
+               }
+
+               public NamedArgument (string name, Location loc, Expression expr, AType modifier)
+                       : base (expr, modifier)
                {
-                       Name = name;
+                       this.Name = name;
+                       this.loc = loc;
                }
 
                public override Expression CreateExpressionTree (ResolveContext ec)
                {
-                       ec.Report.Error (853, Name.Location, "An expression tree cannot contain named argument");
+                       ec.Report.Error (853, loc, "An expression tree cannot contain named argument");
                        return base.CreateExpressionTree (ec);
                }
 
@@ -185,27 +183,39 @@ namespace Mono.CSharp
 
                public void EmitAssign (EmitContext ec)
                {
-                       Expr.Emit (ec);
-                       variable = new LocalTemporary (Expr.Type);
+                       var type = Expr.Type;
+                       if (IsByRef) {
+                               var ml = (IMemoryLocation) Expr;
+                               ml.AddressOf (ec, AddressOp.Load);
+                               type = ReferenceContainer.MakeType (type);
+                       } else {
+                               Expr.Emit (ec);
+                       }
+
+                       variable = new LocalTemporary (type);
                        variable.Store (ec);
 
                        Expr = variable;
                }
-       }
 
+               public Location Location {
+                       get { return loc; }
+               }
+       }
+       
        public class Arguments
        {
-               ArrayList args;                 // TODO: This should really be linked list
-               ArrayList reordered;    // TODO: LinkedList
+               List<Argument> args;
+               List<NamedArgument> reordered;
 
                public Arguments (int capacity)
                {
-                       args = new ArrayList (capacity);
+                       args = new List<Argument> (capacity);
                }
 
-               public int Add (Argument arg)
+               public void Add (Argument arg)
                {
-                       return args.Add (arg);
+                       args.Add (arg);
                }
 
                public void AddRange (Arguments args)
@@ -213,10 +223,10 @@ namespace Mono.CSharp
                        this.args.AddRange (args.args);
                }
 
-               public ArrayList CreateDynamicBinderArguments (ResolveContext rc)
+               public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
                {
-                       ArrayList all = new ArrayList (args.Count);
                        Location loc = Location.Null;
+                       var all = new ArrayInitializer (args.Count, loc);
 
                        MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (loc);
 
@@ -230,21 +240,21 @@ namespace Mono.CSharp
                                var constant = a.Expr as Constant;
                                if (constant != null && constant.IsLiteral) {
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "LiteralConstant", loc));
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "Constant", loc), 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));
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsRef", loc), 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));
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsOut", loc), 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));
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "IsStaticType", loc), loc);
                                }
 
                                var arg_type = a.Expr.Type;
 
-                               if (!TypeManager.IsDynamicType (arg_type)) {
+                               if (arg_type != InternalType.Dynamic) {
                                        MethodGroupExpr mg = a.Expr as MethodGroupExpr;
                                        if (mg != null) {
                                                rc.Report.Error (1976, a.Expr.Location,
@@ -260,16 +270,16 @@ namespace Mono.CSharp
                                        }
 
                                        info_flags = new Binary (Binary.Operator.BitwiseOr, info_flags,
-                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc));
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "UseCompileTimeType", loc), 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));
+                                               new MemberAccess (new MemberAccess (binder, info_flags_enum, loc), "NamedArgument", loc), loc);
 
-                                       named_value = na.Name.Value;
+                                       named_value = na.Name;
                                } else {
                                        named_value = null;
                                }
@@ -356,7 +366,7 @@ namespace Mono.CSharp
                        foreach (Argument a in args) {
                                a.Emit (ec);
                                if (dup_args) {
-                                       ec.ig.Emit (OpCodes.Dup);
+                                       ec.Emit (OpCodes.Dup);
                                        (temps [i++] = new LocalTemporary (a.Type)).Store (ec);
                                }
                        }
@@ -372,21 +382,23 @@ namespace Mono.CSharp
                        }
                }
 
-               public bool GetAttributableValue (ResolveContext ec, out object[] values)
+               public IEnumerator<Argument> GetEnumerator ()
                {
-                       values = new object [args.Count];
-                       for (int j = 0; j < values.Length; ++j) {
-                               Argument a = this [j];
-                               if (!a.Expr.GetAttributableValue (ec, a.Type, out values[j]))
-                                       return false;
-                       }
-
-                       return true;
+                       return args.GetEnumerator ();
                }
 
-               public IEnumerator GetEnumerator ()
-               {
-                       return args.GetEnumerator ();
+               //
+               // At least one argument is of dynamic type
+               //
+               public bool HasDynamic {
+                       get {
+                               foreach (Argument a in args) {
+                                       if (a.Type == InternalType.Dynamic)
+                                               return true;
+                               }
+                               
+                               return false;
+                       }
                }
 
                public void Insert (int index, Argument arg)
@@ -394,16 +406,11 @@ namespace Mono.CSharp
                        args.Insert (index, arg);
                }
 
-#if NET_4_0
                public static System.Linq.Expressions.Expression[] MakeExpression (Arguments args, BuilderContext ctx)
                {
                        if (args == null || args.Count == 0)
                                return null;
 
-                       // TODO: implement
-                       if (args.reordered != null)
-                               throw new NotImplementedException ();
-
                        var exprs = new System.Linq.Expressions.Expression [args.Count];
                        for (int i = 0; i < exprs.Length; ++i) {
                                Argument a = (Argument) args.args [i];
@@ -412,7 +419,6 @@ namespace Mono.CSharp
 
                        return exprs;
                }
-#endif
 
                public void MarkReorderedArgument (NamedArgument a)
                {
@@ -423,7 +429,7 @@ namespace Mono.CSharp
                                return;
 
                        if (reordered == null)
-                               reordered = new ArrayList ();
+                               reordered = new List<NamedArgument> ();
 
                        reordered.Add (a);
                }
@@ -436,16 +442,10 @@ namespace Mono.CSharp
                        dynamic = false;
                        foreach (Argument a in args) {
                                a.Resolve (ec);
-                               dynamic |= TypeManager.IsDynamicType (a.Type);
+                               dynamic |= a.Type == InternalType.Dynamic;
                        }
                }
 
-               public void MutateHoistedGenericType (AnonymousMethodStorey storey)
-               {
-                       foreach (Argument a in args)
-                               a.Expr.MutateHoistedGenericType (storey);
-               }
-
                public void RemoveAt (int index)
                {
                        args.RemoveAt (index);