**** Merged from MCS ****
authorMartin Baulig <martin@novell.com>
Wed, 19 May 2004 14:00:31 +0000 (14:00 -0000)
committerMartin Baulig <martin@novell.com>
Wed, 19 May 2004 14:00:31 +0000 (14:00 -0000)
svn path=/trunk/mcs/; revision=27672

15 files changed:
mcs/gmcs/ChangeLog
mcs/gmcs/attribute.cs
mcs/gmcs/class.cs
mcs/gmcs/const.cs
mcs/gmcs/decl.cs
mcs/gmcs/delegate.cs
mcs/gmcs/ecore.cs
mcs/gmcs/enum.cs
mcs/gmcs/expression.cs
mcs/gmcs/generic.cs
mcs/gmcs/parameter.cs
mcs/gmcs/report.cs
mcs/gmcs/statement.cs
mcs/gmcs/tree.cs
mcs/gmcs/typemanager.cs

index c7cc4ec292da94d76b42e038465b2a3d3b55d65c..df4a2c7c4a4952985681444b4bc0e1c87492fe8d 100755 (executable)
@@ -1,3 +1,126 @@
+2004-04-29  Martin Baulig  <martin@ximian.com>
+
+       * typemanager.cs (TypeManager.CheckStructCycles): Fixed.
+
+2004-04-29  Martin Baulig  <martin@ximian.com>
+
+       Applying a patch from Benjamin Jemlich <pcgod@gmx.net>.
+
+       * ecore.cs (FieldExpr.AddressOf): Make this work for valuetypes.
+
+2004-04-29  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (ConstructorInitializer.Resolve): Check whether the
+       parent .ctor is accessible.  Fixes #52146.
+
+2004-04-29  Martin Baulig  <martin@ximian.com>
+
+       Applying a patch from Benjamin Jemlich <pcgod@gmx.net>.
+
+       * statement.cs (Using.EmitLocalVariableDecls): Use
+       TypeManager.idisposable_type, not typeof (IDisposable).
+       (Foreach.EmitCollectionForeach): Added support for valuetypes.
+
+2004-04-29  Martin Baulig  <martin@ximian.com>
+
+       * class.cs (Event.Define): Don't emit the field and don't set
+       RTSpecialName and SpecialName for events on interfaces.  Fixes
+       #57703. 
+
+2004-04-29  Raja R Harinath  <rharinath@novell.com>
+
+       Refactor Attribute.ApplyAttributes.
+       * attribute.cs (Attributable): New base class for objects that can
+       have Attributes applied on them.
+       (Attribute): Make AttributeUsage fields public.
+       (Attribute.GetFieldValue, Attribute.GetMarshal): Make non-static.
+       (Attribute.IsInternalCall): New property.
+       (Attribute.UsageAttr): Convert to a public read-only property.
+       (Attribute.CheckAttributeType): Use a DeclSpace, not an EmitContext.
+       (Attribute.ResolveType, Attribute.Resolve)
+       (Attribute.ScanForIndexerName): Update to reflect changes.
+       (Attribute.CheckAttributeTarget): Re-format.
+       (Attribute.ApplyAttributes): Refactor, to various
+       Attributable.ApplyAttributeBuilder methods.
+       * decl.cs (MemberCore): Make Attributable.
+       * class.cs (Accessor): Make Attributable.
+       (MethodData.ApplyAttributes): Use proper attribute types, not
+       attribute names.
+       (TypeContainer.LabelParameters): Pass Parameter to ApplyAttributes.
+       (TypeContainer.ApplyAttributeBuilder)
+       (Method.ApplyAttributeBuilder, Constructor.ApplyAttributeBuilder)
+       (Field.ApplyAttributeBuilder, Accessor.ApplyAttributeBuilder)   
+       (PropertyBase.ApplyAttributeBuilder, Event.ApplyAttributeBuilder)
+       (Operator.ApplyAttributeBuilder): New factored-out methods.
+       * const.cs (Const.ApplyAttributeBuilder): Likewise.
+       * delegate.cs (Delegate.ApplyAttributeBuilder): Likewise.
+       * enum.cs (Enum.ApplyAttributeBuilder): Likewise.
+       * parameter.cs (ParameterBase): New Attributable base class
+       that can also represent Return types.
+       (Parameter): Update to the changes.
+
+2004-04-29  Jackson Harper  <jackson@ximian.com>
+
+       * driver.cs: Prefer the corlib system version when looking for
+       assemblies in the GAC. This is still a hack, but its a better hack
+       now.
+       
+2004-04-29  Marek Safar  <marek.safar@seznam.cz>
+
+       * decl.cs, enum.cs: Improved error 3005 reporting.
+  
+       * report.cs (SymbolRelatedToPreviousError): New method for error reporting.
+        (related_symbols): New private member for list of symbols
+       related to reported error/warning.
+        
+       * tree.cs: Do not use now obsolete Report.LocationOfPreviousError.
+
+2004-04-29  Martin Baulig  <martin@ximian.com>
+
+       * ecore.cs (Expression.Constantify): If we're an enum and
+       TypeManager.TypeToCoreType() doesn't give us another type, use
+       t.UnderlyingSystemType.  Fixes #56178.  
+
+2004-04-29  Martin Baulig  <martin@ximian.com>
+
+       * decl.cs (MemberCache.SetupCacheForInterface): Look over all our
+       interfaces and for each interface, only add members directly
+       declared in that interface.  Fixes #53255.
+
+2004-04-28  Martin Baulig  <martin@ximian.com>
+
+       * expression.cs (ConditionalLogicalOperator): Use a temporary
+       variable for `left' to avoid that we evaluate it more than once;
+       bug #52588.
+
+2004-04-28  Martin Baulig  <martin@ximian.com>
+
+       * expression.cs (ComposedCast.DoResolveAsTypeStep): Don't allow
+       `void[]' (CS1547).
+
+2004-04-28  Martin Baulig  <martin@ximian.com>
+
+       * statement.cs (LocalInfo.Resolve): Check whether the type is not
+       void (CS1547).
+
+       * class.cs (MemberBase.CheckParameters, FieldBase.DoDefine): Check
+       whether the type is not void (CS1547).
+
+2004-04-28  Martin Baulig  <martin@ximian.com>
+
+       * expression.cs (Unary.DoResolveLValue): Override this and report
+       CS0131 for anything but Operator.Indirection.
+
+2004-04-28  Martin Baulig  <martin@ximian.com>
+
+       Committing a patch from Ben Maurer; see bug #50820.
+
+       * typemanager.cs (TypeManager.FilterWithClosure): Added CS1540
+       check for classes.
+
+       * ecore.cs (Expression.MemberLookupFailed): Added CS1540 check for
+       classes.        
+
 2004-04-28  Martin Baulig  <martin@ximian.com>
 
        * statement.cs (Block.LookupLabel): Also lookup in implicit child blocks.
        for a named field or property, implicity convert it to the correct
        type.
 
->>>>>>> 1.1450
 2004-04-27  Raja R Harinath  <rharinath@novell.com>
 
        * statement.cs (Block.Block): Implicit blocks share
index 796fd066d70d6659d2c9a0f436c28b7a1c022b4d..4c58bade5f4ca59d09d42236f28b33f979f73e2a 100644 (file)
@@ -20,6 +20,36 @@ using System.Runtime.CompilerServices;
 using System.Text;\r
 \r
 namespace Mono.CSharp {\r
+       /// <summary>\r
+       ///   Base class for objects that can have Attributes applied to them.\r
+       /// </summary>\r
+       public abstract class Attributable {\r
+               /// <summary>\r
+               ///   Attributes for this type\r
+               /// </summary>\r
+               Attributes attributes;\r
+\r
+               public Attributable(Attributes attrs)\r
+               {\r
+                       attributes = attrs;\r
+               }\r
+\r
+               public Attributes OptAttributes \r
+               {\r
+                       get {\r
+                               return attributes;\r
+                       }\r
+                       set {\r
+                               attributes = value;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Use member-specific procedure to apply attribute @a in @cb to the entity being built in @builder\r
+               /// </summary>\r
+               public abstract void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb);\r
+       };\r
+\r
 \r
        public class Attribute {\r
                public readonly string    Name;\r
@@ -33,12 +63,16 @@ namespace Mono.CSharp {
                // The following are only meaningful when the attribute\r
                // being emitted is an AttributeUsage attribute\r
                //\r
-               AttributeTargets Targets;\r
-               bool AllowMultiple;\r
-               bool Inherited;\r
+               public AttributeTargets Targets;\r
+               public bool AllowMultiple;\r
+               public bool Inherited;\r
 \r
-               bool UsageAttr = false;\r
+               bool usage_attr = false;\r
                \r
+               public bool UsageAttr {\r
+                       get { return usage_attr; }\r
+               }\r
+\r
                MethodImplOptions ImplOptions;\r
                UnmanagedType     UnmanagedType;\r
                CustomAttributeBuilder cb;\r
@@ -127,7 +161,8 @@ namespace Mono.CSharp {
 \r
                public Type ResolveType (EmitContext ec)\r
                {\r
-                       Type = CheckAttributeType (ec);\r
+                       if (Type == null)\r
+                               Type = CheckAttributeType (ec);\r
                        return Type;\r
                }\r
 \r
@@ -176,15 +211,14 @@ namespace Mono.CSharp {
                \r
                public CustomAttributeBuilder Resolve (EmitContext ec)\r
                {\r
-                       if (Type == null)\r
-                               Type = CheckAttributeType (ec);\r
+                       ResolveType (ec);\r
                        if (Type == null)\r
                                return null;\r
 \r
                        bool MethodImplAttr = false;\r
                        bool MarshalAsAttr = false;\r
                        bool GuidAttr = false;\r
-                       UsageAttr = false;\r
+                       usage_attr = false;\r
 \r
                        bool DoCompares = true;\r
 \r
@@ -194,7 +228,7 @@ namespace Mono.CSharp {
                         //\r
                         \r
                        if (Type == TypeManager.attribute_usage_type)\r
-                               UsageAttr = true;\r
+                               usage_attr = true;\r
                        else if (Type == TypeManager.methodimpl_attr_type)\r
                                MethodImplAttr = true;\r
                        else if (Type == TypeManager.marshal_as_attr_type)\r
@@ -611,77 +645,25 @@ namespace Mono.CSharp {
                        } else\r
                                targets = attr.Targets;\r
 \r
-\r
-                       if (element is Class) {\r
-                               if ((targets & AttributeTargets.Class) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                               \r
-                       } else if (element is Struct) {\r
-                               if ((targets & AttributeTargets.Struct) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Constructor) {\r
-                               if ((targets & AttributeTargets.Constructor) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Delegate) {\r
-                               if ((targets & AttributeTargets.Delegate) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Enum) {\r
-                               if ((targets & AttributeTargets.Enum) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Event) {\r
-                               if ((targets & AttributeTargets.Event) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Field || element is FieldBuilder) {\r
-                               if ((targets & AttributeTargets.Field) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Interface) {\r
-                               if ((targets & AttributeTargets.Interface) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Method || element is Operator ||\r
-                                   element is Accessor) {\r
-                               if ((targets & AttributeTargets.Method) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is ParameterBuilder) {\r
-                               if ((targets & AttributeTargets.Parameter) != 0 ||\r
-                                    (targets & AttributeTargets.ReturnValue) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is Property || element is Indexer ||\r
-                                  element is Accessor) {\r
-                               if ((targets & AttributeTargets.Property) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is AssemblyClass){\r
-                               if ((targets & AttributeTargets.Assembly) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       } else if (element is ModuleClass){\r
-                               if ((targets & AttributeTargets.Module) != 0)\r
-                                       return true;\r
-                               else\r
-                                       return false;\r
-                       }\r
+                       if (element is Class)           return ((targets & AttributeTargets.Class) != 0);\r
+                       if (element is Struct)          return ((targets & AttributeTargets.Struct) != 0);\r
+                       if (element is Constructor)     return ((targets & AttributeTargets.Constructor) != 0);\r
+                       if (element is Delegate)        return ((targets & AttributeTargets.Delegate) != 0);\r
+                       if (element is Enum)            return ((targets & AttributeTargets.Enum) != 0);\r
+                       if (element is Event)           return ((targets & AttributeTargets.Event) != 0);\r
+                       if (element is Field \r
+                           || element is FieldBuilder) return ((targets & AttributeTargets.Field) != 0);\r
+                       if (element is Interface)       return ((targets & AttributeTargets.Interface) != 0);\r
+                       if (element is Method\r
+                           || element is Operator\r
+                           || element is Accessor)     return ((targets & AttributeTargets.Method) != 0);\r
+                       if (element is ParameterBase)   return ((targets & (AttributeTargets.Parameter \r
+                                                                           | AttributeTargets.ReturnValue)) != 0);\r
+                       if (element is Property\r
+                           || element is Indexer\r
+                           || element is Accessor)     return ((targets & AttributeTargets.Property) != 0);\r
+                       if (element is AssemblyClass)   return ((targets & AttributeTargets.Assembly) != 0);\r
+                       if (element is ModuleClass)     return ((targets & AttributeTargets.Module) != 0);\r
 \r
                        return false;\r
                }\r
@@ -830,25 +812,25 @@ namespace Mono.CSharp {
                        return (bool)pos_values [0];\r
                }\r
 \r
-               static object GetFieldValue (Attribute a, string name)\r
+               object GetFieldValue (string name)\r
                 {\r
                        int i;\r
-                       if (a.field_info_arr == null)\r
+                       if (field_info_arr == null)\r
                                return null;\r
                        i = 0;\r
-                       foreach (FieldInfo fi in a.field_info_arr) {\r
+                       foreach (FieldInfo fi in field_info_arr) {\r
                                if (fi.Name == name)\r
-                                       return a.field_values_arr [i];\r
+                                       return field_values_arr [i];\r
                                i++;\r
                        }\r
                        return null;\r
                }\r
 \r
-               static UnmanagedMarshal GetMarshal (Attribute a)\r
+               public UnmanagedMarshal GetMarshal ()\r
                 {\r
-                       object o = GetFieldValue (a, "ArraySubType");\r
+                       object o = GetFieldValue ("ArraySubType");\r
                        UnmanagedType array_sub_type = o == null ? UnmanagedType.I4 : (UnmanagedType) o;\r
-                       switch (a.UnmanagedType) {\r
+                       switch (UnmanagedType) {\r
                        case UnmanagedType.CustomMarshaler:\r
                                MethodInfo define_custom = typeof (UnmanagedMarshal).GetMethod ("DefineCustom",\r
                                                                        BindingFlags.Static | BindingFlags.Public);\r
@@ -856,9 +838,9 @@ namespace Mono.CSharp {
                                        return null;\r
 \r
                                object [] args = new object [4];\r
-                               args [0] = GetFieldValue (a, "MarshalTypeRef");\r
-                               args [1] = GetFieldValue (a, "MarshalCookie");\r
-                               args [2] = GetFieldValue (a, "MarshalType");\r
+                               args [0] = GetFieldValue ("MarshalTypeRef");\r
+                               args [1] = GetFieldValue ("MarshalCookie");\r
+                               args [2] = GetFieldValue ("MarshalType");\r
                                args [3] = Guid.Empty;\r
                                return (UnmanagedMarshal) define_custom.Invoke (null, args);\r
 \r
@@ -869,16 +851,21 @@ namespace Mono.CSharp {
                                return UnmanagedMarshal.DefineSafeArray (array_sub_type);\r
 \r
                        case UnmanagedType.ByValArray:\r
-                               return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue (a, "SizeConst"));\r
+                               return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue ("SizeConst"));\r
 \r
                        case UnmanagedType.ByValTStr:\r
-                               return UnmanagedMarshal.DefineByValTStr ((int) GetFieldValue (a, "SizeConst"));\r
+                               return UnmanagedMarshal.DefineByValTStr ((int) GetFieldValue ("SizeConst"));\r
 \r
                        default:\r
-                               return UnmanagedMarshal.DefineUnmanagedMarshal (a.UnmanagedType);\r
+                               return UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType);\r
                        }\r
                }\r
 \r
+               public bool IsInternalCall\r
+               {\r
+                       get { return ImplOptions == MethodImplOptions.InternalCall; }\r
+               }\r
+\r
                /// <summary>\r
                ///   Applies the attributes specified on target 'kind' to the `builder'.\r
                /// </summary>\r
@@ -912,12 +899,6 @@ namespace Mono.CSharp {
                                        if (cb == null) \r
                                                continue;\r
                                        \r
-                                       if (!(kind is TypeContainer))\r
-                                               if (!CheckAttributeTarget (a, kind)) {\r
-                                                       Error_AttributeNotValidForElement (a, loc);\r
-                                                       return;\r
-                                               }\r
-\r
                                        //\r
                                        // Perform the check for duplicate attributes\r
                                        //\r
@@ -928,172 +909,39 @@ namespace Mono.CSharp {
                                                return;\r
                                        }\r
 \r
-                                       if (kind is IAttributeSupport) {\r
-                                               if (attr_type == TypeManager.methodimpl_attr_type && a.ImplOptions == MethodImplOptions.InternalCall) {\r
-                                                       ((MethodBuilder) builder).SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);\r
-                                               } \r
-                                               else {\r
-                                                       IAttributeSupport attributeSupport = kind as IAttributeSupport;\r
-                                                       attributeSupport.SetCustomAttribute (cb);\r
-                                               }\r
+                                       if (!CheckAttributeTarget (a, kind)) {\r
+                                               Error_AttributeNotValidForElement (a, loc);\r
+                                               return;\r
                                        }\r
-                                       else if (kind is Method || kind is Operator || kind is Accessor) {\r
-                                               if (attr_type == TypeManager.methodimpl_attr_type) {\r
-                                                       if (a.ImplOptions == MethodImplOptions.InternalCall)\r
-                                                               ((MethodBuilder) builder).\r
-                                                               SetImplementationFlags (\r
-                                                                       MethodImplAttributes.InternalCall |\r
-                                                                       MethodImplAttributes.Runtime);\r
-                                                       else\r
-                                                               ((MethodBuilder) builder).SetCustomAttribute (cb);\r
-                                               } else if (attr_type != TypeManager.dllimport_type){\r
-                                                       ((MethodBuilder) builder).SetCustomAttribute (cb);\r
-                                               }\r
-                                       } else if (kind is Constructor) {\r
-                                               ((ConstructorBuilder) builder).SetCustomAttribute (cb);\r
-                                       } else if (kind is Field) {\r
-                                               if (attr_type == TypeManager.marshal_as_attr_type) {\r
-                                                       UnmanagedMarshal marshal = GetMarshal (a);\r
-                                                       if (marshal == null) {\r
-                                                               Report.Warning (-24, loc,\r
-                                                                       "The Microsoft Runtime cannot set this marshal info. " +\r
-                                                                       "Please use the Mono runtime instead.");\r
-                                                       } else {\r
-                                                               ((FieldBuilder) builder).SetMarshal (marshal);\r
-                                                       }\r
-                                               } else { \r
-                                                       ((FieldBuilder) builder).SetCustomAttribute (cb);\r
-                                               }\r
-                                       } else if (kind is Property || kind is Indexer) {\r
-\r
-                                                if (builder is PropertyBuilder) \r
-                                               ((PropertyBuilder) builder).SetCustomAttribute (cb);\r
-                                                //\r
-                                                // This is for the case we are setting attributes on\r
-                                                // the get and set accessors\r
-                                                //\r
-                                                else if (builder is MethodBuilder)\r
-                                                        ((MethodBuilder) builder).SetCustomAttribute (cb);\r
-                                       } else if (kind is Event) {\r
-                                               ((MyEventBuilder) builder).SetCustomAttribute (cb);\r
-                                       } else if (kind is ParameterBuilder) {\r
-\r
-                                               if (attr_type == TypeManager.marshal_as_attr_type) {\r
-                                                       UnmanagedMarshal marshal = GetMarshal (a);\r
-                                                       if (marshal == null) {\r
-                                                               Report.Warning (-24, loc,\r
-                                                                       "The Microsoft Runtime cannot set this marshal info. " +\r
-                                                                       "Please use the Mono runtime instead.");\r
-                                                       } else {\r
-                                                               ((ParameterBuilder) builder).SetMarshal (marshal);\r
-                                                       }\r
-                                               } else { \r
-\r
-                                                       try {\r
-                                                               ((ParameterBuilder) builder).SetCustomAttribute (cb);\r
-                                                       } catch (System.ArgumentException) {\r
-                                                               Report.Warning (-24, loc,\r
-                                                                               "The Microsoft Runtime cannot set attributes \n" +\r
-                                                                               "on the return type of a method. Please use the \n" +\r
-                                                                               "Mono runtime instead.");\r
-                                                       }\r
-\r
-                                               }\r
-                                       } else if (kind is Enum) {\r
-                                               ((TypeBuilder) builder).SetCustomAttribute (cb); \r
-\r
-                                       } else if (kind is TypeContainer) {\r
-                                               TypeContainer tc = (TypeContainer) kind;\r
-                                               \r
-                                               if (a.UsageAttr) {\r
-                                                       tc.Targets = a.Targets;\r
-                                                       tc.AllowMultiple = a.AllowMultiple;\r
-                                                       tc.Inherited = a.Inherited;\r
-\r
-                                                       TypeManager.RegisterAttributeAllowMultiple (tc.TypeBuilder,\r
-                                                                                                   tc.AllowMultiple);\r
-                                                       \r
-                                               } else if (attr_type == TypeManager.default_member_type) {\r
-                                                       if (tc.Indexers != null) {\r
-                                                               Report.Error (646, loc,\r
-                                                                     "Cannot specify the DefaultMember attribute on" +\r
-                                                                     " a type containing an indexer");\r
-                                                               return;\r
-                                                       }\r
-\r
-                                               } else {\r
-                                                       if (!CheckAttributeTarget (a, kind)) {\r
-                                                               Error_AttributeNotValidForElement (a, loc);\r
-                                                               return;\r
-                                                       }\r
-                                               }\r
-\r
-                                               try {\r
-                                                       ((TypeBuilder) builder).SetCustomAttribute (cb);\r
-                                               } catch (System.ArgumentException) {\r
-                                                       Report.Warning (\r
-                                                               -21, loc,\r
-                                               "The CharSet named property on StructLayout\n"+\r
-                                               "\tdoes not work correctly on Microsoft.NET\n"+\r
-                                               "\tYou might want to remove the CharSet declaration\n"+\r
-                                               "\tor compile using the Mono runtime instead of the\n"+\r
-                                               "\tMicrosoft .NET runtime");\r
-                                               }\r
-                                       } else if (kind is Delegate){\r
-                                               if (!CheckAttributeTarget (a, kind)) {\r
-                                                       Error_AttributeNotValidForElement (a, loc);\r
-                                                       return;\r
-                                               }\r
-                                               try {\r
-                                                       ((TypeBuilder) builder).SetCustomAttribute (cb);\r
-                                               } catch (System.ArgumentException) {\r
-                                                       Report.Warning (\r
-                                                               -21, loc,\r
-                                               "The CharSet named property on StructLayout\n"+\r
-                                               "\tdoes not work correctly on Microsoft.NET\n"+\r
-                                               "\tYou might want to remove the CharSet declaration\n"+\r
-                                               "\tor compile using the Mono runtime instead of the\n"+\r
-                                               "\tMicrosoft .NET runtime");\r
-                                               }\r
-                                       } else if (kind is Interface) {\r
-                                               Interface iface = (Interface) kind;\r
-\r
-                                               if ((attr_type == TypeManager.default_member_type) &&\r
-                                                   (iface.Indexers != null)) {\r
-                                                       Report.Error (\r
-                                                               646, loc,\r
-                                                               "Cannot specify the DefaultMember attribute on" +\r
-                                                               " a type containing an indexer");\r
-                                                       return;\r
-                                               }\r
 \r
-                                               if (!CheckAttributeTarget (a, kind)) {\r
-                                                       Error_AttributeNotValidForElement (a, loc);\r
-                                                       return;\r
-                                               }\r
-\r
-                                               ((TypeBuilder) builder).SetCustomAttribute (cb);\r
-                                       } else if (kind is AssemblyBuilder){\r
-                                               ((AssemblyBuilder) builder).SetCustomAttribute (cb);\r
-                                       } else if (kind is ModuleBuilder) {\r
-                                               ((ModuleBuilder) builder).SetCustomAttribute (cb);\r
-                                       } else if (kind is FieldBuilder) {\r
-                                               if (attr_type == TypeManager.marshal_as_attr_type) {\r
-                                                       UnmanagedMarshal marshal = GetMarshal (a);\r
+                                       if (kind is Attributable) {\r
+                                               Attributable able = kind as Attributable;\r
+                                               able.ApplyAttributeBuilder (builder, a, cb);\r
+                                       }\r
+                                       else if (kind is IAttributeSupport) {\r
+                                               IAttributeSupport attributeSupport = kind as IAttributeSupport;\r
+                                               attributeSupport.SetCustomAttribute (cb);\r
+                                       } \r
+                                       else if (kind is FieldBuilder) {\r
+                                               // This is used only for enumerated constants\r
+                                               if (attr_type == TypeManager.marshal_as_attr_type) {\r
+                                                       UnmanagedMarshal marshal = a.GetMarshal ();\r
                                                        if (marshal == null) {\r
                                                                Report.Warning (-24, loc,\r
-                                                                       "The Microsoft Runtime cannot set this marshal info. " +\r
-                                                                       "Please use the Mono runtime instead.");\r
+                                                                               "The Microsoft Runtime cannot set this marshal info. " +\r
+                                                                               "Please use the Mono runtime instead.");\r
                                                        } else {\r
-                                                               ((ParameterBuilder) builder).SetMarshal (marshal);\r
+                                                               ((FieldBuilder) builder).SetMarshal (marshal);\r
                                                        }\r
                                                } else { \r
                                                        ((FieldBuilder) builder).SetCustomAttribute (cb);\r
                                                }\r
-                                       } else\r
-                                               throw new Exception ("Unknown kind: " + kind);\r
+                                       } \r
+                                       else {\r
+                                               throw new Exception ("" + loc + ": Error applying Attribute " + a.Type \r
+                                                                    + " to unknown kind " + kind);\r
+                                       }\r
 \r
-                                       //\r
                                        // Once an attribute type has been emitted once we\r
                                        // keep track of the info to prevent multiple occurences\r
                                        // for attributes which do not explicitly allow it\r
@@ -1179,7 +1027,7 @@ namespace Mono.CSharp {
                                return null;\r
                        }\r
 \r
-                       Type = CheckAttributeType (ec);\r
+                       ResolveType (ec);\r
                        if (Type == null)\r
                                return null;\r
                        \r
index 626b3fd11dd4fd828f4ec23817d573344511dfac..9003621d17bc0007b3563bc7ff8c21e4fa05bab9 100755 (executable)
@@ -423,6 +423,41 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       TypeBuilder tb = builder as TypeBuilder;
+                                       
+                       if (a.UsageAttr) {
+                               Targets = a.Targets;
+                               AllowMultiple = a.AllowMultiple;
+                               Inherited = a.Inherited;
+                               
+                               TypeManager.RegisterAttributeAllowMultiple (tb, AllowMultiple);
+                       }
+
+                       if (a.Type == TypeManager.default_member_type) {
+                               if (Indexers != null) {
+                                       Report.Error (646, a.Location,
+                                                     "Cannot specify the DefaultMember attribute on" +
+                                                     " a type containing an indexer");
+                                       return;
+                               }
+                       }
+                       
+                       try {
+                               tb.SetCustomAttribute (cb);
+                       } 
+                       catch (System.ArgumentException e) {
+                               Report.Warning (-21, a.Location,
+                                               "The CharSet named property on StructLayout\n"+
+                                               "\tdoes not work correctly on Microsoft.NET\n"+
+                                               "\tYou might want to remove the CharSet declaration\n"+
+                                               "\tor compile using the Mono runtime instead of the\n"+
+                                               "\tMicrosoft .NET runtime.\n"+
+                                               "\tThe runtime reported the error: " + e);
+                       }
+               }
+
                public void RegisterOrder (Interface iface)
                {
                        if (interface_order == null)
@@ -2826,7 +2861,7 @@ namespace Mono.CSharp {
                                        
                                        Attributes attr = p [i].OptAttributes;
                                        if (attr != null){
-                                               Attribute.ApplyAttributes (ec, pb, pb, attr);
+                                               Attribute.ApplyAttributes (ec, pb, p[i], attr);
 
                                                if (par_attr == ParameterAttributes.Out){
                                                        if (attr.Contains (TypeManager.in_attribute_type))
@@ -2877,9 +2912,11 @@ namespace Mono.CSharp {
                        }
 
                        if (ret_attrs != null) {
+                               ParameterBase ret = new ParameterBase (ret_attrs);
+
                                try {
-                                       ret_pb = mb.DefineParameter (0, ParameterAttributes.None, "");
-                                       Attribute.ApplyAttributes (ec, ret_pb, ret_pb, ret_attrs);
+                                       ret_pb = mb.DefineParameter (0, ParameterAttributes.None, "");                          
+                                       Attribute.ApplyAttributes (ec, ret_pb, ret, ret_attrs);
 
                                 } catch (ArgumentOutOfRangeException) {
                                        Report.Warning (
@@ -2982,6 +3019,16 @@ namespace Mono.CSharp {
                                 return false;
                 }
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       MethodBuilder mb = builder as MethodBuilder;
+
+                       if (a.Type == TypeManager.methodimpl_attr_type && a.IsInternalCall)
+                               mb.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
+                       else if (a.Type != TypeManager.dllimport_type)
+                               mb.SetCustomAttribute (cb);
+               }
+
                //
                // Checks our base implementation if any
                //
@@ -3250,14 +3297,24 @@ namespace Mono.CSharp {
                                t = ec.ContainerType;
 
                        parent_constructor_group = Expression.MemberLookup (
-                               ec, t, null, t, ".ctor", 
-                               MemberTypes.Constructor,
+                               ec, t, ".ctor", MemberTypes.Constructor,
                                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                loc);
                        
                        if (parent_constructor_group == null){
-                               Report.Error (1501, loc,
-                                      "Can not find a constructor for this argument list");
+                               parent_constructor_group = Expression.MemberLookup (
+                                       ec, t, ".ctor", MemberTypes.Constructor,
+                                       BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly,
+                                       loc);
+
+                               if (parent_constructor_group != null)
+                                       Report.Error (
+                                               112, loc, "`{0}.{1}' is inaccessible due to " +
+                                               "its protection level", t.FullName, t.Name);
+                               else
+                                       Report.Error (
+                                               1501, loc, "Can not find a constructor for " +
+                                               "this argument list");
                                return false;
                        }
                        
@@ -3361,6 +3418,11 @@ namespace Mono.CSharp {
                                        (Initializer.Arguments == null);
                }
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       ((ConstructorBuilder) builder).SetCustomAttribute (cb);
+               }
+
                protected override bool CheckBase (TypeContainer container)
                {
                        base.CheckBase (container);
@@ -3698,7 +3760,7 @@ namespace Mono.CSharp {
                string obsolete = null;
                bool obsolete_error = false;
 
-               public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method)
+               public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method, DeclSpace ds)
                {
                        if ((opt_attrs == null) || (opt_attrs.AttributeSections == null))
                                return true;
@@ -3708,15 +3770,15 @@ namespace Mono.CSharp {
                                        continue;
                                        
                                foreach (Attribute a in asec.Attributes) {
-                                       if (a.Name == "Conditional") {
+                                       Type attr_type = a.ResolveType (ec);
+                                       if (attr_type == TypeManager.conditional_attribute_type) {
                                                if (!ApplyConditionalAttribute (a))
                                                        return false;
-                                       } else if (a.Name == "Obsolete") {
+                                       } else if (attr_type == TypeManager.obsolete_attribute_type) {
                                                if (!ApplyObsoleteAttribute (a))
                                                        return false;
-                                       } else if (a.Name.IndexOf ("DllImport") != -1) {
+                                       } else if (attr_type == TypeManager.dllimport_type) {
                                                if (!is_method) {
-                                                       a.Type = TypeManager.dllimport_type;
                                                        Attribute.Error_AttributeNotValidForElement (a, method.Location);
                                                        return false;
                                                }
@@ -3881,7 +3943,7 @@ namespace Mono.CSharp {
                        string prefix;
 
                        if (method.OptAttributes != null)
-                               if (!ApplyAttributes (method.OptAttributes, is_method))
+                               if (!ApplyAttributes (method.OptAttributes, is_method, container))
                                        return false;
 
                        if (member.IsExplicitImpl)
@@ -4431,6 +4493,13 @@ namespace Mono.CSharp {
                        bool error = false;
 
                        foreach (Type partype in parameters){
+                               if (partype == TypeManager.void_type) {
+                                       Report.Error (
+                                               1547, Location, "Keyword 'void' cannot " +
+                                               "be used in this context");
+                                       return false;
+                               }
+
                                if (partype.IsPointer){
                                        if (!UnsafeOK (ds))
                                                error = true;
@@ -4649,6 +4718,20 @@ namespace Mono.CSharp {
                        return init_expr;
                }
 
+               protected override bool DoDefine (DeclSpace ds, TypeContainer container)
+               {
+                       if (!base.DoDefine (ds, container))
+                               return false;
+
+                       if (MemberType == TypeManager.void_type) {
+                               Report.Error (1547, Location,
+                                             "Keyword 'void' cannot be used in this context");
+                               return false;
+                       }
+
+                       return true;
+               }
+
                public override string GetSignatureForError ()
                {
                        return TypeManager.GetFullNameSignature (FieldBuilder);
@@ -4701,6 +4784,23 @@ namespace Mono.CSharp {
                {
                }
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       FieldBuilder fb = builder as FieldBuilder;
+
+                       if (a.Type == TypeManager.marshal_as_attr_type) {
+                               UnmanagedMarshal marshal = a.GetMarshal ();
+                               if (marshal == null)
+                                       Report.Warning (-24, a.Location,
+                                                       "The Microsoft Runtime cannot set this marshal info. " +
+                                                       "Please use the Mono runtime instead.");
+                               else
+                                       fb.SetMarshal (marshal);
+                       }
+                       else
+                               fb.SetCustomAttribute (cb);
+               }
+
                public override bool Define (TypeContainer container)
                {
                        Type t = container.ResolveType (Type, false, Location);
@@ -4805,17 +4905,26 @@ namespace Mono.CSharp {
        //
        // `set' and `get' accessors are represented with an Accessor.
        // 
-       public class Accessor {
+       public class Accessor : Attributable {
                //
                // Null if the accessor is empty, or a Block if not
                //
                public Block Block;
-               public Attributes OptAttributes;
                
                public Accessor (Block b, Attributes attrs)
+                       : base (attrs)
                {
                        Block = b;
-                       OptAttributes = attrs;
+               }
+
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       MethodBuilder mb = builder as MethodBuilder;
+
+                       if (a.Type == TypeManager.methodimpl_attr_type && a.IsInternalCall)
+                               mb.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
+                       else if (a.Type != TypeManager.dllimport_type)
+                               mb.SetCustomAttribute (cb);
                }
        }
 
@@ -4982,6 +5091,18 @@ namespace Mono.CSharp {
                {
                }
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (builder is PropertyBuilder) 
+                               ((PropertyBuilder) builder).SetCustomAttribute (cb);
+                       //
+                       // This is for the case we are setting attributes on
+                       // the get and set accessors
+                       //
+                       else if (builder is MethodBuilder)
+                               ((MethodBuilder) builder).SetCustomAttribute (cb);
+               }
+
                protected override bool DoDefine (DeclSpace decl, TypeContainer container)
                {
                        if (!base.DoDefine (decl, container))
@@ -5597,15 +5718,25 @@ namespace Mono.CSharp {
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                name, init, attrs, loc)
                {
+                       IsInterface = is_iface;
                        Add = new AddDelegateMethod (this, add);
                        Remove = new RemoveDelegateMethod (this, remove);
-                       IsInterface = is_iface;
                        this.ds = ds;
                }
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       ((MyEventBuilder) builder).SetCustomAttribute (cb);
+               }
+
                public override bool Define (TypeContainer container)
                {
-                       EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
+                       EventAttributes e_attr;
+                       if (IsInterface)
+                               e_attr = EventAttributes.None;
+                       else
+                               e_attr = EventAttributes.RTSpecialName |
+                                       EventAttributes.SpecialName;
 ;
                        if (!DoDefine (container, container))
                                return false;
@@ -5646,7 +5777,8 @@ namespace Mono.CSharp {
                                EventBuilder = new MyEventBuilder (this,
                                        container.TypeBuilder, Name, e_attr, MemberType);
                                        
-                               if (Add.Accessor == null && Remove.Accessor == null) {
+                               if (Add.Accessor == null && Remove.Accessor == null &&
+                                   !IsInterface) {
                                        FieldBuilder = container.TypeBuilder.DefineField (
                                                Name, MemberType,
                                                FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
@@ -5677,8 +5809,10 @@ namespace Mono.CSharp {
                        Attribute.ApplyAttributes (ec, EventBuilder, this, OptAttributes);
                        }
 
-                       Add.Emit (tc);
-                       Remove.Emit (tc);
+                       if (!IsInterface) {
+                               Add.Emit (tc);
+                               Remove.Emit (tc);
+                       }
 
                        base.Emit (tc);
                }
@@ -6042,6 +6176,11 @@ namespace Mono.CSharp {
                        return container.Name + ".operator " + OperatorType + " (" + FirstArgType + "," +
                                SecondArgType + ")";
                }
+
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb) 
+               {
+                       OperatorMethod.ApplyAttributeBuilder (builder, a, cb);
+               }
                
                protected override bool CheckGenericOverride (MethodInfo method,  string name)
                {
index ec3a079c06c00183272a02fa513eaae2e7ad3be6..d822d157e356a3f7cc4275859585361b4cb3467f 100755 (executable)
@@ -68,6 +68,11 @@ namespace Mono.CSharp {
                }
 #endif
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       throw new NotImplementedException ("Can't apply attributes to constants ???");
+               }
+
                /// <summary>
                ///   Defines the constant in the @parent
                /// </summary>
index 8b78f53637d55c80bac8a33a2abfb927746e389e..3baeb72074e862d9136d042c154f275f524d1051 100755 (executable)
@@ -237,10 +237,10 @@ namespace Mono.CSharp {
        }
 
        /// <summary>
-       ///   Base representation for members.  This is only used to keep track
-       ///   of Name, Location and Modifier flags.
+       ///   Base representation for members.  This is used to keep track
+       ///   of Name, Location and Modifier flags, and handling Attributes.
        /// </summary>
-       public abstract class MemberCore {
+       public abstract class MemberCore : Attributable {
                /// <summary>
                ///   Public name
                /// </summary>
@@ -258,11 +258,6 @@ namespace Mono.CSharp {
                /// </summary>
                public readonly Location Location;
 
-               /// <summary>
-               ///   Attributes for this type
-               /// </summary>
-               Attributes attributes;
-
                [Flags]
                public enum Flags {
                        Obsolete_Undetected = 1,                // Obsolete attribute has not beed detected yet
@@ -278,11 +273,11 @@ namespace Mono.CSharp {
                protected Flags caching_flags;
 
                public MemberCore (MemberName name, Attributes attrs, Location loc)
+                       : base (attrs)
                {
                        Name = name.GetName (!(this is GenericMethod) && !(this is Method));
                        MemberName = name;
                        Location = loc;
-                       attributes = attrs;
                        caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected;
                }
 
@@ -296,16 +291,6 @@ namespace Mono.CSharp {
                        return Name;
                }
 
-               public Attributes OptAttributes 
-               {
-                       get {
-                               return attributes;
-                       }
-                       set {
-                               attributes = value;
-                       }
-               }
-
                /// <summary>
                /// Base Emit method. This is also entry point for CLS-Compliant verification.
                /// </summary>
@@ -415,7 +400,8 @@ namespace Mono.CSharp {
                                return true;
 
                        bool error3006 = false;
-                       foreach (MemberInfo mi in ml) {
+                       for (int i = 0; i < ml.Count; ++i) {
+                               MemberInfo mi = ml [i];
                                if (name == mi.Name) {
                                        MethodBase method = mi as MethodBase;
                                        if (method == null || method == methodBuilder || paramTypes == null || paramTypes.Length == 0)
@@ -446,6 +432,13 @@ namespace Mono.CSharp {
                                                continue;
                                }
 
+                               for (int ii = 0; ii < ml.Count; ++ii) {
+                                       mi = ml [ii];
+                                       if (name == mi.Name)
+                                               continue;
+                                       Report.SymbolRelatedToPreviousError (mi);
+                               }
+
                                if (error3006)
                                        Report.Error_T (3006, Location, GetSignatureForError ());
 
@@ -1338,10 +1331,12 @@ namespace Mono.CSharp {
                                                continue;
 
                                        if (String.Compare (Name, type_name, true) == 0 && 
-                                               AttributeTester.IsClsCompliant (TypeManager.all_imported_types [type_name] as Type))
+                                               AttributeTester.IsClsCompliant (TypeManager.all_imported_types [type_name] as Type)) {
+                                               Report.SymbolRelatedToPreviousError ((Type)TypeManager.all_imported_types [type_name]);
                                                return false;
                                }
                        }
+                       }
 
                        // Seek through generated types
                        foreach (string name in RootContext.Tree.Decls.Keys) {
@@ -1354,10 +1349,12 @@ namespace Mono.CSharp {
                                                continue;
                                        
                                        DeclSpace found_ds = RootContext.Tree.Decls[name] as DeclSpace;
-                                       if (found_ds.IsClsCompliaceRequired (found_ds.Parent))
+                                       if (found_ds.IsClsCompliaceRequired (found_ds.Parent)) {
+                                               Report.SymbolRelatedToPreviousError (found_ds.Location, found_ds.GetSignatureForError ());
                                                return false;
                                }
                        }
+                       }
 
                        return true;
                }
@@ -1773,8 +1770,6 @@ namespace Mono.CSharp {
                protected Hashtable member_hash;
                protected Hashtable method_hash;
                
-               Hashtable interface_hash;
-
                /// <summary>
                ///   Create a new MemberCache for the given IMemberContainer `container'.
                /// </summary>
@@ -1791,7 +1786,6 @@ namespace Mono.CSharp {
                        // TypeManager.object_type), we deep-copy its MemberCache here.
                        if (Container.IsInterface) {
                                MemberCache parent;
-                               interface_hash = new Hashtable ();
                                
                                if (Container.Parent != null)
                                        parent = Container.Parent.MemberCache;
@@ -1836,15 +1830,20 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Add the contents of `new_hash' to `hash'.
                /// </summary>
-               void AddHashtable (Hashtable hash, Hashtable new_hash)
+               void AddHashtable (Hashtable hash, MemberCache cache)
                {
+                       Hashtable new_hash = cache.member_hash;
                        IDictionaryEnumerator it = new_hash.GetEnumerator ();
                        while (it.MoveNext ()) {
                                ArrayList list = (ArrayList) hash [it.Key];
-                               if (list != null)
-                                       list.AddRange ((ArrayList) it.Value);
-                               else
-                                       hash [it.Key] = ((ArrayList) it.Value).Clone ();
+                               if (list == null)
+                                       hash [it.Key] = list = new ArrayList ();
+
+                               foreach (CacheEntry entry in (ArrayList) it.Value) {
+                                       if (entry.Container != cache.Container)
+                                               break;
+                                       list.Add (entry);
+                               }
                        }
                }
 
@@ -1861,23 +1860,12 @@ namespace Mono.CSharp {
                        foreach (TypeExpr iface in ifaces) {
                                Type itype = iface.Type;
 
-                               if (interface_hash.Contains (itype))
-                                       continue;
-                               
-                               interface_hash [itype] = null;
-
                                IMemberContainer iface_container =
                                        TypeManager.LookupMemberContainer (itype);
 
                                MemberCache iface_cache = iface_container.MemberCache;
 
-                               AddHashtable (hash, iface_cache.member_hash);
-                               
-                               if (iface_cache.interface_hash == null)
-                                       continue;
-                               
-                               foreach (Type parent_contains in iface_cache.interface_hash.Keys)
-                                       interface_hash [parent_contains] = null;
+                               AddHashtable (hash, iface_cache);
                        }
 
                        return hash;
@@ -2153,7 +2141,7 @@ namespace Mono.CSharp {
                                applicable = (ArrayList) method_hash [name];
                        else
                                applicable = (ArrayList) member_hash [name];
-                       
+
                        if (applicable == null)
                                return emptyMemberInfo;
 
@@ -2173,6 +2161,7 @@ namespace Mono.CSharp {
 
                        IMemberContainer current = Container;
 
+
                        // `applicable' is a list of all members with the given member name `name'
                        // in the current class and all its parent classes.  The list is sorted in
                        // reverse order due to the way how the cache is initialy created (to speed
index 2895be74f36838f86e83c04cd2a8f6434c275431..4aabb5899eeceef3f2765ae950b95ca3e8a4603a 100644 (file)
@@ -59,6 +59,21 @@ namespace Mono.CSharp {
                        Parameters      = param_list;\r
                }\r
 \r
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)\r
+               {\r
+                       try {\r
+                               ((TypeBuilder) builder).SetCustomAttribute (cb);\r
+                       } catch (System.ArgumentException e) {\r
+                               Report.Warning (-21, a.Location,\r
+                                               "The CharSet named property on StructLayout\n"+\r
+                                               "\tdoes not work correctly on Microsoft.NET\n"+\r
+                                               "\tYou might want to remove the CharSet declaration\n"+\r
+                                               "\tor compile using the Mono runtime instead of the\n"+\r
+                                               "\tMicrosoft .NET runtime\n"+\r
+                                               "\tThe runtime gave the error: " + e);\r
+                       }\r
+               }\r
+  \r
                public override TypeBuilder DefineType ()\r
                {\r
                        if (TypeBuilder != null)\r
@@ -248,7 +263,7 @@ namespace Mono.CSharp {
                                        pb = InvokeBuilder.DefineParameter (i+1, p.Attributes, p.Name);\r
                                        cattr = p.OptAttributes;\r
                                        if (cattr != null)\r
-                                               Attribute.ApplyAttributes (ec, pb, pb, cattr);\r
+                                               Attribute.ApplyAttributes (ec, pb, p, cattr);\r
 \r
                                        if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)\r
                                                out_params++;\r
@@ -261,7 +276,7 @@ namespace Mono.CSharp {
                                        i+1, p.Attributes, p.Name);\r
                                cattr = p.OptAttributes;\r
                                if (cattr != null)\r
-                                       Attribute.ApplyAttributes (ec, pb, pb, cattr);\r
+                                       Attribute.ApplyAttributes (ec, pb, p, cattr);\r
                        }\r
                        \r
                        InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);\r
@@ -301,7 +316,7 @@ namespace Mono.CSharp {
                                        pb = BeginInvokeBuilder.DefineParameter (i+1, p.Attributes, p.Name);\r
                                        cattr = p.OptAttributes;\r
                                        if (cattr != null)\r
-                                               Attribute.ApplyAttributes (ec, pb, pb, cattr);\r
+                                               Attribute.ApplyAttributes (ec, pb, p, cattr);\r
                                }\r
                        }\r
                        if (Parameters.ArrayParameter != null){\r
@@ -310,7 +325,7 @@ namespace Mono.CSharp {
                                pb = BeginInvokeBuilder.DefineParameter (i+1, p.Attributes, p.Name);\r
                                cattr = p.OptAttributes;\r
                                if (cattr != null)\r
-                                       Attribute.ApplyAttributes (ec, pb, pb, cattr);\r
+                                       Attribute.ApplyAttributes (ec, pb, p, cattr);\r
                                i++;\r
                        }\r
 \r
index da830b4129b7a17b818f61def007d3acfc0961b6..b510b3c3cca61cf99792d37f875b93d8073a7a36 100755 (executable)
@@ -485,7 +485,11 @@ namespace Mono.CSharp {
                        else if (t == TypeManager.bool_type)
                                return new BoolConstant ((bool) v);
                        else if (TypeManager.IsEnumType (t)){
-                               Constant e = Constantify (v, TypeManager.TypeToCoreType (v.GetType ()));
+                               Type real_type = TypeManager.TypeToCoreType (v.GetType ());
+                               if (real_type == t)
+                                       real_type = real_type.UnderlyingSystemType;
+
+                               Constant e = Constantify (v, real_type);
 
                                return new EnumConstant (e, t);
                        } else
@@ -679,7 +683,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((qualifier_type != null) && (qualifier_type != ec.ContainerType) &&
-                           ec.ContainerType.IsSubclassOf (qualifier_type)) {
+                           !qualifier_type.IsSubclassOf (ec.ContainerType)) {
                                // Although a derived class can access protected members of
                                // its base class it cannot do so through an instance of the
                                // base class (CS1540).  If the qualifier_type is a parent of the
@@ -3000,8 +3004,20 @@ namespace Mono.CSharp {
                                        IMemoryLocation ml = (IMemoryLocation) instance_expr;
 
                                        ml.AddressOf (ec, AddressOp.LoadStore);
-                               } else
+                               } else {
                                        instance_expr.Emit (ec);
+
+                                       if (instance_expr.Type.IsValueType) {
+                                               LocalBuilder local = ig.DeclareLocal (instance_expr.Type);
+                                               ig.Emit(OpCodes.Stloc, local);
+                                               ig.Emit(OpCodes.Ldloca, local);
+                                               ig.Emit(OpCodes.Ldfld, FieldInfo);
+                                               LocalBuilder local2 = ig.DeclareLocal(type);
+                                               ig.Emit(OpCodes.Stloc, local2);
+                                               ig.Emit(OpCodes.Ldloca, local2);
+                                               return;
+                                       }
+                               }
                                ig.Emit (OpCodes.Ldflda, FieldInfo);
                        }
                }
index 27cbc5c5b0aef3e4bb7eae948caba23eaa3f2460..cb6a8649cc73b20c8c510693a9b7b616101f9347 100755 (executable)
@@ -91,6 +91,11 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       ((TypeBuilder) builder).SetCustomAttribute (cb);
+               }
+
                //
                // This is used by corlib compilation: we map from our
                // type to a type that is consumable by the DefineField
@@ -627,8 +632,8 @@ namespace Mono.CSharp {
 
                                        string enumerator_name = ordered_enums [ii] as string;
                                        if (String.Compare (checked_name, enumerator_name, true) == 0) {
+                                               Report.SymbolRelatedToPreviousError ((Location)member_to_location [enumerator_name], enumerator_name);
                                                Report.Error_T (3005, (Location)member_to_location [checked_name], GetEnumeratorName (checked_name));
-                                               Report.LocationOfPreviousError ((Location)member_to_location [enumerator_name]);
                                                break;
                                        }
                                }
index 47b58f93e06031c35dc247695d651a959f6aa506..c58698c514f99f273c1ed469fb8c49c5ea40ef0c 100755 (executable)
@@ -568,6 +568,16 @@ namespace Mono.CSharp {
                        return ResolveOperator (ec);
                }
 
+               public override Expression DoResolveLValue (EmitContext ec, Expression right)
+               {
+                       if (Oper == Operator.Indirection)
+                               return base.DoResolveLValue (ec, right);
+
+                       Error (131, "The left-hand side of an assignment must be a " +
+                              "variable, property or indexer");
+                       return null;
+               }
+
                public override void Emit (EmitContext ec)
                {
                        ILGenerator ig = ec.ig;
@@ -2969,7 +2979,7 @@ namespace Mono.CSharp {
                                ig.MarkLabel (end);
                                return;
                        }
-                       
+
                        left.Emit (ec);
                        right.Emit (ec);
 
@@ -3347,6 +3357,7 @@ namespace Mono.CSharp {
                }
 
                Expression op_true, op_false, op;
+               LocalTemporary left_temp;
 
                public override Expression DoResolve (EmitContext ec)
                {
@@ -3359,8 +3370,10 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       left_temp = new LocalTemporary (ec, type);
+
                        ArrayList arguments = new ArrayList ();
-                       arguments.Add (new Argument (left, Argument.AType.Expression));
+                       arguments.Add (new Argument (left_temp, Argument.AType.Expression));
                        arguments.Add (new Argument (right, Argument.AType.Expression));
                        method = Invocation.OverloadResolve (
                                ec, (MethodGroupExpr) operator_group, arguments, false, loc)
@@ -3372,8 +3385,8 @@ namespace Mono.CSharp {
 
                        op = new StaticCallExpr (method, arguments, loc);
 
-                       op_true = GetOperatorTrue (ec, left, loc);
-                       op_false = GetOperatorFalse (ec, left, loc);
+                       op_true = GetOperatorTrue (ec, left_temp, loc);
+                       op_false = GetOperatorFalse (ec, left_temp, loc);
                        if ((op_true == null) || (op_false == null)) {
                                Error218 ();
                                return null;
@@ -3390,8 +3403,11 @@ namespace Mono.CSharp {
 
                        ig.Emit (OpCodes.Nop);
 
-                       (is_and ? op_false : op_true).EmitBranchable (ec, false_target, false);
                        left.Emit (ec);
+                       left_temp.Store (ec);
+
+                       (is_and ? op_false : op_true).EmitBranchable (ec, false_target, false);
+                       left_temp.Emit (ec);
                        ig.Emit (OpCodes.Br, end_target);
                        ig.MarkLabel (false_target);
                        op.Emit (ec);
@@ -8646,6 +8662,12 @@ namespace Mono.CSharp {
                        if (ltype == null)
                                return null;
 
+                       if ((ltype == TypeManager.void_type) && (dim != "*")) {
+                               Report.Error (1547, Location,
+                                             "Keyword 'void' cannot be used in this context");
+                               return null;
+                       }
+
                        int pos = 0;
                        while ((pos < dim.Length) && (dim [pos] == '[')) {
                                pos++;
index 88976987b5d4703e178c80b7ea438568943e23f9..633fe935a95c2c82557dfe841182fcbd0d633fa6 100644 (file)
@@ -920,6 +920,11 @@ namespace Mono.CSharp {
                                throw new Exception ();
                        }
                }
+
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       // FIXME
+               }
        }
 
        public class DefaultValueExpression : Expression
index 01e4582b0f4dcd97bfac05c164e416a91100994e..a04a70482779a3bbd01d47bb14c347422fc97cbd 100755 (executable)
@@ -16,11 +16,46 @@ using System.Collections;
 
 namespace Mono.CSharp {
 
+       /// <summary>
+       ///   Base class for parameters of a method.  Can also be
+       ///   used to directly represent the return type of a method
+       /// </summary>
+       public class ParameterBase : Attributable {
+               public ParameterBase (Attributes attrs)
+                       : base (attrs)
+               {
+               }
+
+               public override void ApplyAttributeBuilder (object builder, Attribute a, CustomAttributeBuilder cb)
+               {
+                       ParameterBuilder pb = builder as ParameterBuilder;
+
+                       if (a.Type == TypeManager.marshal_as_attr_type) {
+                               UnmanagedMarshal marshal = a.GetMarshal ();
+                               if (marshal == null)
+                                       Report.Warning (-24, a.Location,
+                                                       "The Microsoft Runtime cannot set this marshal info. " +
+                                                       "Please use the Mono runtime instead.");
+                               else 
+                                       pb.SetMarshal (marshal);
+                       }
+                       else { 
+                               try {
+                                       pb.SetCustomAttribute (cb);
+                               } catch (System.ArgumentException) {
+                                       Report.Warning (-24, a.Location,
+                                                       "The Microsoft Runtime cannot set attributes \n" +
+                                                       "on the return type of a method. Please use the \n" +
+                                                       "Mono runtime instead.");
+                               }
+                       }
+               }
+       }
 
        /// <summary>
        ///   Represents a single method parameter
        /// </summary>
-       public class Parameter {
+       public class Parameter : ParameterBase {
                [Flags]
                public enum Modifier : byte {
                        NONE    = 0,
@@ -33,17 +68,16 @@ namespace Mono.CSharp {
 
                public readonly Expression TypeName;
                public readonly Modifier ModFlags;
-               public Attributes OptAttributes;
                public readonly string Name;
                GenericConstraints constraints;
                Type parameter_type;
                
                public Parameter (Expression type, string name, Modifier mod, Attributes attrs)
+                       : base (attrs)
                {
                        Name = name;
                        ModFlags = mod;
                        TypeName = type;
-                       OptAttributes = attrs;
                }
 
                // <summary>
index 8f5c0c7d9fc13d9cb4af215dd12e5573e0abcf68..5f2a88cd60342a165fa8415a908c1dc0988ad406 100644 (file)
@@ -12,6 +12,7 @@
 using System;
 using System.Text;
 using System.Collections;
+using System.Collections.Specialized;
 using System.Diagnostics;
 using System.Reflection;
 
@@ -58,6 +59,11 @@ namespace Mono.CSharp {
                // Keeps track of the warnings that we are ignoring
                //
                static Hashtable warning_ignore_table;
+
+               /// <summary>
+               /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
+               /// </summary>
+               static StringCollection related_symbols = new StringCollection ();
                
                struct WarningData {
                        public WarningData (int level, string text) {
@@ -159,8 +165,41 @@ namespace Mono.CSharp {
                        return sb.ToString ();
                }
                
-               static public void LocationOfPreviousError (Location loc) {
+               [Obsolete ("Use SymbolRelatedToPreviousError for better error description")]
+               static public void LocationOfPreviousError (Location loc)
+               {
                        Console.WriteLine (String.Format ("{0}({1}) (Location of symbol related to previous error)", loc.Name, loc.Row));
+               }                
+
+               /// <summary>
+                /// In most error cases is very useful to have information about symbol that caused the error.
+                /// Call this method before you call Report.Error when it makes sense.
+               /// </summary>
+               static public void SymbolRelatedToPreviousError (Location loc, string symbol)
+               {
+                       SymbolRelatedToPreviousError (String.Format ("{0}({1})", loc.Name, loc.Row), symbol);
+               }
+
+               static public void SymbolRelatedToPreviousError (MemberInfo mi)
+               {
+                       DeclSpace temp_ds = TypeManager.LookupDeclSpace (mi.DeclaringType);
+                       if (temp_ds == null) {
+                               SymbolRelatedToPreviousError (mi.DeclaringType.Assembly.Location, TypeManager.GetFullNameSignature (mi));
+                       } else {
+                               string name = String.Concat (temp_ds.Name, ".", mi.Name);
+                               MemberCore mc = temp_ds.GetDefinition (name) as MemberCore;
+                               SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
+                       }
+               }
+
+               static public void SymbolRelatedToPreviousError (Type type)
+               {
+                       SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
+               }
+
+               static void SymbolRelatedToPreviousError (string loc, string symbol)
+               {
+                       related_symbols.Add (String.Format ("{0}: ('{1}' name of symbol related to previous error)", loc, symbol));
                }
 
                static public void RealError (string msg)
@@ -168,6 +207,10 @@ namespace Mono.CSharp {
                        Errors++;
                        Console.WriteLine (msg);
 
+                       foreach (string s in related_symbols)
+                               Console.WriteLine (s);
+                       related_symbols.Clear ();
+
                        if (Stacktrace)
                                Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
                        
@@ -182,10 +225,10 @@ namespace Mono.CSharp {
                static public void Warning (int code, Location loc, params object[] args)
                {
                        WarningData warning = GetWarningMsg (code);
-                       if (!warning.IsEnabled ())
-                               return;
+                       if (warning.IsEnabled ())
+                               Warning (code, loc, warning.Format (args));
 
-                       Warning (code, loc, warning.Format (args));
+                       related_symbols.Clear ();
                }
 
                /// <summary>
@@ -231,8 +274,10 @@ namespace Mono.CSharp {
                                code = 8000-code;
                        
                        if (warning_ignore_table != null){
-                               if (warning_ignore_table.Contains (code))
+                               if (warning_ignore_table.Contains (code)) {
+                                       related_symbols.Clear ();
                                        return;
+                               }
                        }
                        
                        if (WarningsAreErrors)
@@ -250,6 +295,11 @@ namespace Mono.CSharp {
 //                                     "{0}({1}) warning CS{2}: {3}",
                                        l.Name,  row, code, text));
                                Warnings++;
+
+                               foreach (string s in related_symbols)
+                                       Console.WriteLine (s);
+                               related_symbols.Clear ();
+
                                Check (code);
 
                                if (Stacktrace)
index baf26f293d27e66cc78b112cf88647732269fbd5..389c25ee7cdd04f025281bd18d439901ea2af2f9 100755 (executable)
@@ -1003,6 +1003,12 @@ namespace Mono.CSharp {
                        if (VariableType == null)
                                VariableType = decl.ResolveType (Type, false, Location);
 
+                       if (VariableType == TypeManager.void_type) {
+                               Report.Error (1547, Location,
+                                             "Keyword 'void' cannot be used in this context");
+                               return false;
+                       }
+
                        if (VariableType == null)
                                return false;
 
@@ -3406,7 +3412,7 @@ namespace Mono.CSharp {
                                converted_vars [i].Emit (ec);
                                ig.Emit (OpCodes.Callvirt, TypeManager.void_dispose_void);
                                } else {
-                                       Expression ml = Expression.MemberLookup(ec, typeof(IDisposable), var.Type, "Dispose", Mono.CSharp.Location.Null);
+                                       Expression ml = Expression.MemberLookup(ec, TypeManager.idisposable_type, var.Type, "Dispose", Mono.CSharp.Location.Null);
 
                                        if (!(ml is MethodGroupExpr)) {
                                                var.Emit (ec);
@@ -3904,11 +3910,18 @@ namespace Mono.CSharp {
                                if (expr is IMemoryLocation){
                                        IMemoryLocation ml = (IMemoryLocation) expr;
 
-                                       ml.AddressOf (ec, AddressOp.Load);
+                                       Expression ml1 = Expression.MemberLookup(ec, TypeManager.ienumerator_type, expr.Type, "GetEnumerator", Mono.CSharp.Location.Null);
+
+                                       if (!(ml1 is MethodGroupExpr)) {
+                                               expr.Emit(ec);
+                                               ec.ig.Emit(OpCodes.Box, expr.Type);
+                                       } else {
+                                               ml.AddressOf (ec, AddressOp.Load);
+                                       }
                                } else
                                        throw new Exception ("Expr " + expr + " of type " + expr.Type +
                                                             " does not implement IMemoryLocation");
-                               ig.Emit (OpCodes.Call, hm.get_enumerator);
+                               ig.Emit (OpCodes.Callvirt, hm.get_enumerator);
                        } else {
                                expr.Emit (ec);
                                ig.Emit (OpCodes.Callvirt, hm.get_enumerator);
index 7165db2cd08db08151d7b6f7afbbabaac222ee35..0267f451d94ab24e91fff3a28be510f8f824d250 100755 (executable)
@@ -56,11 +56,12 @@ namespace Mono.CSharp
                public void RecordDecl (string name, DeclSpace ds)
                {
                        if (decls.Contains (name)){
+                               DeclSpace other = (DeclSpace) decls [name];
+                               Report.SymbolRelatedToPreviousError (other.Location, other.GetSignatureForError ());
+
                                Report.Error (
                                        101, ds.Location,
                                        "There is already a definition for `" + name + "'");
-                               DeclSpace other = (DeclSpace) decls [name];
-                               Report.LocationOfPreviousError (other.Location);
                                return;
                        }
 
index f60d27d97803d9d1303d67bc11605a318e221f1a..ac5f96953d1f80e2d002f48bcd142382be1164b0 100755 (executable)
@@ -2177,11 +2177,6 @@ public class TypeManager {
                        return true;
                seen.Add (tc, null);
 
-               //
-               // `hash' contains all types in the current path.
-               //
-               hash.Add (tc, null);
-
                if (tc.Fields == null)
                        return true;
 
@@ -2202,7 +2197,16 @@ public class TypeManager {
                                return false;
                        }
 
-                       if (!CheckStructCycles (ftc, seen, hash))
+                       //
+                       // `hash' contains all types in the current path.
+                       //
+                       hash.Add (tc, null);
+
+                       bool ok = CheckStructCycles (ftc, seen, hash);
+
+                       hash.Remove (tc);
+
+                       if (!ok)
                                return false;
                }
 
@@ -2830,7 +2834,7 @@ public class TypeManager {
                                // it cannot do so through an instance of the base class (CS1540).
                                if (!mb.IsStatic && (closure_invocation_type != closure_qualifier_type) &&
                                    (closure_qualifier_type != null) &&
-                                   closure_invocation_type.IsSubclassOf (closure_qualifier_type) &&
+                                   ! closure_qualifier_type.IsSubclassOf (closure_invocation_type) &&
                                    !TypeManager.IsNestedChildOf (closure_invocation_type, closure_qualifier_type))
                                        return false;