2002-01-24 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Thu, 24 Jan 2002 15:06:39 +0000 (15:06 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 24 Jan 2002 15:06:39 +0000 (15:06 -0000)
* statement.cs (Do.Emit, While.Emit, For.Emit,
Statement.EmitBoolExpression): Add support to Do and While to
propagate infinite loop as `I do return' semantics.

Improve the For case to also test for boolean constants.

* attribute.cs (Attribute.ApplyAttributes): Add ParameterBuilder
to the list of attributes we can add.

Remove `EmitContext' argument.

* class.cs (Method.Define): Apply parameter attributes.
(Constructor.Define): Apply parameter attributes.
(MethodCore.LabelParameters): Move here the core of labeling
parameters.

* support.cs (ReflectionParameters.ParameterModifier,
InternalParameters.ParameterModifier): Use IsByRef on the type and
only return the OUT bit for these parameters instead of in/out/ref
flags.

This is because I miss-understood things.  The ParameterInfo.IsIn
and IsOut represent whether the parameter has the [In] and [Out]
attributes set.

svn path=/trunk/mcs/; revision=2151

mcs/mcs/ChangeLog
mcs/mcs/attribute.cs
mcs/mcs/class.cs
mcs/mcs/expression.cs
mcs/mcs/statement.cs
mcs/mcs/support.cs

index a53b6faa6854eb1268f366e137126767eceb7eb6..5c823bc3f73d7046c2338caf38d2f5a89a4ee5be 100755 (executable)
@@ -1,3 +1,30 @@
+2002-01-24  Miguel de Icaza  <miguel@ximian.com>
+
+       * statement.cs (Do.Emit, While.Emit, For.Emit,
+       Statement.EmitBoolExpression): Add support to Do and While to
+       propagate infinite loop as `I do return' semantics.
+
+       Improve the For case to also test for boolean constants.
+
+       * attribute.cs (Attribute.ApplyAttributes): Add ParameterBuilder
+       to the list of attributes we can add.
+
+       Remove `EmitContext' argument.
+
+       * class.cs (Method.Define): Apply parameter attributes.
+       (Constructor.Define): Apply parameter attributes.
+       (MethodCore.LabelParameters): Move here the core of labeling
+       parameters. 
+
+       * support.cs (ReflectionParameters.ParameterModifier,
+       InternalParameters.ParameterModifier): Use IsByRef on the type and
+       only return the OUT bit for these parameters instead of in/out/ref
+       flags.
+
+       This is because I miss-understood things.  The ParameterInfo.IsIn
+       and IsOut represent whether the parameter has the [In] and [Out]
+       attributes set.  
+
 2002-01-22  Miguel de Icaza  <miguel@ximian.com>
 
        * ecore.cs (FieldExpr.Emit): Release temporaries.
index 1e10cb1115ca5d21a92428266f8ee0779b88a315..026448e9d1e6e3d8d3389240be5f6581206fbe56 100644 (file)
@@ -310,8 +310,10 @@ namespace Mono.CSharp {
 \r
                public static void error592 (Attribute a, Location loc)\r
                {\r
-                       Report.Error (592, loc, "Attribute '" + a.Name + "' is not valid on this declaration type. " +\r
-                                     "It is valid on " + GetValidPlaces (a) + "declarations only.");\r
+                       Report.Error (\r
+                               592, loc, "Attribute '" + a.Name +\r
+                               "' is not valid on this declaration type. " +\r
+                               "It is valid on " + GetValidPlaces (a) + "declarations only.");\r
                }\r
 \r
                public static bool CheckAttribute (Attribute a, object element)\r
@@ -374,7 +376,7 @@ namespace Mono.CSharp {
                                        return true;\r
                                else\r
                                        return false;\r
-                       } else if (element is Parameter) {\r
+                       } else if (element is ParameterBuilder) {\r
                                if ((targets & AttributeTargets.Parameter) != 0)\r
                                        return true;\r
                                else\r
@@ -384,7 +386,7 @@ namespace Mono.CSharp {
                                        return true;\r
                                else\r
                                        return false;\r
-                       }\r
+                       } \r
 \r
                        return false;\r
                }\r
@@ -410,6 +412,7 @@ namespace Mono.CSharp {
 \r
                                        if (!(kind is TypeContainer))\r
                                                if (!CheckAttribute (a, kind)) {\r
+                                                       Console.WriteLine ("Kind is: " + kind);\r
                                                        error592 (a, loc);\r
                                                        return;\r
                                                }\r
@@ -426,19 +429,16 @@ namespace Mono.CSharp {
                                                \r
                                        } else if (kind is Constructor) {\r
                                                ((ConstructorBuilder) builder).SetCustomAttribute (cb);\r
-\r
                                        } else if (kind is Field) {\r
                                                ((FieldBuilder) builder).SetCustomAttribute (cb);\r
-\r
                                        } else if (kind is Property || kind is Indexer) {\r
                                                ((PropertyBuilder) builder).SetCustomAttribute (cb);\r
-\r
                                        } else if (kind is Event) {\r
                                                ((EventBuilder) builder).SetCustomAttribute (cb);\r
-\r
+                                       } else if (kind is ParameterBuilder){\r
+                                               ((ParameterBuilder) builder).SetCustomAttribute (cb);\r
                                        } else if (kind is Operator) {\r
                                                ((MethodBuilder) builder).SetCustomAttribute (cb);\r
-\r
                                        } else if (kind is Enum) {\r
                                                ((TypeBuilder) builder).SetCustomAttribute (cb); \r
 \r
index 043b731d5e71d52eb5aaf2875f41cc3abcd1bbdf..077f7d48b5209d45be77ee750151b4845269d833 100755 (executable)
@@ -1938,6 +1938,61 @@ namespace Mono.CSharp {
                        
                        return cc;
                }
+
+               public void LabelParameters (EmitContext ec, Type [] parameters, MethodBase builder)
+               {
+                       //
+                       // Define each type attribute (in/out/ref) and
+                       // the argument names.
+                       //
+                       Parameter [] p = Parameters.FixedParameters;
+                       if (p == null)
+                               return;
+
+                       MethodBuilder mb = null;
+                       ConstructorBuilder cb = null;
+
+                       if (builder is MethodBuilder)
+                               mb = (MethodBuilder) builder;
+                       else
+                               cb = (ConstructorBuilder) builder;
+                       
+                       int i;
+                               
+                       for (i = 0; i < p.Length; i++) {
+                               ParameterBuilder pb;
+
+                               if (mb == null)
+                                       pb = cb.DefineParameter (
+                                               i + 1, p [i].Attributes, p [i].Name);
+                               else 
+                                       pb = mb.DefineParameter (
+                                               i + 1, p [i].Attributes, p [i].Name);
+                               
+                               Attributes attr = p [i].OptAttributes;
+                               if (attr != null)
+                                       Attribute.ApplyAttributes (ec, pb, pb, attr, Location);
+                       }
+                       
+                       if (i != parameters.Length) {
+                               ParameterBuilder pb;
+                               
+                               Parameter array_param = Parameters.ArrayParameter;
+                               if (mb == null)
+                                       pb = cb.DefineParameter (
+                                               i + 1, array_param.Attributes,
+                                               array_param.Name);
+                               else
+                                       pb = mb.DefineParameter (
+                                               i + 1, array_param.Attributes,
+                                               array_param.Name);
+                                       
+                               CustomAttributeBuilder a = new CustomAttributeBuilder (
+                                       TypeManager.cons_param_array_attribute, new object [0]);
+                               
+                               pb.SetCustomAttribute (a);
+                       }
+               }
        }
        
        public class Method : MethodCore {
@@ -2280,33 +2335,6 @@ namespace Mono.CSharp {
                                // error 28 if not.
                                //
                        }
-                       
-                       //
-                       // Define each type attribute (in/out/ref) and
-                       // the argument names.
-                       //
-                       Parameter [] p = Parameters.FixedParameters;
-                       if (p != null){
-                               int i;
-                               
-                               for (i = 0; i < p.Length; i++) 
-                                       MethodBuilder.DefineParameter (
-                                                     i + 1, p [i].Attributes, p [i].Name);
-                                       
-                               if (i != parameters.Length) {
-                                       ParameterBuilder pb;
-                                       
-                                       Parameter array_param = Parameters.ArrayParameter;
-                                       pb = MethodBuilder.DefineParameter (
-                                               i + 1, array_param.Attributes,
-                                               array_param.Name);
-
-                                       CustomAttributeBuilder a = new CustomAttributeBuilder (
-                                               TypeManager.cons_param_array_attribute, new object [0]);
-
-                                       pb.SetCustomAttribute (a);
-                               }
-                       }
 
                        return true;
                }
@@ -2323,8 +2351,11 @@ namespace Mono.CSharp {
                        EmitContext ec = new EmitContext (parent, Location, ig,
                                                          GetReturnType (parent), ModFlags);
 
-                       Attribute.ApplyAttributes (ec, MethodBuilder, this, OptAttributes, Location);
+                       if (OptAttributes != null)
+                               Attribute.ApplyAttributes (ec, MethodBuilder, this, OptAttributes, Location);
                        
+
+                       LabelParameters (ec, ParameterTypes (parent), MethodBuilder);
                        
                        //
                        // abstract or extern methods have no bodies
@@ -2544,7 +2575,7 @@ namespace Mono.CSharp {
                                        + "'");
                                return false;
                        }
-                               
+
                        return true;
                }
 
@@ -2565,6 +2596,8 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       LabelParameters (ec, ParameterTypes (parent), ConstructorBuilder);
+                       
                        //
                        // Classes can have base initializers and instance field initializers.
                        //
index f48d896f7997ec76545cda46f84a3eb98bcf0d12..82d30b7cbf47ae4ed1ec1bac28e050192547804c 100755 (executable)
@@ -2540,10 +2540,7 @@ namespace Mono.CSharp {
 
                public Parameter.Modifier GetParameterModifier ()
                {
-                       if (ArgType == AType.Ref)
-                               return Parameter.Modifier.REF;
-
-                       if (ArgType == AType.Out)
+                       if (ArgType == AType.Ref || ArgType == AType.Out)
                                return Parameter.Modifier.OUT;
 
                        return Parameter.Modifier.NONE;
@@ -3243,6 +3240,9 @@ namespace Mono.CSharp {
                                if (a.GetParameterModifier () != pd.ParameterModifier (j) &&
                                    pd.ParameterModifier (pd_count - 1) != Parameter.Modifier.PARAMS) {
                                        if (!Location.IsNull (loc)) {
+                                               Console.WriteLine ("A:P: " + a.GetParameterModifier ());
+                                               Console.WriteLine ("PP:: " + pd.ParameterModifier (j));
+                                               Console.WriteLine ("PT:  " + parameter_type.IsByRef);
                                                Error (1502, loc,
                                                       "The best overloaded match for method '" + FullMethodDesc (method)+
                                                       "' has some invalid arguments");
index b757088dbe2360502c8d6a5a497e9d8685116ba2..7b727617ddcecece33df38b3ba28244442e116b9 100755 (executable)
@@ -26,12 +26,13 @@ namespace Mono.CSharp {
                /// <remarks>
                ///    Emits a bool expression.
                /// </remarks>
-               public static bool EmitBoolExpression (EmitContext ec, Expression e, Label l, bool isTrue)
+               public static Expression EmitBoolExpression (EmitContext ec, Expression e,
+                                                            Label l, bool isTrue)
                {
                        e = e.Resolve (ec);
 
                        if (e == null)
-                               return false;
+                               return null;
 
                        if (e.Type != TypeManager.bool_type)
                                e = Expression.ConvertImplicit (ec, e, TypeManager.bool_type,
@@ -40,7 +41,7 @@ namespace Mono.CSharp {
                        if (e == null){
                                Report.Error (
                                        31, "Can not convert the expression to a boolean");
-                               return false;
+                               return null;
                        }
 
                        bool invert = false;
@@ -69,7 +70,7 @@ namespace Mono.CSharp {
                                        ec.ig.Emit (OpCodes.Brfalse, l);
                        }
                        
-                       return true;
+                       return e;
                }
 
        }
@@ -108,7 +109,7 @@ namespace Mono.CSharp {
                        Label end;
                        bool is_true_ret, is_false_ret;
                        
-                       if (!EmitBoolExpression (ec, Expr, false_target, false))
+                       if (EmitBoolExpression (ec, Expr, false_target, false) == null)
                                return false;
                        
                        is_true_ret = TrueStatement.Emit (ec);
@@ -154,6 +155,7 @@ namespace Mono.CSharp {
                        Label old_begin = ec.LoopBegin;
                        Label old_end = ec.LoopEnd;
                        bool  old_inloop = ec.InLoop;
+                       Expression e;
                        
                        ec.LoopBegin = ig.DefineLabel ();
                        ec.LoopEnd = ig.DefineLabel ();
@@ -162,12 +164,22 @@ namespace Mono.CSharp {
                        ig.MarkLabel (loop);
                        EmbeddedStatement.Emit (ec);
                        ig.MarkLabel (ec.LoopBegin);
-                       EmitBoolExpression (ec, Expr, loop, true);
+                       e = EmitBoolExpression (ec, Expr, loop, true);
                        ig.MarkLabel (ec.LoopEnd);
 
                        ec.LoopBegin = old_begin;
                        ec.LoopEnd = old_end;
                        ec.InLoop = old_inloop;
+
+                       //
+                       // Inform whether we are infinite or not
+                       //
+                       if (e is BoolConstant){
+                               BoolConstant bc = (BoolConstant) e;
+
+                               if (bc.Value == true)
+                                       return true;
+                       }
                        
                        return false;
                }
@@ -189,13 +201,14 @@ namespace Mono.CSharp {
                        Label old_begin = ec.LoopBegin;
                        Label old_end = ec.LoopEnd;
                        bool old_inloop = ec.InLoop;
+                       Expression e;
                        
                        ec.LoopBegin = ig.DefineLabel ();
                        ec.LoopEnd = ig.DefineLabel ();
                        ec.InLoop = true;
                        
                        ig.MarkLabel (ec.LoopBegin);
-                       EmitBoolExpression (ec, Expr, ec.LoopEnd, false);
+                       e = EmitBoolExpression (ec, Expr, ec.LoopEnd, false);
                        Statement.Emit (ec);
                        ig.Emit (OpCodes.Br, ec.LoopBegin);
                        ig.MarkLabel (ec.LoopEnd);
@@ -203,7 +216,16 @@ namespace Mono.CSharp {
                        ec.LoopBegin = old_begin;
                        ec.LoopEnd = old_end;
                        ec.InLoop = old_inloop;
-                       
+
+                       //
+                       // Inform whether we are infinite or not
+                       //
+                       if (e is BoolConstant){
+                               BoolConstant bc = (BoolConstant) e;
+
+                               if (bc.Value == true)
+                                       return true;
+                       }
                        return false;
                }
        }
@@ -232,6 +254,7 @@ namespace Mono.CSharp {
                        Label old_end = ec.LoopEnd;
                        bool old_inloop = ec.InLoop;
                        Label loop = ig.DefineLabel ();
+                       Expression e = null;
 
                        if (InitStatement != null)
                                if (! (InitStatement is EmptyStatement))
@@ -248,7 +271,7 @@ namespace Mono.CSharp {
                        // an infinite loop
                        //
                        if (Test != null)
-                               EmitBoolExpression (ec, Test, ec.LoopEnd, false);
+                               e = EmitBoolExpression (ec, Test, ec.LoopEnd, false);
                
                        Statement.Emit (ec);
                        ig.MarkLabel (ec.LoopBegin);
@@ -261,7 +284,19 @@ namespace Mono.CSharp {
                        ec.LoopEnd = old_end;
                        ec.InLoop = old_inloop;
 
-                       return Test == null;
+                       //
+                       // Inform whether we are infinite or not
+                       //
+                       if (Test != null){
+                               if (e is BoolConstant){
+                                       BoolConstant bc = (BoolConstant) e;
+
+                                       if (bc.Value)
+                                               return true;
+                               }
+                               return false;
+                       } else
+                               return true;
                }
        }
        
index 2b9f085ca65f9c196d38350c44e0b5b17cbadb9a..3cd6cf4df7dba7aa8a79dce80256bfd8879071ec 100755 (executable)
@@ -77,7 +77,8 @@ namespace Mono.CSharp {
                                if (last_arg_is_params)
                                        return Parameter.Modifier.PARAMS;
 
-                       if (pi [pos].IsOut)
+                       Type t = pi [pos].ParameterType;
+                       if (t.IsByRef)
                                return Parameter.Modifier.OUT;
                        
                        return Parameter.Modifier.NONE;
@@ -160,8 +161,18 @@ namespace Mono.CSharp {
                {
                        if (pos >= parameters.FixedParameters.Length)
                                return parameters.ArrayParameter.ModFlags;
-                       else
-                               return parameters.FixedParameters [pos].ModFlags;
+                       else {
+                               Parameter.Modifier m = parameters.FixedParameters [pos].ModFlags;
+
+                               //
+                               // We use a return value of "OUT" for "reference" parameters.
+                               // both out and ref flags in the source map to reference parameters.
+                               //
+                               if (m == Parameter.Modifier.OUT || m == Parameter.Modifier.REF)
+                                       return Parameter.Modifier.OUT;
+                               
+                               return Parameter.Modifier.NONE;
+                       }
                }
                
        }