return false;
}
- static Type TypeParam_EffectiveBaseType (EmitContext ec, GenericConstraints gc)
+ static Type TypeParam_EffectiveBaseType (GenericConstraints gc)
{
ArrayList list = new ArrayList ();
list.Add (gc.EffectiveBaseClass);
GenericConstraints new_gc = TypeManager.GetTypeParameterConstraints (t);
if (new_gc != null)
- list.Add (TypeParam_EffectiveBaseType (ec, new_gc));
+ list.Add (TypeParam_EffectiveBaseType (new_gc));
}
- return FindMostEncompassedType (ec, list);
+ return FindMostEncompassedType (list);
}
- static Expression ImplicitTypeParameterConversion (EmitContext ec, Expression expr,
+ static Expression ImplicitTypeParameterConversion (Expression expr,
Type target_type)
{
Type expr_type = expr.Type;
}
// We're converting from a type parameter which is known to be a reference type.
- Type base_type = TypeParam_EffectiveBaseType (ec, gc);
+ Type base_type = TypeParam_EffectiveBaseType (gc);
if (TypeManager.IsSubclassOf (base_type, target_type))
return new ClassCast (expr, target_type);
}
static EmptyExpression MyEmptyExpr;
- static public Expression ImplicitReferenceConversion (EmitContext ec, Expression expr, Type target_type)
+ static public Expression ImplicitReferenceConversion (Expression expr, Type target_type)
{
Type expr_type = expr.Type;
return null;
if (expr_type.IsGenericParameter)
- return ImplicitTypeParameterConversion (ec, expr, target_type);
+ return ImplicitTypeParameterConversion (expr, target_type);
//
// notice that it is possible to write "ValueType v = 1", the ValueType here
Type target_element_type = TypeManager.GetElementType (target_type);
if (!expr_element_type.IsValueType && !target_element_type.IsValueType)
- if (ImplicitStandardConversionExists (ConstantEC, MyEmptyExpr,
+ if (ImplicitStandardConversionExists (MyEmptyExpr,
target_element_type))
return new EmptyCast (expr, target_type);
}
// Tests whether an implicit reference conversion exists between expr_type
// and target_type
//
- public static bool ImplicitReferenceConversionExists (EmitContext ec, Expression expr, Type target_type)
+ public static bool ImplicitReferenceConversionExists (Expression expr, Type target_type)
{
if (target_type.IsValueType)
return false;
Type expr_type = expr.Type;
if (expr_type.IsGenericParameter)
- return ImplicitTypeParameterConversion (ec, expr, target_type) != null;
+ return ImplicitTypeParameterConversion (expr, target_type) != null;
//
// This is the boxed case.
Type target_element_type = TypeManager.GetElementType (target_type);
if (!expr_element_type.IsValueType && !target_element_type.IsValueType)
- if (ImplicitStandardConversionExists (ConstantEC, MyEmptyExpr,
+ if (ImplicitStandardConversionExists (MyEmptyExpr,
target_element_type))
return true;
}
/// expr is the expression to convert, returns a new expression of type
/// target_type or null if an implicit conversion is not possible.
/// </summary>
- static public Expression ImplicitNumericConversion (EmitContext ec, Expression expr,
+ static public Expression ImplicitNumericConversion (Expression expr,
Type target_type)
{
Type expr_type = expr.Type;
return true;
}
- if (ImplicitStandardConversionExists (ec, expr, target_type))
+ if (ImplicitStandardConversionExists (expr, target_type))
return true;
Expression dummy = ImplicitUserConversion (ec, expr, target_type, Location.Null);
///
/// ec should point to a real EmitContext if expr.Type is TypeManager.anonymous_method_type.
/// </summary>
- public static bool ImplicitStandardConversionExists (EmitContext ec, Expression expr, Type target_type)
+ public static bool ImplicitStandardConversionExists (Expression expr, Type target_type)
{
Type expr_type = expr.Type;
if (TypeManager.IsDelegateType (target_type) && RootContext.Version != LanguageVersion.ISO_1){
MethodGroupExpr mg = expr as MethodGroupExpr;
if (mg != null){
- //
- // This should not happen frequently, so we can create an object
- // to test compatibility
- //
- Expression c = ImplicitDelegateCreation.Create (
- ec, mg, target_type, true, Location.Null);
- return c != null;
+ return DelegateCreation.ImplicitStandardConversionExists (mg, target_type) != null;
}
}
}
- if (ImplicitReferenceConversionExists (ec, expr, target_type))
+ if (ImplicitReferenceConversionExists (expr, target_type))
return true;
//
if (!TypeManager.IsDelegateType (target_type))
return false;
- AnonymousMethod am = (AnonymousMethod) expr;
-
- Expression conv = am.Compatible (ec, target_type, true);
- if (conv != null)
- return true;
+ return true;
}
return false;
/// Finds "most encompassed type" according to the spec (13.4.2)
/// amongst the methods in the MethodGroupExpr
/// </summary>
- static Type FindMostEncompassedType (EmitContext ec, ArrayList types)
+ static Type FindMostEncompassedType (ArrayList types)
{
Type best = null;
}
expr.SetType (t);
- if (ImplicitStandardConversionExists (ec, expr, best))
+ if (ImplicitStandardConversionExists (expr, best))
best = t;
}
foreach (Type t in types) {
if (best == t)
continue;
- if (!ImplicitStandardConversionExists (ec, expr, t)) {
+ if (!ImplicitStandardConversionExists (expr, t)) {
best = null;
break;
}
/// Finds "most encompassing type" according to the spec (13.4.2)
/// amongst the types in the given set
/// </summary>
- static Type FindMostEncompassingType (EmitContext ec, ArrayList types)
+ static Type FindMostEncompassingType (ArrayList types)
{
Type best = null;
}
expr.SetType (best);
- if (ImplicitStandardConversionExists (ec, expr, t))
+ if (ImplicitStandardConversionExists (expr, t))
best = t;
}
if (best == t)
continue;
expr.SetType (t);
- if (!ImplicitStandardConversionExists (ec, expr, best)) {
+ if (!ImplicitStandardConversionExists (expr, best)) {
best = null;
break;
}
/// by making use of FindMostEncomp* methods. Applies the correct rules separately
/// for explicit and implicit conversion operators.
/// </summary>
- static public Type FindMostSpecificSource (EmitContext ec, IList list,
+ static public Type FindMostSpecificSource (IList list,
Expression source, bool apply_explicit_conv_rules)
{
ArrayList src_types_set = new ArrayList ();
ArrayList candidate_set = new ArrayList ();
foreach (Type param_type in src_types_set){
- if (ImplicitStandardConversionExists (ec, source, param_type))
+ if (ImplicitStandardConversionExists (source, param_type))
candidate_set.Add (param_type);
}
if (candidate_set.Count != 0)
- return FindMostEncompassedType (ec, candidate_set);
+ return FindMostEncompassedType (candidate_set);
}
//
// Final case
//
if (apply_explicit_conv_rules)
- return FindMostEncompassingType (ec, src_types_set);
+ return FindMostEncompassingType (src_types_set);
else
- return FindMostEncompassedType (ec, src_types_set);
+ return FindMostEncompassedType (src_types_set);
}
/// <summary>
/// Finds the most specific target Tx according to section 13.4.4
/// </summary>
- static public Type FindMostSpecificTarget (EmitContext ec, IList list,
+ static public Type FindMostSpecificTarget (IList list,
Type target, bool apply_explicit_conv_rules)
{
ArrayList tgt_types_set = new ArrayList ();
foreach (Type ret_type in tgt_types_set){
expr.SetType (ret_type);
- if (ImplicitStandardConversionExists (ec, expr, target))
+ if (ImplicitStandardConversionExists (expr, target))
candidate_set.Add (ret_type);
}
EmptyExpression.Release (expr);
if (candidate_set.Count != 0)
- return FindMostEncompassingType (ec, candidate_set);
+ return FindMostEncompassingType (candidate_set);
}
//
// Okay, final case !
//
if (apply_explicit_conv_rules)
- return FindMostEncompassedType (ec, tgt_types_set);
+ return FindMostEncompassedType (tgt_types_set);
else
- return FindMostEncompassingType (ec, tgt_types_set);
+ return FindMostEncompassingType (tgt_types_set);
}
/// <summary>
return UserDefinedConversion (ec, source, target, loc, true);
}
- static void AddConversionOperators (EmitContext ec, ArrayList list,
+ static void AddConversionOperators (ArrayList list,
Expression source, Type target_type,
bool look_for_explicit,
MethodGroupExpr mg)
Type arg_type = pd.ParameterType (0);
if (source_type != arg_type) {
- if (!ImplicitStandardConversionExists (ec, source, arg_type)) {
+ if (!ImplicitStandardConversionExists (source, arg_type)) {
if (!look_for_explicit)
continue;
expr.SetType (arg_type);
- if (!ImplicitStandardConversionExists (ec, expr, source_type))
+ if (!ImplicitStandardConversionExists (expr, source_type))
continue;
}
}
if (target_type != return_type) {
expr.SetType (return_type);
- if (!ImplicitStandardConversionExists (ec, expr, target_type)) {
+ if (!ImplicitStandardConversionExists (expr, target_type)) {
if (!look_for_explicit)
continue;
expr.SetType (target_type);
- if (!ImplicitStandardConversionExists (ec, expr, return_type))
+ if (!ImplicitStandardConversionExists (expr, return_type))
continue;
}
}
Type source_type = source.Type;
if (source_type != TypeManager.decimal_type) {
- AddConversionOperators (ec, ops, source, target_type, look_for_explicit,
+ AddConversionOperators (ops, source, target_type, look_for_explicit,
Expression.MethodLookup (ec, source_type, "op_Implicit", Location.Null) as MethodGroupExpr);
if (look_for_explicit) {
- AddConversionOperators (ec, ops, source, target_type, look_for_explicit,
+ AddConversionOperators (ops, source, target_type, look_for_explicit,
Expression.MethodLookup (
ec, source_type, "op_Explicit", Location.Null) as MethodGroupExpr);
}
}
if (target_type != TypeManager.decimal_type) {
- AddConversionOperators (ec, ops, source, target_type, look_for_explicit,
+ AddConversionOperators (ops, source, target_type, look_for_explicit,
Expression.MethodLookup (ec, target_type, "op_Implicit", Location.Null) as MethodGroupExpr);
if (look_for_explicit) {
- AddConversionOperators (ec, ops, source, target_type, look_for_explicit,
+ AddConversionOperators (ops, source, target_type, look_for_explicit,
Expression.MethodLookup (
ec, target_type, "op_Explicit", Location.Null) as MethodGroupExpr);
}
if (ops.Count == 0)
return null;
- Type most_specific_source = FindMostSpecificSource (ec, ops, source, look_for_explicit);
+ Type most_specific_source = FindMostSpecificSource (ops, source, look_for_explicit);
if (most_specific_source == null)
return null;
- Type most_specific_target = FindMostSpecificTarget (ec, ops, target_type, look_for_explicit);
+ Type most_specific_target = FindMostSpecificTarget (ops, target_type, look_for_explicit);
if (most_specific_target == null)
return null;
if (expr_type.Equals (target_type) && !TypeManager.IsNullType (expr_type))
return expr;
- e = ImplicitNumericConversion (ec, expr, target_type);
+ e = ImplicitNumericConversion (expr, target_type);
if (e != null)
return e;
- e = ImplicitReferenceConversion (ec, expr, target_type);
+ e = ImplicitReferenceConversion (expr, target_type);
if (e != null)
return e;
// Returns the MethodBase for "Invoke" from a delegate type, this is used
// to extract the signature of a delegate.
//
- public static MethodGroupExpr GetInvokeMethod (EmitContext ec, Type delegate_type,
- Location loc)
+ public static MethodGroupExpr GetInvokeMethod (Type container_type, Type delegate_type, Location loc)
{
- Expression ml = Expression.MemberLookup (
- ec, delegate_type, "Invoke", loc);
+ Expression ml = Expression.MemberLookup (container_type, null, delegate_type,
+ "Invoke", loc);
MethodGroupExpr mg = ml as MethodGroupExpr;
if (mg == null) {
/// Verifies whether the method in question is compatible with the delegate
/// Returns the method itself if okay and null if not.
/// </summary>
- public static MethodBase VerifyMethod (EmitContext ec, Type delegate_type,
+ public static MethodBase VerifyMethod (Type container_type, Type delegate_type,
MethodGroupExpr old_mg, MethodBase mb,
Location loc)
{
- MethodGroupExpr mg = GetInvokeMethod (ec, delegate_type, loc);
+ MethodGroupExpr mg = GetInvokeMethod (container_type, delegate_type, loc);
if (mg == null)
return null;
ParameterData invoke_pd = TypeManager.GetParameterData (invoke_mb);
if (!mg.HasTypeArguments &&
- !TypeManager.InferTypeArguments (ec, invoke_pd, ref mb))
+ !TypeManager.InferTypeArguments (invoke_pd, ref mb))
return null;
ParameterData pd = TypeManager.GetParameterData (mb);
string delegate_desc = Delegate.FullDelegateDesc (type, method, param);
if (!mg.HasTypeArguments &&
- !TypeManager.InferTypeArguments (ec, param, ref found_method))
+ !TypeManager.InferTypeArguments (param, ref found_method))
Report.Error (411, loc, "The type arguments for " +
"method `{0}' cannot be infered from " +
"the usage. Try specifying the type " +
return true;
}
+ public static MethodBase ImplicitStandardConversionExists (MethodGroupExpr mg, Type targetType)
+ {
+ foreach (MethodInfo mi in mg.Methods){
+ MethodBase mb = Delegate.VerifyMethod (mg.DeclaringType, targetType, mg, mi, Location.Null);
+ if (mb != null)
+ return mb;
+ }
+ return null;
+ }
+
protected Expression ResolveMethodGroupExpr (EmitContext ec, MethodGroupExpr mg,
bool check_only)
{
foreach (MethodInfo mi in mg.Methods){
- delegate_method = Delegate.VerifyMethod (ec, type, mg, mi, loc);
+ delegate_method = Delegate.VerifyMethod (ec.ContainerType, type, mg, mi, loc);
if (delegate_method != null)
break;