2007-12-06 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mcs / attribute.cs
index a617519c591f08ee3932923f7ca74e058a438534..64ca04c520fba7cfeca088138ba694c1b1587b05 100644 (file)
@@ -75,7 +75,8 @@ namespace Mono.CSharp {
                public abstract string[] ValidAttributeTargets { get; }
        };
 
-       public class Attribute {
+       public class Attribute : Expression
+       {
                public readonly string ExplicitTarget;
                public AttributeTargets Target;
 
@@ -87,10 +88,6 @@ namespace Mono.CSharp {
                readonly ArrayList PosArguments;
                ArrayList NamedArguments;
 
-               public readonly Location Location;
-
-               public Type Type;
-
                bool resolve_error;
                readonly bool nameEscaped;
 
@@ -121,7 +118,7 @@ namespace Mono.CSharp {
                                PosArguments = (ArrayList)args [0];
                                NamedArguments = (ArrayList)args [1];                           
                        }
-                       Location = loc;
+                       this.loc = loc;
                        ExplicitTarget = target;
                        this.nameEscaped = nameEscaped;
                }
@@ -288,7 +285,7 @@ namespace Mono.CSharp {
                        return Type;
                }
 
-               public string GetSignatureForError ()
+               public override string GetSignatureForError ()
                {
                        if (Type != null)
                                return TypeManager.CSharpName (Type);
@@ -363,7 +360,11 @@ namespace Mono.CSharp {
                        }
 
                        Attributable owner = Owner;
-                       EmitContext ec = new EmitContext (owner.ResolveContext, owner.ResolveContext.DeclContainer, owner.ResolveContext.DeclContainer,
+                       DeclSpace ds = owner.ResolveContext as DeclSpace;
+                       if (ds == null)
+                               ds = owner.ResolveContext.DeclContainer;
+                       
+                       EmitContext ec = new EmitContext (owner.ResolveContext, ds, owner.ResolveContext.DeclContainer,
                                Location, null, typeof (Attribute), owner.ResolveContext.DeclContainer.ModFlags, false);
                        ec.IsAnonymousMethodAllowed = false;
 
@@ -381,6 +382,10 @@ namespace Mono.CSharp {
 
                        CustomAttributeBuilder cb;
                        try {
+                               // SRE does not allow private ctor but we want to report all source code errors
+                               if (ctor.IsPrivate)
+                                       return null;
+
                                if (NamedArguments == null) {
                                        cb = new CustomAttributeBuilder (ctor, pos_values);
 
@@ -418,8 +423,8 @@ namespace Mono.CSharp {
                                                return null;
                                }
                        }
-
-                       MethodGroupExpr mg = Expression.MemberLookup (ec.ContainerType,
+                       
+                       MethodGroupExpr mg = MemberLookupFinal (ec, ec.ContainerType,
                                Type, ".ctor", MemberTypes.Constructor,
                                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                Location) as MethodGroupExpr;
@@ -1268,16 +1273,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;
                }
 
@@ -1288,6 +1293,16 @@ namespace Mono.CSharp {
                                return null;
                        return e.TypeArgument;
                }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       throw new NotImplementedException ();
+               }
        }
        
 
@@ -1585,8 +1600,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);
                        }
@@ -1787,7 +1804,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (oa.Message == null) {
+                       if (oa.Message == null || oa.Message.Length == 0) {
                                Report.Warning (612, 1, loc, "`{0}' is obsolete", member);
                                return;
                        }
@@ -1796,11 +1813,6 @@ 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;
-
                        object excluded = analyzed_method_excluded [mb];
                        if (excluded != null)
                                return excluded == TRUE ? true : false;