Author: sudha
Date: 2005-05-25 05:42:42 -0400 (Wed, 25 May 2005)
New Revision: 44984

Modified:
   trunk/mcs/mbas/ChangeLog
   trunk/mcs/mbas/expression.cs
   trunk/mcs/mbas/statement.cs
Log:
expression.cs, statement.cs: Late binding for method invocations involving 
object arguments


Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog    2005-05-25 09:37:07 UTC (rev 44983)
+++ trunk/mcs/mbas/ChangeLog    2005-05-25 09:42:42 UTC (rev 44984)
@@ -1,3 +1,9 @@
+2005-05-24 Satya Sudha K <[EMAIL PROTECTED]>
+       * statement.cs : Added few more members like 'memberName' and 
'type_expr' to the 'StatementSequence'
+                        class. Added an appropriate constructor for the same.
+       * expression.cs: Late binding for method invocations involving object 
arguments
+                        
+
 2005-05-23 Satya Sudha K <[EMAIL PROTECTED]>
        * statement.cs : Copying back the arguments (matching 'ByRef' 
parameters) in the reverse 
                         order (starting with the last argument backwards) as 
done by vbc

Modified: trunk/mcs/mbas/expression.cs
===================================================================
--- trunk/mcs/mbas/expression.cs        2005-05-25 09:37:07 UTC (rev 44983)
+++ trunk/mcs/mbas/expression.cs        2005-05-25 09:42:42 UTC (rev 44984)
@@ -3845,16 +3845,26 @@
                        return count;
                }
 
+               static ConversionType IsApplicable (EmitContext ec, ArrayList 
arguments, MethodBase candidate,
+                                                   out bool expanded)
+               {
+                       bool objectArgsPresent;
+                       return IsApplicable (ec, arguments, candidate, out 
expanded, out objectArgsPresent);
+               }
+
                /// <summary>
                ///  Determines if the candidate method is applicable (section 
14.4.2.1)
                ///  to the given set of arguments
                /// </summary>
-               static ConversionType IsApplicable (EmitContext ec, ArrayList 
arguments, MethodBase candidate, out bool expanded)
+               static ConversionType IsApplicable (EmitContext ec, ArrayList 
arguments, MethodBase candidate,
+                                                   out bool expanded, out bool 
objectArgsPresent)
                {
                        int arg_count;
                        Type param_type;
 
-                       expanded = false;
+                       expanded = objectArgsPresent = false;
+                       int num_narr_conv = 0;          // Count the narrowing 
conversion not involving object
+                                                       // arguments
                        
                        if (arguments == null)
                                arg_count = 0;
@@ -3931,13 +3941,23 @@
                                                match = 
CheckParameterAgainstArgument (ec, pd, i, a, param_type);
                                        if (match == ConversionType.None)
                                                return ConversionType.None;
-                                       if (result == ConversionType.None)
+
+                                       if (match == ConversionType.Narrowing) {
                                                result = match;
-                                       else if (match == 
ConversionType.Narrowing)
-                                               result = 
ConversionType.Narrowing;                                      
+                                               if (a.Expr.Type == 
TypeManager.object_type)
+                                                       objectArgsPresent = 
true;
+                                               else {
+                                                       objectArgsPresent = 
false;
+                                                       num_narr_conv ++;
+                                               }
+                                       } else if (result == 
ConversionType.None)
+                                               result = match;
                                }
                        }
 
+                       if (num_narr_conv > 0)  // There were narrowing 
conversions other than those for object arguments
+                               objectArgsPresent = false;
+
                        return result;
                }
 
@@ -3998,6 +4018,13 @@
                        return (m.Name == ((string) filterCriteria));
                }
 
+               public static MethodBase OverloadResolve (EmitContext ec, 
MethodGroupExpr me,
+                                                         ref ArrayList 
Arguments, Location loc)
+               {
+                       bool isLateBindingRequired;
+                       return OverloadResolve (ec, me, ref Arguments, loc, out 
isLateBindingRequired); 
+               }
+
                // We need an overload for OverloadResolve because 
Invocation.DoResolve
                // must pass Arguments by reference, since a later call to 
IsApplicable
                // can change the argument list if optional parameters are 
defined
@@ -4043,20 +4070,29 @@
                ///   loc: The location if we want an error to be reported, or 
a Null
                ///        location for "probing" purposes.
                ///
+               ///   isLateBindingRequired : Flag to indicate that this method 
call is
+               ///                           is a candidate for late binding. 
Set to true if
+               ///                           there is atleast one object 
argument and we get
+               ///                           * Two or more candidates that 
require widening conv
+               ///                           * Two or more candidates require 
narrowing conversions
+               ///                             (for object arguments **only**)
                ///   Returns: The MethodBase (either a ConstructorInfo or a 
MethodInfo)
                ///            that is the best match of me on Arguments.
                ///
                /// </summary>
                public static MethodBase OverloadResolve (EmitContext ec, 
MethodGroupExpr me,
-                                                         ref ArrayList 
Arguments, Location loc)
+                                                         ref ArrayList 
Arguments, Location loc,
+                                                         out bool 
isLateBindingRequired)
                {
                        MethodBase method = null;
                        int argument_count;
                        ArrayList candidates = new ArrayList ();
+                       ArrayList lateBindingCandidates = new ArrayList ();
                        Hashtable expanded_candidates = new Hashtable();
                        int narrow_count = 0;
                        bool narrowing_candidate = false;
                        errorMsg = "";
+                       isLateBindingRequired = false;
                        CaseInsensitiveHashtable namedArgs = new 
CaseInsensitiveHashtable ();
 
                        if (Arguments == null)
@@ -4072,7 +4108,7 @@
 
                        ArrayList newarglist = Arguments;
                        foreach (MethodBase candidate in me.Methods){
-                               bool candidate_expanded;
+                               bool candidate_expanded, object_args_present;
                                newarglist = Arguments;
                                if (argument_count > 0 && namedArgs.Count != 0) 
{
                                        newarglist = ReorderArguments 
(candidate, Arguments, namedArgs, ref errorMsg, loc);
@@ -4080,12 +4116,15 @@
                                                continue;
                                }
 
-                               ConversionType m = IsApplicable (ec, 
newarglist, candidate, out candidate_expanded);
+                               ConversionType m = IsApplicable (ec, 
newarglist, candidate, out candidate_expanded, out object_args_present);
                                if (candidate_expanded)
                                        expanded_candidates [candidate] = 
candidate;
                                if (m == ConversionType.None)
                                        continue;
                                else if (m == ConversionType.Narrowing) {
+                                       if (object_args_present)   // if the 
narrowing conversion was due 
+                                                                  // to the 
argument being an object
+                                               lateBindingCandidates.Add 
(candidate);
                                        if (method == null) {
                                                method = candidate;
                                                narrowing_candidate = true;
@@ -4107,15 +4146,23 @@
                        }
 
                        if (candidates.Count == 0) {
-                               if (narrow_count > 1)
-                                       method = null;
-                               else if (narrow_count == 1)
+                               if (lateBindingCandidates.Count > 1) {
+                                       isLateBindingRequired = true;
+                                       return null;
+                               }
+
+                               if (narrow_count > 1) {
+                                       if (lateBindingCandidates.Count == 1)
+                                               method = (MethodBase) 
lateBindingCandidates [0];
+                                       else 
+                                               method = null;
+                               } else if (narrow_count == 1)
                                        candidates = null;
                        } else if (candidates.Count == 1) {
                                method = (MethodBase)candidates [0];
                                candidates = null;
                        } else
-                               narrow_count = 0;
+                               narrow_count  = 0;
 
                        if (method == null) {
                                //
@@ -4493,9 +4540,20 @@
                        if (expr is MethodGroupExpr) 
                        {
                                MethodGroupExpr mg = (MethodGroupExpr) expr;
-                               method = OverloadResolve (ec, mg, ref 
Arguments, loc);
+                               bool isLateBindingRequired = false;
+                               method = OverloadResolve (ec, mg, ref 
Arguments, loc, out isLateBindingRequired);
                                if (method == null)
                                {
+                                       if (isLateBindingRequired) {
+                                               Expression type_expr = new 
TypeOf (Parser.DecomposeQI (mg.DeclaringType.Name, loc), loc);
+                                               StatementSequence etmp = new 
StatementSequence (ec.CurrentBlock, 
+                                                                       loc, 
null, mg.Name, type_expr, 
+                                                                       
Arguments, is_retval_required, is_left_hand);
+                                               if (! etmp.ResolveArguments 
(ec))
+                                                       return null;
+                                               
etmp.GenerateLateBindingStatements ();
+                                               return etmp.Resolve (ec);
+                                       }
                                        Error (30455,
                                                "Could not find any applicable 
function to invoke for this argument list" + errorMsg);
                                        return null;

Modified: trunk/mcs/mbas/statement.cs
===================================================================
--- trunk/mcs/mbas/statement.cs 2005-05-25 09:37:07 UTC (rev 44983)
+++ trunk/mcs/mbas/statement.cs 2005-05-25 09:42:42 UTC (rev 44984)
@@ -3456,17 +3456,40 @@
                Expression expr;
                bool isRetValRequired;
                bool isLeftHandSide;
+               bool isIndexerAccess;
+               string memberName;
+               Expression type_expr;
 
                public StatementSequence (Block parent, Location loc, 
Expression expr) 
                        : this (parent, loc, expr, null)
                { }
 
+               public StatementSequence (Block parent, Location loc, 
Expression expr, string name, 
+                                         Expression type_expr, ArrayList a, 
bool isRetValRequired,
+                                         bool isLeftHandSide) 
+                       : this (parent, loc, expr, a)
+               {
+                       this.memberName = name;
+                       this.type_expr = type_expr;
+                       this.isRetValRequired = isRetValRequired;
+                       this.isLeftHandSide = isLeftHandSide;
+               }
+
                public StatementSequence (Block parent, Location loc, 
Expression expr, ArrayList a,
                                          bool isRetValRequired, bool 
isLeftHandSide) 
                        : this (parent, loc, expr, a)
                {
                        this.isRetValRequired = isRetValRequired;
                        this.isLeftHandSide = isLeftHandSide;
+                       if (expr is MemberAccess) {
+                               this.expr = ((MemberAccess)expr).Expr;
+                               this.memberName = 
((MemberAccess)expr).Identifier;
+                               this.isIndexerAccess = false;
+                       } else if (expr is IndexerAccess) {
+                               this.expr = ((IndexerAccess) expr).Instance;
+                               this.memberName = "";
+                               this.isIndexerAccess = true;
+                       }
                }
 
                public StatementSequence (Block parent, Location loc, 
Expression expr, ArrayList a) 
@@ -3485,6 +3508,8 @@
                        stmtBlock.IsLateBindingRequired = true;
                        this.loc = loc;
                        this.isRetValRequired = this.isLeftHandSide = false;
+                       this.memberName = "";
+                       this.type_expr = null;
                }
 
                public ArrayList Arguments {
@@ -3578,20 +3603,12 @@
                                stmtBlock.AddStatement (new StatementExpression 
((ExpressionStatement) assign_stmt, loc));
                        }
 
-                       Expression tempExpr = expr;
-                       string memName = "";
-                       bool isIndexerAccess = true;
-                       if (expr is MemberAccess) {
-                               tempExpr = ((MemberAccess)expr).Expr;
-                               memName = ((MemberAccess)expr).Identifier;
-                               isIndexerAccess = false;
-                       } else if (expr is IndexerAccess) {
-                               tempExpr = ((IndexerAccess) expr).Instance;
-                       }
+                       //string memName = "";
+                       //bool isIndexerAccess = true;
 
                        ArrayList invocationArgs = new ArrayList ();
-                       if (isIndexerAccess) {
-                               invocationArgs.Add (new Argument (tempExpr, 
Argument.AType.Expression));
+                       if (isIndexerAccess || memberName == "") {
+                               invocationArgs.Add (new Argument (expr, 
Argument.AType.Expression));
                                invocationArgs.Add (new Argument (v1, 
Argument.AType.Expression));
                                invocationArgs.Add (new Argument 
(NullLiteral.Null, Argument.AType.Expression));
                                Expression tmp = null;
@@ -3604,9 +3621,16 @@
                                stmtBlock.AddStatement (new StatementExpression 
((ExpressionStatement) invStmt, loc));
                                return;
                        }
-                       invocationArgs.Add (new Argument (tempExpr, 
Argument.AType.Expression));
-                       invocationArgs.Add (new Argument (NullLiteral.Null, 
Argument.AType.Expression));
-                       invocationArgs.Add (new Argument (new StringLiteral 
(memName), Argument.AType.Expression));
+
+                       if (expr != null)
+                               invocationArgs.Add (new Argument (expr, 
Argument.AType.Expression));
+                       else
+                               invocationArgs.Add (new Argument 
(NullLiteral.Null, Argument.AType.Expression));
+                       if (type_expr != null)
+                               invocationArgs.Add (new Argument (type_expr, 
Argument.AType.Expression));
+                       else
+                               invocationArgs.Add (new Argument 
(NullLiteral.Null, Argument.AType.Expression));
+                       invocationArgs.Add (new Argument (new StringLiteral 
(memberName), Argument.AType.Expression));
                        invocationArgs.Add (new Argument (v1, 
Argument.AType.Expression));
                        if (ArgumentNames != null && ArgumentNames.Count > 0)
                                invocationArgs.Add (new Argument (v2, 
Argument.AType.Expression));

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to