2005-01-26 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / mbas / const.cs
index 44bce7bac54aa2aa43bd5ed229eed73570aeaed9..09282a89d9dc61b2bae309b39a44477773a03145 100644 (file)
@@ -28,7 +28,6 @@ namespace Mono.MonoBASIC {
        public class Const : MemberCore {
                public Expression ConstantType;
                public Expression Expr;
-               public Attributes  OptAttributes;
                public FieldBuilder FieldBuilder;
 
                object ConstantValue = null;
@@ -45,13 +44,18 @@ namespace Mono.MonoBASIC {
 
                public Const (Expression constant_type, string name, Expression expr, int mod_flags,
                              Attributes attrs, Location loc)
-                       : base (name, loc)
+                       : base (name, attrs, loc)
                {
                        ConstantType = constant_type;
                        Name = name;
                        Expr = expr;
                        ModFlags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PRIVATE, loc);
-                       OptAttributes = attrs;
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Field;
+                       }
                }
 
                public FieldAttributes FieldAttr {
@@ -132,18 +136,30 @@ namespace Mono.MonoBASIC {
                                
                                if ((list.Count > 0) && ((ModFlags & Modifiers.SHADOWS) == 0))
                                        Report.Warning (
-                                                       40004, 2, Location, 
-                                                       "Const '" + Name + "' should be declared " +
-                            "Shadows since the base type '" + ptype.Name /*parent.MakeName (Name)*/ + 
-                                                       "' has a Const with same name");
-
-                               /*if (list.Count == 0)
-                                       if ((ModFlags & Modifiers.NEW) != 0)
+                                               40004, 2, Location, 
+                                               "Const '" + Name + "' should be declared " +
+                                               "Shadows since the base type '" + ptype.Name + 
+                                               "' has a Const with same name");
+                               if (list.Count == 0) {
+                                       // if a member of module is not inherited from Object class
+                                       // can not be declared protected
+                                       if ((parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                                               Report.Error (30593, Location,
+                                                       "'Const' inside a 'Module' can not be " +
+                                                       "declared as 'Protected'");
+
+                                       /*if ((ModFlags & Modifiers.NEW) != 0)
                                                WarningNotHiding (parent);*/
-
-                       } /*else if ((ModFlags & Modifiers.NEW) != 0)
+                               }
+                       } 
+                       /*else if ((ModFlags & Modifiers.NEW) != 0)
                                WarningNotHiding (parent);*/
 
+                       if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (30435, Location,
+                                       "'Const' inside a 'Structure' can not be " +
+                                       "declared as 'Protected'");
+
                        FieldBuilder = parent.TypeBuilder.DefineField (Name, type, FieldAttr);
 
                        TypeManager.RegisterConstant (FieldBuilder, this);
@@ -188,7 +204,7 @@ namespace Mono.MonoBASIC {
                                        Expr = un_expr.Expr;
                                else if ((ch_expr != null) && (ch_expr.Expr is Constant))
                                        Expr = ch_expr.Expr;
-                               else \r
+                               else 
                                {
                                        Report.Error (30059, Location, "A constant value is expected");
                                        return null;
@@ -267,5 +283,11 @@ namespace Mono.MonoBASIC {
                        
                        return;
                }
+               
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       FieldBuilder.SetCustomAttribute (cb);
+               }
+               
        }
 }