Author: raja
Date: 2006-03-23 09:56:16 -0500 (Thu, 23 Mar 2006)
New Revision: 58360

Modified:
   trunk/mcs/errors/known-issues-gmcs
   trunk/mcs/gmcs/
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/attribute.cs
   trunk/mcs/gmcs/cfold.cs
   trunk/mcs/gmcs/class.cs
   trunk/mcs/gmcs/constant.cs
   trunk/mcs/gmcs/cs-parser.jay
   trunk/mcs/gmcs/ecore.cs
   trunk/mcs/gmcs/expression.cs
   trunk/mcs/gmcs/typemanager.cs
   trunk/mcs/tests/known-issues-gmcs
Log:
** merge revision 57358 from mcs/

Modified: trunk/mcs/errors/known-issues-gmcs
===================================================================
--- trunk/mcs/errors/known-issues-gmcs  2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/errors/known-issues-gmcs  2006-03-23 14:56:16 UTC (rev 58360)
@@ -11,7 +11,6 @@
 # csXXXX.cs NO ERROR   : error test case doesn't report any error. An 
exception is considered
 #                        as NO ERROR and CS5001 is automatically ignored.
 
-cs0221-5.cs NO ERROR
 cs0229-2.cs
 cs0229.cs NO ERROR
 cs0525.cs
@@ -25,9 +24,6 @@
 cs0567.cs
 cs0612-2.cs NO ERROR
 cs0619-42.cs
-cs0619-47.cs NO ERROR
-cs0619-48.cs NO ERROR
-cs0619-49.cs
 cs0625-3.cs NO ERROR
 cs0631-2.cs
 cs0647-3.cs


Property changes on: trunk/mcs/gmcs
___________________________________________________________________
Name: gmcs
   - Latest GMCS merging status:
- merged everything until r57289 (on 2006-02-25).
- not merging r49122, ie. we're keeping r48609 and r48610; see #75925.
- r37007 will never be merged; it's a mcs-only change.
- r43124 doesn't work in GMCS; not merged yet.

   + Latest GMCS merging status:
- merged everything until r57358 (on 2006-02-28).
- not merging r49122, ie. we're keeping r48609 and r48610; see #75925.
- r37007 will never be merged; it's a mcs-only change.
- r43124 doesn't work in GMCS; not merged yet.


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/ChangeLog    2006-03-23 14:56:16 UTC (rev 58360)
@@ -1,3 +1,34 @@
+2006-02-27  Marek Safar  <[EMAIL PROTECTED]>
+
+       * attribute.cs (Attribute.PosArguments, Attribute.NamedArguments): Use
+       these two separated members to simplify the code.
+       (Attribute.Resolve): Refactored to use new fields and methods.
+       (Attribute.ResolveConstructor): Extracted from ResolveArguments and
+       implemented obsolete attribute checking.
+       (Attribute.ResolveNamedArguments): Extracted from ResolveArguments and
+       implemented obsolete checking again. It look line never ending quest ;-)
+       (GlobalAttribute.ResolveConstructor): Need to override as the rest.
+
+       * cfold.cs (BinaryFold): TryReduce throws an exception to indicate 
error.
+
+       * constanct.cs (TryReduce): Throws OverflowException to indicate error.
+
+       *class.cs (Property.Define): Add RegisterProperty call.
+
+       * cs-parser.jay: Replaced ArrayList with fixed array for attribute
+       argument groups (only 2).
+
+       * ecore.cs (Expression.GetAttributableValue): New virtual method used 
for
+       encoding expression to arguments.
+       (Expression.ExprClassToResolveFlags): Just turned to property.
+
+       * expression.cs (ArrayCreation.ValidateInitializers): Slightly 
optimized.
+       (ArrayCreation.GetAttributableValue): Renamed from EncodeAsAttribute and
+       optimized as well as implemented support for zero-length attributes.
+
+       * typemanager.cs (TypeManager.RegisterProperty, 
TypeManager.GetProperty):
+       Add caching of PropertyInfo's.
+
 2006-02-25  Marek Safar  <[EMAIL PROTECTED]>
 
        * delegate.cs (DelegateCreation.ResolveMethodGroupExpr): Don't report

Modified: trunk/mcs/gmcs/attribute.cs
===================================================================
--- trunk/mcs/gmcs/attribute.cs 2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/attribute.cs 2006-03-23 14:56:16 UTC (rev 58360)
@@ -83,7 +83,8 @@
                public readonly Expression LeftExpr;
                public readonly string Identifier;
 
-               public readonly ArrayList Arguments;
+               readonly ArrayList PosArguments;
+               readonly ArrayList NamedArguments;
 
                public readonly Location Location;
 
@@ -93,8 +94,9 @@
                readonly bool nameEscaped;
                Attributable owner;
 
-               static AttributeUsageAttribute DefaultUsageAttribute = new 
AttributeUsageAttribute (AttributeTargets.All);
+               static readonly AttributeUsageAttribute DefaultUsageAttribute = 
new AttributeUsageAttribute (AttributeTargets.All);
                static Assembly orig_sec_assembly;
+               public static readonly object[] EmptyObject = new object [0];
 
                // non-null if named args present after Resolve () is called
                PropertyInfo [] prop_info_arr;
@@ -104,13 +106,19 @@
                object [] pos_values;
 
                static PtrHashtable usage_attr_cache = new PtrHashtable ();
+
+               // Cache for parameter-less attributes
+               static PtrHashtable att_cache = new PtrHashtable ();
                
-               public Attribute (string target, Expression left_expr, string 
identifier, ArrayList args, Location loc, bool nameEscaped)
+               public Attribute (string target, Expression left_expr, string 
identifier, object[] args, Location loc, bool nameEscaped)
                {
                        LeftExpr = left_expr;
                        Identifier = identifier;
                        Name = LeftExpr == null ? identifier : LeftExpr + "." + 
identifier;
-                       Arguments = args;
+                       if (args != null) {
+                               PosArguments = (ArrayList)args [0];
+                               NamedArguments = (ArrayList)args [1];           
                
+                       }
                        Location = loc;
                        ExplicitTarget = target;
                        this.nameEscaped = nameEscaped;
@@ -135,17 +143,12 @@
                                      "attribute parameter type", name);
                }
 
-               static void Error_AttributeArgumentNotValid (string extra, 
Location loc)
+               public static void Error_AttributeArgumentNotValid (Location 
loc)
                {
                        Report.Error (182, loc,
                                      "An attribute argument must be a constant 
expression, typeof " +
-                                     "expression or array creation expression" 
+ extra);
+                                     "expression or array creation 
expression");
                }
-
-               static void Error_AttributeArgumentNotValid (Location loc)
-               {
-                       Error_AttributeArgumentNotValid ("", loc);
-               }
                
                static void Error_TypeParameterInAttribute (Location loc)
                {
@@ -266,41 +269,6 @@
                        return LeftExpr == null ? Identifier : 
LeftExpr.GetSignatureForError () + "." + Identifier;
                }
 
-               //
-               // Given an expression, if the expression is a valid 
attribute-argument-expression
-               // returns an object that can be used to encode it, or null on 
failure.
-               //
-               public static bool GetAttributeArgumentExpression (Expression 
e, Location loc, Type arg_type, out object result)
-               {
-                       Constant constant = e as Constant;
-                       if (constant != null) {
-                               constant = constant.ToType (arg_type, loc);
-                               if (constant == null) {
-                                       result = null;
-                                       return false;
-                               }
-                               result = constant.GetTypedValue ();
-                               return true;
-                       } else if (e is TypeOf) {
-                               result = ((TypeOf) e).TypeArg;
-                               return true;
-                       } else if (e is ArrayCreation){
-                               result =  ((ArrayCreation) e).EncodeAsAttribute 
();
-                               if (result != null)
-                                       return true;
-                       } else if (e is EmptyCast) {
-                               Expression child = ((EmptyCast)e).Child;
-                               return GetAttributeArgumentExpression (child, 
loc, child.Type, out result);
-                       } else if (e is As) {
-                               As as_e = (As) e;
-                               return GetAttributeArgumentExpression 
(as_e.Expr, loc, as_e.ProbeType.Type, out result);
-                       }
-
-                       result = null;
-                       Error_AttributeArgumentNotValid (loc);
-                       return false;
-               }
-
                bool IsValidArgumentType (Type t)
                {
                        if (t.IsArray)
@@ -313,9 +281,6 @@
                                t == TypeManager.type_type;
                }
 
-               // Cache for parameter-less attributes
-               static PtrHashtable att_cache = new PtrHashtable ();
-
                public CustomAttributeBuilder Resolve ()
                {
                        if (resolve_error)
@@ -339,7 +304,7 @@
                                AttributeTester.Report_ObsoleteMessage 
(obsolete_attr, TypeManager.CSharpName (Type), Location);
                        }
 
-                       if (Arguments == null) {
+                       if (PosArguments == null && NamedArguments == null) {
                                object o = att_cache [Type];
                                if (o != null) {
                                        resolve_error = false;
@@ -347,7 +312,10 @@
                                }
                        }
 
-                       ConstructorInfo ctor = ResolveArguments ();
+                       EmitContext ec = new EmitContext (owner.ResolveContext, 
owner.ResolveContext.DeclContainer, owner.ResolveContext.DeclContainer,
+                               Location, null, null, 
owner.ResolveContext.DeclContainer.ModFlags, false);
+
+                       ConstructorInfo ctor = ResolveConstructor (ec);
                        if (ctor == null) {
                                if (Type is TypeBuilder && 
                                    TypeManager.LookupDeclSpace 
(Type).MemberCache == null)
@@ -360,111 +328,167 @@
                        CustomAttributeBuilder cb;
 
                        try {
-                               if (prop_info_arr != null || field_info_arr != 
null) {
-                                       cb = new CustomAttributeBuilder (
-                                               ctor, pos_values,
-                                               prop_info_arr, prop_values_arr,
-                                               field_info_arr, 
field_values_arr);
-                               } else {
-                                       cb = new CustomAttributeBuilder (
-                                               ctor, pos_values);
+                               if (NamedArguments == null) {
+                                       cb = new CustomAttributeBuilder (ctor, 
pos_values);
 
                                        if (pos_values.Length == 0)
                                                att_cache.Add (Type, cb);
+
+                                       resolve_error = false;
+                                       return cb;
                                }
+
+                               if (!ResolveNamedArguments (ec)) {
+                                       return null;
+                               }
+
+                               cb = new CustomAttributeBuilder (ctor, 
pos_values,
+                                               prop_info_arr, prop_values_arr,
+                                               field_info_arr, 
field_values_arr);
+
+                               resolve_error = false;
+                               return cb;
                        }
                        catch (Exception) {
                                Error_AttributeArgumentNotValid (Location);
                                return null;
                        }
-
-                       resolve_error = false;
-                       return cb;
                }
 
-               protected virtual ConstructorInfo ResolveArguments ()
+               protected virtual ConstructorInfo ResolveConstructor 
(EmitContext ec)
                {
-                       // Now we extract the positional and named arguments
-                       
-                       ArrayList pos_args = null;
-                       ArrayList named_args = null;
-                       int pos_arg_count = 0;
-                       int named_arg_count = 0;
-                       
-                       if (Arguments != null) {
-                               pos_args = (ArrayList) Arguments [0];
-                               if (pos_args != null)
-                                       pos_arg_count = pos_args.Count;
-                               if (Arguments.Count > 1) {
-                                       named_args = (ArrayList) Arguments [1];
-                                       named_arg_count = named_args.Count;
+                       if (PosArguments != null) {
+                               for (int i = 0; i < PosArguments.Count; i++) {
+                                       Argument a = (Argument) PosArguments 
[i];
+
+                                       if (!a.Resolve (ec, Location))
+                                               return null;
                                }
                        }
 
-                       pos_values = new object [pos_arg_count];
+                       Expression mg = Expression.MemberLookup 
(ec.ContainerType,
+                               Type, ".ctor", MemberTypes.Constructor,
+                               BindingFlags.Public | BindingFlags.Instance | 
BindingFlags.DeclaredOnly,
+                               Location);
 
-                       //
-                       // First process positional arguments 
-                       //
+                       MethodBase constructor = Invocation.OverloadResolve (
+                               ec, (MethodGroupExpr) mg, PosArguments, false, 
Location);
 
-                       EmitContext ec = new EmitContext (owner.ResolveContext, 
owner.ResolveContext.DeclContainer, owner.ResolveContext.DeclContainer,
-                                       Location, null, null, 
owner.ResolveContext.DeclContainer.ModFlags, false);
+                       if (constructor == null)
+                               return null;
 
-                       int i;
-                       for (i = 0; i < pos_arg_count; i++) {
-                               Argument a = (Argument) pos_args [i];
-                               Expression e;
+                       ObsoleteAttribute oa = 
AttributeTester.GetMethodObsoleteAttribute (constructor);
+                       if (oa != null && 
!owner.ResolveContext.IsInObsoleteScope) {
+                               AttributeTester.Report_ObsoleteMessage (oa, 
mg.GetSignatureForError (), mg.Location);
+                       }
 
-                               if (!a.Resolve (ec, Location))
-                                       return null;
+                       if (PosArguments == null) {
+                               pos_values = EmptyObject;
+                               return (ConstructorInfo)constructor;
+                       }
 
-                               e = a.Expr;
+                       ParameterData pd = TypeManager.GetParameterData 
(constructor);
 
-                               object val;
-                               if (!GetAttributeArgumentExpression (e, 
Location, a.Type, out val))
-                                       return null;
+                       int pos_arg_count = PosArguments.Count;
+                       int last_real_param = pd.Count;
 
-                               pos_values [i] = val;
+                       pos_values = new object [pos_arg_count];
 
-                               if (i == 0 && Type == 
TypeManager.attribute_usage_type && (int)val == 0) {
-                                       Report.Error (591, Location, "Invalid 
value for argument to 'System.AttributeUsage' attribute");
+                       if (pd.HasParams) {
+                               // When the params is not filled we need to put 
one
+                               if (last_real_param > pos_arg_count) {
+                                       object [] new_pos_values = new object 
[pos_arg_count + 1];
+                                       pos_values.CopyTo (new_pos_values, 0);
+                                       new_pos_values [pos_arg_count] = new 
object [] {} ;
+                                       pos_values = new_pos_values;
+                               }
+                               last_real_param--;
+                       }
+
+                       for (int j = 0; j < pos_arg_count; ++j) {
+                               Argument a = (Argument) PosArguments [j];
+
+                               if (!a.Expr.GetAttributableValue (out 
pos_values [j]))
                                        return null;
+                               
+                               if (TypeManager.IsPrimitiveType (a.Type) && 
a.Type != pos_values [j].GetType ()) {
+                                       bool fail;
+                                       // This can happen only for constants 
in same range
+                                       pos_values [j] = TypeManager.ChangeType 
(pos_values [j], a.Type, out fail);
                                }
+
+                               if (j < last_real_param)
+                                       continue;
+                               
+                               if (j == last_real_param) {
+                                       object [] array = new object 
[pos_arg_count - last_real_param];
+                                       array [0] = pos_values [j];
+                                       pos_values [j] = array;
+                                       continue;
+                               }
+
+                               object [] params_array = (object []) pos_values 
[last_real_param];
+                               params_array [j - last_real_param] = pos_values 
[j];
                        }
 
-                       //
-                       // Now process named arguments
-                       //
+                       // Adjust the size of the pos_values if it had params
+                       if (last_real_param != pos_arg_count) {
+                               object [] new_pos_values = new object 
[last_real_param + 1];
+                               Array.Copy (pos_values, new_pos_values, 
last_real_param + 1);
+                               pos_values = new_pos_values;
+                       }
 
-                       ArrayList field_infos = null;
-                       ArrayList prop_infos  = null;
-                       ArrayList field_values = null;
-                       ArrayList prop_values = null;
-                       Hashtable seen_names = null;
+                       // Here we do the checks which should be done by corlib 
or by runtime.
+                       // However Zoltan doesn't like it and every Mono 
compiler has to do it again.
+                       
+                       if (Type == TypeManager.guid_attr_type) {
+                               try {
+                                       new Guid ((string)pos_values [0]);
+                               }
+                               catch (Exception e) {
+                                       Error_AttributeEmitError (e.Message);
+                                       return null;
+                               }
+                       }
 
-                       if (named_arg_count > 0) {
-                               field_infos = new ArrayList (4);
-                               prop_infos  = new ArrayList (4);
-                               field_values = new ArrayList (4);
-                               prop_values = new ArrayList (4);
+                       if (Type == TypeManager.attribute_usage_type && 
(int)pos_values [0] == 0) {
+                               Report.Error (591, Location, "Invalid value for 
argument to 'System.AttributeUsage' attribute");
+                               return null;
+                       }
 
-                               seen_names = new Hashtable(4);
+                       if (Type == TypeManager.methodimpl_attr_type && 
pos_values.Length == 1 &&
+                               pd.ParameterType (0) == TypeManager.short_type 
&&
+                               !System.Enum.IsDefined (typeof 
(MethodImplOptions), pos_values [0].ToString ())) {
+                               Error_AttributeEmitError ("Incorrect argument 
value.");
+                               return null;
                        }
+
+                       return (ConstructorInfo)constructor;
+               }
+
+               protected virtual bool ResolveNamedArguments (EmitContext ec)
+               {
+                       int named_arg_count = NamedArguments.Count;
+
+                       ArrayList field_infos = new ArrayList (named_arg_count);
+                       ArrayList prop_infos  = new ArrayList (named_arg_count);
+                       ArrayList field_values = new ArrayList 
(named_arg_count);
+                       ArrayList prop_values = new ArrayList (named_arg_count);
+
+                       ArrayList seen_names = new ArrayList(named_arg_count);
                        
-                       for (i = 0; i < named_arg_count; i++) {
-                               DictionaryEntry de = (DictionaryEntry) 
named_args [i];
+                       foreach (DictionaryEntry de in NamedArguments) {
                                string member_name = (string) de.Key;
-                               Argument a  = (Argument) de.Value;
-                               Expression e;
 
                                if (seen_names.Contains(member_name)) {
                                        Report.Error(643, Location, "'" + 
member_name + "' duplicate named attribute argument");
-                                       return null;
+                                       return false;
                                }                               
-                               seen_names.Add(member_name, 1);
-                               
+                               seen_names.Add(member_name);
+
+                               Argument a = (Argument) de.Value;
                                if (!a.Resolve (ec, Location))
-                                       return null;
+                                       return false;
 
                                Expression member = Expression.MemberLookup (
                                        ec.ContainerType, Type, member_name,
@@ -479,187 +503,107 @@
 
                                        if (member != null) {
                                                Expression.ErrorIsInaccesible 
(Location, member.GetSignatureForError ());
-                                               return null;
+                                               return false;
                                        }
                                }
 
                                if (member == null){
                                        Report.Error (117, Location, "`{0}' 
does not contain a definition for `{1}'",
                                                      TypeManager.CSharpName 
(Type), member_name);
-                                       return null;
+                                       return false;
                                }
                                
                                if (!(member is PropertyExpr || member is 
FieldExpr)) {
                                        Error_InvalidNamedArgument 
(member_name);
-                                       return null;
+                                       return false;
                                }
 
-                               e = a.Expr;
-                               if (e is TypeParameterExpr){
+                               if (a.Expr is TypeParameterExpr){
                                        Error_TypeParameterInAttribute 
(Location);
-                                       return null;
+                                       return false;
                                }
-                                       
+
+                               ObsoleteAttribute obsolete_attr;
+
                                if (member is PropertyExpr) {
-                                       PropertyExpr pe = (PropertyExpr) member;
-                                       PropertyInfo pi = pe.PropertyInfo;
+                                       PropertyInfo pi = ((PropertyExpr) 
member).PropertyInfo;
 
                                        if (!pi.CanWrite || !pi.CanRead) {
                                                
Report.SymbolRelatedToPreviousError (pi);
                                                Error_InvalidNamedArgument 
(member_name);
-                                               return null;
+                                               return false;
                                        }
 
                                        if (!IsValidArgumentType 
(pi.PropertyType)) {
                                                
Report.SymbolRelatedToPreviousError (pi);
                                                Error_InvalidNamedAgrumentType 
(member_name);
-                                               return null;
+                                               return false;
                                        }
 
+                                       Expression e = 
Convert.ImplicitConversionRequired (ec, a.Expr, pi.PropertyType, 
a.Expr.Location);
+                                       if (e == null)
+                                               return false;
+
                                        object value;
-                                       if (!GetAttributeArgumentExpression (e, 
Location, pi.PropertyType, out value))
-                                               return null;
+                                       if (!e.GetAttributableValue (out value))
+                                               return false;
 
+                                       PropertyBase pb = 
TypeManager.GetProperty (pi);
+                                       if (pb != null)
+                                               obsolete_attr = 
pb.GetObsoleteAttribute ();
+                                       else
+                                               obsolete_attr = 
AttributeTester.GetMemberObsoleteAttribute (pi);
+
                                        prop_values.Add (value);
                                        prop_infos.Add (pi);
                                        
-                               } else if (member is FieldExpr) {
-                                       FieldExpr fe = (FieldExpr) member;
-                                       FieldInfo fi = fe.FieldInfo;
+                               } else {
+                                       FieldInfo fi = ((FieldExpr) 
member).FieldInfo;
 
                                        if (fi.IsInitOnly) {
                                                Error_InvalidNamedArgument 
(member_name);
-                                               return null;
+                                               return false;
                                        }
 
                                        if (!IsValidArgumentType 
(fi.FieldType)) {
                                                
Report.SymbolRelatedToPreviousError (fi);
                                                Error_InvalidNamedAgrumentType 
(member_name);
-                                               return null;
+                                               return false;
                                        }
+                                       Expression e = 
Convert.ImplicitConversionRequired (ec, a.Expr, fi.FieldType, a.Expr.Location);
+                                       if (e == null)
+                                               return false;
 
                                        object value;
-                                       if (!GetAttributeArgumentExpression (e, 
Location, fi.FieldType, out value))
-                                               return null;
+                                       if (!e.GetAttributableValue (out value))
+                                               return false;
 
+                                       FieldBase fb = TypeManager.GetField 
(fi);
+                                       if (fb != null)
+                                               obsolete_attr = 
fb.GetObsoleteAttribute ();
+                                       else
+                                               obsolete_attr = 
AttributeTester.GetMemberObsoleteAttribute (fi);
+
                                        field_values.Add (value);               
                        
                                        field_infos.Add (fi);
                                }
-                       }
 
-                       Expression mg = Expression.MemberLookup 
(ec.ContainerType,
-                               Type, ".ctor", MemberTypes.Constructor,
-                               BindingFlags.Public | BindingFlags.Instance | 
BindingFlags.DeclaredOnly,
-                                Location);
-
-                       if (mg == null) {
-                               // FIXME: Punt the issue for now.
-                               if (Type is TypeBuilder)
-                                       return null;
-                               throw new InternalErrorException ("Type " + 
Type + " doesn't have constructors");
+                               if (obsolete_attr != null && 
!owner.ResolveContext.IsInObsoleteScope)
+                                       AttributeTester.Report_ObsoleteMessage 
(obsolete_attr, member.GetSignatureForError (), member.Location);
                        }
 
-                       MethodBase constructor = Invocation.OverloadResolve (
-                               ec, (MethodGroupExpr) mg, pos_args, false, 
Location);
+                       prop_info_arr = new PropertyInfo [prop_infos.Count];
+                       field_info_arr = new FieldInfo [field_infos.Count];
+                       field_values_arr = new object [field_values.Count];
+                       prop_values_arr = new object [prop_values.Count];
 
-                       if (constructor == null) {
-                               return null;
-                       }
+                       field_infos.CopyTo  (field_info_arr, 0);
+                       field_values.CopyTo (field_values_arr, 0);
 
+                       prop_values.CopyTo  (prop_values_arr, 0);
+                       prop_infos.CopyTo   (prop_info_arr, 0);
 
-                       // Here we do the checks which should be done by corlib 
or by runtime.
-                       // However Zoltan doesn't like it and every Mono 
compiler has to do it again.
-                       
-                       if (Type == TypeManager.guid_attr_type) {
-                               try {
-                                       new Guid ((string)pos_values [0]);
-                               }
-                               catch (Exception e) {
-                                       Error_AttributeEmitError (e.Message);
-                                       return null;
-                               }
-                       }
-
-                       if (Type == TypeManager.methodimpl_attr_type &&
-                               pos_values.Length == 1 && ((Argument)pos_args 
[0]).Type == TypeManager.short_type &&
-                               !System.Enum.IsDefined (typeof 
(MethodImplOptions), pos_values [0])) {
-                                       Error_AttributeEmitError ("Incorrect 
argument value.");
-                               return null;
-                       }
-
-                       //
-                       // Now we perform some checks on the positional args as 
they
-                       // cannot be null for a constructor which expects a 
parameter
-                       // of type object
-                       //
-
-                       ParameterData pd = TypeManager.GetParameterData 
(constructor);
-
-                       int last_real_param = pd.Count;
-                       if (pd.HasParams) {
-                               // When the params is not filled we need to put 
one
-                               if (last_real_param > pos_arg_count) {
-                                       object [] new_pos_values = new object 
[pos_arg_count + 1];
-                                       pos_values.CopyTo (new_pos_values, 0);
-                                       new_pos_values [pos_arg_count] = new 
object [] {} ;
-                                       pos_values = new_pos_values;
-                               }
-                               last_real_param--;
-                       }
-
-                       for (int j = 0; j < pos_arg_count; ++j) {
-                               Argument a = (Argument) pos_args [j];
-                               
-                               if (a.Expr is NullLiteral && pd.ParameterType 
(j) == TypeManager.object_type) {
-                                       Error_AttributeArgumentNotValid 
(Location);
-                                       return null;
-                               }
-
-                               object value = pos_values [j];
-                               if (value != null && a.Type != value.GetType () 
&& TypeManager.IsPrimitiveType (a.Type)) {
-                                       bool fail;
-                                       pos_values [j] = TypeManager.ChangeType 
(value, a.Type, out fail);
-                                       if (fail) {
-                                               // TODO: Can failed ?
-                                               throw new 
NotImplementedException ();
-                                       }
-                               }
-
-                               if (j < last_real_param)
-                                       continue;
-                               
-                               if (j == last_real_param) {
-                                       object [] array = new object 
[pos_arg_count - last_real_param];
-                                       array [0] = pos_values [j];
-                                       pos_values [j] = array;
-                                       continue;
-                               }
-
-                               object [] params_array = (object []) pos_values 
[last_real_param];
-                               params_array [j - last_real_param] = pos_values 
[j];
-                       }
-
-                       // Adjust the size of the pos_values if it had params
-                       if (last_real_param != pos_arg_count) {
-                               object [] new_pos_values = new object 
[last_real_param + 1];
-                               Array.Copy (pos_values, new_pos_values, 
last_real_param + 1);
-                               pos_values = new_pos_values;
-                       }
-
-                       if (named_arg_count > 0) {
-                               prop_info_arr = new PropertyInfo 
[prop_infos.Count];
-                               field_info_arr = new FieldInfo 
[field_infos.Count];
-                               field_values_arr = new object 
[field_values.Count];
-                               prop_values_arr = new object 
[prop_values.Count];
-
-                               field_infos.CopyTo  (field_info_arr, 0);
-                               field_values.CopyTo (field_values_arr, 0);
-
-                               prop_values.CopyTo  (prop_values_arr, 0);
-                               prop_infos.CopyTo   (prop_info_arr, 0);
-                       }
-
-                       return (ConstructorInfo) constructor;
+                       return true;
                }
 
                /// <summary>
@@ -1214,12 +1158,8 @@
 
                        // Here we are testing attribute arguments for array 
usage (error 3016)
                        if (owner.IsClsComplianceRequired ()) {
-                               if (Arguments == null)
-                                       return;
-
-                               ArrayList pos_args = (ArrayList) Arguments [0];
-                               if (pos_args != null) {
-                                       foreach (Argument arg in pos_args) { 
+                               if (PosArguments != null) {
+                                       foreach (Argument arg in PosArguments) 
{ 
                                                // Type is undefined (was error 
246)
                                                if (arg.Type == null)
                                                        return;
@@ -1231,11 +1171,10 @@
                                        }
                                }
                        
-                               if (Arguments.Count < 2)
+                               if (NamedArguments == null)
                                        return;
                        
-                               ArrayList named_args = (ArrayList) Arguments 
[1];
-                               foreach (DictionaryEntry de in named_args) {
+                               foreach (DictionaryEntry de in NamedArguments) {
                                        Argument arg  = (Argument) de.Value;
 
                                        // Type is undefined (was error 246)
@@ -1367,15 +1306,10 @@
 
                private Expression GetValue () 
                {
-                       if ((Arguments == null) || (Arguments.Count < 1))
+                       if (PosArguments == null || PosArguments.Count < 1)
                                return null;
-                       ArrayList al = (ArrayList) Arguments [0];
-                       if ((al == null) || (al.Count < 1))
-                               return null;
-                       Argument arg = (Argument) al [0];
-                       if ((arg == null) || (arg.Expr == null))
-                               return null;
-                       return arg.Expr;
+
+                       return ((Argument) PosArguments [0]).Expr;
                }
 
                public string GetString () 
@@ -1405,7 +1339,7 @@
                public readonly NamespaceEntry ns;
 
                public GlobalAttribute (NamespaceEntry ns, string target, 
-                                       Expression left_expr, string 
identifier, ArrayList args, Location loc, bool nameEscaped):
+                                       Expression left_expr, string 
identifier, object[] args, Location loc, bool nameEscaped):
                        base (target, left_expr, identifier, args, loc, 
nameEscaped)
                {
                        this.ns = ns;
@@ -1454,16 +1388,27 @@
                        }
                }
 
-               protected override ConstructorInfo ResolveArguments ()
+               protected override ConstructorInfo ResolveConstructor 
(EmitContext ec)
                {
                        try {
                                Enter ();
-                               return base.ResolveArguments ();
+                               return base.ResolveConstructor (ec);
                        }
                        finally {
                                Leave ();
                        }
                }
+
+               protected override bool ResolveNamedArguments (EmitContext ec)
+               {
+                       try {
+                               Enter ();
+                               return base.ResolveNamedArguments (ec);
+                       }
+                       finally {
+                               Leave ();
+                       }
+               }
        }
 
        public class Attributes {

Modified: trunk/mcs/gmcs/cfold.cs
===================================================================
--- trunk/mcs/gmcs/cfold.cs     2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/cfold.cs     2006-03-23 14:56:16 UTC (rev 58360)
@@ -550,8 +550,14 @@
                                        Error_CompileTimeOverflow (loc);
                                }
 
-                               if (wrap_as != null)
-                                       return result.TryReduce (ec, wrap_as, 
loc);
+                               if (wrap_as != null) {
+                                       try {
+                                               return result.TryReduce (ec, 
wrap_as, loc);
+                                       }
+                                       catch (OverflowException) {
+                                               return null;
+                                       }
+                               }
                                else
                                        return result;
 
@@ -682,8 +688,14 @@
                                        Error_CompileTimeOverflow (loc);
                                }
 
-                               if (wrap_as != null)
-                                       return result.TryReduce (ec, wrap_as, 
loc);
+                               if (wrap_as != null) {
+                                       try {
+                                               return result.TryReduce (ec, 
wrap_as, loc);
+                                       }
+                                       catch (OverflowException) {
+                                               return null;
+                                       }
+                               }
 
                                return result;
                                

Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs     2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/class.cs     2006-03-23 14:56:16 UTC (rev 58360)
@@ -4357,7 +4357,7 @@
                        if ((RootContext.WarningLevel >= 4) && 
((Parent.ModFlags & Modifiers.SEALED) != 0 && (ModFlags & Modifiers.PROTECTED) 
!= 0)) {
                                Report.Warning (628, 4, Location, "`{0}': new 
protected member declared in sealed class", GetSignatureForError ());
                        }
-                       
+
                        return true;
                }
                
@@ -4414,7 +4414,7 @@
                                }
                                ConstructorBuilder.SetImplementationFlags 
(MethodImplAttributes.InternalCall);
                        }
-                       
+
                        TypeManager.AddMethod (ConstructorBuilder, this);
 
                        return true;
@@ -6525,6 +6525,7 @@
                        if (!Set.IsDummy)
                                PropertyBuilder.SetSetMethod (SetBuilder);
 
+                       TypeManager.RegisterProperty (PropertyBuilder, this);
                        return true;
                }
        }

Modified: trunk/mcs/gmcs/constant.cs
===================================================================
--- trunk/mcs/gmcs/constant.cs  2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/constant.cs  2006-03-23 14:56:16 UTC (rev 58360)
@@ -39,6 +39,12 @@
                        return this.GetType ().Name + " (" + AsString () + ")";
                }
 
+               public override bool GetAttributableValue (out object value)
+               {
+                       value = GetTypedValue ();
+                       return true;
+               }
+
                /// <summary>
                ///  This is used to obtain the actual value of the literal
                ///  cast into an object.
@@ -233,6 +239,10 @@
                                throw new OverflowException ();
                }
 
+               /// <summary>
+               /// Maybe ConvertTo name is better. It tries to convert `this' 
constant to target_type.
+               /// It throws OverflowException 
+               /// </summary>
                public abstract Constant Reduce (EmitContext ec, Type 
target_type);
 
                /// <summary>
@@ -244,11 +254,9 @@
                                return  TryReduce (ec, target_type);
                        }
                        catch (OverflowException) {
-                               if (ec.ConstantCheckState) {
-                                       Report.Error (221, loc, "Constant value 
`{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)",
-                                               GetValue ().ToString (), 
TypeManager.CSharpName (target_type));
-                               }
-                               return null;
+                               Report.Error (221, loc, "Constant value `{0}' 
cannot be converted to a `{1}' (use `unchecked' syntax to override)",
+                                       GetValue ().ToString (), 
TypeManager.CSharpName (target_type));
+                               throw;
                        }
                }
 

Modified: trunk/mcs/gmcs/cs-parser.jay
===================================================================
--- trunk/mcs/gmcs/cs-parser.jay        2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/cs-parser.jay        2006-03-23 14:56:16 UTC (rev 58360)
@@ -641,7 +641,7 @@
                                      "'<' unexpected: attributes cannot be 
generic");
                }
 
-               ArrayList arguments = (ArrayList) $2;
+               object [] arguments = (object []) $2;
                MemberName left = mname.Left;
                string identifier = mname.Name;
 
@@ -675,29 +675,18 @@
                if ($1 == null)
                        $$ = null;
                else {
-                       ArrayList args = new ArrayList (4);
-                       args.Add ($1);
-               
-                       $$ = args;
+                       $$ = new object [] { $1, null };
                }
          }
-        | positional_argument_list COMMA named_argument_list
+    | positional_argument_list COMMA named_argument_list
          {
-               ArrayList args = new ArrayList (4);
-               args.Add ($1);
-               args.Add ($3);
-
-               $$ = args;
+               $$ = new object[] { $1, $3 };
          }
-        | named_argument_list
+    | named_argument_list
          {
-               ArrayList args = new ArrayList (4);
-               args.Add (null);
-               args.Add ($1);
-               
-               $$ = args;
+               $$ = new object [] { null, $1 };
          }
-        ;
+    ;
 
 
 opt_positional_argument_list

Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs     2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/ecore.cs     2006-03-23 14:56:16 UTC (rev 58360)
@@ -137,6 +137,13 @@
                // Not nice but we have broken hierarchy
                public virtual void CheckMarshallByRefAccess (Type container) {}
 
+               public virtual bool GetAttributableValue (out object value)
+               {
+                       Attribute.Error_AttributeArgumentNotValid (loc);
+                       value = null;
+                       return false;
+               }
+
                public virtual string GetSignatureForError ()
                {
                        return TypeManager.CSharpName (type);
@@ -324,28 +331,29 @@
                                TypeManager.CSharpName (type), name);
                }
 
-               ResolveFlags ExprClassToResolveFlags ()
+               ResolveFlags ExprClassToResolveFlags
                {
-                       switch (eclass) {
-                       case ExprClass.Type:
-                       case ExprClass.Namespace:
-                               return ResolveFlags.Type;
+                       get {
+                               switch (eclass) {
+                                       case ExprClass.Type:
+                                       case ExprClass.Namespace:
+                                               return ResolveFlags.Type;
 
-                       case ExprClass.MethodGroup:
-                               return ResolveFlags.MethodGroup;
+                                       case ExprClass.MethodGroup:
+                                               return ResolveFlags.MethodGroup;
 
-                       case ExprClass.Value:
-                       case ExprClass.Variable:
-                       case ExprClass.PropertyAccess:
-                       case ExprClass.EventAccess:
-                       case ExprClass.IndexerAccess:
-                               return ResolveFlags.VariableOrValue;
+                                       case ExprClass.Value:
+                                       case ExprClass.Variable:
+                                       case ExprClass.PropertyAccess:
+                                       case ExprClass.EventAccess:
+                                       case ExprClass.IndexerAccess:
+                                               return 
ResolveFlags.VariableOrValue;
 
-                       default:
-                               throw new Exception ("Expression " + GetType () 
+
-                                                    " ExprClass is Invalid 
after resolve");
+                                       default:
+                                               throw new Exception 
("Expression " + GetType () +
+                                                       " ExprClass is Invalid 
after resolve");
+                               }
                        }
-
                }
               
                /// <summary>
@@ -369,10 +377,10 @@
                                ec.OmitStructFlowAnalysis = true;
 
                        Expression e;
-                       bool intermediate = (flags & ResolveFlags.Intermediate) 
== ResolveFlags.Intermediate;
-                       if (this is SimpleName)
+                       if (this is SimpleName) {
+                               bool intermediate = (flags & 
ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
                                e = ((SimpleName) this).DoResolve (ec, 
intermediate);
-
+                       }
                        else 
                                e = DoResolve (ec);
 
@@ -382,7 +390,7 @@
                        if (e == null)
                                return null;
 
-                       if ((flags & e.ExprClassToResolveFlags ()) == 0) {
+                       if ((flags & e.ExprClassToResolveFlags) == 0) {
                                e.Error_UnexpectedKind (flags, loc);
                                return null;
                        }
@@ -1150,8 +1158,8 @@
        ///
        /// </summary>
        public class EmptyCast : Expression {
-               protected Expression child;
-               
+               protected readonly Expression child;
+
                public Expression Child {
                        get {
                                return child;
@@ -1178,6 +1186,12 @@
                {
                        child.Emit (ec);
                }
+
+               public override bool GetAttributableValue (out object value)
+               {
+                       return child.GetAttributableValue (out value);
+               }
+
        }
        /// <summary>
        ///     This is a numeric cast to a Decimal
@@ -3493,6 +3507,7 @@
                // We also perform the permission checking here, as the 
PropertyInfo does not
                // hold the information for the accessibility of its 
setter/getter
                //
+               // TODO: can use TypeManager.GetProperty to boost performance
                void ResolveAccessors (Type containerType)
                {
                        FindAccessors (containerType);

Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs        2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/expression.cs        2006-03-23 14:56:16 UTC (rev 58360)
@@ -1290,7 +1290,12 @@
 
                        Error_CannotConvertType (etype, type, loc);
                        return null;
-               }                               
+               }
+       
+               public override bool GetAttributableValue (out object value)
+               {
+                       return expr.GetAttributableValue (out value);
+               }
        }
        
        /// <summary>
@@ -1365,9 +1370,14 @@
 
                        Constant c = expr as Constant;
                        if (c != null) {
-                               c = c.TryReduce (ec, type, loc);
-                               if (c != null)
-                                       return c;
+                               try {
+                                       c = c.TryReduce (ec, type, loc);
+                                       if (c != null)
+                                               return c;
+                               }
+                               catch (OverflowException) {
+                                       return null;
+                               }
                        }
 
                        if (type.IsPointer && !ec.InUnsafe) {
@@ -6309,10 +6319,7 @@
                public bool ValidateInitializers (EmitContext ec, Type 
array_type)
                {
                        if (initializers == null) {
-                               if (expect_initializers)
-                                       return false;
-                               else
-                                       return true;
+                               return !expect_initializers;
                        }
                        
                        if (underlying_type == null)
@@ -6325,17 +6332,12 @@
                        array_data = new ArrayList ();
                        bounds = new Hashtable ();
                        
-                       bool ret;
-
                        if (arguments != null) {
-                               ret = CheckIndices (ec, initializers, 0, true);
-                               return ret;
+                               return CheckIndices (ec, initializers, 0, true);
                        } else {
                                arguments = new ArrayList ();
 
-                               ret = CheckIndices (ec, initializers, 0, false);
-                               
-                               if (!ret)
+                               if (!CheckIndices (ec, initializers, 0, false))
                                        return false;
                                
                                UpdateIndices (ec);
@@ -6345,7 +6347,7 @@
                                        return false;
                                }
 
-                               return ret;
+                               return true;
                        }
                }
 
@@ -6806,32 +6808,33 @@
                        }
                }
 
-               public object EncodeAsAttribute ()
+               public override bool GetAttributableValue (out object value)
                {
                        if (!is_one_dimensional){
-                               Report.Error (-211, Location, "attribute can 
not encode multi-dimensional arrays");
-                               return null;
+//                             Report.Error (-211, Location, "attribute can 
not encode multi-dimensional arrays");
+                               return base.GetAttributableValue (out value);
                        }
 
-                       if (array_data == null){
-                               Report.Error (-212, Location, "array should be 
initialized when passing it to an attribute");
-                               return null;
+                       if (array_data == null) {
+                               Constant c = (Constant)((Argument)arguments 
[0]).Expr;
+                               if (c.IsDefaultValue) {
+                                       value = new object [0];
+                                       return true;
+                               }
+//                             Report.Error (-212, Location, "array should be 
initialized when passing it to an attribute");
+                               return base.GetAttributableValue (out value);
                        }
                        
                        object [] ret = new object [array_data.Count];
-                       int i = 0;
-                       foreach (Expression e in array_data){
-                               object v;
-                               
-                               if (e is NullLiteral)
-                                       v = null;
-                               else {
-                                       if 
(!Attribute.GetAttributeArgumentExpression (e, Location, array_element_type, 
out v))
-                                               return null;
+                       for (int i = 0; i < ret.Length; ++i)
+                       {
+                               if (!((Expression)array_data 
[i]).GetAttributableValue (out ret [i])) {
+                                       value = null;
+                                       return false;
                                }
-                               ret [i++] = v;
                        }
-                       return ret;
+                       value = ret;
+                       return true;
                }
        }
        
@@ -7096,7 +7099,7 @@
        ///   Implements the typeof operator
        /// </summary>
        public class TypeOf : Expression {
-               public Expression QueriedType;
+               readonly Expression QueriedType;
                protected Type typearg;
                
                public TypeOf (Expression queried_type, Location l)
@@ -7136,8 +7139,10 @@
                        ec.ig.Emit (OpCodes.Call, 
TypeManager.system_type_get_type_from_handle);
                }
 
-               public Type TypeArg { 
-                       get { return typearg; }
+               public override bool GetAttributableValue (out object value)
+               {
+                       value = typearg;
+                       return true;
                }
        }
 

Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs       2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/gmcs/typemanager.cs       2006-03-23 14:56:16 UTC (rev 58360)
@@ -243,7 +243,9 @@
        public static Hashtable AllClsTopLevelTypes;
 
        static Hashtable fieldbuilders_to_fields;
+       static Hashtable propertybuilder_to_property;
        static Hashtable fields;
+       static Hashtable events;
 
        static PtrHashtable assembly_internals_vis_attrs;
 
@@ -266,8 +268,8 @@
                fieldbuilders_to_fields = null;
                events = null;
                priv_fields_events = null;
-
                type_hash = null;
+               propertybuilder_to_property = null;
 
                assembly_internals_vis_attrs = null;
                
@@ -365,6 +367,7 @@
                builder_to_ifaces = new PtrHashtable ();
                
                fieldbuilders_to_fields = new Hashtable ();
+               propertybuilder_to_property = new Hashtable ();
                fields = new Hashtable ();
                type_hash = new DoubleHash ();
 
@@ -1874,6 +1877,16 @@
                return (IConstant)fields [fb];
        }
 
+       public static void RegisterProperty (PropertyInfo pi, PropertyBase pb)
+       {
+               propertybuilder_to_property.Add (pi, pb);
+       }
+
+       public static PropertyBase GetProperty (PropertyInfo pi)
+       {
+               return (PropertyBase)propertybuilder_to_property [pi];
+       }
+
        static public bool RegisterFieldBase (FieldBuilder fb, FieldBase f)
        {
                if (fieldbuilders_to_fields.Contains (fb))
@@ -1894,8 +1907,6 @@
                return (FieldBase) fieldbuilders_to_fields [fb];
        }
        
-       static Hashtable events;
-
        static public void RegisterEvent (MyEventBuilder eb, MethodBase add, 
MethodBase remove)
        {
                if (events == null)

Modified: trunk/mcs/tests/known-issues-gmcs
===================================================================
--- trunk/mcs/tests/known-issues-gmcs   2006-03-23 14:29:14 UTC (rev 58359)
+++ trunk/mcs/tests/known-issues-gmcs   2006-03-23 14:56:16 UTC (rev 58360)
@@ -10,7 +10,6 @@
 test-xml-027.cs
 test-465.cs IGNORE     # need to fix the path separator to work both on Unix 
and Windows
 test-476.cs
-test-492.cs
 test-494.cs
 test-495.cs
 test-anon-11.cs

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

Reply via email to