svn path=/branches/mono-1-1-9/mcs/; revision=51212
[mono.git] / mcs / mcs / modifiers.cs
old mode 100755 (executable)
new mode 100644 (file)
index 4c11403..e5c73c5
@@ -27,8 +27,17 @@ namespace Mono.CSharp {
                public const int UNSAFE    = 0x2000;
                public const int TOP       = 0x2000;
 
+               public const int PROPERTY_CUSTOM = 0x4000; // Custom property modifier
+
+               //
+               // We use this internally to flag that the method contains an iterator
+               //
+               public const int METHOD_YIELDS = 0x8000;
+
                public const int Accessibility =
                        PUBLIC | PROTECTED | INTERNAL | PRIVATE;
+               public const int AllowedExplicitImplFlags =
+                       UNSAFE | EXTERN;
                
                static public string Name (int i)
                {
@@ -61,17 +70,38 @@ namespace Mono.CSharp {
                                s = "extern"; break;
                        case Modifiers.VOLATILE:
                                s = "volatile"; break;
+                       case Modifiers.UNSAFE:
+                               s = "unsafe"; break;
                        }
 
                        return s;
                }
 
-               public static TypeAttributes TypeAttr (int mod_flags, TypeContainer caller)
+               public static string GetDescription (MethodAttributes ma)
+               {
+                       if ((ma & MethodAttributes.Assembly) != 0)
+                               return "internal";
+
+                       if ((ma & MethodAttributes.Family) != 0)
+                               return "protected";
+
+                       if ((ma & MethodAttributes.Public) != 0)
+                               return "public";
+
+                       if ((ma & MethodAttributes.FamANDAssem) != 0)
+                               return "protected internal";
+
+                       if ((ma & MethodAttributes.Private) != 0)
+                               return "private";
+
+                       throw new NotImplementedException (ma.ToString ());
+               }
+
+               public static TypeAttributes TypeAttr (int mod_flags, bool is_toplevel)
                {
                        TypeAttributes t = 0;
-                       bool top_level = caller.IsTopLevel;
 
-                       if (top_level){
+                       if (is_toplevel){
                                if ((mod_flags & PUBLIC) != 0)
                                        t |= TypeAttributes.Public;
                                if ((mod_flags & PRIVATE) != 0)
@@ -94,9 +124,17 @@ namespace Mono.CSharp {
                        if ((mod_flags & ABSTRACT) != 0)
                                t |= TypeAttributes.Abstract;
 
+                       return t;
+               }
+               
+               public static TypeAttributes TypeAttr (int mod_flags, TypeContainer caller)
+               {
+                       TypeAttributes t = TypeAttr (mod_flags, caller.IsTopLevel);
+
                        // If we do not have static constructors, static methods
                        // can be invoked without initializing the type.
-                       if (!caller.HaveStaticConstructor)
+                       if (!caller.UserDefinedStaticConstructor &&
+                           (caller.Kind != Kind.Interface))
                                t |= TypeAttributes.BeforeFieldInit;
                                
                        return t;
@@ -130,7 +168,7 @@ namespace Mono.CSharp {
 
                public static MethodAttributes MethodAttr (int mod_flags)
                {
-                       MethodAttributes ma = 0;
+                       MethodAttributes ma = MethodAttributes.HideBySig;
 
                        if ((mod_flags & PUBLIC) != 0)
                                ma |= MethodAttributes.Public;
@@ -149,8 +187,7 @@ namespace Mono.CSharp {
                        if ((mod_flags & STATIC) != 0)
                                ma |= MethodAttributes.Static;
                        if ((mod_flags & ABSTRACT) != 0){
-                               ma |= MethodAttributes.Abstract | MethodAttributes.Virtual |
-                                       MethodAttributes.HideBySig;
+                               ma |= MethodAttributes.Abstract | MethodAttributes.Virtual;
                        }
                        if ((mod_flags & SEALED) != 0)
                                ma |= MethodAttributes.Final;
@@ -159,15 +196,12 @@ namespace Mono.CSharp {
                                ma |= MethodAttributes.Virtual;
 
                        if ((mod_flags & OVERRIDE) != 0)
-                               ma |= MethodAttributes.Virtual | MethodAttributes.HideBySig;
+                               ma |= MethodAttributes.Virtual;
                        else {
                                if ((ma & MethodAttributes.Virtual) != 0)
                                        ma |= MethodAttributes.NewSlot;
                        }
                        
-                       if ((mod_flags & NEW) != 0)
-                               ma |= MethodAttributes.HideBySig;
-                       
                        return ma;
                }
 
@@ -185,11 +219,7 @@ namespace Mono.CSharp {
                                int a = mod;
 
                                if ((mod & Modifiers.UNSAFE) != 0){
-                                       if (!RootContext.Unsafe){
-                                               Report.Error (227, l,
-                                                             "Unsafe code requires the --unsafe command " +
-                                                             "line option to be specified");
-                                       }
+                                       RootContext.CheckUnsafeOption (l);
                                }
                                
                                //
@@ -217,15 +247,19 @@ namespace Mono.CSharp {
                                return mod;
                        }
                        
-                       for (i = 1; i < TOP; i <<= 1){
+                       for (i = 1; i <= TOP; i <<= 1){
                                if ((i & invalid_flags) == 0)
                                        continue;
 
-                               Report.Error (106, l, "the modifier `" + Name (i) +
-                                             "' is not valid for this item");
+                               Error_InvalidModifier (l, Name (i));
                        }
 
                        return allowed & mod;
                }
+
+               public static void Error_InvalidModifier (Location l, string name)
+               {
+                       Report.Error (106, l, "The modifier `" + name + "' is not valid for this item");
+               }
        }
 }