Author: marek
Date: 2007-07-10 14:40:02 -0400 (Tue, 10 Jul 2007)
New Revision: 81734
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/statement.cs
Log:
2007-07-10 Marek Safar <[EMAIL PROTECTED]>
* attribute.cs (Attribute.ResolveConstructor): Uses method group.
* class.cs (ConstructorInitializer.Resolve): Use and keep method group
instead of method. Re-use standard error handling.
(ConstructorInitializer.Emit): Simplified.
* delegate.cs: Updated after Invocation.EmitCall change.
* ecore.cs (GetOperatorTrueOrFalse): Uses MethodGroupExpr only.
(SimpleName.SimpleNameResolve): Set and reset in_transit flag correctly.
(ExtensionMethodGroupExpr): Refactored to use same OverloadResolve
method and don't permanently changing input arguments.
(MethodGroupExpr): Introduced resolved best_candidate, when method group
is resolved it has one of the candidates is the best one which is later
used to emit. Removed a few unused method.
(MethodGroupExpr.MakeUnionSet): Moved from Invocation, it belongs here.
* expression.cs (StaticCallExpr.MakeSimpleCall): Uses method group.
(Binary.ResolveOperator): Ditto.
(ConditionalLogicalOperator.DoResolve): Ditto.
(Invocation): Uses method group.
(Invocation.DoResolve): Simplified.
(Invocation.EmitCall): Removed useless is_static.
(Invocation.Emit): Delegate to method group.
(Invocation.EmitStatement): Simplified.
(New): Uses method group.
(MemberAccess.DoResolve): Don't destroy original expression.
* statement.cs (ForEach.Resolve): Use null for no method arguments.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2007-07-10 18:39:23 UTC (rev 81733)
+++ trunk/mcs/mcs/ChangeLog 2007-07-10 18:40:02 UTC (rev 81734)
@@ -1,3 +1,35 @@
+2007-07-10 Marek Safar <[EMAIL PROTECTED]>
+
+ * attribute.cs (Attribute.ResolveConstructor): Uses method group.
+
+ * class.cs (ConstructorInitializer.Resolve): Use and keep method group
+ instead of method. Re-use standard error handling.
+ (ConstructorInitializer.Emit): Simplified.
+
+ * delegate.cs: Updated after Invocation.EmitCall change.
+
+ * ecore.cs (GetOperatorTrueOrFalse): Uses MethodGroupExpr only.
+ (SimpleName.SimpleNameResolve): Set and reset in_transit flag correctly.
+ (ExtensionMethodGroupExpr): Refactored to use same OverloadResolve
+ method and don't permanently changing input arguments.
+ (MethodGroupExpr): Introduced resolved best_candidate, when method group
+ is resolved it has one of the candidates is the best one which is later
+ used to emit. Removed a few unused method.
+ (MethodGroupExpr.MakeUnionSet): Moved from Invocation, it belongs here.
+
+ * expression.cs (StaticCallExpr.MakeSimpleCall): Uses method group.
+ (Binary.ResolveOperator): Ditto.
+ (ConditionalLogicalOperator.DoResolve): Ditto.
+ (Invocation): Uses method group.
+ (Invocation.DoResolve): Simplified.
+ (Invocation.EmitCall): Removed useless is_static.
+ (Invocation.Emit): Delegate to method group.
+ (Invocation.EmitStatement): Simplified.
+ (New): Uses method group.
+ (MemberAccess.DoResolve): Don't destroy original expression.
+
+ * statement.cs (ForEach.Resolve): Use null for no method arguments.
+
2007-07-04 Marek Safar <[EMAIL PROTECTED]>
* ecore.cs (VarExpr.DoResolveLValue): More restriction checks.
Modified: trunk/mcs/mcs/attribute.cs
===================================================================
--- trunk/mcs/mcs/attribute.cs 2007-07-10 18:39:23 UTC (rev 81733)
+++ trunk/mcs/mcs/attribute.cs 2007-07-10 18:40:02 UTC (rev 81734)
@@ -419,20 +419,21 @@
}
}
- Expression mg = Expression.MemberLookup
(ec.ContainerType,
+ MethodGroupExpr mg = Expression.MemberLookup
(ec.ContainerType,
Type, ".ctor", MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance |
BindingFlags.DeclaredOnly,
- Location);
+ Location) as MethodGroupExpr;
if (mg == null)
return null;
- MethodBase constructor =
((MethodGroupExpr)mg).OverloadResolve (
- ec, PosArguments, false, Location);
-
- if (constructor == null)
+ mg = mg.OverloadResolve (ec, PosArguments, false,
Location);
+ if (mg == null)
return null;
+
+ ConstructorInfo constructor = (ConstructorInfo)mg;
+ // TODO: move to OverloadResolve
ObsoleteAttribute oa =
AttributeTester.GetMethodObsoleteAttribute (constructor);
if (oa != null &&
!Owner.ResolveContext.IsInObsoleteScope) {
AttributeTester.Report_ObsoleteMessage (oa,
mg.GetSignatureForError (), mg.Location);
@@ -440,7 +441,7 @@
if (PosArguments == null) {
pos_values = EmptyObject;
- return (ConstructorInfo)constructor;
+ return constructor;
}
ParameterData pd = TypeManager.GetParameterData
(constructor);
Modified: trunk/mcs/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs 2007-07-10 18:39:23 UTC (rev 81733)
+++ trunk/mcs/mcs/class.cs 2007-07-10 18:40:02 UTC (rev 81734)
@@ -4590,9 +4590,9 @@
}
public abstract class ConstructorInitializer {
- ArrayList argument_list;
- protected ConstructorInfo base_constructor;
- Location loc;
+ readonly ArrayList argument_list;
+ MethodGroupExpr base_constructor_group;
+ readonly Location loc;
public ConstructorInitializer (ArrayList argument_list,
Location loc)
{
@@ -4608,9 +4608,7 @@
public bool Resolve (ConstructorBuilder caller_builder, Block
block, EmitContext ec)
{
- Expression base_constructor_group;
Type t;
- bool error = false;
ec.CurrentBlock = block;
@@ -4648,54 +4646,55 @@
base_constructor_group = Expression.MemberLookup (
ec.ContainerType, t, ".ctor",
MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance |
BindingFlags.DeclaredOnly,
- loc);
+ loc) as MethodGroupExpr;
- if (base_constructor_group == null){
- error = true;
+ bool error_non_public = false;
+ if (base_constructor_group == null) {
+ error_non_public = true;
base_constructor_group =
Expression.MemberLookup (
- t, null, t, ".ctor",
MemberTypes.Constructor,
- BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.DeclaredOnly,
- loc);
+ ec.ContainerType, t, ".ctor",
MemberTypes.Constructor,
+ BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.DeclaredOnly,
+ loc) as MethodGroupExpr;
+
+ // TODO: because of MemberLookup is so broken.
It does not return private members
+ // even if you ask for them.
+ if (base_constructor_group == null) {
+ Expression.MemberLookupFailed
(ec.ContainerType, t, t, ".ctor", null, true, loc);
+ return false;
+ }
}
- int errors = Report.Errors;
- if (base_constructor_group != null)
- base_constructor = (ConstructorInfo)
- ((MethodGroupExpr)
base_constructor_group).OverloadResolve (
- ec, argument_list,
- false, loc);
+ base_constructor_group =
base_constructor_group.OverloadResolve (
+ ec, argument_list, false, loc);
- if (base_constructor == null) {
- if (errors == Report.Errors)
- Invocation.Error_WrongNumArguments
(loc, TypeManager.CSharpSignature (caller_builder),
- argument_list == null ? 0 :
argument_list.Count);
+ if (base_constructor_group == null)
return false;
- }
- if (error) {
- Report.SymbolRelatedToPreviousError
(base_constructor);
- Expression.ErrorIsInaccesible (loc,
TypeManager.CSharpSignature (base_constructor));
- base_constructor = null;
- return false;
- }
+ ConstructorInfo base_ctor =
(ConstructorInfo)base_constructor_group;
- if (base_constructor == caller_builder){
+ if (base_ctor == caller_builder){
Report.Error (516, loc, "Constructor `{0}'
cannot call itself", TypeManager.CSharpSignature (caller_builder));
- return false;
}
+ if (error_non_public) {
+ Report.SymbolRelatedToPreviousError (base_ctor);
+ Expression.ErrorIsInaccesible (loc,
TypeManager.CSharpSignature (base_ctor));
+ }
+
return true;
}
- public virtual void Emit (EmitContext ec)
+ public void Emit (EmitContext ec)
{
- if (base_constructor != null){
- ec.Mark (loc, false);
- if (ec.IsStatic)
- Invocation.EmitCall (ec, true, true,
null, base_constructor, argument_list, loc);
- else
- Invocation.EmitCall (ec, true, false,
ec.GetThis (loc), base_constructor, argument_list, loc);
- }
+ // It can be null for static initializers
+ if (base_constructor_group == null)
+ return;
+
+ ec.Mark (loc, false);
+ if (!ec.IsStatic)
+ base_constructor_group.InstanceExpression =
ec.GetThis (loc);
+
+ base_constructor_group.EmitCall (ec, argument_list);
}
}
Modified: trunk/mcs/mcs/delegate.cs
===================================================================
--- trunk/mcs/mcs/delegate.cs 2007-07-10 18:39:23 UTC (rev 81733)
+++ trunk/mcs/mcs/delegate.cs 2007-07-10 18:40:02 UTC (rev 81734)
@@ -960,7 +960,7 @@
// Invocation on delegates call the virtual Invoke
member
// so we are always `instance' calls
//
- Invocation.EmitCall (ec, false, false, InstanceExpr,
method, Arguments, loc);
+ Invocation.EmitCall (ec, false, InstanceExpr, method,
Arguments, loc);
}
public override void EmitStatement (EmitContext ec)
Modified: trunk/mcs/mcs/ecore.cs
===================================================================
--- trunk/mcs/mcs/ecore.cs 2007-07-10 18:39:23 UTC (rev 81733)
+++ trunk/mcs/mcs/ecore.cs 2007-07-10 18:40:02 UTC (rev 81734)
@@ -846,7 +846,7 @@
}
MemberList ml = TypeManager.FindMembers (queried_type,
MemberTypes.Constructor,
-
BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public |
BindingFlags.DeclaredOnly, null, null);
+
BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic |
BindingFlags.DeclaredOnly, null, null);
if (name == ".ctor" && ml.Count == 0)
{
Report.Error (143, loc, "The type `{0}' has no
constructors defined", TypeManager.CSharpName (queried_type));
@@ -877,27 +877,26 @@
static Expression GetOperatorTrueOrFalse (EmitContext ec,
Expression e, bool is_true, Location loc)
{
- MethodBase method;
- Expression operator_group;
+ MethodGroupExpr operator_group;
#if GMCS_SOURCE
if (TypeManager.IsNullableType (e.Type))
return new Nullable.OperatorTrueOrFalse (e,
is_true, loc).Resolve (ec);
#endif
- operator_group = MethodLookup (ec.ContainerType,
e.Type, is_true ? "op_True" : "op_False", loc);
+ operator_group = MethodLookup (ec.ContainerType,
e.Type, is_true ? "op_True" : "op_False", loc) as MethodGroupExpr;
if (operator_group == null)
return null;
- ArrayList arguments = new ArrayList ();
+ ArrayList arguments = new ArrayList (1);
arguments.Add (new Argument (e,
Argument.AType.Expression));
- method = ((MethodGroupExpr)
operator_group).OverloadResolve (
+ operator_group = operator_group.OverloadResolve (
ec, arguments, false, loc);
- if (method == null)
+ if (operator_group == null)
return null;
- return new StaticCallExpr ((MethodInfo) method,
arguments, loc);
+ return new StaticCallExpr ((MethodInfo) operator_group,
arguments, loc);
}
/// <summary>
@@ -2209,9 +2208,11 @@
{
if (in_transit)
return null;
- in_transit = true;
+ in_transit = true;
Expression e = DoSimpleNameResolve (ec, right_side,
intermediate);
+ in_transit = false;
+
if (e == null)
return null;
@@ -2905,7 +2906,6 @@
if (!IsStatic) {
SimpleName.Error_ObjectRefRequired (ec,
loc, GetSignatureForError ());
- return null;
}
return this;
@@ -2956,7 +2956,8 @@
///
public class ExtensionMethodGroupExpr : MethodGroupExpr
{
- NamespaceEntry namespaceEntry;
+ readonly NamespaceEntry namespaceEntry;
+ public Expression ExtensionExpression;
public ExtensionMethodGroupExpr (ArrayList list, NamespaceEntry
n, Type extensionType, Location l)
: base (list, l)
@@ -2977,45 +2978,71 @@
get { return namespaceEntry == null; }
}
- public override MethodBase OverloadExtensionResolve
(EmitContext ec, ref ArrayList arguments, ref MethodGroupExpr mg,
- Expression expr, Location loc)
+ public override void EmitArguments (EmitContext ec, ArrayList
arguments)
{
if (arguments == null)
+ arguments = new ArrayList (1);
+ arguments.Insert (0, new Argument
(ExtensionExpression));
+ base.EmitArguments (ec, arguments);
+ }
+
+ public override void EmitCall (EmitContext ec, ArrayList
arguments)
+ {
+ if (arguments == null)
arguments = new ArrayList (1);
+ arguments.Insert (0, new Argument
(ExtensionExpression));
+ base.EmitCall (ec, arguments);
+ }
- Expression extension_argument =
((MemberAccess)expr).Expr;
- if ((extension_argument.eclass & (ExprClass.Value |
ExprClass.Variable)) == 0)
- return null;
+ public override MethodGroupExpr OverloadResolve (EmitContext
ec, ArrayList arguments, bool may_fail, Location loc)
+ {
+ if ((ExtensionExpression.eclass & (ExprClass.Value |
ExprClass.Variable)) == 0)
+ return base.OverloadResolve (ec, arguments,
may_fail, loc);
- Argument a = new Argument (extension_argument);
- a.Resolve (ec, loc);
- arguments.Insert (0, a);
+ if (arguments == null)
+ arguments = new ArrayList (1);
- mg = this;
- do {
- MethodBase method = mg.OverloadResolve (ec,
arguments, true, loc);
- if (method != null)
- return method;
+ arguments.Insert (0, new Argument
(ExtensionExpression));
+ MethodGroupExpr mg = ResolveOverloadExtensions (ec,
arguments, namespaceEntry, loc);
- ExtensionMethodGroupExpr e =
namespaceEntry.LookupExtensionMethod (type, null, Name);
- if (e == null)
- return mg.OverloadResolve (ec,
arguments, false, loc);
+ // Restore original arguments
+ arguments.RemoveAt (0);
- mg = e;
- namespaceEntry = e.namespaceEntry;
- } while (true);
+ if (mg != null)
+ return mg;
+
+ if (!may_fail)
+ return base.OverloadResolve (ec, arguments,
may_fail, loc);
+
+ return null;
}
+
+ MethodGroupExpr ResolveOverloadExtensions (EmitContext ec,
ArrayList arguments, NamespaceEntry ns, Location loc)
+ {
+ // Use normal resolve rules
+ MethodGroupExpr mg = base.OverloadResolve (ec,
arguments, true, loc);
+ if (mg != null)
+ return mg;
+
+ // Search continues
+ ExtensionMethodGroupExpr e = ns.LookupExtensionMethod
(type, null, Name);
+ if (e == null)
+ return null;
+
+ e.ExtensionExpression = ExtensionExpression;
+ return e.ResolveOverloadExtensions (ec, arguments,
e.namespaceEntry, loc);
+ }
}
/// <summary>
- /// MethodGroup Expression.
- ///
- /// This is a fully resolved expression that evaluates to a type
+ /// MethodGroupExpr represents a group of method candidates which
+ /// can be resolved to the best method overload
/// </summary>
public class MethodGroupExpr : MemberExpr {
- public MethodBase [] Methods;
- bool has_type_arguments = false;
- bool identical_type_name = false;
+ public readonly MethodBase [] Methods;
+ MethodBase best_candidate;
+ bool has_type_arguments;
+ bool identical_type_name;
bool is_base;
public MethodGroupExpr (MemberInfo [] mi, Location l)
@@ -3090,6 +3117,9 @@
public override string GetSignatureForError ()
{
+ if (best_candidate != null)
+ return TypeManager.CSharpSignature
(best_candidate);
+
return TypeManager.CSharpSignature (Methods [0]);
}
@@ -3118,7 +3148,17 @@
return false;
}
}
+
+ public static explicit operator ConstructorInfo
(MethodGroupExpr mg)
+ {
+ return (ConstructorInfo)mg.best_candidate;
+ }
+ public static explicit operator MethodInfo (MethodGroupExpr mg)
+ {
+ return (MethodInfo)mg.best_candidate;
+ }
+
/// <summary>
/// Determines "better conversion" as specified in 14.4.2.3
///
@@ -3360,9 +3400,6 @@
override public Expression DoResolve (EmitContext ec)
{
- if (!IsInstance)
- InstanceExpression = null;
-
if (InstanceExpression != null) {
InstanceExpression =
InstanceExpression.DoResolve (ec);
if (InstanceExpression == null)
@@ -3382,6 +3419,16 @@
{
ReportUsageError ();
}
+
+ public virtual void EmitArguments (EmitContext ec, ArrayList
arguments)
+ {
+ Invocation.EmitArguments (ec, best_candidate,
arguments, false, null);
+ }
+
+ public virtual void EmitCall (EmitContext ec, ArrayList
arguments)
+ {
+ Invocation.EmitCall (ec, IsBase, InstanceExpression,
best_candidate, arguments, loc);
+ }
public static bool IsAncestralType (Type first_type, Type
second_type)
{
@@ -3414,7 +3461,52 @@
return true;
}
+
+ public static MethodGroupExpr MakeUnionSet (Expression mg1,
Expression mg2, Location loc)
+ {
+ MemberInfo [] miset;
+ MethodGroupExpr union;
+ if (mg1 == null) {
+ if (mg2 == null)
+ return null;
+ return (MethodGroupExpr) mg2;
+ } else {
+ if (mg2 == null)
+ return (MethodGroupExpr) mg1;
+ }
+
+ MethodGroupExpr left_set = null, right_set = null;
+ int length1 = 0, length2 = 0;
+
+ left_set = (MethodGroupExpr) mg1;
+ length1 = left_set.Methods.Length;
+
+ right_set = (MethodGroupExpr) mg2;
+ length2 = right_set.Methods.Length;
+
+ ArrayList common = new ArrayList ();
+
+ foreach (MethodBase r in right_set.Methods){
+ if (TypeManager.ArrayContainsMethod
(left_set.Methods, r))
+ common.Add (r);
+ }
+
+ miset = new MemberInfo [length1 + length2 -
common.Count];
+ left_set.Methods.CopyTo (miset, 0);
+
+ int k = length1;
+
+ foreach (MethodBase r in right_set.Methods) {
+ if (!common.Contains (r))
+ miset [k++] = r;
+ }
+
+ union = new MethodGroupExpr (miset, loc);
+
+ return union;
+ }
+
static Type MoreSpecific (Type p, Type q)
{
if (TypeManager.IsGenericParameter (p) &&
!TypeManager.IsGenericParameter (q))
@@ -3458,26 +3550,6 @@
return null;
}
- public virtual MethodBase OverloadExtensionResolve (EmitContext
ec, ref ArrayList arguments, ref MethodGroupExpr mg,
- Expression expr, Location loc)
- {
- MethodBase method = OverloadResolve (ec, arguments,
true, loc);
- if (method != null) {
- mg = this;
- return method;
- }
-
- MemberAccess mexpr = expr as MemberAccess;
- if (mexpr != null) {
- ExtensionMethodGroupExpr emg =
ec.DeclContainer.LookupExtensionMethod (mexpr.Expr.Type, Name);
- if (emg != null) {
- return OverloadExtensionResolve (ec,
ref arguments, ref mg, expr, loc);
- }
- }
-
- return OverloadResolve (ec, arguments, false, loc);
- }
-
/// <summary>
/// Find the Applicable Function Members (7.4.2.1)
///
@@ -3494,10 +3566,9 @@
/// that is the best match of me on Arguments.
///
/// </summary>
- public virtual MethodBase OverloadResolve (EmitContext ec,
ArrayList Arguments,
+ public virtual MethodGroupExpr OverloadResolve (EmitContext ec,
ArrayList Arguments,
bool may_fail, Location loc)
{
- MethodBase method = null;
bool method_params = false;
Type applicable_type = null;
int arg_count = 0;
@@ -3734,20 +3805,20 @@
// Now we actually find the best method
//
- method = (MethodBase) candidates [0];
- method_params = candidate_to_form != null &&
candidate_to_form.Contains (method);
+ best_candidate = (MethodBase) candidates [0];
+ 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];
- if (candidate == method)
+ if (candidate == best_candidate)
continue;
bool cand_params = candidate_to_form != null &&
candidate_to_form.Contains (candidate);
if (BetterFunction (ec, Arguments, arg_count,
candidate, cand_params,
- method, method_params)) {
- method = candidate;
+ best_candidate, method_params)) {
+ best_candidate = candidate;
method_params = cand_params;
}
}
@@ -3759,12 +3830,12 @@
for (int ix = 0; ix < candidate_top; ix++) {
MethodBase candidate = (MethodBase) candidates
[ix];
- if (candidate == method)
+ if (candidate == best_candidate)
continue;
bool cand_params = candidate_to_form != null &&
candidate_to_form.Contains (candidate);
if (!BetterFunction (ec, Arguments, arg_count,
- method, method_params,
+ best_candidate, method_params,
candidate, cand_params))
{
if (!may_fail)
@@ -3774,24 +3845,24 @@
}
if (ambiguous != null) {
- Report.SymbolRelatedToPreviousError (method);
+ Report.SymbolRelatedToPreviousError
(best_candidate);
Report.Error (121, loc, "The call is ambiguous
between the following methods or properties: `{0}' and `{1}'",
- TypeManager.CSharpSignature
(ambiguous), TypeManager.CSharpSignature (method));
- return method;
+ TypeManager.CSharpSignature
(ambiguous), TypeManager.CSharpSignature (best_candidate));
+ return this;
}
//
// If the method is a virtual function, pick an
override closer to the LHS type.
//
- if (!IsBase && method.IsVirtual) {
- if (TypeManager.IsOverride (method))
+ if (!IsBase && best_candidate.IsVirtual) {
+ if (TypeManager.IsOverride (best_candidate))
throw new InternalErrorException (
- "Should not happen. An
'override' method took part in overload resolution: " + method);
+ "Should not happen. An
'override' method took part in overload resolution: " + best_candidate);
if (candidate_overrides != null)
foreach (MethodBase candidate in
candidate_overrides) {
- if (IsOverride (candidate,
method))
- method = candidate;
+ if (IsOverride (candidate,
best_candidate))
+ best_candidate =
candidate;
}
}
@@ -3801,17 +3872,17 @@
// necessary etc. and return if everything is
// all right
//
- if (!Invocation.VerifyArgumentsCompat (ec, Arguments,
arg_count, method,
+ if (!Invocation.VerifyArgumentsCompat (ec, Arguments,
arg_count, best_candidate,
method_params, null, may_fail, loc))
return null;
- if (method == null)
+ if (best_candidate == null)
return null;
- MethodBase the_method =
TypeManager.DropGenericMethodArguments (method);
+ MethodBase the_method =
TypeManager.DropGenericMethodArguments (best_candidate);
#if GMCS_SOURCE
if (the_method.IsGenericMethodDefinition &&
- !ConstraintChecker.CheckConstraints (ec,
the_method, method, loc))
+ !ConstraintChecker.CheckConstraints (ec,
the_method, best_candidate, loc))
return null;
#endif
@@ -3819,46 +3890,9 @@
if (data != null)
data.SetMemberIsUsed ();
- return method;
+ return this;
}
-
-
- bool RemoveMethods (bool keep_static)
- {
- ArrayList smethods = new ArrayList ();
-
- foreach (MethodBase mb in Methods){
- if (mb.IsStatic == keep_static)
- smethods.Add (mb);
- }
-
- if (smethods.Count == 0)
- return false;
-
- Methods = new MethodBase [smethods.Count];
- smethods.CopyTo (Methods, 0);
-
- return true;
- }
- /// <summary>
- /// Removes any instance methods from the MethodGroup, returns
- /// false if the resulting set is empty.
- /// </summary>
- public bool RemoveInstanceMethods ()
- {
- return RemoveMethods (true);
- }
-
- /// <summary>
- /// Removes any static methods from the MethodGroup, returns
- /// false if the resulting set is empty.
- /// </summary>
- public bool RemoveStaticMethods ()
- {
- return RemoveMethods (false);
- }
-
public Expression ResolveGeneric (EmitContext ec, TypeArguments
args)
{
#if GMCS_SOURCE
@@ -4726,7 +4760,7 @@
}
}
- Invocation.EmitCall (ec, IsBase, IsStatic,
InstanceExpression, getter, null, loc, prepared, false);
+ Invocation.EmitCall (ec, IsBase, InstanceExpression,
getter, null, loc, prepared, false);
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
@@ -4767,7 +4801,7 @@
ArrayList args = new ArrayList (1);
args.Add (new Argument (my_source,
Argument.AType.Expression));
- Invocation.EmitCall (ec, IsBase, IsStatic,
InstanceExpression, setter, args, loc, false, prepared);
+ Invocation.EmitCall (ec, IsBase, InstanceExpression,
setter, args, loc, false, prepared);
if (temp != null) {
temp.Emit (ec);
@@ -4937,10 +4971,10 @@
if (source_del.IsAddition)
Invocation.EmitCall (
- ec, false, IsStatic,
InstanceExpression, add_accessor, args, loc);
+ ec, false, InstanceExpression,
add_accessor, args, loc);
else
Invocation.EmitCall (
- ec, false, IsStatic,
InstanceExpression, remove_accessor, args, loc);
+ ec, false, InstanceExpression,
remove_accessor, args, loc);
}
}
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2007-07-10 18:39:23 UTC (rev 81733)
+++ trunk/mcs/mcs/expression.cs 2007-07-10 18:40:02 UTC (rev 81734)
@@ -57,7 +57,6 @@
Expression e, Location
loc)
{
ArrayList args;
- MethodBase method;
args = new ArrayList (1);
Argument a = new Argument (e,
Argument.AType.Expression);
@@ -67,13 +66,12 @@
return null;
args.Add (a);
- method = mg.OverloadResolve (
- ec, args, false, loc);
+ mg = mg.OverloadResolve (ec, args, false, loc);
- if (method == null)
+ if (mg == null)
return null;
- return new StaticCallExpr ((MethodInfo) method, args,
loc);
+ return new StaticCallExpr ((MethodInfo) mg, args, loc);
}
public override void EmitStatement (EmitContext ec)
@@ -1817,7 +1815,7 @@
// Do not perform operator overload resolution when
both sides are
// built-in types
//
- Expression left_operators = null, right_operators =
null;
+ MethodGroupExpr left_operators = null, right_operators
= null;
if (!(TypeManager.IsPrimitiveType (l) &&
TypeManager.IsPrimitiveType (r))) {
//
// Step 1: Perform Operator Overload location
@@ -1825,24 +1823,24 @@
string op = oper_names [(int) oper];
MethodGroupExpr union;
- left_operators = MemberLookup
(ec.ContainerType, l, op, MemberTypes.Method, AllBindingFlags, loc);
+ left_operators = MemberLookup
(ec.ContainerType, l, op, MemberTypes.Method, AllBindingFlags, loc) as
MethodGroupExpr;
if (r != l){
right_operators = MemberLookup (
- ec.ContainerType, r, op,
MemberTypes.Method, AllBindingFlags, loc);
- union = Invocation.MakeUnionSet
(left_operators, right_operators, loc);
+ ec.ContainerType, r, op,
MemberTypes.Method, AllBindingFlags, loc) as MethodGroupExpr;
+ union = MethodGroupExpr.MakeUnionSet
(left_operators, right_operators, loc);
} else
- union = (MethodGroupExpr)
left_operators;
+ union = left_operators;
if (union != null) {
ArrayList args = new ArrayList (2);
args.Add (new Argument (left,
Argument.AType.Expression));
args.Add (new Argument (right,
Argument.AType.Expression));
- MethodBase method =
union.OverloadResolve (ec, args, true, Location.Null);
+ union = union.OverloadResolve (ec,
args, true, Location.Null);
- if (method != null) {
- MethodInfo mi = (MethodInfo)
method;
- return new BinaryMethod
(mi.ReturnType, method, args);
+ if (union != null) {
+ MethodInfo mi = (MethodInfo)
union;
+ return new BinaryMethod
(mi.ReturnType, mi, args);
}
}
}
@@ -1978,9 +1976,7 @@
ArrayList args = new ArrayList
(2);
args.Add (new Argument (left,
Argument.AType.Expression));
args.Add (new Argument (left,
Argument.AType.Expression));
- MethodBase method =
((MethodGroupExpr)left_operators).OverloadResolve (
- ec, args, true,
Location.Null);
- if (method != null)
+ if
(left_operators.OverloadResolve (ec, args, true, Location.Null) != null)
Warning_UnintendedReferenceComparison (loc, "right", l);
}
@@ -1989,9 +1985,7 @@
ArrayList args = new ArrayList
(2);
args.Add (new Argument (right,
Argument.AType.Expression));
args.Add (new Argument (right,
Argument.AType.Expression));
- MethodBase method =
((MethodGroupExpr)right_operators).OverloadResolve (
- ec, args, true,
Location.Null);
- if (method != null)
+ if
(right_operators.OverloadResolve (ec, args, true, Location.Null) != null)
Warning_UnintendedReferenceComparison (loc, "left", r);
}
@@ -2184,14 +2178,14 @@
return this;
}
- left_operators = l == TypeManager.bool_type ?
+ Expression left_operators_e = l ==
TypeManager.bool_type ?
left : Convert.ImplicitUserConversion
(ec, left, TypeManager.bool_type, loc);
- right_operators = r == TypeManager.bool_type ?
+ Expression right_operators_e = r ==
TypeManager.bool_type ?
right : Convert.ImplicitUserConversion
(ec, right, TypeManager.bool_type, loc);
- if (left_operators != null && right_operators
!= null) {
- left = left_operators;
- right = right_operators;
+ if (left_operators_e != null &&
right_operators_e != null) {
+ left = left_operators_e;
+ right = right_operators_e;
type = TypeManager.bool_type;
return this;
}
@@ -2285,8 +2279,8 @@
ArrayList args = new ArrayList (2);
args.Add (new Argument (left,
Argument.AType.Expression));
args.Add (new Argument (right,
Argument.AType.Expression));
- MethodBase method = ops.OverloadResolve (ec,
args, true, Location.Null);
- return new BinaryMethod (type, method, args);
+ ops = ops.OverloadResolve (ec, args, true,
Location.Null);
+ return new BinaryMethod (type, (MethodInfo)ops,
args);
}
return this;
@@ -3142,10 +3136,9 @@
public override Expression DoResolve (EmitContext ec)
{
- MethodInfo method;
- Expression operator_group;
+ MethodGroupExpr operator_group;
- operator_group = MethodLookup (ec.ContainerType, type,
is_and ? "op_BitwiseAnd" : "op_BitwiseOr", loc);
+ operator_group = MethodLookup (ec.ContainerType, type,
is_and ? "op_BitwiseAnd" : "op_BitwiseOr", loc) as MethodGroupExpr;
if (operator_group == null) {
Error19 ();
return null;
@@ -3156,14 +3149,13 @@
ArrayList arguments = new ArrayList (2);
arguments.Add (new Argument (left_temp,
Argument.AType.Expression));
arguments.Add (new Argument (right,
Argument.AType.Expression));
- method = ((MethodGroupExpr)
operator_group).OverloadResolve (
- ec, arguments, false, loc)
- as MethodInfo;
- if (method == null) {
+ operator_group = operator_group.OverloadResolve (ec,
arguments, false, loc);
+ if (operator_group == null) {
Error19 ();
return null;
}
+ MethodInfo method = (MethodInfo)operator_group;
if (method.ReturnType != type) {
Report.Error (217, loc, "In order to be
applicable as a short circuit operator a user-defined logical operator `{0}' " +
"must have the same return type
as the type of its 2 parameters", TypeManager.CSharpSignature (method));
@@ -4032,31 +4024,26 @@
/// Invocation of methods or delegates.
/// </summary>
public class Invocation : ExpressionStatement {
- public ArrayList Arguments;
-
+ ArrayList Arguments;
Expression expr;
- MethodBase method = null;
+ MethodGroupExpr mg;
//
// arguments is an ArrayList, but we do not want to typecast,
// as it might be null.
//
- // FIXME: only allow expr to be a method invocation or a
- // delegate invocation (7.5.5)
- //
public Invocation (Expression expr, ArrayList arguments)
{
- this.expr = expr;
+ SimpleName sn = expr as SimpleName;
+ if (sn != null)
+ this.expr = sn.GetMethodGroup ();
+ else
+ this.expr = expr;
+
Arguments = arguments;
loc = expr.Location;
}
- public Expression Expr {
- get {
- return expr;
- }
- }
-
public static string FullMethodDesc (MethodBase mb)
{
if (mb == null)
@@ -4074,51 +4061,6 @@
return sb.ToString ();
}
- public static MethodGroupExpr MakeUnionSet (Expression mg1,
Expression mg2, Location loc)
- {
- MemberInfo [] miset;
- MethodGroupExpr union;
-
- if (mg1 == null) {
- if (mg2 == null)
- return null;
- return (MethodGroupExpr) mg2;
- } else {
- if (mg2 == null)
- return (MethodGroupExpr) mg1;
- }
-
- MethodGroupExpr left_set = null, right_set = null;
- int length1 = 0, length2 = 0;
-
- left_set = (MethodGroupExpr) mg1;
- length1 = left_set.Methods.Length;
-
- right_set = (MethodGroupExpr) mg2;
- length2 = right_set.Methods.Length;
-
- ArrayList common = new ArrayList ();
-
- foreach (MethodBase r in right_set.Methods){
- if (TypeManager.ArrayContainsMethod
(left_set.Methods, r))
- common.Add (r);
- }
-
- miset = new MemberInfo [length1 + length2 -
common.Count];
- left_set.Methods.CopyTo (miset, 0);
-
- int k = length1;
-
- foreach (MethodBase r in right_set.Methods) {
- if (!common.Contains (r))
- miset [k++] = r;
- }
-
- union = new MethodGroupExpr (miset, loc);
-
- return union;
- }
-
public static bool IsParamsMethodApplicable (EmitContext ec,
MethodGroupExpr me,
ArrayList
arguments, int arg_count,
ref MethodBase
candidate)
@@ -4421,26 +4363,13 @@
return false;
}
- private bool resolved = false;
public override Expression DoResolve (EmitContext ec)
{
- if (resolved)
- return this.method == null ? null : this;
-
- resolved = true;
- //
- // First, resolve the expression that is used to
- // trigger the invocation
- //
- SimpleName sn = expr as SimpleName;
- if (sn != null)
- expr = sn.GetMethodGroup ();
-
Expression expr_resolved = expr.Resolve (ec,
ResolveFlags.VariableOrValue | ResolveFlags.MethodGroup);
if (expr_resolved == null)
return null;
- MethodGroupExpr mg = expr_resolved as MethodGroupExpr;
+ mg = expr_resolved as MethodGroupExpr;
if (mg == null) {
Type expr_type = expr_resolved.Type;
@@ -4462,28 +4391,26 @@
}
}
- MethodBase method = mg.OverloadExtensionResolve (ec,
ref Arguments, ref mg, expr, loc);
- if (method == null)
+ mg = mg.OverloadResolve (ec, Arguments, false, loc);
+ if (mg == null)
return null;
- expr = mg;
-
- MethodInfo mi = method as MethodInfo;
- if (mi != null) {
- type = TypeManager.TypeToCoreType
(mi.ReturnType);
+ MethodInfo method = (MethodInfo)mg;
+ if (method != null) {
+ type = TypeManager.TypeToCoreType
(method.ReturnType);
Expression iexpr = mg.InstanceExpression;
- if (mi.IsStatic) {
+ if (method.IsStatic) {
if (iexpr == null ||
iexpr is This || iexpr is
EmptyExpression ||
mg.IdenticalTypeName) {
mg.InstanceExpression = null;
} else {
- MemberExpr.error176 (loc,
TypeManager.CSharpSignature (mi));
+ MemberExpr.error176 (loc,
mg.GetSignatureForError ());
return null;
}
} else {
if (iexpr == null || iexpr is
EmptyExpression) {
-
SimpleName.Error_ObjectRefRequired (ec, loc, TypeManager.CSharpSignature (mi));
+
SimpleName.Error_ObjectRefRequired (ec, loc, mg.GetSignatureForError ());
return null;
}
}
@@ -4534,7 +4461,6 @@
}
eclass = ExprClass.Value;
- this.method = method;
return this;
}
@@ -4707,10 +4633,10 @@
/// Arguments is the list of arguments to pass to the method
or constructor.
/// </remarks>
public static void EmitCall (EmitContext ec, bool is_base,
- bool is_static, Expression
instance_expr,
+ Expression instance_expr,
MethodBase method, ArrayList
Arguments, Location loc)
{
- EmitCall (ec, is_base, is_static, instance_expr,
method, Arguments, loc, false, false);
+ EmitCall (ec, is_base, instance_expr, method,
Arguments, loc, false, false);
}
// `dup_args' leaves an extra copy of the arguments on the stack
@@ -4720,7 +4646,7 @@
// would have the same set of arguments. However, each argument
would
// only have been evaluated once.
public static void EmitCall (EmitContext ec, bool is_base,
- bool is_static, Expression
instance_expr,
+ Expression instance_expr,
MethodBase method, ArrayList
Arguments, Location loc,
bool dup_args, bool omit_args)
{
@@ -4767,6 +4693,7 @@
if (IsMethodExcluded (method))
return;
+ bool is_static = method.IsStatic;
if (!is_static){
if (instance_expr == EmptyExpression.Null) {
SimpleName.Error_ObjectRefRequired (ec,
loc, TypeManager.CSharpSignature (method));
@@ -4868,9 +4795,7 @@
public override void Emit (EmitContext ec)
{
- MethodGroupExpr mg = (MethodGroupExpr) this.expr;
-
- EmitCall (ec, mg.IsBase, method.IsStatic,
mg.InstanceExpression, method, Arguments, loc);
+ mg.EmitCall (ec, Arguments);
}
public override void EmitStatement (EmitContext ec)
@@ -4880,11 +4805,8 @@
//
// Pop the return value if there is one
//
- if (method is MethodInfo){
- Type ret = ((MethodInfo)method).ReturnType;
- if (TypeManager.TypeToCoreType (ret) !=
TypeManager.void_type)
- ec.ig.Emit (OpCodes.Pop);
- }
+ if (TypeManager.TypeToCoreType (type) !=
TypeManager.void_type)
+ ec.ig.Emit (OpCodes.Pop);
}
protected override void CloneTo (CloneContext clonectx,
Expression t)
@@ -5023,7 +4945,7 @@
/// Implements the new expression
/// </summary>
public class New : ExpressionStatement, IMemoryLocation {
- public ArrayList Arguments;
+ ArrayList Arguments;
//
// During bootstrap, it contains the RequestedType,
@@ -5032,7 +4954,7 @@
//
public Expression RequestedType;
- MethodBase method = null;
+ MethodGroupExpr method;
//
// If set, the new expression is for a value_target, and
@@ -5251,9 +5173,9 @@
if (ml == null)
return null;
- MethodGroupExpr mg = ml as MethodGroupExpr;
+ method = ml as MethodGroupExpr;
- if (mg == null) {
+ if (method == null) {
ml.Error_UnexpectedKind (ec.DeclContainer,
"method group", loc);
return null;
}
@@ -5264,8 +5186,8 @@
return null;
}
}
-
- method = mg.OverloadResolve (ec, Arguments, false, loc);
+
+ method = method.OverloadResolve (ec, Arguments, false,
loc);
if (method == null) {
if (almostMatchedMembers.Count != 0)
MemberLookupFailed (ec.ContainerType,
type, type, ".ctor", null, true, loc);
@@ -5363,12 +5285,12 @@
}
if (method != null)
- Invocation.EmitArguments (ec, method,
Arguments, false, null);
+ method.EmitArguments (ec, Arguments);
if (is_value_type){
if (method == null)
ig.Emit (OpCodes.Initobj, type);
- else
+ else
ig.Emit (OpCodes.Call,
(ConstructorInfo) method);
if (need_value_on_stack){
value_target.Emit (ec);
@@ -5428,13 +5350,12 @@
IMemoryLocation ml = (IMemoryLocation) value_target;
ml.AddressOf (ec, AddressOp.Store);
- if (method != null)
- Invocation.EmitArguments (ec, method,
Arguments, false, null);
-
- if (method == null)
+ if (method == null) {
ec.ig.Emit (OpCodes.Initobj, type);
- else
+ } else {
+ method.EmitArguments (ec, Arguments);
ec.ig.Emit (OpCodes.Call, (ConstructorInfo)
method);
+ }
((IMemoryLocation) value_target).AddressOf (ec, Mode);
}
@@ -6823,10 +6744,6 @@
TypeArguments args;
- public Expression Expr {
- get { return expr; }
- }
-
protected string LookupIdentifier {
get { return MemberName.MakeName (Identifier, args); }
}
@@ -6846,15 +6763,15 @@
//
SimpleName original = expr as SimpleName;
- expr = expr.Resolve (ec,
+ Expression expr_resolved = expr.Resolve (ec,
ResolveFlags.VariableOrValue |
ResolveFlags.Type |
ResolveFlags.Intermediate |
ResolveFlags.DisableStructFlowAnalysis);
- if (expr == null)
+ if (expr_resolved == null)
return null;
- if (expr is Namespace) {
- Namespace ns = (Namespace) expr;
+ if (expr_resolved is Namespace) {
+ Namespace ns = (Namespace) expr_resolved;
FullNamedExpression retval = ns.Lookup
(ec.DeclContainer, LookupIdentifier, loc);
#if GMCS_SOURCE
if ((retval != null) && (args != null))
@@ -6866,8 +6783,8 @@
return retval;
}
- Type expr_type = expr.Type;
- if (expr_type.IsPointer || expr_type ==
TypeManager.void_type || expr is NullLiteral){
+ Type expr_type = expr_resolved.Type;
+ if (expr_type.IsPointer || expr_type ==
TypeManager.void_type || expr_resolved is NullLiteral){
Unary.Error_OperatorCannotBeApplied (loc, ".",
expr_type);
return null;
}
@@ -6876,7 +6793,7 @@
return null;
}
- Constant c = expr as Constant;
+ Constant c = expr_resolved as Constant;
if (c != null && c.GetValue () == null) {
Report.Warning (1720, 1, loc, "Expression will
always cause a `{0}'",
"System.NullReferenceException");
@@ -6892,9 +6809,11 @@
}
#endif
if (member_lookup == null) {
- member_lookup =
ec.DeclContainer.LookupExtensionMethod (expr_type, Identifier);
- if (member_lookup != null)
- return member_lookup.DoResolve (ec);
+ ExtensionMethodGroupExpr ex_method_lookup =
ec.DeclContainer.LookupExtensionMethod (expr_type, Identifier);
+ if (ex_method_lookup != null) {
+ ex_method_lookup.ExtensionExpression =
expr_resolved;
+ return ex_method_lookup.DoResolve (ec);
+ }
MemberLookupFailed (
ec.ContainerType, expr_type, expr_type,
Identifier, null, true, loc);
@@ -6903,8 +6822,8 @@
TypeExpr texpr = member_lookup as TypeExpr;
if (texpr != null) {
- if (!(expr is TypeExpr) &&
- (original == null ||
!original.IdenticalNameAndTypeName (ec, expr, loc))) {
+ if (!(expr_resolved is TypeExpr) &&
+ (original == null ||
!original.IdenticalNameAndTypeName (ec, expr_resolved, loc))) {
Report.Error (572, loc, "`{0}': cannot
reference a type through an expression; try `{1}' instead",
Identifier,
member_lookup.GetSignatureForError ());
return null;
@@ -6917,7 +6836,7 @@
}
#if GMCS_SOURCE
- ConstructedType ct = expr as ConstructedType;
+ ConstructedType ct = expr_resolved as
ConstructedType;
if (ct != null) {
//
// When looking up a nested type in a
generic instance
@@ -6936,7 +6855,7 @@
}
MemberExpr me = (MemberExpr) member_lookup;
- member_lookup = me.ResolveMemberAccess (ec, expr, loc,
original);
+ member_lookup = me.ResolveMemberAccess (ec,
expr_resolved, loc, original);
if (member_lookup == null)
return null;
@@ -6951,7 +6870,7 @@
if (original != null && !TypeManager.IsValueType
(expr_type)) {
me = member_lookup as MemberExpr;
if (me != null && me.IsInstance) {
- LocalVariableReference var = expr as
LocalVariableReference;
+ LocalVariableReference var =
expr_resolved as LocalVariableReference;
if (var != null && !var.VerifyAssigned
(ec))
return null;
}
@@ -7996,7 +7915,7 @@
public void Emit (EmitContext ec, bool leave_copy)
{
- Invocation.EmitCall (ec, is_base_indexer, false,
instance_expr, get, arguments, loc, prepared, false);
+ Invocation.EmitCall (ec, is_base_indexer,
instance_expr, get, arguments, loc, prepared, false);
if (leave_copy) {
ec.ig.Emit (OpCodes.Dup);
temp = new LocalTemporary (Type);
@@ -8028,7 +7947,7 @@
a.Expr = temp;
}
- Invocation.EmitCall (ec, is_base_indexer, false,
instance_expr, set, set_arguments, loc, false, prepared);
+ Invocation.EmitCall (ec, is_base_indexer,
instance_expr, set, set_arguments, loc, false, prepared);
if (temp != null) {
temp.Emit (ec);
Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs 2007-07-10 18:39:23 UTC (rev 81733)
+++ trunk/mcs/mcs/statement.cs 2007-07-10 18:40:02 UTC (rev 81734)
@@ -5224,7 +5224,7 @@
enumerator = new TemporaryVariable
(enumerator_type, loc);
enumerator.Resolve (ec);
- init = new Invocation (get_enumerator, new
ArrayList ());
+ init = new Invocation (get_enumerator, null);
init = init.Resolve (ec);
if (init == null)
return false;
@@ -5235,7 +5235,7 @@
MethodGroupExpr mg = new
MethodGroupExpr (mi, loc);
mg.InstanceExpression = enumerator;
- move_next_expr = new Invocation (mg,
new ArrayList ());
+ move_next_expr = new Invocation (mg,
null);
}
get_current.InstanceExpression = enumerator;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches