2007-10-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mcs / attribute.cs
index 9083bce55f5b292f70922931bc914107656df689..612f299403fd70fa8d4ed4409697e9760ef51b64 100644 (file)
@@ -95,7 +95,7 @@ namespace Mono.CSharp {
                readonly bool nameEscaped;
 
                // It can contain more onwers when the attribute is applied to multiple fiels.
-               Attributable[] owners;
+               protected Attributable[] owners;
 
                static readonly AttributeUsageAttribute DefaultUsageAttribute = new AttributeUsageAttribute (AttributeTargets.All);
                static Assembly orig_sec_assembly;
@@ -137,7 +137,7 @@ namespace Mono.CSharp {
                        att_cache = new PtrHashtable ();
                }
 
-               public void AttachTo (Attributable owner)
+               public virtual void AttachTo (Attributable owner)
                {
                        if (this.owners == null) {
                                this.owners = new Attributable[1] { owner };
@@ -364,7 +364,7 @@ namespace Mono.CSharp {
 
                        Attributable owner = Owner;
                        EmitContext ec = new EmitContext (owner.ResolveContext, owner.ResolveContext.DeclContainer, owner.ResolveContext.DeclContainer,
-                               Location, null, null, owner.ResolveContext.DeclContainer.ModFlags, false);
+                               Location, null, typeof (Attribute), owner.ResolveContext.DeclContainer.ModFlags, false);
                        ec.IsAnonymousMethodAllowed = false;
 
                        ConstructorInfo ctor = ResolveConstructor (ec);
@@ -419,20 +419,21 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       Expression mg = Expression.MemberLookup (ec.ContainerType,
+                       MethodGroupExpr mg = Expression.MemberLookup (ec.ContainerType,
                                Type, ".ctor", MemberTypes.Constructor,
                                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
-                               Location);
+                               Location) as MethodGroupExpr;
 
                        if (mg == null)
                                return null;
 
-                       MethodBase constructor = ((MethodGroupExpr)mg).OverloadResolve (
-                               ec, PosArguments, false, Location);
-
-                       if (constructor == null)
+                       mg = mg.OverloadResolve (ec, PosArguments, false, Location);
+                       if (mg == null)
                                return null;
+                       
+                       ConstructorInfo constructor = (ConstructorInfo)mg;
 
+                       // TODO: move to OverloadResolve
                        ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (constructor);
                        if (oa != null && !Owner.ResolveContext.IsInObsoleteScope) {
                                AttributeTester.Report_ObsoleteMessage (oa, mg.GetSignatureForError (), mg.Location);
@@ -440,7 +441,7 @@ namespace Mono.CSharp {
 
                        if (PosArguments == null) {
                                pos_values = EmptyObject;
-                               return (ConstructorInfo)constructor;
+                               return constructor;
                        }
 
                        ParameterData pd = TypeManager.GetParameterData (constructor);
@@ -1267,16 +1268,16 @@ namespace Mono.CSharp {
                public string GetString () 
                {
                        Expression e = GetValue ();
-                       if (e is StringLiteral)
-                               return (e as StringLiteral).Value;
+                       if (e is StringConstant)
+                               return ((StringConstant)e).Value;
                        return null;
                }
 
                public bool GetBoolean () 
                {
                        Expression e = GetValue ();
-                       if (e is BoolLiteral)
-                               return (e as BoolLiteral).Value;
+                       if (e is BoolConstant)
+                               return ((BoolConstant)e).Value;
                        return false;
                }
 
@@ -1303,6 +1304,20 @@ namespace Mono.CSharp {
                        base (target, left_expr, identifier, args, loc, nameEscaped)
                {
                        this.ns = ns;
+                       this.owners = new Attributable[1];
+               }
+               
+               public override void AttachTo (Attributable owner)
+               {
+                       if (ExplicitTarget == "assembly") {
+                               owners [0] = CodeGen.Assembly;
+                               return;
+                       }
+                       if (ExplicitTarget == "module") {
+                               owners [0] = CodeGen.Module;
+                               return;
+                       }
+                       throw new NotImplementedException ("Unknown global explicit target " + ExplicitTarget);
                }
 
                void Enter ()
@@ -1570,8 +1585,10 @@ namespace Mono.CSharp {
                        }
 
                        bool result;
-                       if (type.IsArray || type.IsByRef)       {
+                       if (type.IsArray || type.IsByRef) {
                                result = IsClsCompliant (TypeManager.GetElementType (type));
+                       } else if (TypeManager.IsNullableType (type)) {
+                               result = IsClsCompliant (TypeManager.GetTypeArguments (type) [0]);
                        } else {
                                result = AnalyzeTypeCompliance (type);
                        }
@@ -1592,11 +1609,14 @@ namespace Mono.CSharp {
                        if (fb != null) {
                                return fb as IFixedBuffer;
                        }
+                       
+                       if (TypeManager.GetConstant (fi) != null)
+                               return null;
 
 #if NET_2_0
                        object o = fixed_buffer_cache [fi];
                        if (o == null) {
-                               if (System.Attribute.GetCustomAttribute (fi, TypeManager.fixed_buffer_attr_type) == null) {
+                               if (!fi.IsDefined (TypeManager.fixed_buffer_attr_type, false)) {
                                        fixed_buffer_cache.Add (fi, FALSE);
                                        return null;
                                }
@@ -1779,6 +1799,7 @@ namespace Mono.CSharp {
                public static bool IsConditionalMethodExcluded (MethodBase mb)
                {
                        mb = TypeManager.DropGenericMethodArguments (mb);
+                       // TODO: Has to be fixed for partial methods
                        if ((mb is MethodBuilder) || (mb is ConstructorBuilder))
                                return false;