Author: marek
Date: 2007-03-31 13:05:04 -0500 (Sat, 31 Mar 2007)
New Revision: 75245
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/generic.cs
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/anonymous.cs
trunk/mcs/mcs/codegen.cs
trunk/mcs/mcs/statement.cs
trunk/mcs/mcs/support.cs
Log:
2007-03-31 Marek Safar <[EMAIL PROTECTED]>
* generic.cs (InferTypeArguments): Restored validation check.
(InferTypeArguments): Move all logic to Compatible method for
re-usability.
2007-03-31 Marek Safar <[EMAIL PROTECTED]>
* anonymous.cs (AnonymousMethodExpression.Compatible): Handles both
argument and return type inferring.
* codegen.cs (InferReturnType): Flag whether return can be inferred.
(ReturnType): Turned to property.
* statement.cs (Return): Implemented return type inferring.
* support.cs (ReflectionParameters): Use local types if possible.
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2007-03-31 17:57:24 UTC (rev 75244)
+++ trunk/mcs/gmcs/ChangeLog 2007-03-31 18:05:04 UTC (rev 75245)
@@ -1,3 +1,8 @@
+2007-03-31 Marek Safar <[EMAIL PROTECTED]>
+
+ * generic.cs (InferTypeArguments): Restored validation check.
+ (InferTypeArguments): Move all logic to Compatible method for
re-usability.
+
2007-03-25 Marek Safar <[EMAIL PROTECTED]>
* generic.cs (InferTypeArguments): Infer arguments before they are used
Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs 2007-03-31 17:57:24 UTC (rev 75244)
+++ trunk/mcs/gmcs/generic.cs 2007-03-31 18:05:04 UTC (rev 75245)
@@ -2410,6 +2410,11 @@
if (!UnifyType (param_types [i], arg_types [i],
inferred_types))
return false;
}
+
+ for (int i = 0; i < inferred_types.Length; ++i)
+ if (inferred_types [i] == null)
+ return false;
+
return true;
}
@@ -2582,19 +2587,12 @@
continue;
AnonymousMethodExpression am =
(AnonymousMethodExpression)a.Expr;
- if (!InferTypeArguments
(dtype.GetGenericArguments (), am.Parameters.Types, inferred_types))
- return false;
- Type[] inferred_delegate = new
Type[am.Parameters.Types.Length];
- int index = 0;
- foreach (Type t in
dtype.GetGenericArguments ()) {
- inferred_delegate[index++] =
inferred_types[t.GenericParameterPosition];
- }
- Type infered_type =
dtype.GetGenericTypeDefinition ().MakeGenericType (inferred_delegate);
-
- if (am.Compatible (ec, infered_type) ==
null)
+ Expression e = am.Compatible (ec,
dtype);
+ if (e == null)
return false;
+ arg_types[i] = e.Type;
continue;
}
@@ -2613,10 +2611,6 @@
return false;
}
- for (int i = 0; i < inferred_types.Length; ++i)
- if (inferred_types[i] == null)
- return false;
-
method = ((MethodInfo)method).MakeGenericMethod
(inferred_types);
#if MS_COMPATIBLE
@@ -2657,10 +2651,6 @@
if (!InferTypeArguments (param_types, arg_types,
inferred_types))
return false;
- foreach (Type t in inferred_types)
- if (t == null)
- return false;
-
method = ((MethodInfo)method).MakeGenericMethod
(inferred_types);
return true;
}
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2007-03-31 17:57:24 UTC (rev 75244)
+++ trunk/mcs/mcs/ChangeLog 2007-03-31 18:05:04 UTC (rev 75245)
@@ -1,3 +1,15 @@
+2007-03-31 Marek Safar <[EMAIL PROTECTED]>
+
+ * anonymous.cs (AnonymousMethodExpression.Compatible): Handles both
+ argument and return type inferring.
+
+ * codegen.cs (InferReturnType): Flag whether return can be inferred.
+ (ReturnType): Turned to property.
+
+ * statement.cs (Return): Implemented return type inferring.
+
+ * support.cs (ReflectionParameters): Use local types if possible.
+
2007-03-30 Raja R Harinath <[EMAIL PROTECTED]>
* flowanalysis.cs (FlowBranching.Reachability): Remove.
Modified: trunk/mcs/mcs/anonymous.cs
===================================================================
--- trunk/mcs/mcs/anonymous.cs 2007-03-31 17:57:24 UTC (rev 75244)
+++ trunk/mcs/mcs/anonymous.cs 2007-03-31 18:05:04 UTC (rev 75245)
@@ -1257,6 +1257,37 @@
MethodInfo invoke_mb = (MethodInfo) invoke_mg.Methods
[0];
ParameterData invoke_pd = TypeManager.GetParameterData
(invoke_mb);
+#if GMCS_SOURCE
+ Type[] infered_arguments = null;
+ if (TypeManager.IsGenericType (delegate_type)) {
+
+ Type[] g_arguments =
delegate_type.GetGenericArguments ();
+ infered_arguments = new
Type[g_arguments.Length];
+ for (int i = 0; i < g_arguments.Length; ++i) {
+ infered_arguments [i] = g_arguments[i];
+ }
+
+ for (int i = 0; i < invoke_pd.Count; ++i) {
+ if
(!invoke_pd.Types[i].IsGenericParameter)
+ continue;
+
+ infered_arguments
[invoke_pd.Types[i].GenericParameterPosition] = Parameters.Types[i];
+ invoke_pd.Types[i] =
Parameters.Types[i];
+
+ // HACK: to update both parameter type
copies
+ Parameters p = invoke_pd as Parameters;
+ if (p != null)
+
p.FixedParameters[i].ParameterType = Parameters.Types[i];
+ }
+ }
+
+ int return_type_pos = -1;
+ if (TypeManager.IsGenericParameter
(invoke_mb.ReturnType)) {
+ ec.InferReturnType = true;
+ return_type_pos =
invoke_mb.ReturnType.GenericParameterPosition;
+ }
+#endif
+
Parameters parameters;
if (Parameters == null) {
//
@@ -1311,6 +1342,19 @@
if (!anonymous.Resolve (ec))
return null;
+#if GMCS_SOURCE
+ if (return_type_pos != -1) {
+ if (infered_arguments == null)
+ infered_arguments = new Type
[delegate_type.GetGenericArguments ().Length];
+
+ infered_arguments [return_type_pos] =
anonymous.ReturnType;
+ }
+
+ if (infered_arguments != null &
TypeManager.IsGenericType (delegate_type)) {
+ anonymous.AnonymousDelegate.Type =
delegate_type.GetGenericTypeDefinition ().MakeGenericType (infered_arguments);
+ anonymous.DelegateType =
anonymous.AnonymousDelegate.Type;
+ }
+#endif
return anonymous.AnonymousDelegate;
}
@@ -1447,6 +1491,7 @@
aec.CurrentAnonymousMethod = this;
aec.IsFieldInitializer = ec.IsFieldInitializer;
aec.IsStatic = ec.IsStatic;
+ aec.InferReturnType = ec.InferReturnType;
Report.Debug (64, "RESOLVE ANONYMOUS METHOD #1", this,
Location, ec, aec,
RootScope, Parameters, Block);
@@ -1457,6 +1502,9 @@
Report.Debug (64, "RESOLVE ANONYMOUS METHOD #3", this,
ec, aec, Block);
+ if (aec.InferReturnType)
+ ReturnType = aec.ReturnType;
+
method = DoCreateMethodHost (ec);
if (Scope != null)
@@ -1517,7 +1565,7 @@
public class AnonymousMethod : AnonymousContainer
{
- public readonly Type DelegateType;
+ public Type DelegateType;
//
// The value return by the Compatible call, this ensure that
Modified: trunk/mcs/mcs/codegen.cs
===================================================================
--- trunk/mcs/mcs/codegen.cs 2007-03-31 17:57:24 UTC (rev 75244)
+++ trunk/mcs/mcs/codegen.cs 2007-03-31 18:05:04 UTC (rev 75245)
@@ -289,11 +289,13 @@
/// </summary>
public bool IsFieldInitializer;
+ public bool InferReturnType;
+
/// <summary>
/// The value that is allowed to be returned or NULL if there
is no
/// return type.
/// </summary>
- public readonly Type ReturnType;
+ Type returnType;
/// <summary>
/// Points to the Type (extracted from the TypeContainer) that
@@ -432,9 +434,6 @@
flags |= Flags.InUnsafe;
}
loc = l;
-
- if (ReturnType == TypeManager.void_type)
- ReturnType = null;
}
public EmitContext (IResolveContext rc, DeclSpace ds, Location
l, ILGenerator ig,
@@ -714,7 +713,7 @@
}
#endif
- if (ReturnType != null && !unreachable) {
+ if (returnType != null && !unreachable) {
if (CurrentAnonymousMethod == null) {
Report.Error (161, md.Location, "`{0}':
not all code paths return a value", md.GetSignatureForError ());
return false;
@@ -732,6 +731,16 @@
return true;
}
+ public Type ReturnType {
+ set {
+ returnType = value == TypeManager.void_type ?
+ null : value;
+ }
+ get {
+ return returnType;
+ }
+ }
+
public void EmitResolvedTopBlock (ToplevelBlock block, bool
unreachable)
{
if (block != null)
@@ -763,7 +772,7 @@
if ((block != null) && block.IsDestructor) {
// Nothing to do; S.R.E automatically
emits a leave.
} else if (HasReturnLabel || (!unreachable &&
!in_iterator)) {
- if (ReturnType != null)
+ if (returnType != null)
ig.Emit (OpCodes.Ldloc,
TemporaryReturn ());
ig.Emit (OpCodes.Ret);
}
@@ -886,7 +895,7 @@
public LocalBuilder TemporaryReturn ()
{
if (return_value == null){
- return_value = ig.DeclareLocal (ReturnType);
+ return_value = ig.DeclareLocal (returnType);
if (!HasReturnLabel){
ReturnLabel = ig.DefineLabel ();
HasReturnLabel = true;
Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs 2007-03-31 17:57:24 UTC (rev 75244)
+++ trunk/mcs/mcs/statement.cs 2007-03-31 18:05:04 UTC (rev 75245)
@@ -720,10 +720,10 @@
if (ec.ReturnType == null){
if (Expr != null){
- if (ec.CurrentAnonymousMethod != null){
+ if (am != null){
Report.Error (1662, loc,
"Cannot convert
anonymous method block to delegate type `{0}' because some of the return types
in the block are not implicitly convertible to the delegate return type",
-
ec.CurrentAnonymousMethod.GetSignatureForError ());
+ am.GetSignatureForError
());
}
Error (127, "A return keyword must not
be followed by any expression when method returns void");
return false;
@@ -741,10 +741,14 @@
return false;
if (Expr.Type != ec.ReturnType) {
- Expr =
Convert.ImplicitConversionRequired (
- ec, Expr, ec.ReturnType, loc);
- if (Expr == null)
- return false;
+ if (ec.InferReturnType) {
+ ec.ReturnType = Expr.Type;
+ } else {
+ Expr =
Convert.ImplicitConversionRequired (
+ ec, Expr,
ec.ReturnType, loc);
+ if (Expr == null)
+ return false;
+ }
}
}
@@ -1242,6 +1246,9 @@
VariableType = texpr.Type;
}
+ if (TypeManager.IsGenericParameter (VariableType))
+ return true;
+
if (VariableType == TypeManager.void_type) {
Expression.Error_VoidInvalidInTheContext
(Location);
return false;
Modified: trunk/mcs/mcs/support.cs
===================================================================
--- trunk/mcs/mcs/support.cs 2007-03-31 17:57:24 UTC (rev 75244)
+++ trunk/mcs/mcs/support.cs 2007-03-31 18:05:04 UTC (rev 75245)
@@ -138,7 +138,7 @@
if (is_varargs && pos >= pi.Length)
return TypeManager.runtime_argument_handle_type;
- return pi [pos].ParameterType;
+ return types [pos];
}
public string ParameterName (int pos)
@@ -192,7 +192,7 @@
if (gpd != null)
return gpd.ParameterModifier (pos);
- Type t = pi [pos].ParameterType;
+ Type t = types [pos];
if (t.IsByRef){
if ((pi [pos].Attributes &
(ParameterAttributes.Out|ParameterAttributes.In)) == ParameterAttributes.Out)
return Parameter.Modifier.OUT;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches