Author: marek
Date: 2008-01-21 11:52:12 -0500 (Mon, 21 Jan 2008)
New Revision: 93414

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/attribute.cs
   trunk/mcs/mcs/class.cs
   trunk/mcs/mcs/delegate.cs
   trunk/mcs/mcs/ecore.cs
   trunk/mcs/mcs/expression.cs
   trunk/mcs/mcs/linq.cs
   trunk/mcs/mcs/typemanager.cs
Log:
2008-01-21  Marek Safar  <[EMAIL PROTECTED]>

        * attribute.cs, ecore.cs, class.cs, delegate.cs, expression.cs, linq.cs,
        typemanager.cs: A refactoring of params arguments to reuse existing
        expressions (params -> array initializer) to emit params argument 
instead
        of specialized handling.
        It was required by expression tree implementation and it has other 
benefits
        as well, we now apply same optimization for params arguments as we do 
for
        array initializers.
        


Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/ChangeLog     2008-01-21 16:52:12 UTC (rev 93414)
@@ -1,3 +1,13 @@
+2008-01-21  Marek Safar  <[EMAIL PROTECTED]>
+
+       * attribute.cs, ecore.cs, class.cs, delegate.cs, expression.cs, linq.cs,
+       typemanager.cs: A refactoring of params arguments to reuse existing
+       expressions (params -> array initializer) to emit params argument 
instead
+       of specialized handling.
+       It was required by expression tree implementation and it has other 
benefits
+       as well, we now apply same optimization for params arguments as we do 
for
+       array initializers.
+       
 2008-01-18  Marek Safar  <[EMAIL PROTECTED]>
 
        A fix for bug #353526

Modified: trunk/mcs/mcs/attribute.cs
===================================================================
--- trunk/mcs/mcs/attribute.cs  2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/attribute.cs  2008-01-21 16:52:12 UTC (rev 93414)
@@ -85,7 +85,7 @@
                public readonly Expression LeftExpr;
                public readonly string Identifier;
 
-               readonly ArrayList PosArguments;
+               ArrayList PosArguments;
                ArrayList NamedArguments;
 
                bool resolve_error;
@@ -432,7 +432,7 @@
                        if (mg == null)
                                return null;
 
-                       mg = mg.OverloadResolve (ec, PosArguments, false, 
Location);
+                       mg = mg.OverloadResolve (ec, ref PosArguments, false, 
Location);
                        if (mg == null)
                                return null;
                        
@@ -452,48 +452,14 @@
                        ParameterData pd = TypeManager.GetParameterData 
(constructor);
 
                        int pos_arg_count = PosArguments.Count;
-                       int last_real_param = pd.Count;
-
                        pos_values = new object [pos_arg_count];
-
-                       if (pd.HasParams) {
-                               // When the params is not filled we need to put 
one
-                               if (last_real_param > pos_arg_count) {
-                                       object [] new_pos_values = new object 
[pos_arg_count + 1];
-                                       pos_values.CopyTo (new_pos_values, 0);
-                                       new_pos_values [pos_arg_count] = new 
object [] {} ;
-                                       pos_values = new_pos_values;
-                               }
-                               last_real_param--;
-                       }
-
                        for (int j = 0; j < pos_arg_count; ++j) {
                                Argument a = (Argument) PosArguments [j];
 
                                if (!a.Expr.GetAttributableValue (a.Type, out 
pos_values [j]))
                                        return null;
-                               
-                               if (j < last_real_param)
-                                       continue;
-                               
-                               if (j == last_real_param) {
-                                       object [] array = new object 
[pos_arg_count - last_real_param];
-                                       array [0] = pos_values [j];
-                                       pos_values [j] = array;
-                                       continue;
-                               }
-
-                               object [] params_array = (object []) pos_values 
[last_real_param];
-                               params_array [j - last_real_param] = pos_values 
[j];
                        }
 
-                       // Adjust the size of the pos_values if it had params
-                       if (last_real_param != pos_arg_count) {
-                               object [] new_pos_values = new object 
[last_real_param + 1];
-                               Array.Copy (pos_values, new_pos_values, 
last_real_param + 1);
-                               pos_values = new_pos_values;
-                       }
-
                        // Here we do the checks which should be done by corlib 
or by runtime.
                        // However Zoltan doesn't like it and every Mono 
compiler has to do it again.
                        

Modified: trunk/mcs/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs      2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/class.cs      2008-01-21 16:52:12 UTC (rev 93414)
@@ -4644,7 +4644,7 @@
 
        public abstract class ConstructorInitializer : Expression
        {
-               readonly ArrayList argument_list;
+               ArrayList argument_list;
                MethodGroupExpr base_constructor_group;
                
                public ConstructorInitializer (ArrayList argument_list, 
Location loc)
@@ -4700,7 +4700,7 @@
                                return false;
                        
                        base_constructor_group = 
base_constructor_group.OverloadResolve (
-                               ec, argument_list, false, loc);
+                               ec, ref argument_list, false, loc);
                        
                        if (base_constructor_group == null)
                                return false;

Modified: trunk/mcs/mcs/delegate.cs
===================================================================
--- trunk/mcs/mcs/delegate.cs   2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/delegate.cs   2008-01-21 16:52:12 UTC (rev 93414)
@@ -562,7 +562,7 @@
                        }
 
                        return me.VerifyArgumentsCompat (
-                                       ec, args, arg_count, mb, 
+                                       ec, ref args, arg_count, mb, 
                                        is_params_applicable || (!is_applicable 
&& params_method),
                                        false, loc);
                }
@@ -674,8 +674,8 @@
                                                atype = atype.GetElementType ();
                                                break;
                                        case Parameter.Modifier.ARGLIST:
-                                               // TODO: investigate and test
-                                               throw new 
NotImplementedException ();
+                                               // __arglist is not valid
+                                               throw new 
InternalErrorException ("__arglist modifier");
                                        default:
                                                atype_modifier = 
Argument.AType.Expression;
                                                break;
@@ -692,7 +692,9 @@
                        MethodInfo invoke_method = Delegate.GetInvokeMethod 
(ec.ContainerType, type);
                        method_group.DelegateType = type;
                        method_group.CustomErrorHandler = this;
-                       method_group = method_group.OverloadResolve (ec, 
CreateDelegateMethodArguments (invoke_method), false, loc);
+
+                       ArrayList arguments = CreateDelegateMethodArguments 
(invoke_method);
+                       method_group = method_group.OverloadResolve (ec, ref 
arguments, false, loc);
                        if (method_group == null)
                                return null;
 

Modified: trunk/mcs/mcs/ecore.cs
===================================================================
--- trunk/mcs/mcs/ecore.cs      2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/ecore.cs      2008-01-21 16:52:12 UTC (rev 93414)
@@ -927,7 +927,7 @@
                        ArrayList arguments = new ArrayList (1);
                        arguments.Add (new Argument (e, 
Argument.AType.Expression));
                        operator_group = operator_group.OverloadResolve (
-                               ec, arguments, false, loc);
+                               ec, ref arguments, false, loc);
 
                        if (operator_group == null)
                                return null;
@@ -3100,10 +3100,10 @@
                        base.EmitCall (ec, arguments);
                }
 
-               public override MethodGroupExpr OverloadResolve (EmitContext 
ec, ArrayList arguments, bool may_fail, Location loc)
+               public override MethodGroupExpr OverloadResolve (EmitContext 
ec, ref ArrayList arguments, bool may_fail, Location loc)
                {
                        if ((ExtensionExpression.eclass & (ExprClass.Value | 
ExprClass.Variable)) == 0)
-                               return base.OverloadResolve (ec, arguments, 
may_fail, loc);
+                               return base.OverloadResolve (ec, ref arguments, 
may_fail, loc);
 
                        if (arguments == null)
                                arguments = new ArrayList (1);
@@ -3122,7 +3122,7 @@
                MethodGroupExpr ResolveOverloadExtensions (EmitContext ec, 
ArrayList arguments, NamespaceEntry ns, Location loc)
                {
                        // Use normal resolve rules
-                       MethodGroupExpr mg = base.OverloadResolve (ec, 
arguments, ns != null, loc);
+                       MethodGroupExpr mg = base.OverloadResolve (ec, ref 
arguments, ns != null, loc);
                        if (mg != null)
                                return mg;
 
@@ -3132,7 +3132,7 @@
                        // Search continues
                        ExtensionMethodGroupExpr e = ns.LookupExtensionMethod 
(type, null, Name);
                        if (e == null)
-                               return base.OverloadResolve (ec, arguments, 
false, loc);
+                               return base.OverloadResolve (ec, ref arguments, 
false, loc);
 
                        e.ExtensionExpression = ExtensionExpression;
                        return e.ResolveOverloadExtensions (ec, arguments, 
e.namespace_entry, loc);
@@ -3547,7 +3547,7 @@
                
                public virtual void EmitArguments (EmitContext ec, ArrayList 
arguments)
                {
-                       Invocation.EmitArguments (ec, best_candidate, 
arguments, false, null);  
+                       Invocation.EmitArguments (ec, arguments, false, null);  
                }
                
                public virtual void EmitCall (EmitContext ec, ArrayList 
arguments)
@@ -3876,7 +3876,7 @@
                ///            that is the best match of me on Arguments.
                ///
                /// </summary>
-               public virtual MethodGroupExpr OverloadResolve (EmitContext ec, 
ArrayList Arguments,
+               public virtual MethodGroupExpr OverloadResolve (EmitContext ec, 
ref ArrayList Arguments,
                        bool may_fail, Location loc)
                {
                        bool method_params = false;
@@ -4004,7 +4004,7 @@
                                        if (ex_method_lookup != null) {
                                                
ex_method_lookup.ExtensionExpression = InstanceExpression;
                                                
ex_method_lookup.SetTypeArguments (type_arguments);
-                                               return 
ex_method_lookup.OverloadResolve (ec, Arguments, may_fail, loc);
+                                               return 
ex_method_lookup.OverloadResolve (ec, ref Arguments, may_fail, loc);
                                        }
                                }
                                
@@ -4048,7 +4048,7 @@
                                                        }
                                                }
                                                
-                                               if (VerifyArgumentsCompat (ec, 
Arguments, arg_count, best_candidate, cand_params, may_fail, loc))
+                                               if (VerifyArgumentsCompat (ec, 
ref Arguments, arg_count, best_candidate, cand_params, may_fail, loc))
                                                        throw new 
InternalErrorException ("Overload verification expected failure");
                                                return null;
                                        }
@@ -4132,7 +4132,9 @@
                        //
 
                        best_candidate = (MethodBase) candidates [0];
-                       method_params = candidate_to_form != null && 
candidate_to_form.Contains (best_candidate);
+                       if (delegate_type == null)
+                               method_params = candidate_to_form != null && 
candidate_to_form.Contains (best_candidate);
+
                        for (int ix = 1; ix < candidate_top; ix++) {
                                MethodBase candidate = (MethodBase) candidates 
[ix];
 
@@ -4223,7 +4225,7 @@
                        // necessary etc. and return if everything is
                        // all right
                        //
-                       if (!VerifyArgumentsCompat (ec, Arguments, arg_count, 
best_candidate,
+                       if (!VerifyArgumentsCompat (ec, ref Arguments, 
arg_count, best_candidate,
                                method_params, may_fail, loc))
                                return null;
 
@@ -4249,7 +4251,7 @@
                        type_arguments = ta;
                }
 
-               public bool VerifyArgumentsCompat (EmitContext ec, ArrayList 
arguments,
+               public bool VerifyArgumentsCompat (EmitContext ec, ref 
ArrayList arguments,
                                                          int arg_count, 
MethodBase method,
                                                          bool 
chose_params_expanded,
                                                          bool may_fail, 
Location loc)
@@ -4259,9 +4261,11 @@
                        int errors = Report.Errors;
                        Parameter.Modifier p_mod = 0;
                        Type pt = null;
-                       int a_idx = 0;
+                       int a_idx = 0, a_pos = 0;
                        Argument a = null;
-                       for (; a_idx < arg_count; a_idx++) {
+                       ArrayList params_initializers = null;
+
+                       for (; a_idx < arg_count; a_idx++, ++a_pos) {
                                a = (Argument) arguments [a_idx];
                                if (p_mod != Parameter.Modifier.PARAMS) {
                                        p_mod = pd.ParameterModifier (a_idx);
@@ -4281,8 +4285,10 @@
                                        }
 
                                        if (p_mod == Parameter.Modifier.PARAMS) 
{
-                                               if (chose_params_expanded)
+                                               if (chose_params_expanded) {
+                                                       params_initializers = 
new ArrayList (arg_count - a_idx);
                                                        pt = 
TypeManager.GetElementType (pt);
+                                               }
                                        } else if (p_mod != 0) {
                                                pt = TypeManager.GetElementType 
(pt);
                                        }
@@ -4301,25 +4307,59 @@
                                        continue;
                                }
                
-                               if (TypeManager.IsEqual (a.Type, pt))
+                               Expression conv;
+                               if (TypeManager.IsEqual (a.Type, pt)) {
+                                       conv = a.Expr;
+                               } else {
+                                       conv = Convert.ImplicitConversion (ec, 
a.Expr, pt, loc);
+                                       if (conv == null)
+                                               break;
+                               }
+
+                               //
+                               // Convert params arguments to an array 
initializer
+                               //
+                               if (params_initializers != null) {
+                                       params_initializers.Add (conv);
+                                       arguments.RemoveAt (a_idx--);
+                                       --arg_count;
                                        continue;
+                               }
                                
-                               Expression conv = Convert.ImplicitConversion 
(ec, a.Expr, pt, loc);
-                               if (conv == null)
-                                       break;
-
-                               if (!chose_params_expanded && (p_mod & 
Parameter.Modifier.PARAMS) != 0 && a.Type == TypeManager.null_type)
-                                       conv.Type = pd.ParameterType (a_idx);
-
                                // Update the argument with the implicit 
conversion
                                a.Expr = conv;
                        }
 
-                       if (a_idx == arg_count)
+                       //
+                       // Fill not provided arguments required by params 
modifier
+                       //
+                       if (params_initializers == null && pd.HasParams && 
arg_count < pd.Count) {
+                               if (arguments == null)
+                                       arguments = new ArrayList (1);
+
+                               pt = pd.Types [GetApplicableParametersCount 
(method, pd) - 1];
+                               pt = TypeManager.GetElementType (pt);
+                               params_initializers = new ArrayList (0);
+                       }
+
+                       if (a_idx == arg_count) {
+                               //
+                               // Append an array argument with all params 
arguments
+                               //
+                               if (params_initializers != null) {
+                                       arguments.Add (new Argument (
+                                               new ArrayCreation (new 
TypeExpression (pt, loc), "[]",
+                                               params_initializers, 
loc).Resolve (ec)));
+                               }
                                return true;
+                       }
 
-                       if (!may_fail && Report.Errors == errors)
-                               Error_InvalidArguments (ec, loc, a_idx, method, 
a, pd, pt);
+                       if (!may_fail && Report.Errors == errors) {
+                               if (CustomErrorHandler != null)
+                                       CustomErrorHandler.NoExactMatch (ec, 
best_candidate);
+                               else
+                                       Error_InvalidArguments (ec, loc, a_pos, 
method, a, pd, pt);
+                       }
                        return false;
                }
        }

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/expression.cs 2008-01-21 16:52:12 UTC (rev 93414)
@@ -46,9 +46,7 @@
 
                public override void Emit (EmitContext ec)
                {
-                       if (args != null) 
-                               Invocation.EmitArguments (ec, mi, args, false, 
null);
-
+                       Invocation.EmitArguments (ec, args, false, null);
                        ec.ig.Emit (OpCodes.Call, mi);
                        return;
                }
@@ -66,7 +64,7 @@
                                 return null;
 
                         args.Add (a);
-                       mg = mg.OverloadResolve (ec, args, false, loc);
+                       mg = mg.OverloadResolve (ec, ref args, false, loc);
 
                        if (mg == null)
                                return null;
@@ -1981,7 +1979,7 @@
                                        args.Add (new Argument (left, 
Argument.AType.Expression));
                                        args.Add (new Argument (right, 
Argument.AType.Expression));
 
-                                       union = union.OverloadResolve (ec, 
args, true, Location.Null);
+                                       union = union.OverloadResolve (ec, ref 
args, true, Location.Null);
 
                                        if (union != null) {
                                                MethodInfo mi = (MethodInfo) 
union;
@@ -2130,7 +2128,7 @@
                                                ArrayList args = new ArrayList 
(2);
                                                args.Add (new Argument (left, 
Argument.AType.Expression));
                                                args.Add (new Argument (left, 
Argument.AType.Expression));
-                                               if 
(left_operators.OverloadResolve (ec, args, true, Location.Null) != null)
+                                               if 
(left_operators.OverloadResolve (ec, ref args, true, Location.Null) != null)
                                                        
Warning_UnintendedReferenceComparison (loc, "right", l);
                                        }
 
@@ -2139,7 +2137,7 @@
                                                ArrayList args = new ArrayList 
(2);
                                                args.Add (new Argument (right, 
Argument.AType.Expression));
                                                args.Add (new Argument (right, 
Argument.AType.Expression));
-                                               if 
(right_operators.OverloadResolve (ec, args, true, Location.Null) != null)
+                                               if 
(right_operators.OverloadResolve (ec, ref args, true, Location.Null) != null)
                                                        
Warning_UnintendedReferenceComparison (loc, "left", r);
                                        }
 
@@ -2433,7 +2431,7 @@
                                ArrayList args = new ArrayList (2);
                                args.Add (new Argument (left, 
Argument.AType.Expression));
                                args.Add (new Argument (right, 
Argument.AType.Expression));
-                               ops = ops.OverloadResolve (ec, args, true, 
Location.Null);
+                               ops = ops.OverloadResolve (ec, ref args, true, 
Location.Null);
                                return new BinaryMethod (type, (MethodInfo)ops, 
args);
                        }
 
@@ -3085,8 +3083,7 @@
                {
                        ILGenerator ig = ec.ig;
                        
-                       if (Arguments != null) 
-                               Invocation.EmitArguments (ec, method, 
Arguments, false, null);
+                       Invocation.EmitArguments (ec, Arguments, false, null);
                        
                        if (method is MethodInfo)
                                ig.Emit (OpCodes.Call, (MethodInfo) method);
@@ -3100,30 +3097,21 @@
        // b, c, d... may be strings or objects.
        //
        public class StringConcat : Expression {
-               ArrayList operands;
-               bool invalid = false;
-               bool emit_conv_done = false;
-               //
-               // Are we also concating objects?
-               //
-               bool is_strings_only = true;
+               ArrayList arguments;
                
                public StringConcat (EmitContext ec, Location loc, Expression 
left, Expression right)
                {
                        this.loc = loc;
                        type = TypeManager.string_type;
                        eclass = ExprClass.Value;
-               
-                       operands = new ArrayList (2);
+
+                       arguments = new ArrayList (2);
                        Append (ec, left);
                        Append (ec, right);
                }
                
                public override Expression DoResolve (EmitContext ec)
                {
-                       if (invalid)
-                               return null;
-                       
                        return this;
                }
                
@@ -3134,119 +3122,54 @@
                        //
                        StringConstant sc = operand as StringConstant;
                        if (sc != null) {
-// TODO: it will be better to do this silently as an optimalization
-// int i = 0;
-// string s = "" + i;
-// because this code has poor performace
-//                             if (sc.Value.Length == 0)
-//                                     Report.Warning (-300, 3, Location, 
"Appending an empty string has no effect. Did you intend to append a space 
string?");
-
-                               if (operands.Count != 0) {
-                                       StringConstant last_operand = operands 
[operands.Count - 1] as StringConstant;
-                                       if (last_operand != null) {
-                                               operands [operands.Count - 1] = 
new StringConstant (last_operand.Value + ((StringConstant) operand).Value, 
last_operand.Location);
+                               if (arguments.Count != 0) {
+                                       Argument last_argument = (Argument) 
arguments [arguments.Count - 1];
+                                       StringConstant last_expr_constant = 
last_argument.Expr as StringConstant;
+                                       if (last_expr_constant != null) {
+                                               last_argument.Expr = new 
StringConstant (
+                                                       
last_expr_constant.Value + sc.Value, sc.Location);
                                                return;
                                        }
                                }
+                       } else {
+                               //
+                               // Multiple (3+) concatenation are resolved as 
multiple StringConcat instances
+                               //
+                               StringConcat concat_oper = operand as 
StringConcat;
+                               if (concat_oper != null) {
+                                       arguments.AddRange 
(concat_oper.arguments);
+                                       return;
+                               }
                        }
                        
-
                        //
-                       // Multiple (3+) concatenation are resolved as multiple 
StringConcat instances
-                       //
-                       StringConcat concat_oper = operand as StringConcat;
-                       if (concat_oper != null) {
-                               operands.AddRange (concat_oper.operands);
-                               return;
-                       }                       
-                       
-                       //
                        // Conversion to object
                        //
                        if (operand.Type != TypeManager.string_type) {
-                               Expression no = Convert.ImplicitConversion (ec, 
operand, TypeManager.object_type, loc);
-                               
-                               if (no == null) {
+                               Expression expr = Convert.ImplicitConversion 
(ec, operand, TypeManager.object_type, loc);
+                               if (expr == null) {
                                        Binary.Error_OperatorCannotBeApplied 
(loc, "+", TypeManager.string_type, operand.Type);
-                                       invalid = true;
+                                       return;
                                }
-                               operand = no;
+                               operand = expr;
                        }
                        
-                       operands.Add (operand);
+                       arguments.Add (new Argument (operand));
                }
 
+               Expression CreateConcatInvocation ()
+               {
+                       return new Invocation (
+                               new MemberAccess (new MemberAccess (new 
QualifiedAliasMember ("global", "System", loc), "String", loc), "Concat", loc),
+                               arguments, true);
+               }
+
                public override void Emit (EmitContext ec)
                {
-                       MethodInfo concat_method = null;
-                       
-                       //
-                       // Do conversion to arguments; check for strings only
-                       //
-                       
-                       // This can get called multiple times, so we have to 
deal with that.
-                       if (!emit_conv_done) {
-                               emit_conv_done = true;
-                               for (int i = 0; i < operands.Count; i ++) {
-                                       Expression e = (Expression) operands 
[i];
-                                       is_strings_only &= e.Type == 
TypeManager.string_type;
-                               }
-                               
-                               for (int i = 0; i < operands.Count; i ++) {
-                                       Expression e = (Expression) operands 
[i];
-                                       
-                                       if (! is_strings_only && e.Type == 
TypeManager.string_type) {
-                                               // need to make sure this is an 
object, because the EmitParams
-                                               // method might look at the 
type of this expression, see it is a
-                                               // string and emit a string [] 
when we want an object [];
-                                               
-                                               e = EmptyCast.Create (e, 
TypeManager.object_type);
-                                       }
-                                       operands [i] = new Argument (e, 
Argument.AType.Expression);
-                               }
-                       }
-                       
-                       //
-                       // Find the right method
-                       //
-                       switch (operands.Count) {
-                       case 1:
-                               //
-                               // This should not be possible, because simple 
constant folding
-                               // is taken care of in the Binary code.
-                               //
-                               throw new Exception ("how did you get here?");
-                       
-                       case 2:
-                               concat_method = is_strings_only ? 
-                                       TypeManager.string_concat_string_string 
:
-                                       TypeManager.string_concat_object_object 
;
-                               break;
-                       case 3:
-                               concat_method = is_strings_only ? 
-                                       
TypeManager.string_concat_string_string_string :
-                                       
TypeManager.string_concat_object_object_object ;
-                               break;
-                       case 4:
-                               //
-                               // There is not a 4 param overlaod for object 
(the one that there is
-                               // is actually a varargs methods, and is only 
in corlib because it was
-                               // introduced there before.).
-                               //
-                               if (!is_strings_only)
-                                       goto default;
-                               
-                               concat_method = 
TypeManager.string_concat_string_string_string_string;
-                               break;
-                       default:
-                               concat_method = is_strings_only ? 
-                                       
TypeManager.string_concat_string_dot_dot_dot :
-                                       
TypeManager.string_concat_object_dot_dot_dot ;
-                               break;
-                       }
-                       
-                       Invocation.EmitArguments (ec, concat_method, operands, 
false, null);
-                       ec.ig.Emit (OpCodes.Call, concat_method);
+                       Expression concat = CreateConcatInvocation ();
+                       concat = concat.Resolve (ec);
+                       if (concat != null)
+                               concat.Emit (ec);
                }
        }
 
@@ -3274,7 +3197,7 @@
                {
                        ILGenerator ig = ec.ig;
                        
-                       Invocation.EmitArguments (ec, method, args, false, 
null);
+                       Invocation.EmitArguments (ec, args, false, null);
                        
                        ig.Emit (OpCodes.Call, (MethodInfo) method);
                        ig.Emit (OpCodes.Castclass, type);
@@ -3339,7 +3262,7 @@
                        ArrayList arguments = new ArrayList (2);
                        arguments.Add (new Argument (left_temp, 
Argument.AType.Expression));
                        arguments.Add (new Argument (right, 
Argument.AType.Expression));
-                       operator_group = operator_group.OverloadResolve (ec, 
arguments, false, loc);
+                       operator_group = operator_group.OverloadResolve (ec, 
ref arguments, false, loc);
                        if (operator_group == null) {
                                Error19 ();
                                return null;
@@ -4238,6 +4161,7 @@
                protected ArrayList Arguments;
                Expression expr;
                protected MethodGroupExpr mg;
+               bool arguments_resolved;
                
                //
                // arguments is an ArrayList, but we do not want to typecast,
@@ -4255,6 +4179,12 @@
                        loc = expr.Location;
                }
 
+               public Invocation (Expression expr, ArrayList arguments, bool 
arguments_resolved)
+                       : this (expr, arguments)
+               {
+                       this.arguments_resolved = arguments_resolved;
+               }
+
                public static string FullMethodDesc (MethodBase mb)
                {
                        if (mb == null)
@@ -4316,8 +4246,7 @@
                        //
                        // Next, evaluate all the expressions in the argument 
list
                        //
-                       if (Arguments != null)
-                       {
+                       if (Arguments != null && !arguments_resolved) {
                                for (int i = 0; i < Arguments.Count; ++i)
                                {
                                        if 
(!((Argument)Arguments[i]).Resolve(ec, loc))
@@ -4383,7 +4312,7 @@
 
                protected virtual MethodGroupExpr DoResolveOverload 
(EmitContext ec)
                {
-                       return mg.OverloadResolve (ec, Arguments, false, loc);
+                       return mg.OverloadResolve (ec, ref Arguments, false, 
loc);
                }
 
                bool IsSpecialMethodInvocation (MethodBase method)
@@ -4398,38 +4327,6 @@
                        return true;
                }
 
-               // <summary>
-               //   Emits the list of arguments as an array
-               // </summary>
-               static void EmitParams (EmitContext ec, ArrayList arguments, 
int idx, int count)
-               {
-                       ILGenerator ig = ec.ig;
-                       Type t = null;
-                       for (int j = 0; j < count; j++){
-                               Argument a = (Argument) arguments [j + idx];
-                               if (j == 0) {
-                                       t = a.Expr.Type;
-                                       IntConstant.EmitInt (ig, count);
-                                       ig.Emit (OpCodes.Newarr, 
TypeManager.TypeToCoreType (t));
-                               }
-                               
-                               ig.Emit (OpCodes.Dup);
-                               IntConstant.EmitInt (ig, j);
-
-                               bool is_stobj, has_type_arg;
-                               OpCode op = ArrayAccess.GetStoreOpcode (t, out 
is_stobj, out has_type_arg);
-                               if (is_stobj)
-                                       ig.Emit (OpCodes.Ldelema, t);
-
-                               a.Emit (ec);
-
-                               if (has_type_arg)
-                                       ig.Emit (op, t);
-                               else
-                                       ig.Emit (op);
-                       }
-               }
-               
                /// <summary>
                ///   Emits a list of resolved Arguments that are in the 
arguments
                ///   ArrayList.
@@ -4444,10 +4341,12 @@
                ///   which will be duplicated before any other args. Only 
EmitCall
                ///   should be using this interface.
                /// </summary>
-               public static void EmitArguments (EmitContext ec, MethodBase 
mb, ArrayList arguments, bool dup_args, LocalTemporary this_arg)
+               public static void EmitArguments (EmitContext ec, ArrayList 
arguments, bool dup_args, LocalTemporary this_arg)
                {
-                       ParameterData pd = mb == null ? null : 
TypeManager.GetParameterData (mb);
-                       int top = pd.Count;
+                       if (arguments == null)
+                               return;
+
+                       int top = arguments.Count;
                        LocalTemporary [] temps = null;
                        
                        if (dup_args && top != 0)
@@ -4455,42 +4354,7 @@
 
                        int argument_index = 0;
                        Argument a;
-                       for (int i = 0; i < top; i++){
-                               if (pd != null){
-                                       if (pd.ParameterModifier (i) == 
Parameter.Modifier.PARAMS){
-                                               Type p_type = pd.ParameterType 
(i);
-                                               int params_args_count = 
arguments == null ?
-                                                       0 : arguments.Count - 
top + 1;
-
-                                               // Fill not provided argument
-                                               if (params_args_count <= 0) {
-                                                       ILGenerator ig = ec.ig;
-                                                       IntConstant.EmitInt 
(ig, 0);
-                                                       ig.Emit 
(OpCodes.Newarr, TypeManager.GetElementType (p_type));
-                                               } else {
-                                                       //
-                                                       // Special case if we 
are passing the same data as the
-                                                       // params argument, we 
do not need to recreate an array.
-                                                       //
-                                                       a = (Argument) 
arguments [argument_index];
-                                                       if (params_args_count 
== 1 && p_type == a.Type) {
-                                                               
++argument_index;
-                                                               a.Emit (ec);
-                                                       } else {
-                                                               EmitParams (ec, 
arguments, i, params_args_count);
-                                                               argument_index 
+= params_args_count;
-                                                       }
-                                               }
-
-                                               if (dup_args) {
-                                                       ec.ig.Emit 
(OpCodes.Dup);
-                                                       temps [i] = new 
LocalTemporary (p_type);
-                                                       temps [i].Store (ec);
-                                               }
-                                               continue;
-                                       }
-                               }
-
+                       for (int i = 0; i < top; i++) {
                                a = (Argument) arguments [argument_index++];
                                a.Emit (ec);
                                if (dup_args) {
@@ -4690,7 +4554,7 @@
                        }
 
                        if (!omit_args)
-                               EmitArguments (ec, method, Arguments, dup_args, 
this_arg);
+                               EmitArguments (ec, Arguments, dup_args, 
this_arg);
 
 #if GMCS_SOURCE
                        if ((instance_expr != null) && 
(instance_expr.Type.IsGenericParameter))
@@ -5120,7 +4984,7 @@
                                return null;
                        }
 
-                       method = method.OverloadResolve (ec, Arguments, false, 
loc);
+                       method = method.OverloadResolve (ec, ref Arguments, 
false, loc);
                        if (method == null)
                                return null;
 
@@ -6343,7 +6207,7 @@
                {
                        Report.Error (1952, loc, "An expression tree cannot 
contain a method with variable arguments");
                        return null;
-               }               
+               }
 
                public override Expression DoResolve (EmitContext ec)
                {
@@ -6768,8 +6632,10 @@
                                        "System.NullReferenceException");
                        }
 
-                       if (args != null)
-                               args.Resolve (ec);
+                       if (args != null) {
+                               if (!args.Resolve (ec))
+                                       return null;
+                       }
 
                        Expression member_lookup;
                        member_lookup = MemberLookup (
@@ -7843,7 +7709,7 @@
                        }
 
                        MethodGroupExpr mg = new IndexerMethodGroupExpr (ilist, 
loc);
-                       mg = mg.OverloadResolve (ec, arguments, false, loc);
+                       mg = mg.OverloadResolve (ec, ref arguments, false, loc);
                        if (mg == null)
                                return null;
 

Modified: trunk/mcs/mcs/linq.cs
===================================================================
--- trunk/mcs/mcs/linq.cs       2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/linq.cs       2008-01-21 16:52:12 UTC (rev 93414)
@@ -83,7 +83,7 @@
                        protected override MethodGroupExpr DoResolveOverload 
(EmitContext ec)
                        {
                                mg.CustomErrorHandler = this;
-                               MethodGroupExpr rmg = mg.OverloadResolve (ec, 
Arguments, false, loc);
+                               MethodGroupExpr rmg = mg.OverloadResolve (ec, 
ref Arguments, false, loc);
                                return rmg;
                        }
 

Modified: trunk/mcs/mcs/typemanager.cs
===================================================================
--- trunk/mcs/mcs/typemanager.cs        2008-01-21 16:47:35 UTC (rev 93413)
+++ trunk/mcs/mcs/typemanager.cs        2008-01-21 16:52:12 UTC (rev 93414)
@@ -171,13 +171,6 @@
        //
        // These methods are called by code generated by the compiler
        //
-       static public MethodInfo string_concat_string_string;
-       static public MethodInfo string_concat_string_string_string;
-       static public MethodInfo string_concat_string_string_string_string;
-       static public MethodInfo string_concat_string_dot_dot_dot;
-       static public MethodInfo string_concat_object_object;
-       static public MethodInfo string_concat_object_object_object;
-       static public MethodInfo string_concat_object_dot_dot_dot;
        static public MethodInfo string_isinterned_string;
        static public MethodInfo system_type_get_type_from_handle;
        static public MethodInfo bool_movenext_void;
@@ -1233,29 +1226,6 @@
                //
                // Now load the default methods that we use.
                //
-               Type [] string_string = { string_type, string_type };
-               string_concat_string_string = GetMethod (
-                       string_type, "Concat", string_string);
-               Type [] string_string_string = { string_type, string_type, 
string_type };
-               string_concat_string_string_string = GetMethod (
-                       string_type, "Concat", string_string_string);
-               Type [] string_string_string_string = { string_type, 
string_type, string_type, string_type };
-               string_concat_string_string_string_string = GetMethod (
-                       string_type, "Concat", string_string_string_string);
-               Type[] params_string = { GetConstructedType (string_type, "[]") 
};
-               string_concat_string_dot_dot_dot = GetMethod (
-                       string_type, "Concat", params_string);
-
-               Type [] object_object = { object_type, object_type };
-               string_concat_object_object = GetMethod (
-                       string_type, "Concat", object_object);
-               Type [] object_object_object = { object_type, object_type, 
object_type };
-               string_concat_object_object_object = GetMethod (
-                       string_type, "Concat", object_object_object);
-               Type[] params_object = { GetConstructedType (object_type, "[]") 
};
-               string_concat_object_dot_dot_dot = GetMethod (
-                       string_type, "Concat", params_object);
-
                Type [] string_ = { string_type };
                string_isinterned_string = GetMethod (
                        string_type, "IsInterned", string_);

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to