* Makefile: Build the make-map.exe in Mono.Unix.Native; add /nowarn:0618 to
[mono.git] / mcs / mcs / attribute.cs
index 0e9d3dfc9a0362b579ea2646eb12d5c02d2f8ff1..7a046567ef9cd4e969ac62ccecd1bf9e17f2a014 100644 (file)
@@ -192,11 +192,11 @@ namespace Mono.CSharp {
                        bool t1_is_attr = false;
                        Type t1 = ResolvePossibleAttributeType (ec, Identifier, true, ref t1_is_attr);
 
-                       // FIXME: Shouldn't do this for quoted attributes: [@A]
                        bool t2_is_attr = false;
-                       Type t2 = ResolvePossibleAttributeType (ec, Identifier + "Attribute", true, ref t2_is_attr);
+                       Type t2 = nameEscaped ? null :
+                               ResolvePossibleAttributeType (ec, Identifier + "Attribute", true, ref t2_is_attr);
 
-                       if (t1_is_attr && t2_is_attr && !nameEscaped) {
+                       if (t1_is_attr && t2_is_attr) {
                                Report.Error (1614, Location, "`{0}' is ambiguous between `{0}' and `{0}Attribute'. Use either `@{0}' or `{0}Attribute'", GetSignatureForError ());
                                resolve_error = true;
                                return;
@@ -259,6 +259,9 @@ namespace Mono.CSharp {
                        } 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;
@@ -268,8 +271,10 @@ namespace Mono.CSharp {
 
                bool IsValidArgumentType (Type t)
                {
+                       if (t.IsArray)
+                               t = t.GetElementType ();
+
                        return TypeManager.IsPrimitiveType (t) ||
-                               (t.IsArray && TypeManager.IsPrimitiveType (t.GetElementType ())) ||
                                TypeManager.IsEnumType (t) ||
                                t == TypeManager.string_type ||
                                t == TypeManager.object_type ||
@@ -938,11 +943,16 @@ namespace Mono.CSharp {
                        return null;
                }
 
+               //
+               // Theoretically, we can get rid of this, since FieldBuilder.SetCustomAttribute()
+               // and ParameterBuilder.SetCustomAttribute() are supposed to handle this attribute.
+               // However, we can't, since it appears that the .NET 1.1 SRE hangs when given a MarshalAsAttribute.
+               //
                public UnmanagedMarshal GetMarshal (Attributable attr)
                {
                        UnmanagedType UnmanagedType;
                        if (!RootContext.StdLib || pos_values [0].GetType () != typeof (UnmanagedType))
-                               UnmanagedType = (UnmanagedType)System.Enum.ToObject (typeof (UnmanagedType), pos_values [0]);
+                               UnmanagedType = (UnmanagedType) System.Enum.ToObject (typeof (UnmanagedType), pos_values [0]);
                        else
                                UnmanagedType = (UnmanagedType) pos_values [0];
 
@@ -953,12 +963,12 @@ namespace Mono.CSharp {
                        }
 
                        object o = GetFieldValue ("ArraySubType");
-                       UnmanagedType array_sub_type = o == null ? UnmanagedType.I4 : (UnmanagedType) o;
-                       
+                       UnmanagedType array_sub_type = o == null ? (UnmanagedType) 0x50 /* NATIVE_MAX */ : (UnmanagedType) o;
+
                        switch (UnmanagedType) {
                        case UnmanagedType.CustomMarshaler: {
                                MethodInfo define_custom = typeof (UnmanagedMarshal).GetMethod ("DefineCustom",
-                                                                       BindingFlags.Static | BindingFlags.Public);
+                                       BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                                if (define_custom == null) {
                                        Report.RuntimeMissingSupport (Location, "set marshal info");
                                        return null;
@@ -976,7 +986,8 @@ namespace Mono.CSharp {
                                object size_param_index = GetFieldValue ("SizeParamIndex");
 
                                if ((size_const != null) || (size_param_index != null)) {
-                                       MethodInfo define_array = typeof (UnmanagedMarshal).GetMethod ("DefineLPArrayInternal", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
+                                       MethodInfo define_array = typeof (UnmanagedMarshal).GetMethod ("DefineLPArrayInternal",
+                                               BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                                        if (define_array == null) {
                                                Report.RuntimeMissingSupport (Location, "set marshal info");
                                                return null;
@@ -993,7 +1004,7 @@ namespace Mono.CSharp {
                        }
                        case UnmanagedType.SafeArray:
                                return UnmanagedMarshal.DefineSafeArray (array_sub_type);
-                       
+
                        case UnmanagedType.ByValArray:
                                FieldMember fm = attr as FieldMember;
                                if (fm == null) {
@@ -1001,10 +1012,10 @@ namespace Mono.CSharp {
                                        return null;
                                }
                                return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue ("SizeConst"));
-                       
+
                        case UnmanagedType.ByValTStr:
                                return UnmanagedMarshal.DefineByValTStr ((int) GetFieldValue ("SizeConst"));
-                       
+
                        default:
                                return UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType);
                        }